LIS 4273 Module #7 Assignment
#1.1 Define the relationship model between the predictor (x) and the response (Y) variable:
A simple linear regression can model the relationship between the predictor variable x and the response variable y.
#1.2 Calculate the coefficients?
> 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)
> summary(model)
Call:
lm(formula = y ~ x)
Residuals:
Min 1Q Median 3Q Max
-11.435 -7.406 -4.608 6.681 16.834
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 19.206 15.691 1.224 0.2558
x 3.269 1.088 3.006 0.0169 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 10.48 on 8 degrees of freedom
Multiple R-squared: 0.5303, Adjusted R-squared: 0.4716
F-statistic: 9.033 on 1 and 8 DF, p-value: 0.01693
#2.1 Define the relationship model between the predictor (x) and the response variable(y).
> visit <- data.frame(
+ discharge = c(3.600, 1.800, 3.333, 2.283, 4.533, 2.883),
+ waiting = c(79, 54, 74, 62, 85, 55)
+ )
> model_visit <- lm(discharge ~ waiting, data = visit)
> summary(model_visit)
Call:
lm(formula = discharge ~ waiting, data = visit)
Residuals:
1 2 3 4 5 6
-0.2039 -0.3149 -0.1331 -0.3724 0.3238 0.7005
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.53317 1.12328 -1.365 0.2440
waiting 0.06756 0.01623 4.162 0.0141 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.4724 on 4 degrees of freedom
Multiple R-squared: 0.8124, Adjusted R-squared: 0.7655
F-statistic: 17.32 on 1 and 4 DF, p-value: 0.01413
#2.2 Extract the parameters of the estimated regression equation with the coefficients function.
> coefficients(model_visit)
(Intercept) waiting
-1.53317418 0.06755757
#2.3 Determine the fit of the eruption duration using the estimated regression equation.> predict(model_visit, newdata = data.frame(waiting = 80)) 1 3.871431 #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 explain what the multi-regression model and coefficients talk about in the data?
> input <- mtcars[, c("mpg", "disp", "hp", "wt")]
> multi_model <- lm(mpg ~ disp + hp + wt, data = input)
> summary(multi_model)
Call:
lm(formula = mpg ~ disp + hp + wt, data = input)
Residuals:
Min 1Q Median 3Q Max
-3.891 -1.640 -0.172 1.061 5.861
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 37.105505 2.110815 17.579 < 2e-16 ***
disp -0.000937 0.010350 -0.091 0.92851
hp -0.031157 0.011436 -2.724 0.01097 *
wt -3.800891 1.066191 -3.565 0.00133 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 2.639 on 28 degrees of freedom
Multiple R-squared: 0.8268, Adjusted R-squared: 0.8083
F-statistic: 44.57 on 3 and 28 DF, p-value: 8.65e-11
#4 According to the fitted model, what is the predicted metabolic rate for a body weight of 70 kg?
> library(ISwR)
> data(rmr)
> plot(metabolic.rate ~ body.weight, data = rmr)
> rmr_model <- lm(metabolic.rate ~ body.weight, data = rmr)
> summary(rmr_model)
Call:
lm(formula = metabolic.rate ~ body.weight, data = rmr)
Residuals:
Min 1Q Median 3Q Max
-245.74 -113.99 -32.05 104.96 484.81
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 811.2267 76.9755 10.539 2.29e-13 ***
body.weight 7.0595 0.9776 7.221 7.03e-09 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 157.9 on 42 degrees of freedom
Multiple R-squared: 0.5539, Adjusted R-squared: 0.5433
F-statistic: 52.15 on 1 and 42 DF, p-value: 7.025e-09
> predict(rmr_model, newdata = data.frame(body.weight = 70))
1
1305.394
Comments
Post a Comment