我正在寻找一种令人愉悦且信息丰富的方式来可视化混合模型,其中响应变量和预测变量都是二元的。
m_0 <- glmer(Preselected_0 ~ N_G_altnt_Q_YN + (N_G_altnt_Q_YN | File / Person_anon), family = "binomial",
data = df)
我使用得到的图plot_model
是这样的:
library(sjPlot)
plot_model(m_0, type = "eff", terms = c("N_G_altnt_Q_YN"), #pred.type = "fe", ci.lvl = .68, line.size = 1.2,
title = ""
)
我想要得到的情节是这样的:或者,如果二元预测器不可能或不建议这样做,那么其他一些更具视觉吸引力和信息量的可视化 - 任何帮助都会受到赞赏!
数据:
df <- structure(list(N_G_altnt_Q_YN = structure(c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L,
1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L,
1L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L,
1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,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"F01", "F01", "F01", "F01",
"F01", "F01", "F01", "F01", "F01", "F01", "F01", "F01", "F01",
"F01", "F01", "F01", "F01", "F04", "F04", "F04", "F04", "F04",
"F04", "F04", "F04", "F04", "F04", "F04", "F04", "F04", "F04",
"F04", "F04", "F04", "F04", "F04", "F04", "F04", "F04", "F04",
"F04", "F04", "F04", "F04", "F04", "F04", "F04", "F04", "F04",
"F04", "F04", "F04", "F04", "F04", "F04", "F04", "F04", "F04",
"F04", "F04", "F04", "F04", "F04", "F04", "F04", "F04", "F04",
"F04", "F04", "F04", "F04", "F04", "F04", "F04", "F04", "F04",
"F04", "F04", "F04", "F04", "F04", "F07", "F07", "F07", "F07",
"F07", "F07", "F07", "F07", "F07", "F07", "F07", "F07", "F07",
"F07", "F07", "F07", "F07", "F07", "F07", "F07", "F07", "F07",
"F07", "F07", "F07", "F07", "F07", "F07", "F07", "F07", "F07",
"F07", "F07", "F07", "F07", "F07", "F07", "F07", "F07", "F07",
"F07", "F07", "F07", "F07", "F07", "F07", "F07", "F07", "F07",
"F07", "F07", "F07", "F07", "F08", "F08", "F08", "F08", "F08",
"F08", "F08", "F08", "F08", "F08", "F08", "F08", "F08", "F08",
"F08", "F08", "F08", "F08", "F08", "F08", "F08", "F08", "F08",
"F08", "F08", "F08", "F08", "F08", "F08", "F08", "F08", "F08",
"F08", "F08", "F08", "F08", "F08", "F08", "F08", "F12", "F12",
"F12", "F12", "F12", "F12", "F12", "F12", "F12", "F12", "F12",
"F12", "F12", "F12", "F12", "F12", "F12", "F12", "F12", "F12",
"F12", "F12", "F12", "F12", "F12", "F12", "F12", "F12", "F16",
"F16", "F16", "F16", "F16", "F16", "F16", "F16", "F16", "F16",
"F16", "F16", "F16", "F16", "F16", "F16", "F16", "F16", "F16",
"F18", "F18", "F18", "F18", "F18", "F18", "F18", "F18", "F18",
"F18", "F18", "F18", "F18", "F18", "F18", "F18", "F18", "F18",
"F18", "F18", "F18", "F18", "F18", "F20", "F20", "F20", "F20",
"F20", "F20", "F20", "F20", "F20", "F20", "F20", "F20", "F20",
"F20", "F20", "F20", "F20", "F20", "F20", "F22", "F22", "F22",
"F22", "F22", "F22", "F22", "F22", "F22", "F22", "F23", "F23",
"F23", "F23", "F23", "F23", "F23", "F23", "F23", "F23", "F23",
"F23", "F23", "F23", "F23", "F23", "F23", "F23", "F23", "F23",
"F23", "F23", "F23", "F23", "F23", "F23", "F23", "F23", "F23",
"F23", "F23", "F23", "F23", "F23", "F23", "F23", "F23", "F23",
"F23", "F19", "F19", "F19", "F19", "F19", "F19", "F19", "F19",
"F19", "F19", "F19", "F16"), Person_anon = c("GGGGGGGGGGGGGGGl",
"IIIIIIIIIIIIt", "IIIIIIIIIIIIt", "IIIIIIIIIIIIt", "IIIIIIIIIIIIt",
"IIIIIIIIIIIIt", "IIIIIIIIIIIIt", "GGGGGGGGGGGGGGGl", "IIIIIIIIIIIIt",
"IIIIIIIIIIIIt", "KKKKKKKKKKr", "IIIIIIIIIIIIt", "KKKKKKKKKKr",
"IIIIIIIIIIIIt", "IIIIIIIIIIIIt", "IIIIIIIIIIIIt", "GGGGGGGGGGGGGGGl",
"IIIIIIIIIIIIt", "IIIIIIIIIIIIt", "KKKKKKKKKKr", "IIIIIIIIIIIIt",
"IIIIIIIIIIIIt", "IIIIIIIIIIIIt", "IIIIIIIIIIIIt", "IIIIIIIIIIIIt",
"IIIIIIIIIIIIt", "DDDDDDDDDDDDe", "AAAAAAAAAAAAAn", "DDDDDDDDDDDDe",
"DDDDDDDDDDDDe", "DDDDDDDDDDDDe", "DDDDDDDDDDDDe", "DDDDDDDDDDDDe",
"DDDDDDDDDDDDe", "DDDDDDDDDDDDe", "CCCCCCCCCCx", "CCCCCCCCCCx",
"DDDDDDDDDDDDe", "DDDDDDDDDDDDe", "DDDDDDDDDDDDe", "DDDDDDDDDDDDe",
"DDDDDDDDDDDDe", "AAAAAAAAAAAAAn", "DDDDDDDDDDDDe", "CCCCCCCCCCx",
"CCCCCCCCCCx", "CCCCCCCCCCx", "AAAAAAAAAAAAAn", "AAAAAAAAAAAAAn",
"AAAAAAAAAAAAAn", "DDDDDDDDDDDDe", "DDDDDDDDDDDDe", "AAAAAAAAAAAAAn",
"DDDDDDDDDDDDe", "CCCCCCCCCCx", "DDDDDDDDDDDDe", "DDDDDDDDDDDDe",
"AAAAAAAAAAAAAn", "AAAAAAAAAAAAAn", "CCCCCCCCCCx", "DDDDDDDDDDDDe",
"AAAAAAAAAAAAAn", "CCCCCCCCCCx", "DDDDDDDDDDDDe", "DDDDDDDDDDDDe",
"AAAAAAAAAAAAAn", "AAAAAAAAAAAAAn", "CCCCCCCCCCx", "CCCCCCCCCCx",
"CCCCCCCCCCx", "DDDDDDDDDDDDe", "DDDDDDDDDDDDe", "DDDDDDDDDDDDe",
"DDDDDDDDDDDDe", "DDDDDDDDDDDDe", "DDDDDDDDDDDDe", "DDDDDDDDDDDDe",
"CCCCCCCCCCx", "DDDDDDDDDDDDe", "AAAAAAAAAAAAAn", "AAAAAAAAAAAAAn",
"CCCCCCCCCCx", "AAAAAAAAAAAAAn", "CCCCCCCCCCx", "DDDDDDDDDDDDe",
"CCCCCCCCCCx", "DDDDDDDDDDDDe", "CCCCCCCCCCx", "DDDDDDDDDDDDe",
"CCCCCCCCCCx", "LLLLLLLLLLLLLn", "LLLLLLLLLLLLLn", "LLLLLLLLLLLLLn",
"CCCCCCCCCCx", "LLLLLLLLLLLLLn", "AAAAAAAAAAAAAn", "AAAAAAAAAAAAAn",
"AAAAAAAAAAAAAn", "LLLLLLLLLLLLLn", "LLLLLLLLLLLLLn", "AAAAAAAAAAAAAn",
"AAAAAAAAAAAAAn", "CCCCCCCCCCx", "AAAAAAAAAAAAAn", "AAAAAAAAAAAAAn",
"AAAAAAAAAAAAAn", "CCCCCCCCCCx", "AAAAAAAAAAAAAn", "AAAAAAAAAAAAAn",
"AAAAAAAAAAAAAn", "CCCCCCCCCCx", "AAAAAAAAAAAAAn", "LLLLLLLLLLLLLn",
"LLLLLLLLLLLLLn", "AAAAAAAAAAAAAn", "AAAAAAAAAAAAAn", "LLLLLLLLLLLLLn",
"AAAAAAAAAAAAAn", "CCCCCCCCCCx", "CCCCCCCCCCx", "CCCCCCCCCCx",
"AAAAAAAAAAAAAn", "AAAAAAAAAAAAAn", "AAAAAAAAAAAAAn", "CCCCCCCCCCx",
"AAAAAAAAAAAAAn", "AAAAAAAAAAAAAn", "AAAAAAAAAAAAAn", "AAAAAAAAAAAAAn",
"CCCCCCCCCCx", "CCCCCCCCCCx", "LLLLLLLLLLLLLn", "AAAAAAAAAAAAAn",
"CCCCCCCCCCx", "AAAAAAAAAAAAAn", "AAAAAAAAAAAAAn", "AAAAAAAAAAAAAn",
"AAAAAAAAAAAAAn", "AAAAAAAAAAAAAn", "AAAAAAAAAAAAAn", "AAAAAAAAAAAAAn",
"AAAAAAAAAAAAAn", "LLLLLLLLLLLLLn", "LLLLLLLLLLLLLo", "LLLLLLLLLLLLLo",
"LLLLLLLLLLLLLn", "LLLLLLLLLLLLLn", "LLLLLLLLLLLLLo", "NNNNNNNNNNNr",
"NNNNNNNNNNNr", "LLLLLLLLLLLLLn", "LLLLLLLLLLLLLn", "NNNNNNNNNNNr",
"NNNNNNNNNNNr", "NNNNNNNNNNNr", "NNNNNNNNNNNr", "NNNNNNNNNNNr",
"LLLLLLLLLLLLLo", "LLLLLLLLLLLLLo", "NNNNNNNNNNNr", "LLLLLLLLLLLLLo",
"NNNNNNNNNNNr", "NNNNNNNNNNNr", "NNNNNNNNNNNr", "NNNNNNNNNNNr",
"NNNNNNNNNNNr", "LLLLLLLLLLLLLn", "LLLLLLLLLLLLLn", "NNNNNNNNNNNr",
"LLLLLLLLLLLLLo", "LLLLLLLLLLLLLo", "LLLLLLLLLLLLLo", "LLLLLLLLLLLLLn",
"LLLLLLLLLLLLLo", "NNNNNNNNNNNr", "NNNNNNNNNNNr", "LLLLLLLLLLLLLn",
"LLLLLLLLLLLLLn", "NNNNNNNNNNNr", "LLLLLLLLLLLLLn", "NNNNNNNNNNNr",
"NNNNNNNNNNNr", "LLLLLLLLLLLLLo", "LLLLLLLLLLLLLo", "CCCCCCCCCCx",
"LLLLLLLLLLLLLo", "DDDDDDDDDDDDe", "CCCCCCCCCCx", "LLLLLLLLLLLLLo",
"LLLLLLLLLLLLLo", "LLLLLLLLLLLLLo", "DDDDDDDDDDDDe", "DDDDDDDDDDDDe",
"DDDDDDDDDDDDe", "CCCCCCCCCCx", "DDDDDDDDDDDDe", "CCCCCCCCCCx",
"CCCCCCCCCCx", "CCCCCCCCCCx", "CCCCCCCCCCx", "DDDDDDDDDDDDe",
"CCCCCCCCCCx", "CCCCCCCCCCx", "DDDDDDDDDDDDe", "DDDDDDDDDDDDe",
"DDDDDDDDDDDDe", "DDDDDDDDDDDDe", "LLLLLLLLLLLLLo", "DDDDDDDDDDDDe",
"DDDDDDDDDDDDe", "CCCCCCCCCCx", "CCCCCCCCCCx", "AAAAAAAAAAo",
"AAAAAAAAAAo", "AAAAAAAAAAo", "AAAAAAAAAAo", "AAAAAAAAAAo",
"AAAAAAAAAAo", "CCCCCCCCCCx", "CCCCCCCCCCCCCCx", "AAAAAAAAAAo",
"AAAAAAAAAAo", "AAAAAAAAAAo", "AAAAAAAAAAo", "AAAAAAAAAAo",
"AAAAAAAAAAo", "CCCCCCCCCCCCCCx", "AAAAAAAAAAo", "CCCCCCCCCCCCCCx",
"SSSSSSSSSSd", "SSSSSSSSSSd", "GGGGGGGGGGGGGi", "SSSSSSSSSSd",
"SSSSSSSSSSd", "AAAAAAAAAAo", "SSSSSSSSSSd", "SSSSSSSSSSd",
"AAAAAAAAAAo", "SSSSSSSSSSd", "AAAAAAAAAAo", "SSSSSSSSSSd",
"SSSSSSSSSSd", "SSSSSSSSSSd", "AAAAAAAAAAo", "SSSSSSSSSSd",
"GGGGGGGGGGGGGi", "GGGGGGGGGGGGGi", "GGGGGGGGGGGGGi", "GGGGGGGGGGGGGi",
"GGGGGGGGGGGGGi", "GGGGGGGGGGGGGi", "SSSSSSSSSSd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CCCCCd", "CCCCCCCCCCCCd", "CCCCCCCCCCCCd", "CCCCCCCCCCCCd",
"CCCCCCCCCCCCd", "CCCCCCCCCCCCd", "LLLLLLLLLLn", "LLLLLLLLLLn",
"LLLLLLLLLLn", "LLLLLLLLLLn", "OOOOOOOOOOOOm", "LLLLLLLLLLLLLLLLLLLl",
"LLLLLLLLLLLLLLLLLLLl", "LLLLLLLLLLLLLLLLLLLl", "LLLLLLLLLLLLLLLLLLLl",
"LLLLLLLLLLLLLLLLLLLl", "LLLLLLLLLLLLLLLLLLLl", "LLLLLLLLLLLLLLLLLLLl",
"LLLLLLLLLLLLLLLLLLLl", "LLLLLLLLLLLLLLLLLLLl", "LLLLLLLLLLLLLLLLLLLl",
"LLLLLLLLLLLLLLLLLLLl", "AAAAAAAAAAo")), row.names = c(NA,
-332L), class = c("tbl_df", "tbl", "data.frame"))
您可以通过将分类结果拟合为实际的 0/1 编码虚拟效果来轻松实现此目的。这是在任何拟合例程中都会发生的情况,但后续
predict
方法将不知道如何处理我们想要去的地方:我不会在这里展示它,但这不会改变模型的固定或随机估计,它只是从预测变量中删除了因子类型。如果你在这个因素中有两个以上的水平,你就必须创建更多的虚拟人,但同样的原则仍然成立(同样,这也是
model.matrix
任何模型中都会做的事情)。最大的优点是我们现在可以使用
predict
0/1 以外的其他值——如果您愿意的话,甚至可以超出这些范围,尽管显然这毫无意义。我们在最后一次调用中做了一些事情:询问整个预测范围内的固定效应预测平均值和标准误差,并使用这些计算 Wald 型 95% 置信区间。最后,所有内容都从对数赔率尺度反向转换为响应(概率)尺度。您需要最后执行该步骤,因为您无法直接计算响应量表中的置信区间。
现在剩下的就是制作一个情节了。我会坚持基本例程而不是例如
ggplot2
:一些结束语: