gpt4 book ai didi

R:具有连续变量和分类变量的 GLMM 交互图 (lme4)

转载 作者:行者123 更新时间:2023-12-04 16:29:42 26 4
gpt4 key购买 nike

我想制作一个交互图,以从回归模型的结果中直观地显示分类变量(4 个级别)和标准化连续变量的交互斜率的差异或相似性。
with(GLMModel, interaction.plot(continuous.var, categorical.var, response.var))不是我要找的。它生成一个图,其中斜率随连续变量的每个值而变化。我正在寻找一个具有恒定斜率的图,如下图所示:

enter image description here

有任何想法吗?

适合形状的模型fit<-glmer(resp.var ~ cont.var*cat.var + (1|rand.eff) , data = sample.data , poisson)以下是一些示例数据:

structure(list(cat.var = structure(c(4L, 4L, 1L, 4L, 1L, 2L, 
1L, 1L, 1L, 1L, 4L, 1L, 1L, 3L, 2L, 4L, 1L, 1L, 1L, 2L, 1L, 2L,
2L, 1L, 3L, 1L, 1L, 2L, 4L, 1L, 2L, 1L, 1L, 4L, 1L, 3L, 1L, 3L,
3L, 4L, 3L, 4L, 1L, 3L, 3L, 1L, 2L, 3L, 4L, 3L, 4L, 2L, 1L, 1L,
4L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 1L, 4L, 4L, 3L, 3L, 1L, 3L, 3L,
3L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 4L, 1L, 3L, 4L, 1L, 1L, 4L,
1L, 3L, 1L, 1L, 3L, 2L, 4L, 1L, 4L, 1L, 4L, 4L, 4L, 4L, 2L, 4L,
4L, 1L, 2L, 1L, 4L, 3L, 1L, 1L, 3L, 2L, 4L, 4L, 1L, 4L, 1L, 3L,
2L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 4L, 1L,
2L, 2L, 1L, 1L, 2L, 3L, 1L, 4L, 4L, 4L, 1L, 4L, 4L, 3L, 2L, 4L,
1L, 3L, 1L, 1L, 4L, 4L, 2L, 4L, 1L, 1L, 3L, 4L, 2L, 1L, 3L, 3L,
4L, 3L, 2L, 3L, 1L, 4L, 2L, 2L, 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4L, 4L, 2L, 4L, 1L, 1L, 2L, 4L,
4L, 2L, 3L, 4L, 4L, 3L, 1L, 4L, 1L, 2L, 4L, 1L, 1L, 4L, 1L, 1L,
1L, 1L, 1L, 3L, 4L, 1L, 4L, 4L, 2L, 2L, 2L, 2L, 3L, 4L, 4L, 1L,
1L, 4L, 2L, 3L, 3L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 3L, 4L, 2L,
3L, 1L, 1L, 1L, 4L, 1L, 1L, 4L, 4L, 4L, 1L, 1L, 1L, 1L), .Label = c("A",
"B", "C", "D"), class = "factor"), cont.var = c(-0.0682900527296927,
0.546320421837542, -0.273160210918771, -0.887770685486005, 0.136580105459385,
0.75119058002662, 0.546320421837542, -0.273160210918771, -0.682900527296927,
0.136580105459385, 0.75119058002662, 0.75119058002662, 0.75119058002662,
0.341450263648464, 0.75119058002662, 0.546320421837542, 0.546320421837542,
-0.478030369107849, -0.478030369107849, -0.682900527296927, -0.682900527296927,
0.546320421837542, -0.478030369107849, -0.0682900527296927, 0.136580105459385,
0.136580105459385, 0.75119058002662, -0.478030369107849, 0.75119058002662,
-0.887770685486005, 0.136580105459385, -0.478030369107849, 0.341450263648464,
-0.682900527296927, -0.478030369107849, 0.341450263648464, -0.478030369107849,
0.546320421837542, 0.75119058002662, -0.478030369107849, -0.273160210918771,
0.546320421837542, -0.682900527296927, 0.75119058002662, -0.478030369107849,
-0.887770685486005, 0.136580105459385, -0.887770685486005, -0.0682900527296927,
-0.478030369107849, 0.546320421837542, 0.75119058002662, 0.136580105459385,
-0.273160210918771, -0.273160210918771, 0.75119058002662, -0.682900527296927,
0.136580105459385, -0.273160210918771, -0.273160210918771, 0.136580105459385,
0.136580105459385, 0.341450263648464, 0.136580105459385, -0.273160210918771,
-0.273160210918771, -0.682900527296927, -0.887770685486005, -0.0682900527296927,
0.136580105459385, -0.0682900527296927, -0.273160210918771, -0.273160210918771,
0.341450263648464, 0.75119058002662, -0.682900527296927, -0.0682900527296927,
-0.273160210918771, -0.887770685486005, -0.0682900527296927,
0.75119058002662, 0.546320421837542, 0.75119058002662, 0.75119058002662,
-0.887770685486005, 0.341450263648464, 0.75119058002662, -0.887770685486005,
0.136580105459385, -0.273160210918771, 0.546320421837542, 0.546320421837542,
-0.682900527296927, 0.75119058002662, 0.136580105459385, -0.0682900527296927,
-0.478030369107849, 0.75119058002662, -0.478030369107849, 0.341450263648464,
0.136580105459385, -0.0682900527296927, -0.478030369107849, -0.0682900527296927,
-0.0682900527296927, 0.546320421837542, -0.273160210918771, 0.75119058002662,
0.341450263648464, 0.546320421837542, -0.478030369107849, 0.136580105459385,
-0.887770685486005, -0.273160210918771, -0.273160210918771, -0.478030369107849,
-0.478030369107849, 0.75119058002662, -0.682900527296927, -0.0682900527296927,
0.546320421837542, 0.75119058002662, 0.546320421837542, 0.136580105459385,
-0.478030369107849, 0.136580105459385, 0.546320421837542, -0.478030369107849,
-0.0682900527296927, -0.0682900527296927, 0.546320421837542,
-0.273160210918771, 0.136580105459385, -0.0682900527296927, 0.75119058002662,
-0.0682900527296927, 0.546320421837542, -0.887770685486005, -0.0682900527296927,
-0.682900527296927, -0.478030369107849, -0.478030369107849, -0.682900527296927,
0.75119058002662, 0.341450263648464, -0.0682900527296927, 0.341450263648464,
-0.0682900527296927, -0.887770685486005, -0.887770685486005,
-0.273160210918771, -0.0682900527296927, 0.546320421837542, -0.0682900527296927,
-0.0682900527296927, 0.75119058002662, -0.0682900527296927, -0.273160210918771,
-0.478030369107849, 0.546320421837542, 0.546320421837542, 0.546320421837542,
0.341450263648464, 0.136580105459385, -0.478030369107849, 0.136580105459385,
0.136580105459385, 0.136580105459385, -0.478030369107849, -0.273160210918771,
-0.273160210918771, -0.273160210918771, 0.341450263648464, -0.273160210918771,
-0.0682900527296927, 0.136580105459385, 0.546320421837542, -0.478030369107849,
-0.273160210918771, 0.546320421837542, 0.546320421837542, -0.273160210918771,
-0.0682900527296927, 0.341450263648464, 0.546320421837542, -0.0682900527296927,
0.136580105459385, -0.478030369107849, 0.75119058002662, -0.478030369107849,
-0.682900527296927, -0.478030369107849, 0.136580105459385, -0.273160210918771,
-0.0682900527296927, -0.887770685486005, -0.887770685486005,
0.546320421837542, -0.273160210918771, 0.546320421837542, -0.478030369107849,
0.546320421837542, -0.0682900527296927, 0.75119058002662, -0.273160210918771,
0.546320421837542, 0.341450263648464, -0.0682900527296927, -0.0682900527296927,
-0.0682900527296927, -0.887770685486005, 0.136580105459385, -0.273160210918771,
-0.478030369107849, 0.75119058002662, 0.341450263648464, 0.546320421837542,
-0.273160210918771, 0.546320421837542, 0.75119058002662, -0.273160210918771,
0.75119058002662, 0.546320421837542, -0.273160210918771, -0.273160210918771,
0.75119058002662, -0.273160210918771, -0.0682900527296927, 0.136580105459385,
-0.478030369107849, 0.75119058002662, 0.75119058002662, -0.887770685486005,
-0.887770685486005, 0.546320421837542, -0.682900527296927, -0.887770685486005,
0.136580105459385, 0.75119058002662, 0.75119058002662, -0.478030369107849,
0.136580105459385, 0.75119058002662, -0.273160210918771, -0.682900527296927,
-0.273160210918771, 0.136580105459385, 0.546320421837542, -0.682900527296927,
-0.478030369107849, 0.136580105459385, -0.682900527296927, -0.0682900527296927,
-0.478030369107849, 0.136580105459385, -0.887770685486005, -0.273160210918771,
-0.0682900527296927, -0.273160210918771, -0.887770685486005,
0.546320421837542, 0.546320421837542, -0.478030369107849, -0.273160210918771,
-0.0682900527296927, 0.136580105459385, -0.478030369107849, 0.75119058002662,
0.341450263648464, 0.136580105459385, 0.136580105459385, 0.75119058002662,
0.136580105459385, -0.0682900527296927, 0.546320421837542, -0.0682900527296927,
-0.887770685486005, 0.75119058002662, 0.75119058002662, 0.546320421837542,
-0.887770685486005, -0.0682900527296927, -0.682900527296927,
-0.682900527296927, 0.75119058002662, 0.75119058002662, -0.478030369107849,
0.546320421837542, -0.273160210918771, 0.75119058002662, -0.0682900527296927,
0.546320421837542, -0.0682900527296927, -0.273160210918771, 0.546320421837542,
0.75119058002662, -0.0682900527296927, 0.546320421837542, -0.682900527296927,
-0.273160210918771, -0.0682900527296927, -0.478030369107849,
-0.478030369107849, 0.136580105459385, -0.273160210918771, 0.136580105459385,
0.546320421837542, 0.75119058002662, -0.273160210918771, 0.341450263648464,
-0.273160210918771, 0.136580105459385, 0.546320421837542, 0.546320421837542,
0.136580105459385, 0.136580105459385, -0.682900527296927, 0.341450263648464,
0.341450263648464, -0.273160210918771, -0.682900527296927, -0.0682900527296927,
0.75119058002662, -0.887770685486005, -0.478030369107849, -0.273160210918771,
-0.478030369107849, -0.478030369107849, 0.136580105459385, -0.478030369107849,
0.136580105459385, -0.478030369107849, 0.136580105459385, -0.0682900527296927,
-0.273160210918771, 0.136580105459385, 0.341450263648464, -0.478030369107849,
0.75119058002662, 0.136580105459385, 0.341450263648464, 0.546320421837542,
-0.887770685486005, 0.75119058002662, 0.341450263648464, -0.0682900527296927,
-0.478030369107849, 0.546320421837542, 0.136580105459385, -0.682900527296927,
-0.0682900527296927, 0.341450263648464, -0.478030369107849, -0.0682900527296927,
-0.478030369107849, -0.0682900527296927, 0.341450263648464, -0.478030369107849,
-0.682900527296927, 0.75119058002662, -0.478030369107849, -0.682900527296927,
0.341450263648464, -0.887770685486005, -0.478030369107849, 0.546320421837542,
-0.887770685486005, -0.478030369107849, -0.478030369107849, 0.341450263648464,
0.75119058002662, -0.682900527296927, 0.75119058002662, 0.75119058002662,
0.341450263648464, -0.0682900527296927, 0.546320421837542, -0.0682900527296927,
0.136580105459385, 0.136580105459385, 0.136580105459385, 0.136580105459385,
0.546320421837542, 0.546320421837542, -0.0682900527296927, 0.75119058002662,
-0.0682900527296927, -0.0682900527296927, -0.682900527296927,
-0.273160210918771, -0.682900527296927, -0.478030369107849, 0.136580105459385,
0.75119058002662, 0.546320421837542, 0.341450263648464, -0.887770685486005,
-0.0682900527296927, 0.136580105459385, 0.75119058002662, -0.273160210918771,
-0.682900527296927, 0.136580105459385, -0.478030369107849, -0.273160210918771,
-0.273160210918771, 0.136580105459385, 0.341450263648464, -0.478030369107849,
-0.0682900527296927, -0.682900527296927, 0.75119058002662, -0.273160210918771,
-0.478030369107849, -0.0682900527296927, -0.0682900527296927,
-0.273160210918771, -0.0682900527296927, -0.478030369107849,
0.75119058002662, -0.0682900527296927, 0.136580105459385, 0.546320421837542,
0.546320421837542, -0.478030369107849, -0.273160210918771, 0.546320421837542,
-0.478030369107849, -0.682900527296927, 0.75119058002662, -0.0682900527296927,
-0.682900527296927, -0.682900527296927, 0.75119058002662, 0.341450263648464,
-0.478030369107849, 0.75119058002662, 0.136580105459385, -0.887770685486005,
0.341450263648464, 0.341450263648464, 0.546320421837542, -0.273160210918771,
0.136580105459385, 0.75119058002662, -0.0682900527296927, -0.682900527296927,
-0.478030369107849, -0.478030369107849, 0.75119058002662, 0.546320421837542,
-0.478030369107849, 0.546320421837542, 0.136580105459385, -0.887770685486005,
0.75119058002662, -0.0682900527296927, 0.75119058002662, 0.75119058002662,
-0.273160210918771, -0.682900527296927, 0.546320421837542, 0.546320421837542,
-0.887770685486005, 0.75119058002662, -0.273160210918771, 0.546320421837542,
-0.0682900527296927, 0.136580105459385, 0.341450263648464, -0.478030369107849,
0.136580105459385, 0.136580105459385, -0.273160210918771, 0.546320421837542,
-0.273160210918771, -0.273160210918771, -0.273160210918771, 0.75119058002662,
-0.887770685486005, -0.887770685486005, -0.0682900527296927,
-0.478030369107849, -0.0682900527296927, 0.75119058002662, -0.273160210918771,
0.136580105459385, -0.478030369107849, -0.273160210918771, 0.136580105459385,
0.75119058002662, 0.546320421837542, -0.478030369107849, -0.273160210918771,
-0.273160210918771, 0.136580105459385, -0.273160210918771, -0.0682900527296927,
0.75119058002662, 0.136580105459385), resp.var = c(2L, 1L, 0L,
1L, 0L, 0L, 0L, 0L, 0L, 1L, 3L, 1L, 0L, 1L, 0L, 1L, 2L, 0L, 1L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 2L,
1L, 0L, 0L, 0L, 0L, 0L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 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L,
37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L,
37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L,
37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L,
37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L,
37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L,
37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L,
37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L,
37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L,
37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L,
37L, 37L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L,
43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L,
43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L,
43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L,
43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L,
43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L,
43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L,
43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L,
43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L,
43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L,
43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L)), .Names = c("cat.var",
"cont.var", "resp.var", "rand.eff"), row.names = c(NA, 500L), class = "data.frame")

