This is probably simple, but I just can't see it...

I want to calculate the R^2s for a series of linear models where each term is dropped in turn. I can get the RSS from drop1(), and the r.squared from summary() for a given model, but don't know how to use the
result of drop1() to get the r.squared for each model with one term dropped.

Working example:

library(vcd)         # for Baseball
library(car)         # for vif/recode
data(Baseball)

# sal87 appears as a factor because missing is coded as '.' rather than NA
Baseball$sal87 <- as.numeric(recode(Baseball$sal87, "'.'=NA"))
Baseball$logsal <- log(Baseball$sal87)

base.mod <- lm(logsal ~ years+atbat+hits+homeruns+runs+rbi+walks, data=Baseball)
vif(base.mod)
(drop.mod <- drop1(base.mod))

Single term deletions

Model:
logsal ~ years + atbat + hits + homeruns + runs + rbi + walks
        Df Sum of Sq      RSS      AIC
<none>                 124.612 -180.447
years     1     0.010  124.622 -182.426
atbat     1     0.570  125.182 -181.247
hits      1     0.256  124.869 -181.906
homeruns  1     0.001  124.613 -182.445
runs      1     0.691  125.303 -180.993
rbi       1     0.091  124.704 -182.254
walks     1     0.408  125.020 -181.588


--
Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept.
York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street    http://www.math.yorku.ca/SCS/friendly.html
Toronto, ONT  M3J 1P3 CANADA

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to