如何正确为glmer(和simr)指定'mustart'值?

时间:2019-10-25 16:13:18

标签: r simulation lme4 sample-size

我正在尝试建立一个既包含对象又包含主题因素的数据模型。尝试使用{ role: "admin" }进行功效分析和样本量估算时遇到一些问题。

以下是一些模拟数据和模型来说明我的问题:

simr

我想知道我是否没有正确指定## List of required packages Pkgs <- c("tidyverse","magrittr", "lme4", "lmerTest", "MCMCglmm", "simr") # Load packages lapply(Pkgs, require, c = T) ## Build a simulated data set Sub_Group <- data.frame(Subject = LETTERS[1:20], Group = c(rep("Y", 10), rep("Z", 10))) Cat_Item <- data.frame(expand.grid(Category = c(rep("U", 25), rep("V", 25)), Item = factor(rep(c(1:25),2)))) Cond <- data.frame(Condition = letters[1:5]) Cond_Cat_Item <- merge(Cond, Cat_Item, by = NULL) Data <- merge(Sub_Group, Cond_Cat_Item, by = NULL) %>% mutate(Y = round(rtnorm(nrow(.), 4.5, 2, 1, 9), digits = 0)) ## Run initial glmer without any specified starting values summary(Mod1 <- glmer(Y ~ Category + Condition + Group + (1 + Group|Subject), data = Data, family = gaussian(link = "log"))) plot(powerCurve(extend(Mod1, along = "Subject", n = 50), along = "Subject", nsim = 10)) # Errors suggesting to provide starting values lastResult()$errors # "cannot find valid starting values: please specify some" ## Second glmer with starting values summary(Mod2 <- glmer(Y ~ Category + Condition + Group + (1 + Group|Subject), data = Data, mustart = Data$Y, family = gaussian(link = "log"))) plot(powerCurve(extend(Mod2, along = "Subject", n = 50), along = "Subject", nsim = 10)) ## Errors regarding variable lengths lastResult()$errors # "variable lengths differ (found for '(mustart)')" 值(即使模型运行正常),或者是否有问题或我应该为mustart做些什么。 / p>

0 个答案:

没有答案