I'm trying to use boot.stepAIC for feature selection; I need to be able to
specify the name of the dependent variable programmatically, but this appear to
fail:
In R-Studio with MS R Open 3.4:
library(bootStepAIC)
#Fake data
n<-200
x1 <- runif(n, -3, 3)
x2 <- runif(n, -3, 3)
x3 <- runif(n, -3, 3)
x4 <- runif(n, -3, 3)
x5 <- runif(n, -3, 3)
x6 <- runif(n, -3, 3)
x7 <- runif(n, -3, 3)
x8 <- runif(n, -3, 3)
y1 <- 42+x3 + 2*x6 + 3*x8 + runif(n, -0.5, 0.5)
dat <- data.frame(x1,x2,x3,x4,x5,x6,x7,x8,y1)
#the real data won't have these names...
cn <- names(dat)
trg <- "y1"
xvars <- cn[cn!=trg]
frm1<-as.formula(paste(trg,"~1"))
frm2<-as.formula(paste(trg,"~ 1 + ",paste(xvars,collapse = "+")))
strt=lm(y1~1,dat) # boot.stepAIC Works fine
#strt=do.call("lm",list(frm1,data=dat)) ## boot.stepAIC FAILS ##
#strt=lm(frm1,dat) ## boot.stepAIC FAILS ##
limit<-5
stp=stepAIC(strt,direction='forward',steps=limit,
scope=list(lower=frm1,upper=frm2))
bst <- boot.stepAIC(strt,dat,B=50,alpha=0.05,direction='forward',steps=limit,
scope=list(lower=frm1,upper=frm2))
b1 <- bst$Covariates
ball <- data.frame(b1)
names(ball)=unlist(trg)
Any ideas?
Cheers,
SOH
[[alternative HTML version deleted]]
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.