For the dataset Fat in R package Faraway. a smaller model using only age, weight
ID: 3172269 • Letter: F
Question
For the dataset Fat in R package Faraway. a smaller model using only age, weight, height, andabdom was proposed on the grounds that these predictors are either known by the individual or easily measured.
• Compute a 95% condence interval for median predictor values (age, weight, height, andobdom) and compare to the results to the interval for the full model which contains all the predictor variables.
• Compute a 90% prediction interval for median predictor values. Is the interval wider or narrower comparing to the condence interval on mean response at the same condence level?
To start the problem: Open the R software, and install the package faraway if it has not been installed previously.
library(faraway)
data(fat)
Explanation / Answer
It is not given which variable is the dependent variable , so we shall consider brozek as the dependent variable . The complete R snippet is as follows
library(faraway)
data(fat)
data.df<- data.frame(fat)
formula <- age+weight+height+abdom
fit<- lm(brozek ~ age+weight+height+abdom, data = data.df)
summary(fit)
confint(fit, 'age', level=0.95)
confint(fit, 'weight', level=0.95)
confint(fit, 'height', level=0.95)
confint(fit, 'abdom', level=0.95)
####################
# fit the whole model
fit1<- lm(brozek ~., data = data.df)
summary(fit1)
confint(fit1, 'age', level=0.95)
confint(fit1, 'weight', level=0.95)
confint(fit1, 'height', level=0.95)
confint(fit1, 'abdom', level=0.95)
#################
# 90% confidence interval
formula <- age+weight+height+abdom
fit<- lm(brozek ~ age+weight+height+abdom, data = data.df)
summary(fit)
confint(fit, 'age', level=0.90)
confint(fit, 'weight', level=0.90)
confint(fit, 'height', level=0.90)
confint(fit, 'abdom', level=0.90)
####################
# fit the whole model
fit1<- lm(brozek ~., data = data.df)
summary(fit1)
confint(fit1, 'age', level=0.90)
confint(fit1, 'weight', level=0.90)
confint(fit1, 'height', level=0.90)
confint(fit1, 'abdom', level=0.90)
#### The results are
> library(faraway)
> data(fat)
> data.df<- data.frame(fat)
>
>
> formula <- age+weight+height+abdom
Error: object 'age' not found
>
> fit<- lm(brozek ~ age+weight+height+abdom, data = data.df)
> summary(fit)
Call:
lm(formula = brozek ~ age + weight + height + abdom, data = data.df)
Residuals:
Min 1Q Median 3Q Max
-11.5105 -2.9346 0.0087 2.8942 9.4179
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -32.769636 6.541902 -5.009 1.04e-06 ***
age -0.007051 0.024342 -0.290 0.772
weight -0.123722 0.025046 -4.940 1.44e-06 ***
height -0.116694 0.082727 -1.411 0.160
abdom 0.889704 0.067267 13.226 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 4.126 on 247 degrees of freedom
Multiple R-squared: 0.7211, Adjusted R-squared: 0.7166
F-statistic: 159.7 on 4 and 247 DF, p-value: < 2.2e-16
>
>
> confint(fit, 'age', level=0.95)
2.5 % 97.5 %
age -0.05499491 0.04089239
> confint(fit, 'weight', level=0.95)
2.5 % 97.5 %
weight -0.1730518 -0.07439172
> confint(fit, 'height', level=0.95)
2.5 % 97.5 %
height -0.2796341 0.04624622
> confint(fit, 'abdom', level=0.95)
2.5 % 97.5 %
abdom 0.7572136 1.022195
>
>
> ####################
> # fit the whole model
>
>
> fit1<- lm(brozek ~., data = data.df)
> summary(fit1)
Call:
lm(formula = brozek ~ ., data = data.df)
Residuals:
Min 1Q Median 3Q Max
-1.11191 -0.04847 0.00277 0.04625 1.47542
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 12.1524013 4.1718589 2.913 0.00393 **
siri 0.8884085 0.0111341 79.792 < 2e-16 ***
density -9.8456305 3.7471770 -2.627 0.00917 **
age -0.0005268 0.0012935 -0.407 0.68421
weight 0.0084855 0.0036200 2.344 0.01991 *
height -0.0005459 0.0044439 -0.123 0.90234
adipos -0.0153248 0.0124778 -1.228 0.22062
free -0.0097388 0.0044270 -2.200 0.02880 *
neck 0.0005002 0.0094279 0.053 0.95773
chest 0.0021454 0.0043013 0.499 0.61840
abdom 0.0014464 0.0044217 0.327 0.74388
hip -0.0044514 0.0058941 -0.755 0.45087
thigh 0.0156926 0.0059507 2.637 0.00892 **
knee -0.0252126 0.0098531 -2.559 0.01113 *
ankle 0.0027790 0.0089580 0.310 0.75667
biceps -0.0147134 0.0069201 -2.126 0.03454 *
forearm 0.0149983 0.0080832 1.855 0.06478 .
wrist 0.0326518 0.0218000 1.498 0.13554
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.1706 on 234 degrees of freedom
Multiple R-squared: 0.9995, Adjusted R-squared: 0.9995
F-statistic: 3.046e+04 on 17 and 234 DF, p-value: < 2.2e-16
>
> confint(fit1, 'age', level=0.95)
2.5 % 97.5 %
age -0.003075257 0.002021709
> confint(fit1, 'weight', level=0.95)
2.5 % 97.5 %
weight 0.001353604 0.01561745
> confint(fit1, 'height', level=0.95)
2.5 % 97.5 %
height -0.009301052 0.008209322
> confint(fit1, 'abdom', level=0.95)
2.5 % 97.5 %
abdom -0.007265078 0.01015786
>
>
> #################
> # 90% confidence interval
>
>
>
> formula <- age+weight+height+abdom
Error: object 'age' not found
>
> fit<- lm(brozek ~ age+weight+height+abdom, data = data.df)
> summary(fit)
Call:
lm(formula = brozek ~ age + weight + height + abdom, data = data.df)
Residuals:
Min 1Q Median 3Q Max
-11.5105 -2.9346 0.0087 2.8942 9.4179
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -32.769636 6.541902 -5.009 1.04e-06 ***
age -0.007051 0.024342 -0.290 0.772
weight -0.123722 0.025046 -4.940 1.44e-06 ***
height -0.116694 0.082727 -1.411 0.160
abdom 0.889704 0.067267 13.226 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 4.126 on 247 degrees of freedom
Multiple R-squared: 0.7211, Adjusted R-squared: 0.7166
F-statistic: 159.7 on 4 and 247 DF, p-value: < 2.2e-16
>
>
> confint(fit, 'age', level=0.90)
5 % 95 %
age -0.04724042 0.03313791
> confint(fit, 'weight', level=0.90)
5 % 95 %
weight -0.1650731 -0.08237044
> confint(fit, 'height', level=0.90)
5 % 95 %
height -0.2532799 0.01989202
> confint(fit, 'abdom', level=0.90)
5 % 95 %
abdom 0.7786428 1.000765
>
>
> ####################
> # fit the whole model
>
>
> fit1<- lm(brozek ~., data = data.df)
> summary(fit1)
Call:
lm(formula = brozek ~ ., data = data.df)
Residuals:
Min 1Q Median 3Q Max
-1.11191 -0.04847 0.00277 0.04625 1.47542
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 12.1524013 4.1718589 2.913 0.00393 **
siri 0.8884085 0.0111341 79.792 < 2e-16 ***
density -9.8456305 3.7471770 -2.627 0.00917 **
age -0.0005268 0.0012935 -0.407 0.68421
weight 0.0084855 0.0036200 2.344 0.01991 *
height -0.0005459 0.0044439 -0.123 0.90234
adipos -0.0153248 0.0124778 -1.228 0.22062
free -0.0097388 0.0044270 -2.200 0.02880 *
neck 0.0005002 0.0094279 0.053 0.95773
chest 0.0021454 0.0043013 0.499 0.61840
abdom 0.0014464 0.0044217 0.327 0.74388
hip -0.0044514 0.0058941 -0.755 0.45087
thigh 0.0156926 0.0059507 2.637 0.00892 **
knee -0.0252126 0.0098531 -2.559 0.01113 *
ankle 0.0027790 0.0089580 0.310 0.75667
biceps -0.0147134 0.0069201 -2.126 0.03454 *
forearm 0.0149983 0.0080832 1.855 0.06478 .
wrist 0.0326518 0.0218000 1.498 0.13554
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.1706 on 234 degrees of freedom
Multiple R-squared: 0.9995, Adjusted R-squared: 0.9995
F-statistic: 3.046e+04 on 17 and 234 DF, p-value: < 2.2e-16
>
> confint(fit1, 'age', level=0.90)
5 % 95 %
age -0.002662924 0.001609376
> confint(fit1, 'weight', level=0.90)
5 % 95 %
weight 0.002507517 0.01446354
> confint(fit1, 'height', level=0.90)
5 % 95 %
height -0.007884501 0.006792772
> confint(fit1, 'abdom', level=0.90)
5 % 95 %
abdom -0.0058556 0.008748386
As the confidence interval increases the interval widens and as the confidence interval decreases the width of the interval decreases.