我安装了以下形式的混合模型:
global.mod <- lmer(log(y) ~
x1 + x2 + x3 + x4 + x5 + (1 + x1|a/b),
REML = FALSE, data = lmerDat,
na.action = 'na.fail', control = lmerControl(optimizer="bobyqa",optCtrl=list(maxfun=2e4)))
然后我用它predge
来创建下面的模型组合,效果很好。
require(parallel) || require(snow)
clusterType <- if(length(find.package("snow", quiet = TRUE))) "SOCK" else "PSOCK"
clust <- try(makeCluster(getOption("cl.cores", 4), type = clusterType))
clusterEvalQ(clust, library(lme4))
clusterExport(clust, "lmerDat")
model.set <- pdredge(global.mod, clust,
m.lim = c(2, NA), rank = AIC, extra = "adjR^2", trace = 2)
然后我尝试以稍微不同的格式指定我的模型,如下所示:
PredictorVariables <- names(lmerDat)[c(5:9)] # this is x1 till x5
fixed.part <- paste("log(y) ~", paste(PredictorVariables, collapse=" + "))
random.part <- paste('(1 + x1|a/b)')
Formula <- formula(paste(fixed.part, random.part, sep = " + "))
global.mod <- lmer(Formula, data = lmerDat, na.action = 'na.fail', control =
lmerControl(optimizer="bobyqa",optCtrl=list(maxfun=2e4)), REML = FALSE)
require(parallel) || require(snow)
clusterType <- if(length(find.package("snow", quiet = TRUE))) "SOCK" else "PSOCK"
clust <- try(makeCluster(getOption("cl.cores", 4), type = clusterType))
clusterEvalQ(clust, library(lme4))
clusterExport(clust, "lmerDat")
model.set <- pdredge(global.mod, clust,
m.lim = c(2, NA), rank = AIC, extra = "adjR^2", trace = 2)
但是,这给了我以下错误
Error in sprintf(gettext(fmt, domain = domain), ...) :
invalid format '%d'; use format %f, %e, %g or %a for numeric objects
不幸的是,后者是我想要做模型规范的方式,因为先验我不知道预测变量的名称是什么names(lmerDat)[c(5:9)]
。谁能帮我理解错误以及如何解决它?
编辑
我的回溯输出如下(请注意,这是我的原始数据而不是上面的虚拟数据)。
7: sprintf(gettext(fmt, domain = domain), ...)
6: gettextf(Message, ..., domain = domain)
5: structure(list(message = as.character(message), call = call),
class = class)
4: simpleError(gettextf(Message, ..., domain = domain), Call)
3: stop(simpleError(gettextf(Message, ..., domain = domain), Call))
2: cry(, "number of non-fixed predictors [%d] exceeds the allowed maximum of %d (with %d variants)",
nov, novMax, nVariants)
1: pdredge(global.mod, clust)