Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For the prostate data set, from the faraway package in R., fit a model with lpsa

ID: 3208028 • Letter: F

Question

For the prostate data set, from the faraway package in R., fit a model with lpsa as the response, and the other variables as
predictors.

Install faraway data package in R., or download data at: https://cran.r-project.org/web/packages/faraway/index.html


(a) Suppose a new patient with the following values arrives:
lcavol = 1.45000, lweight = 3.59801, age = 63.00000, lbph = 0.30010,
svi = 0.00000, lcp = -0.79851, gleason = 7.00000, pgg45 = 15.00000.


Predict the lpsa for this patient along with an appropriate 95% prediction interval.


(b) Repeat the questions in (a) for a patient with the same values except that he is age
20. Explain why the prediction interval is wider.


(c) For the model of the previous question, remove all the predictors that are not
significant at the 5% level. Using the reduced model recompute the predictions for the
x values given in the previous questions (a) and (b). Are the new prediction intervals
wider or narrower than in parts (a) and (b)? Which predictions would you prefer?
Explain.

Explanation / Answer

The R-code :

"

library(faraway)
prostate
names(prostate)
lpsa=prostate$lpsa
lcavol=prostate$lcavol
lweight=prostate$lweight
age=prostate$age
lbph=prostate$lbph
svi=prostate$svi
lcp=prostate$lcp
gleason=prostate$gleason
pgg45=prostate$pgg45
lm=lm(lpsa~lcavol+lweight+age+lbph+svi+lcp+gleason+pgg45)
lm
summary(lm)
#a)
0.669337+0.587022*1.45000+ 0.454467 *3.59801-0.019637*63.00000+0.107054*
0.30010+0.766157*0.00000+0.105474*0.79851+0.045142*7.00000+ 0.004525*15.00000
#=2.418783##redicted lpsa)
#b)
0.669337+0.587022*1.45000+ 0.454467 *3.59801-0.019637*20.00000+0.107054*
0.30010+0.766157*0.00000+0.105474*0.79851+0.045142*7.00000+ 0.004525*15.00000

#=3.263174 ##predicted lpsa

#c)
new_lm=lm(lpsa~lcavol+lweight+svi+lcp+gleason+pgg45)
##since age and lbph are significant
new_lm"


output

