In: Statistics and Probability
I have coded in R for the first part. The code is as
follows:
> library(swgee)
> attach(framingham)
The following objects are masked from
framingham (pos = 3):
age, bmi, BPVar, cigpday, cursmoke,
female, glucose, heartrte,
outcome, time_outcome, totchol
The following objects are masked from framingham (pos = 4):
age, bmi, BPVar, cigpday, cursmoke,
female, glucose, heartrte,
outcome, time_outcome, totchol
The following objects are masked from framingham (pos = 5):
age, bmi, BPVar, cigpday, cursmoke,
female, glucose, heartrte,
outcome, time_outcome, totchol
The following objects are masked from framingham (pos = 6):
age, bmi, BPVar, cigpday, cursmoke,
female, glucose, heartrte,
outcome, time_outcome, totchol
The following objects are masked from framingham (pos = 7):
age, bmi, BPVar, cigpday, cursmoke,
female, glucose, heartrte,
outcome, time_outcome, totchol
The following objects are masked from framingham (pos = 8):
age, bmi, BPVar, cigpday, cursmoke,
female, glucose, heartrte,
outcome, time_outcome, totchol
The following objects are masked from framingham (pos = 9):
age, bmi, BPVar, cigpday, cursmoke,
female, glucose, heartrte,
outcome, time_outcome, totchol
The following objects are masked from framingham (pos = 10):
age, bmi, BPVar, cigpday, cursmoke,
female, glucose, heartrte,
outcome, time_outcome, totchol
> data=framingham
> LinMod=lm(totchol~bmi+age+female+cursmoke,data)
> summary(LinMod)
Call:
lm(formula = totchol ~ bmi + age + female + cursmoke, data =
data)
Residuals:
Min 1Q Median 3Q Max
-112.139 -27.323 -3.522 24.073 244.440
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 116.6729 8.4932 13.737 < 2e-16 ***
bmi 1.4556 0.2544 5.721 1.2e-08 ***
age 1.5196 0.1048 14.502 < 2e-16 ***
female 5.7306 1.7463 3.281 0.00105 **
cursmoke 4.3192 1.7528 2.464 0.01381 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’
1
Residual standard error: 40.04 on
2311 degrees of freedom
Multiple R-squared: 0.09854, Adjusted R-squared: 0.09698
F-statistic: 63.15 on 4 and 2311 DF, p-value: <
2.2e-16
> LinMod
Call:
lm(formula = totchol ~ bmi + age + female + cursmoke, data =
data)
Coefficients:
(Intercept) bmi age female cursmoke
116.673 1.456 1.520 5.731 4.319
Thus, the linear model is:
totchol = 116.673
+1.456*bmi+1.520*age+5.731*female+4.319*cursmoke
Now, the given values are:
bmi | age | female | cursmoke | |
sample1 | 25 | 50 | 1 | 0 |
sample2 | 32 | 25 | 1 | 1 |
Thus, the first prediction is:
totchol = 116.673
+1.456*25+1.520*50+5.731*1+4.319*0
= 234.804
The second prediction is:
totchol = 116.673
+1.456*32+1.520*25+5.731*1+4.319*1
= 211.315
PS. If you do find the dataset under swgee, it
will be under LocalControl
I hope this clarifies your doubt. If you're satisfied with the
solution, hit the Like button. For further
clarification, comment below. Thank You. :)