r - Create and Call Linear Models from List -
so i'm trying compare different linear models in order determine if 1 better another. have several models, want create list of models , call on them. possible?
models <- list(lm(y~a),lm(y~b),lm(y~c) models2 <- list(lm(y~a+b),lm(y~a+c),lm(y~b+c)) anova(models2[1],models[1])
thank help!
if have 2 lists of models, , want compare each pair of models, want map
:
models1 <- list(lm(y ~ a), lm(y ~ b), lm(y ~ c) models2 <- list(lm(y ~ + b), lm(y ~ + c), lm(y ~ b + c)) map(anova, models1, models2)
this equivalent following loop:
out <- vector("list", length(models1)) (i in seq_along(out) { out[[i]] <- anova(models1[[i]], models2[[i]]) }
map example of functional, , can find out more them @ https://github.com/hadley/devtools/wiki/functionals
Comments
Post a Comment