> library(faraway)
> prostate
lcavol lweight age lbph svi lcp gleason pgg45 lpsa
1 -0.5798185 2.7695 50 -1.386294 0 -1.38629 6 0 -0.43078
2 -0.9942523 3.3196 58 -1.386294 0 -1.38629 6 0 -0.16252
3 -0.5108256 2.6912 74 -1.386294 0 -1.38629 7 20 -0.16252
4 -1.2039728 3.2828 58 -1.386294 0 -1.38629 6 0 -0.16252
5 0.7514161 3.4324 62 -1.386294 0 -1.38629 6 0 0.37156
6 -1.0498221 3.2288 50 -1.386294 0 -1.38629 6 0 0.76547
7 0.7371641 3.4735 64 0.615186 0 -1.38629 6 0 0.76547
8 0.6931472 3.5395 58 1.536867 0 -1.38629 6 0 0.85442
9 -0.7765288 3.5395 47 -1.386294 0 -1.38629 6 0 1.04732
10 0.2231436 3.2445 63 -1.386294 0 -1.38629 6 0 1.04732
11 0.2546422 3.6041 65 -1.386294 0 -1.38629 6 0 1.26695
12 -1.3470736 3.5987 63 1.266948 0 -1.38629 6 0 1.26695
13 1.6134299 3.0229 63 -1.386294 0 -0.59784 7 30 1.26695
14 1.4770487 2.9982 67 -1.386294 0 -1.38629 7 5 1.34807
15 1.2059708 3.4420 57 -1.386294 0 -0.43078 7 5 1.39872
16 1.5411591 3.0611 66 -1.386294 0 -1.38629 6 0 1.44692
17 -0.4155154 3.5160 70 1.244155 0 -0.59784 7 30 1.47018
18 2.2884862 3.6494 66 -1.386294 0 0.37156 6 0 1.49290
19 -0.5621189 3.2677 41 -1.386294 0 -1.38629 6 0 1.55814
20 0.1823216 3.8254 70 1.658228 0 -1.38629 6 0 1.59939
21 1.1474025 3.4194 59 -1.386294 0 -1.38629 6 0 1.63900
22 2.0592388 3.5010 60 1.474763 0 1.34807 7 20 1.65823
23 -0.5447272 3.3759 59 -0.798508 0 -1.38629 6 0 1.69562
24 1.7817091 3.4516 63 0.438255 0 1.17865 7 60 1.71380
25 0.3852624 3.6674 69 1.599388 0 -1.38629 6 0 1.73166
26 1.4469190 3.1246 68 0.300105 0 -1.38629 6 0 1.76644
27 0.5128236 3.7197 65 -1.386294 0 -0.79851 7 70 1.80006
28 -0.4004776 3.8660 67 1.816452 0 -1.38629 7 20 1.81645
29 1.0402767 3.1290 67 0.223144 0 0.04879 7 80 1.84845
30 2.4096442 3.3759 65 -1.386294 0 1.61939 6 0 1.89462
31 0.2851789 4.0902 65 1.962908 0 -0.79851 6 0 1.92425
32 0.1823216 6.1076 65 1.704748 0 -1.38629 6 0 2.00821
33 1.2753628 3.0374 71 1.266948 0 -1.38629 6 0 2.00821
34 0.0099503 3.2677 54 -1.386294 0 -1.38629 6 0 2.02155
35 -0.0100503 3.2169 63 -1.386294 0 -0.79851 6 0 2.04769
36 1.3083328 4.1198 64 2.171337 0 -1.38629 7 5 2.08567
37 1.4231083 3.6571 73 -0.579818 0 1.65823 8 15 2.15756
38 0.4574248 2.3749 64 -1.386294 0 -1.38629 7 15 2.19165
39 2.6609586 4.0851 68 1.373716 1 1.83258 7 35 2.21375
40 0.7975072 3.0131 56 0.936093 0 -0.16252 7 5 2.27727
41 0.6205765 3.1420 60 -1.386294 0 -1.38629 9 80 2.29757
42 1.4422020 3.6826 68 -1.386294 0 -1.38629 7 10 2.30757
43 0.5822156 3.8660 62 1.713798 0 -0.43078 6 0 2.32728
44 1.7715568 3.8969 61 -1.386294 0 0.81093 7 6 2.37491
45 1.4861397 3.4095 66 1.749200 0 -0.43078 7 20 2.52172
46 1.6639261 3.3928 61 0.615186 0 -1.38629 7 15 2.55334
47 2.7278528 3.9954 79 1.879465 1 2.65676 9 100 2.56879
48 1.1631508 4.0351 68 1.713798 0 -0.43078 7 40 2.56879
49 1.7457155 3.4980 43 -1.386294 0 -1.38629 6 0 2.59152
50 1.2208299 3.5681 70 1.373716 0 -0.79851 6 0 2.59152
51 1.0919233 3.9936 68 -1.386294 0 -1.38629 7 50 2.65676
52 1.6601310 4.2348 64 2.073172 0 -1.38629 6 0 2.67759
53 0.5128236 3.6336 64 1.492904 0 0.04879 7 70 2.68444
54 2.1270405 4.1215 68 1.766442 0 1.44692 7 40 2.69124
55 3.1535904 3.5160 59 -1.386294 0 -1.38629 7 5 2.70471
56 1.2669476 4.2801 66 2.122262 0 -1.38629 7 15 2.71800
57 0.9745596 2.8651 47 -1.386294 0 0.50078 7 4 2.78809
58 0.4637340 3.7647 49 1.423108 0 -1.38629 6 0 2.79423
59 0.5423243 4.1782 70 0.438255 0 -1.38629 7 20 2.80639
60 1.0612565 3.8512 61 1.294727 0 -1.38629 7 40 2.81241
61 0.4574248 4.5245 73 2.326302 0 -1.38629 6 0 2.84200
62 1.9974177 3.7197 63 1.619388 1 1.90954 7 40 2.85359
63 2.7757088 3.5249 72 -1.386294 0 1.55814 9 95 2.85359
64 2.0347056 3.9170 66 2.008214 1 2.11021 7 60 2.88200
65 2.0731719 3.6230 64 -1.386294 0 -1.38629 6 0 2.88200
66 1.4586150 3.8362 61 1.321756 0 -0.43078 7 20 2.88759
67 2.0228712 3.8785 68 1.783391 0 1.32176 7 70 2.92047
68 2.1983351 4.0509 72 2.307573 0 -0.43078 7 10 2.96269
69 -0.4462871 4.4085 69 -1.386294 0 -1.38629 6 0 2.96269
70 1.1939225 4.7804 72 2.326302 0 -0.79851 7 5 2.97298
71 1.8640801 3.5932 60 -1.386294 1 1.32176 7 60 3.01308
72 1.1600209 3.3411 77 1.749200 0 -1.38629 7 25 3.03735
73 1.2149127 3.8254 69 -1.386294 1 0.22314 7 20 3.05636
74 1.8389611 3.2367 60 0.438255 1 1.17865 9 90 3.07501
75 2.9992262 3.8491 69 -1.386294 1 1.90954 7 20 3.27526
76 3.1411305 3.2638 68 -0.051293 1 2.42037 7 50 3.33755
77 2.0108950 4.4338 72 2.122262 0 0.50078 7 60 3.39283
78 2.5376572 4.3548 78 2.326302 0 -1.38629 7 10 3.43560
79 2.6483002 3.5821 69 -1.386294 1 2.58400 7 70 3.45789
80 2.7794402 3.8232 63 -1.386294 0 0.37156 7 50 3.51304
81 1.4678743 3.0704 66 0.559616 0 0.22314 7 40 3.51601
82 2.5136561 3.4735 57 0.438255 0 2.32728 7 60 3.53076
83 2.6130067 3.8888 77 -0.527633 1 0.55962 7 30 3.56530
84 2.6775910 3.8384 65 1.115142 0 1.74920 9 70 3.57094
85 1.5623463 3.7099 60 1.695616 0 0.81093 7 30 3.58768
86 3.3028493 3.5190 64 -1.386294 1 2.32728 7 60 3.63099
87 2.0241931 3.7317 58 1.638997 0 -1.38629 6 0 3.68009
88 1.7316555 3.3690 62 -1.386294 1 0.30010 7 30 3.71235
89 2.8075938 4.7181 65 -1.386294 1 2.46385 7 60 3.98434
90 1.5623463 3.6951 76 0.936093 1 0.81093 7 75 3.99360
91 3.2464910 4.1018 68 -1.386294 0 -1.38629 6 0 4.02981
92 2.5329028 3.6776 61 1.348073 1 -1.38629 7 15 4.12955
93 2.8302678 3.8764 68 -1.386294 1 1.32176 7 60 4.38515
94 3.8210036 3.8969 44 -1.386294 1 2.16905 7 40 4.68444
95 2.9074474 3.3962 52 -1.386294 1 2.46385 7 10 5.14312
96 2.8825636 3.7739 68 1.558145 1 1.55814 7 80 5.47751
97 3.4719665 3.9750 68 0.438255 1 2.90417 7 20 5.58293
> names(prostate)
[1] "lcavol" "lweight" "age" "lbph" "svi" "lcp" "gleason"
[8] "pgg45" "lpsa"   
> lpsa=prostate$lpsa
> lcavol=prostate$lcavol
> lweight=prostate$lweight
> age=prostate$age
> lbph=prostate$lbph
> svi=prostate$svi
> lcp=prostate$lcp
> gleason=prostate$gleason
> pgg45=prostate$pgg45
> lm=lm(lpsa~lcavol+lweight+age+lbph+svi+lcp+gleason+pgg45)
> lm

