Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Shimanto authored Mar 20, 2018
1 parent 6dc5b11 commit 31300b1
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions Stepwise Regression with python & R/stepwise regression with R.R
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.

0 comments on commit 31300b1

Please sign in to comment.