-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Shimanto
authored
Mar 20, 2018
1 parent
6dc5b11
commit 31300b1
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
Stepwise Regression with python & R/stepwise regression with R.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
## ------------------------------------------------------------------------ | ||
mhours <- read.csv("http://www.personal.psu.edu/~mar36/stat_462/manhours.csv",header=T) | ||
library(psych) | ||
pairs.panels(mhours[,-1],ellipses=FALSE,smooth=FALSE,lm=TRUE) | ||
|
||
## ----eval=FALSE---------------------------------------------------------- | ||
summary(lm(hours~ocup,data=mhours)) | ||
summary(lm(hours~check,data=mhours)) | ||
summary(lm(hours~service,data=mhours)) | ||
summary(lm(hours~sqfoot,data=mhours)) | ||
summary(lm(hours~wings,data=mhours)) | ||
summary(lm(hours~cap,data=mhours)) | ||
summary(lm(hours~rooms,data=mhours)) | ||
|
||
## ----eval=FALSE---------------------------------------------------------- | ||
summary(lm(hours~ocup+check+service+sqfoot+wings+cap+rooms,data=mhours)) | ||
summary(lm(hours~(ocup+check+service+sqfoot+wings+cap+rooms)^2,data=mhours)) | ||
|
||
## ----eval=FALSE---------------------------------------------------------- | ||
# Starring point | ||
start <- lm(hours~1,data=mhours) | ||
summary(start) | ||
# Ending point | ||
end <- lm(hours~ocup+check+service+sqfoot+wings+cap+rooms,data=mhours) | ||
summary(end) | ||
# Use the "step" function | ||
step(start,scope=list(upper=end),direction="forward",test="F") | ||
res.f <- step(start,scope=list(upper=end),direction="forward",test="F") | ||
summary(res.f) | ||
|
||
## ----eval=FALSE---------------------------------------------------------- | ||
res.f2 <- step(start,scope=list(upper=end),direction="forward", | ||
test="F",k=4) | ||
summary(res.f2) | ||
|
||
## ----eval=FALSE---------------------------------------------------------- | ||
res.b <- step(end,direction="backward",test="F") | ||
summary(res.b) | ||
|
||
## ----eval=FALSE---------------------------------------------------------- | ||
res.both <- step(start,scope=list(upper=end),direction="both",test="F") | ||
summary(res.both) | ||
|
||
## ----eval=FALSE---------------------------------------------------------- | ||
end.i <- lm(hours~(ocup+check+service+sqfoot+wings+cap+rooms)^2,data=mhours) | ||
res.f3 <- step(start,scope=list(upper=end.i),direction="forward",test="F") | ||
summary(res.f3) | ||
res.f3$call | ||
|
||
## ----eval=FALSE---------------------------------------------------------- | ||
end.p <- lm(hours~ocup+check+service+sqfoot+ | ||
wings+cap+rooms+I(rooms^2)+I(cap^2)+I(check^2),data=mhours) | ||
res.f4 <- step(start,scope=list(upper=end.p),direction="forward",test="F") | ||
summary(res.f4) | ||
|
||
## ----eval=FALSE---------------------------------------------------------- | ||
start <- lm(hours~check,data=mhours) | ||
res.f4.2 <- step(start,scope=list(upper=end.p),direction="forward", | ||
,test="F") | ||
summary(res.f4.2) | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.