Call:
lm(formula = lpsa ~ lcavol + lweight + age + lbph + svi + lcp +
gleason + pgg45)

Coefficients:
(Intercept) lcavol lweight age lbph svi
0.669337 0.587022 0.454467 -0.019637 0.107054 0.766157
lcp gleason pgg45
-0.105474 0.045142 0.004525

> summary(lm)

Call:
lm(formula = lpsa ~ lcavol + lweight + age + lbph + svi + lcp +
gleason + pgg45)

Residuals:
Min 1Q Median 3Q Max
-1.7331 -0.3713 -0.0170 0.4141 1.6381

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.669337 1.296387 0.516 0.60693
lcavol 0.587022 0.087920 6.677 2.11e-09 ***
lweight 0.454467 0.170012 2.673 0.00896 **
age -0.019637 0.011173 -1.758 0.08229 .
lbph 0.107054 0.058449 1.832 0.07040 .
svi 0.766157 0.244309 3.136 0.00233 **
lcp -0.105474 0.091013 -1.159 0.24964
gleason 0.045142 0.157465 0.287 0.77503
pgg45 0.004525 0.004421 1.024 0.30886
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.7084 on 88 degrees of freedom
Multiple R-squared: 0.6548, Adjusted R-squared: 0.6234
F-statistic: 20.86 on 8 and 88 DF, p-value: < 2.2e-16

> help("predict")
starting httpd help server ... done
> new <- data.frame(x = seq(-3, 3, 0.5))
> new
x
1 -3.0
2 -2.5
3 -2.0
4 -1.5
5 -1.0
6 -0.5
7 0.0
8 0.5
9 1.0
10 1.5
11 2.0
12 2.5
13 3.0
> 0.669337+0.587022*1.45000+ 0.454467 *3.59801-0.019637*63.00000+0.107054*
+ 0.30010+0.766157*0.00000+0.105474*0.79851+0.045142*7.00000+ 0.004525*15.00000
[1] 2.418783
>
> 0.669337+0.587022*1.45000+ 0.454467 *3.59801-0.019637*20.00000+0.107054*
+ 0.30010+0.766157*0.00000+0.105474*0.79851+0.045142*7.00000+ 0.004525*15.00000
[1] 3.263174
> #c)
> new_lm=lm(lpsa~lcavol+lweight+svi+lcp+gleason+pgg45)
> ##since age and lbph are significant
> new_lm

Call:
lm(formula = lpsa ~ lcavol + lweight + svi + lcp + gleason +
pgg45)

Coefficients:
(Intercept) lcavol lweight svi lcp gleason
-0.639390 0.562525 0.512902 0.696992 -0.082867 0.033161
pgg45
0.003905

>