[R] boot.stepAIC fails with computed formula

Steve O'Hagan SOHagan at manchester.ac.uk
Tue Aug 22 19:08:53 CEST 2017


The error is "the model fit failed in 50 bootstrap samples
Error: non-character argument"

Cheers,
SOH.

On 22/08/2017 17:52, Bert Gunter wrote:
> Failed?  What was the error message?
>
> Cheers,
>
> Bert
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Tue, Aug 22, 2017 at 8:17 AM, Stephen O'hagan
> <SOhagan at manchester.ac.uk> wrote:
>> 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 at 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.



More information about the R-help mailing list