【问题标题】:Compare degree of polynomial across the fixed and random effects比较固定效应和随机效应的多项式次数
【发布时间】:2017-10-24 09:23:55
【问题描述】:

我的数据包含许多设备,每个设备都包含几个测量数据点(电压放大),因此数据按 Serial_number 分组。 然后我有一个 lmer 模型,一般描述为:

fit<- lmer(log(log(Amplification)) ~ poly(Voltage, **degree**) + (poly(Voltage, **degree**) | Serial_number), data = APD)

现在我想比较不同的多项式,每个多项式的次数最多为 3,以获得固定效应和随机效应。

例如:

fit01<- lmer(log(log(Amplification)) ~ poly(Voltage, **0**) + (poly(Voltage, **1**) | Serial_number), data = APD)
fit11<- lmer(log(log(Amplification)) ~ poly(Voltage, **1**) + (poly(Voltage, **1**) | Serial_number), data = APD)

等等。我是否必须检查所有可能性(有 16 个),或者我可以因为任何明智的假设而减少它吗? 最后我会有anova(fit11,fit01)等等.. 问题是:当我现在每次比较两个不同的模型时,我真的需要做很多比较。

【问题讨论】:

    标签: r lme4


    【解决方案1】:

    您可以通过编程方式拟合模型,然后使用 AIC 进行比较:

    library(lme4)
    
    combinations <- expand.grid(fixed = 1:3, random = 1:3)
    
    models <- lapply(seq_len(nrow(combinations)), function(i) {
      f <- as.formula(paste(
        'mpg ~ poly(qsec,', combinations[i, 1], ') + (poly(qsec,', combinations[i, 2], ') | cyl)'
      ))
      lmer(f, mtcars)
    })
    
    names(models) <- apply(combinations, 1, paste, collapse = '_')
    aics <- sapply(models, function(m) summary(m)$AIC)
    
    result <- data.frame(model = names(models), AIC = aics)
    result <- result[order(result$AIC), ]
    result$dAIC <- result$AIC - result$AIC[1]
    
    result
    
             model      AIC      dAIC
    3_3.REML   3_3 155.7776 0.0000000
    3_2.REML   3_2 155.9683 0.1907229
    3_1.REML   3_1 156.0175 0.2398943
    2_3.REML   2_3 160.1618 4.3842105
    2_2.REML   2_2 160.2372 4.4595903
    2_1.REML   2_1 160.3215 4.5438645
    1_3.REML   1_3 164.5201 8.7424622
    1_2.REML   1_2 165.2802 9.5025476
    1_1.REML   1_1 165.3264 9.5487699
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-05
      • 2021-08-18
      • 2015-09-26
      • 2022-11-27
      • 1970-01-01
      • 2014-07-24
      • 2020-11-05
      • 2018-08-08
      相关资源
      最近更新 更多