【问题标题】:How do I simulate data for a power analysis of a repeated measure linear mixed effects regression using simr?如何使用 simr 模拟重复测量线性混合效应回归的功效分析数据?
【发布时间】:2022-01-28 01:00:29
【问题描述】:

我想对lmer 中的线性混合模型进行基于仿真的功率分析,并从头开始重复测量。我知道simr 可能是要使用的软件包。但是,我不明白我必须做什么,也无法理解我在网上阅读的任何内容。

我想测试一个随机截距模型,其中

  • y(z 标准化结果变量)~
    • a + b(z 标准化协变量)
    • + c + d(二元协变量)
    • + time1 + time2(时间假人表示在 t1 或 t2 而非 t0 进行测量)
    • + group(一组有两个表达式)
    • + group:time1 + group:time2
    • + (1 | participant)

即,使用随机截距将三个测量值嵌套在参与者中。

我如何模拟数据,以便能够找出合适的样本量,以便以 0.80 的幂找到 beta = .3 的交互效应(例如 group:time1)?我需要哪些额外信息才能做到这一点?

【问题讨论】:

    标签: r simulation lme4


    【解决方案1】:

    有诸如 simr 之类的包可以为您完成所有这些工作,甚至更多(并且也可以处理不平衡的设计),但是这里有一个简单的方法来模拟混合模型的数据,然后您可以从头开始用于功率分析:

    有几个重要的参数需要考虑:

    • 整体数据大小
    • 数据是否平衡
    • 参加人数
    • 固定效果
    • 随机效应方差
    • 剩余方差

    这里我们使用平衡设计,这使得设置更容易,但将其扩展到不平衡设计也不会太难:

    library(lme4)
    set.seed(15)
    
    N <- 10    # number of unique values of a and b for each participant
    N.participant <- 20   # number of participants
    betas <- c(10, 1, 2, 3, 4, 5, 6, 7)   # fixed effects
    s <- 0.5   # variance of random effects
    e <- 1  # residual variance
    
    # form the balanced data frame
    dt <- expand.grid(a = rnorm(N), b = rnorm(N), c = c(0,1), d = c(0,1), time = c(0,1,2), group = c(0,1), participant = LETTERS[1:N.participant])
    
    # form the model matrix for fixed effects
    X <- model.matrix(~ a + b + c + d + time + group + time:group, data = dt)
    
    # set a vector of 1s for the outcome. This is needed so we can easily compute the
    # model matrix for random effects (in this case just the random intercetps)
    dt$y <- 1
    
    # The final model formula
    myFormula <- "y ~ a + b + c + d + time + group + time:group + (1 | participant)"
    
    # obtain the model matrix for random effects
    foo <- lFormula(eval(myFormula), dt)
    Z <- t(as.matrix(foo$reTrms$Zt))
    
    # simulate the random effects
    u <- rnorm(N.participant , 0, s)
    
    # simulate y using the general mixed model equation and residual variance e
    dt$y <- X %*% betas + Z %*% u + rnorm(nrow(dt), 0, e)
    
    # fit the model
    m0 <- lmer(myFormula, dt)
    summary(m0)
    

    您将为每组参数运行多次,当然使用不同的种子,并计算相关的蒙特卡罗估计值,以及每组达到的功效。

    【讨论】:

    • 非常感谢您的回答和愿意提供帮助的意愿!我仍然无法理解您编写的所有内容,我想如果您对代码进行更多评论可能会对我有所帮助。或者你能帮我用simr怎么做吗?祝你一切顺利!
    • 不客气。我已经在代码中包含了几个 cmets,但是如果您有什么特别不明白的地方,我可以很高兴地添加一些。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-22
    • 2018-04-04
    • 2017-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多