|
| 1 | +## ------------------------------------------------------------------------ |
| 2 | +mhours <- read.csv("http://www.personal.psu.edu/~mar36/stat_462/manhours.csv",header=T) |
| 3 | +library(psych) |
| 4 | +pairs.panels(mhours[,-1],ellipses=FALSE,smooth=FALSE,lm=TRUE) |
| 5 | + |
| 6 | +## ----eval=FALSE---------------------------------------------------------- |
| 7 | +summary(lm(hours~ocup,data=mhours)) |
| 8 | +summary(lm(hours~check,data=mhours)) |
| 9 | +summary(lm(hours~service,data=mhours)) |
| 10 | +summary(lm(hours~sqfoot,data=mhours)) |
| 11 | +summary(lm(hours~wings,data=mhours)) |
| 12 | +summary(lm(hours~cap,data=mhours)) |
| 13 | +summary(lm(hours~rooms,data=mhours)) |
| 14 | + |
| 15 | +## ----eval=FALSE---------------------------------------------------------- |
| 16 | +summary(lm(hours~ocup+check+service+sqfoot+wings+cap+rooms,data=mhours)) |
| 17 | +summary(lm(hours~(ocup+check+service+sqfoot+wings+cap+rooms)^2,data=mhours)) |
| 18 | + |
| 19 | +## ----eval=FALSE---------------------------------------------------------- |
| 20 | +# Starring point |
| 21 | +start <- lm(hours~1,data=mhours) |
| 22 | +summary(start) |
| 23 | +# Ending point |
| 24 | +end <- lm(hours~ocup+check+service+sqfoot+wings+cap+rooms,data=mhours) |
| 25 | +summary(end) |
| 26 | +# Use the "step" function |
| 27 | +step(start,scope=list(upper=end),direction="forward",test="F") |
| 28 | +res.f <- step(start,scope=list(upper=end),direction="forward",test="F") |
| 29 | +summary(res.f) |
| 30 | + |
| 31 | +## ----eval=FALSE---------------------------------------------------------- |
| 32 | +res.f2 <- step(start,scope=list(upper=end),direction="forward", |
| 33 | + test="F",k=4) |
| 34 | +summary(res.f2) |
| 35 | + |
| 36 | +## ----eval=FALSE---------------------------------------------------------- |
| 37 | +res.b <- step(end,direction="backward",test="F") |
| 38 | +summary(res.b) |
| 39 | + |
| 40 | +## ----eval=FALSE---------------------------------------------------------- |
| 41 | +res.both <- step(start,scope=list(upper=end),direction="both",test="F") |
| 42 | +summary(res.both) |
| 43 | + |
| 44 | +## ----eval=FALSE---------------------------------------------------------- |
| 45 | +end.i <- lm(hours~(ocup+check+service+sqfoot+wings+cap+rooms)^2,data=mhours) |
| 46 | +res.f3 <- step(start,scope=list(upper=end.i),direction="forward",test="F") |
| 47 | +summary(res.f3) |
| 48 | +res.f3$call |
| 49 | + |
| 50 | +## ----eval=FALSE---------------------------------------------------------- |
| 51 | +end.p <- lm(hours~ocup+check+service+sqfoot+ |
| 52 | + wings+cap+rooms+I(rooms^2)+I(cap^2)+I(check^2),data=mhours) |
| 53 | +res.f4 <- step(start,scope=list(upper=end.p),direction="forward",test="F") |
| 54 | +summary(res.f4) |
| 55 | + |
| 56 | +## ----eval=FALSE---------------------------------------------------------- |
| 57 | +start <- lm(hours~check,data=mhours) |
| 58 | +res.f4.2 <- step(start,scope=list(upper=end.p),direction="forward", |
| 59 | + ,test="F") |
| 60 | +summary(res.f4.2) |
| 61 | + |
0 commit comments