我想制作一个交互图,从回归模型的结果中直观地显示分类变量(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, 1L, 3L, 1L, 3L, 4L, 2L, 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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, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 2L,
0L, 3L, 2L, 0L, 2L, 2L, 0L, 0L, 0L, 1L, 1L, 3L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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, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 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")
答案 0 :(得分:14)
以下是各种答案(顺便说一句,您上面的数据框中有一些缺少的引号,必须手动修复...)
适合模特:
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)
现在使用Poisson 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))
现在在响应规模上:
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))
答案 1 :(得分:3)
jtools
包(CRAN link)可以使这种模型的绘图非常简单。我是该软件包的开发者。
我们将像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"
)。
答案 2 :(得分:1)