lme4
またはnlme
パッケージを使用して、さまざまな線形混合効果モデルを比較するためのより柔軟なアプローチを可能にするスクリプトを書くのに苦労しています。追加または削除するモデルごとにスクリプトを調整したくないので、動的なアプローチを探しています。そうすることで、モデル式の文字列を含む 1 つの変数を調整するだけで済みます。
これは、適切なクラスを含む要素のリストを受け入れない限り、正常に機能anova()
します。anova()
###### Here is my problem
# comparing models by means of ANOVA
anova(lme.lst) #### --> does not work
anova(lme.lst[[1]], lme.lst[[2]], lme.lst[[3]]) #### would work but kills the dynamic approach
######
anova()
リストを分解して複数の引数を関数に渡すきちんとした方法がわかりませんでした。unlist()
私は成功せずに試しました。
これは最小限の例です(lme4マニュアル、p。8から適応):
require(lme4)
require(AICcmodavg)
# Variable containing of strings in order to describe the fixed effect terms
# (wihout response/dependen variable) ### should be orderd from
callModel <- c("angle ~ recipe + temp + (1|recipe:replicate)", # model1 ### small
"angle ~ recipe + temperature + (1|recipe:replicate)", # model2 ### too
"angle ~ recipe * temperature + (1|recipe:replicate)") # model3 ### BIG
# convert string array 'callFeVar' into a list of formulas
callModel <- sapply(callModel, as.formula)
# create an empty list for safing the results of fitted model
lme.lst <- list()
# do model fitting in a loop and change list names
for (i in 1 : length(callModel)) {
lmeTmp <- lmer(callModel[[i]], cake, REML= FALSE)
lme.lst[i] <- list(lmeTmp)
names(lme.lst)[i] <- deparse(callModel[[i]])
}
# remove temporary variable
rm(lmeTmp)
# summary of models
lapply(lme.lst, summary)
###### Here is my problem
# comparing models by means of ANOVA
anova(lme.lst) #### --> does not work
anova(lme.lst[[1]], lme.lst[[2]], lme.lst[[3]]) #### would work but kills the dynamic approach
######
# comparing models by means of AICc
aictab(lme.lst) #### accepts list