比较固定效应和随机效应的多项式次数
Compare degree of polynomial across the fixed and random effects
我的数据包含很多设备,每个设备都包含几个测量数据点(针对电压的放大),因此数据按 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)
等等..
问题是:当我现在每次比较两个不同的模型时,我真的需要做很多比较。
您可以通过编程方式拟合模型,然后使用 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
我的数据包含很多设备,每个设备都包含几个测量数据点(针对电压的放大),因此数据按 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)
等等..
问题是:当我现在每次比较两个不同的模型时,我真的需要做很多比较。
您可以通过编程方式拟合模型,然后使用 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