My experience #7

This is my ADV STAT module #7 assignment where used different datasets to practice creating regression models, finding coefficients, and using the models to make predictions

1.1 Define the relationship model between the predictor (x) and the response (Y) variable.

R Code:

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

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

model <- lm(y ~ x)

model

R Output:

Call:

lm(formula = y ~ x)

Coefficients:

(Intercept)            x

   19.2056       3.2691

Answer:

Y = 19.2056 + 3.2691X

The positive coefficient means that as x increases, y also tends to increase.

1.2 Calculate the coefficients.

R Code:

coefficients(model)

R Output:

(Intercept)           x

 19.20560       3.26911

Answer:

The intercept is 19.20560 and the coefficient for x is 3.26911. This means that for every one-unit increase in x, y is expected to increase by about 3.27.

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

R Code:

data(“faithful”)

eruptionLM <- lm(eruptions ~ waiting, data = faithful)

eruptionLM

R Output:

Call:

lm(formula = eruptions ~ waiting, data = faithful)

Coefficients:

(Intercept)      waiting

   -1.87402      0.07563

Answer:

Y = -1.8740 + 0.0756X

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

R Code:

coefficients(eruptionLM)

R Output:

(Intercept)     waiting

 -1.874016     0.075628

Answer:

The intercept is -1.874016 and the coefficient for waiting is 0.075628.

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

R Code:

coefficients(eruptionLM)[1] + coefficients(eruptionLM)[2] * 80

R Output:

4.17622

Answer:

When the waiting time is 80 minutes, the predicted eruption duration is approximately 4.18 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?

R Code:

input <- mtcars[,c(“mpg”,”disp”,”hp”,”wt”)]

lm(formula = mpg ~ disp + hp + wt, data = input)

R Output:

Call:

lm(formula = mpg ~ disp + hp + wt, data = input)

Coefficients:

(Intercept)         disp           hp           wt

 37.105505    -0.000937    -0.031157    -3.800891

Answer:

The multiple regression equation is:

mpg = 37.1055 – 0.000937(disp) – 0.031157(hp) – 3.800891(wt)

The model uses displacement, horsepower, and weight to predict mpg. All three coefficients are negative, which means that as these variables increase, mpg tends to go down. Weight has the largest coefficient, so it seems to have the biggest effect on mpg compared to the other variables.

4. From our textbook pp. 124, 6.5-Exercises # 6.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?

R Code:

library(ISwR)

plot(metabolic.rate~body.weight,data=rmr)

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

metabolic.lm

R Output

Call:

lm(formula = metabolic.rate ~ body.weight, data = rmr)

Coefficients:

(Intercept)  body.weight

  811.2267       7.0595

Answer:

metabolic.rate = 811.227 + 7.060(body.weight)

predict(metabolic.lm, newdata = data.frame(body.weight = 70))

R Output:

       1

1305.394

The predicted metabolic rate for a body weight of 70 kg is approximately 1305.394 kcal/24hr. The results show a positive relationship between body weight and metabolic rate, meaning that as body weight increases, metabolic rate also tends to increase.

Leave a comment