R当存在“混淆”交互时,如何绘制“净互动效应”(或边际效应)

时间:2014-04-27 14:15:22

标签: r plot ggplot2 panel-data

我想在下面的回归中绘制x1和x2之间的交互效果(让y成为面板数据集中的正计数变量)

library(lme4)
glmer.repex<-glmer.nb(y ~ x1 + x2 +I(x2^2) + x1:x2 +x1:I(x2^2) + (1|Year), data=repex, nAGQ = 1L)

简单的互动情节是:

interaction.plot(x1,x2,y) ; interaction.plot(x1,x2,fitted(test.lmer,ndf, type="response"))

现在我要承认,如果x1更改x1*x2的值,x1^2也会更改,这将更改拟合值。在绘制净互动效应时,应考虑所有这些因素。它可能是例如这样x1和x2都与y正相关,但它们的相互作用减弱了这种正面效应,可能会改变预测的方向。这可能另外取决于x1*x2 ...

的值

因此,简单的interaction.plot不再起作用,因为其他变量也会影响结果。 有没有一种简单的方法可以使用predicteffect

执行此操作

这是一个名为repex

的可重现的示例数据集(plm.data对象)

dput(repex) structure(list(ID = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L), .Label = c("1", "2", "4", "6", "7", "8", "9", "10", "11", "13", "15", "16", "17", "18", "20", "22", "24", "26", "28", "29", "32", "34", "35", "36", "37", "39", "41", "42", "44", "47"), class = "factor"), Year = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L), .Label = c("1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006"), class = "factor"), y = c(5, 10, 6, 9, 9, 4, 2, 2, 3, 7, 12, 13, 0, 5, 5, 1, 1, 3, 0, 0, 1, 0, 3, 0, 0, 4, 9, 9, 12, 9, 10, 6, 14, 12, 6, 2, 20, 15, 18, 14, 26, 17, 0, 0, 0, 0, 2, 0, 5, 1, 2, 2, 5, 3, 0, 0, 0, 1, 0, 0), x1 = c(0L, 0L, 3L, 3L, 3L, 5L, 0L, 0L, 0L, 0L, 0L, 3L, 0L, 2L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 2L, 1L, 0L, 0L, 2L, 0L, 2L, 8L, 4L, 1L, 0L, 4L, 2L, 1L, 1L, 1L, 1L, 0L, 1L, 3L, 5L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 1L, 1L, 2L, 6L, 0L, 0L, 1L, 1L, 1L, 0L), x2 = structure(c(4.22657266700715, 7.07828323739468, 5.58155937520987, 6.09945741088926, 4.98990473760187, 13.1975509132969, 0.136363636363636, 0.164922480620155, 0.981640399790555, 1.61119564479727, 4.27951983102512, 4.52440902710094, 2.41282572727806, 2.77748331046807, 7.00223921984389, 3.55837337174436, 5.31590575343992, 2.61930006177923, 0.211351052048726, 0.525647451963241, 0.696630753538187, 0.666082288178836, 1.09492110512526, 3.8035303566375, 0.548336215316966, 0.85237681730237, 0.982747572848003, 6.59758768791534, 8.74094242997363, 9.29913186611362, 3.5542234379174, 3.24728026722101, 3.60927964544638, 3.33459121950297, 2.88526780610146, 4.56612429882729, 26.45256036788, 21.0190838535023, 19.3769702276769, 19.7227148506334, 17.6596029433548, 23.6531530880185, 0.138888888888889, 0.249009205804338, 0.394159544159544, 0.316399286987522, 0.0413533834586466, 3.02315977564407, 3.94214293703149, 1.9143052531528, 3.16707069146414, 5.70642767128218, 4.38285025038957, 4.23425019314604, 0, 0, 0, 0, 0.0416666666666667, 0), .Dim = 60L, .Dimnames = list(c("1990_ABT", "1991_ABT", "1992_ABT", "1993_ABT", "1994_ABT", "1995_ABT", "1990_AKN", "1991_AKN", "1992_AKN", "1993_AKN", "1994_AKN", "1995_AKN", "1990_ALL", "1991_ALL", "1992_ALL", "1993_ALL", "1994_ALL", "1995_ALL", "1990_AMG", "1991_AMG", "1992_AMG", "1993_AMG", "1994_AMG", "1995_AMG", "1990_AZN", "1991_AZN", "1992_AZN", "1993_AZN", "1994_AZN", "1995_AZN", "1990_BAX", "1991_BAX", "1992_BAX", "1993_BAX", "1994_BAX", "1995_BAX", "1990_BAY", "1991_BAY", "1992_BAY", "1993_BAY", "1994_BAY", "1995_BAY", "1990_BIO", "1991_BIO", "1992_BIO", "1993_BIO", "1994_BIO", "1995_BIO", "1990_BMS", "1991_BMS", "1992_BMS", "1993_BMS", "1994_BMS", "1995_BMS", "1990_ABT", "1990_ABT", "1990_ABT", "1990_ABT", "1994_CHU", "1990_ABT")))), .Names = c("ID", "Year", "y", "x1", "x2"), row.names = c(1L, 2L, 3L, 4L, 160L, 5L, 172L, 173L, 174L, 175L, 176L, 177L, 188L, 12L, 190L, 191L, 192L, 13L, 212L, 213L, 214L, 215L, 216L, 217L, 22L, 23L, 230L, 231L, 232L, 233L, 28L, 29L, 30L, 31L, 248L, 249L, 36L, 37L, 38L, 39L, 40L, 41L, 276L, 156L, 52L, 158L, 159L, 281L, 56L, 57L, 58L, 295L, 59L, 297L, 588L, 391L, 392L, 393L, 187L, 395L), class = c("plm.dim", "data.frame"))

谢谢!

0 个答案:

没有答案