library(brms)
我有一个适合 brms ( )的多级负二项式模型
fit1 <- brm(TOTAL_VIOLATIONS ~ LN_POP + Source_binary + Source_purchased + (1|TYPE_consolidated) + (1|COUNTY), data = Data, family = negbinomial())
这是数据的样子:
> dput(droplevels(Data[1:20, c(3, 9, 20, 21, 22, 23)]))
structure(list(COUNTY = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L), .Label = c("ALAMEDA",
"ALPINE", "AMADOR"), class = "factor"), TYPE_consolidated = structure(c(9L,
6L, 3L, 2L, 5L, 7L, 1L, 1L, 4L, 12L, 1L, 1L, 1L, 1L, 8L, 10L,
6L, 5L, 11L, 2L), .Label = c("City", "County Water District",
"CSA", "CSD", "IOU", "MHP", "MUD", "MWC", "PA", "Private", "PUD",
"Special Act District"), class = "factor"), TOTAL_VIOLATIONS = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 0L,
8L, 0L, 0L), LN_POP = c(3.91202300542815, 6.29710931993394, 6.21260609575152,
12.7367008965923, 10.9852927228879, 14.1374128813017, 11.9290007521904,
11.1991321074213, 11.2374881189349, 12.332000202128, 10.2255710517052,
6.10924758276437, 6.62007320653036, 6.21460809842219, 3.91202300542815,
3.2188758248682, 4.24849524204936, 7.88231491898027, 8.96839619119826,
4.91265488573605), Source_binary = structure(c(1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L
), .Label = c("GW", "SW"), class = "factor"), Source_purchased = structure(c(1L,
1L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L,
1L, 1L, 2L), .Label = c("No", "Purchased"), class = "factor")), row.names = c(NA,
20L), class = "data.frame")
我想探索包含第一个随机效应(TYPE_consolidated)与仅具有第二个随机截距(COUNTY)的相同模型的价值,但我一生无法弄清楚如何icc()
使用by_group
. 无论有没有这个参数,输出都是完全相同的(见下文)。我有一种感觉,这是因为它是一个 brms 对象,因为根据帮助,这些模型的输出是不同的,但我还没有想出另一种方法来获得它。有谁知道获得单个随机效应的方差比的方法(或者可以看到我做错了什么by_group
)?如果没有,是否有标准方法来比较嵌套模型之间的 ICC?如果是这样,也许我可以为我的模型的两个不同版本计算它,然后改为这样做?
> performance::icc(fit1, by_group = TRUE)
# Random Effect Variances and ICC
Conditioned on: all random effects
## Variance Ratio (comparable to ICC)
Ratio: 0.94 CI 95%: [0.80 0.99]
## Variances of Posterior Predicted Distribution
Conditioned on fixed effects: 7.39 CI 95%: [ 2.50 20.03]
Conditioned on rand. effects: 117.57 CI 95%: [59.15 331.86]
## Difference in Variances
Difference: 109.10 CI 95%: [50.23 320.86]
> performance::icc(fit1)
# Random Effect Variances and ICC
Conditioned on: all random effects
## Variance Ratio (comparable to ICC)
Ratio: 0.94 CI 95%: [0.79 0.99]
## Variances of Posterior Predicted Distribution
Conditioned on fixed effects: 7.42 CI 95%: [ 2.48 20.19]
Conditioned on rand. effects: 117.90 CI 95%: [59.53 349.90]
## Difference in Variances
Difference: 109.71 CI 95%: [51.20 340.30]```