Question
First, run the following code in the R Console. The update function takes an existing fitted model and updates it. The notation . ~ .
First, run the following code in the R Console. The update function takes an existing fitted model and
updates it. The notation . ~ . + var means keep the existing response and regressors but add var to the
model.
# fit model with an intercept
lmod1 <- lm(lpsa ~ 1, data = prostate)
summary(lmod1)$r.squared
# fit model with an intercept and lcavol
lmod2 <- update(lmod1, . ~ . + lcavol, data = prostate)
summary(lmod2)$r.squared
# fit model with an intercept, lcavol, and lweight
lmod3 <- update(lmod2, . ~ . + lweight, data = prostate)
summary(lmod3)$r.squared
# fit model with an intercept, lcavol, lweight, and age
lmod4 <- update(lmod3, . ~ . + age, data = prostate)
summary(lmod4)$r.squared
lmod5 <- update(lmod4, . ~ . + lbph, data = prostate)
summary(lmod5)$r.squared
lmod6 <- update(lmod5, . ~ . + svi, data = prostate)
summary(lmod6)$r.squared
lmod7 <- update(lmod6, . ~ . + lcp, data = prostate)
summary(lmod7)$r.squared
lmod8 <- update(lmod7, . ~ . + gleason, data = prostate)
summary(lmod8)$r.squared
lmod9 <- update(lmod7, . ~ . + rnorm(97), data = prostate)
summary(lmod9)$r.squared
(a)
Complete a table with the results from the code above with the following format. Replace x with the R2
value from the fitted model.