Assignment #7

1
The data in this assignment:

x <- c(16, 17, 13, 18, 12, 14, 19, 11, 11, 10)

y <- c(63, 81, 56, 91, 47, 57, 76, 72, 62, 48)

1.1 Define the relationship model between the predictor and the response variable:

The predictor variable is the value of x. It usually predicts or describes the value of y. y is the response variable that is predicted by x. It is dependent on x.
1.2 Calculate the coefficients?

> relation <- lm(y~x)

> print(relation)

Call: lm(formula = y ~ x)

Coefficients:

(Intercept) x

19.206 3.269

2. The following question is posted by Chi Yau (Links to an external site.) the author of  R Tutorial With Bayesian Statistics Using Stan (Links to an external site.) and his blog posting regarding Regression analysis (Links to an external site.).

Problem –

Apply the simple linear regression model (see the above formula) for the data set called “visit” (see below), and estimate the the discharge duration if the waiting time since the last eruption has been 80 minutes.
> head(visit) 
  discharge  waiting 
1     3.600      79 
2     1.800      54 
3     3.333      74 
4     2.283      62 
5     4.533      85 
6     2.883      55 

Employ the following formula discharge ~ waiting and data=visit)

2.1 Define the relationship model between the predictor and the response variable.

discharge is our response variable dependent on waiting, our x variable. The amount of time between each eruption determines how long each eruption lasts. The longer the wait, the longer the eruption.


2.2 Extract the parameters of the estimated regression equation with the coefficients function.

> discharge <- c(3.600, 1.800, 3.333, 2.283, 4.533, 2.883)

> waiting <- c(79, 54, 74, 62, 85, 55

) > visit.lm <- lm(discharge ~ waiting)

> coeffs = coefficients(visit.lm); coeffs

(Intercept) waiting

-1.53317418 0.06755757


2.3 Determine the fit of the eruption duration using the estimated regression equation.

> waiting = 80

> duration <- coeffs[1] + coeffs[2]*waiting

> duration

(Intercept)

3.871431

If the wait time since the last eruption was 80 minutes, we can predict the next eruption to last 3.87 minutes.

3.1 Examine the relationship Multi Regression Model as stated above and its Coefficients using 4 different variables from mtcars (mpg, disp, hp and wt).
Report on the result and explanation what does the multi regression model and coefficients tells about the data? 

 input <- mtcars[,c(“mpg”,”disp”,”hp”,”wt”)]
lm(formula = mpg ~ disp + hp + wt, data = input)

Coefficients: (Intercept) disp hp wt

37.105505 -0.000937 -0.031157 -3.800891

The coefficients tells us how much the dependent variable changes when one of the independent variables increases by one unit, holding all other variables constant. For example, the coefficient of disp is -0.000937, which means that for every one unit increase in disp, the mpg decreases by 0.000937 units on average, assuming that hp and wt do not change.

4.  From our textbook pp. 110 Exercises # 5.1
With the rmr data set, plot metabolic rate versus body weight. Fit a linear regression to the relation. According to the fitted model, what is the predicted metabolic rate for a body weight of 70 kg? 
The data set rmr is R, make sure to install the book R package: ISwR. After installing the ISwR package, here is a simple illustration to the set of the problem.

library(ISwR)

> rmr.lm <- lm(metabolic.rate~body.weight,data=rmr)

> coeffs <- coefficients(rmr.lm); coeffs

(Intercept) body.weight

811.226674 7.059528

> weight <- 70

> predicted_metabolic_rate<- coeffs[1] + coeffs[2]*weight

> predicted_metabolic_rate

(Intercept)

1305.394

According to fitted model in R, we can predict that at a weight of 70 kg, there will be a metabolic rate of 1305.39.

Leave a comment