最佳答案

这是各种答案(顺便说一下,您在上面的数据框中缺少一些引号,必须手动修复...)

拟合模型:

library(lme4)
fit <- glmer(resp.var ~ cont.var:cat.var + (1|rand.eff) ,
data = sample.data , poisson)

(请注意,这是一个有点奇怪的模型规范 - 强制所有类别在 cont.var==0 处具有相同的值。您的意思是 cont.var*cat.var 吗?
library(ggplot2)
theme_update(theme_bw()) ## set white rather than gray background

快速而肮脏的线性回归:
ggplot(sample.data,aes(cont.var,resp.var,linetype=cat.var))+
geom_smooth(method="lm",se=FALSE)

现在使用泊松 GLM(但不包含随机效应),并显示数据点:
ggplot(sample.data,aes(cont.var,resp.var,colour=cat.var))+
stat_sum(aes(size=..n..),alpha=0.5)+
geom_smooth(method="glm",family="poisson")

下一位需要 lme4 的开发(r-forge)版本,其中有一个 predict方法:

设置数据框进行预测:
predframe <- with(sample.data,
expand.grid(cat.var=levels(cat.var),
cont.var=seq(min(cont.var),
max(cont.var),length=51)))

在人口水平 ( REform=NA ),在线性预测变量 (logit) 尺度上进行预测(这是您在绘图上获得直线的唯一方法)
predframe$pred.logit <- predict(fit,newdata=predframe,REform=NA)

minmaxvals <- range(sample.data$cont.var)

ggplot(predframe,aes(cont.var,pred.logit,linetype=cat.var))+geom_line()+
geom_point(data=subset(predframe,cont.var %in% minmaxvals),
aes(shape=cat.var))

enter image description here
现在在响应量表上:
predframe$pred <- predict(fit,newdata=predframe,REform=NA,type="response")
ggplot(predframe,aes(cont.var,pred,linetype=cat.var))+geom_line()+
geom_point(data=subset(predframe,cont.var %in% minmaxvals),
aes(shape=cat.var))

enter image description here

关于R:具有连续变量和分类变量的 GLMM 交互图 (lme4),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10457756/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com