我正在尝试使用 ggplot2 绘制负二项式回归的预测值,一个打开二进制变量,另一个关闭它。所以会有两个可以比较的两个地块。
此处的链接演示了如何在页面底部执行此操作,但我希望能够使用稳健的标准误差在预测值的图周围创建阴影。我看不出如何从 predict() 函数中得到这个。此代码示例是否有任何解决方法来获得强大的标准错误以在绘制的线周围进行阴影处理?
我使用此站点的代码来生成可靠的标准错误:
require(sandwich)
cov.nb1 <- vcovHC(nb1, type = "HC0")
std.err <- sqrt(diag(cov.nb1))
r.est <- cbind(Estimate = coef(nb1), `Robust SE` = std.err, `Pr(>|z|)` = 2 *
pnorm(abs(coef(nb1)/std.err), lower.tail = FALSE), LL = coef(nb1) - 1.96 *
std.err, UL = coef(nb1) + 1.96 * std.err)
r.est
我使用的模型是这样的:
nb1 <- glm.nb(citecount ~ expbin*novcr + expbin*I(novcr^2) + disease + length +
as.factor(year), data = nov4d.dt)
我正在使用的数据样本是这样的:
nov4d.dt <-
structure(list(PMID = c(1279136L, 1279186L, 1279186L, 1279187L,
1279187L, 1279190L, 1279257L, 1279317L, 1279332L, 1279523L),
min = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), max = c(32L,
32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L), mean = c(11L,
13L, 13L, 19L, 19L, 16L, 24L, 15L, 8L, 19L), length = c(45L,
120L, 120L, 78L, 78L, 136L, 45L, 36L, 171L, 78L), threslength = c(13L,
20L, 20L, 7L, 7L, 26L, 4L, 6L, 77L, 14L), novlength = c(5L,
6L, 6L, 3L, 3L, 6L, 3L, 3L, 36L, 5L), novind = c("TRUE",
"TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE",
"TRUE"), novcr = c(0.111111, 0.05, 0.05, 0.0384615, 0.0384615,
0.0441176, 0.0666667, 0.0833333, 0.210526, 0.0641026), novcrt = c(0.288889,
0.166667, 0.166667, 0.0897436, 0.0897436, 0.191176, 0.0888889,
0.166667, 0.450292, 0.179487), year = c(1991L, 1991L, 1992L,
1992L, 1992L, 1992L, 1992L, 1992L, 1991L, 1992L), disease = structure(c(1L,
4L, 2L, 4L, 2L, 1L, 4L, 4L, 2L, 4L), .Label = c("alz", "bc",
"cl", "lc"), class = "factor"), citecount = c(5L, 8L, 8L,
12L, 12L, 0L, 1L, 0L, 92L, 0L), novind2 = c(TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE), rad = c(FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
), exp = c(260, 351, 351, 65, 65, 480, 104, 273, 223, 0),
novind4 = c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, TRUE, FALSE), novind5 = c(FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, TRUE, FALSE), novind6 = c(FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
), expbin = c(TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, FALSE,
TRUE, TRUE, FALSE), expbin2 = c(TRUE, TRUE, TRUE, FALSE,
FALSE, TRUE, FALSE, TRUE, TRUE, FALSE)), .Names = c("PMID",
"min", "max", "mean", "length", "threslength", "novlength", "novind",
"novcr", "novcrt", "year", "disease", "citecount", "novind2",
"rad", "exp", "novind4", "novind5", "novind6", "expbin", "expbin2"
), sorted = "PMID", class = c("data.frame"), row.names = c(NA,
-10L))