use stepAIC on a list of models

前端 未结 2 726

I want to do stepwise regression using AIC on a list of linear models. idea is to use e a list of linear models and then apply stepAIC on each list element. It fails.

<
2条回答
  •  离开以前
    2020-12-03 13:40

    As it seems that stepAIC goes out of loop environment (that is in global environment) to look for the data it needs, I trick it using the assign function:

        results <- do.call(rbind, lapply(response, function (i) { 
        assign("i", response, envir = .GlobalEnv)
                mdl <- gls(as.formula(paste0(i,"~",paste(expvar, collapse = "+")), data= parevt, correlation = corARMA(p=1,q=1,form= ~as.integer(Year)), weights= varIdent(~1/Linf_var), method="ML")
                mdl <- stepAIC(mdl, direction ="backward")
    }))
    

提交回复
热议问题