5

我想制作一个交互图,以直观地显示回归模型结果中分类变量(4个级别)和标准化连续变量的交互斜率的差异或相似性。

with(GLMModel, interaction.plot(continuous.var, categorical.var, response.var)) 不是我要找的。它会生成一个绘图,其中斜率随连续变量的每个值而变化。我正在寻找一个具有恒定斜率的图,如下图所示:

在此处输入图像描述

有任何想法吗?

我适合以下形式的模型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, 1L, 4L, 1L, 2L, 3L, 4L, 1L, 4L, 
2L, 1L, 3L, 3L, 3L, 4L, 1L, 1L,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 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, 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L, 
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, 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")
4

3 回答 3

16

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

拟合模型:

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")

下一位需要开发(r-forge)版本lme4,它有一个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

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))

在此处输入图像描述 现在在响应量表上:

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))

在此处输入图像描述

于 2012-05-05T14:03:05.237 回答
3

jtools软件包(CRAN 链接)可以使这种模型的绘图非常简单。我是那个包的开发者。

我们将像 Ben 在他的回答中所做的那样拟合模型:

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

jtools我们只需使用这样的函数interact_plot

library(jtools)
interact_plot(fit, pred = cont.var, modx = cat.var)

结果:

默认情况下,它绘制在响应比例上,但您可以使用outcome.scale = "link"参数(默认为"response")将其绘制在线性比例上。

于 2017-10-16T13:51:39.103 回答
1

效果包支持lme4模型,应该能够做你想做的事。

效果:线性、广义线性和其他模型的效果显示

具有线性预测变量的各种统计模型的图形和表格效果显示,例如交互作用。

它还附带了两篇稍微过时的论文(您可以将它们视为小插图)。

于 2015-02-06T21:58:16.353 回答