Good afternoon,
I want to create graphs of the predicted probabilities from a multilevel model, which I do with the code below:
jvalues1 <- with(sanctions.data.scaled, seq(from = min(lagtradeshareeu100),
to = max(lagtradeshareeu100), length.out = 100))
pp1 <- lapply(jvalues1, function(j) {tmpdat$lagtradeshareeu100 <- j
predict(multi.sanctions.bust, newdata = tmpdat, type = "response")})
sapply(pp1[c(0, 10, 20, 30, 40, 50, 60, 70, 80)], mean)
plotdat1 <- t(sapply(pp1, function(x) {
c(M = mean(x), quantile(x, c(0.25, 0.75)))
}))
plotdat1 <- as.data.frame(cbind(plotdat1, jvalues1))
colnames(plotdat1) <- c("PredictedProbability", "Lower", "Upper",
"LagTradeShareEU")
head(plotdat1)
ggplot(plotdat1, aes(x = LagTradeShareEU, y = PredictedProbability)) +
geom_line(size = 2, color="red") +
ylim(c(0, .25)) + + geom_linerange(aes(ymin = Lower, ymax = Upper))
The header from plotdat1 is here:
PredictedProbability Lower Upper LagTradeShareEU
1 0.1968789 0.006504205 0.2161600 -2.017769
2 0.1948356 0.006298856 0.2107395 -1.978162
3 0.1928083 0.006099950 0.2054193 -1.938554
4 0.1907968 0.005907288 0.2001993 -1.898947
5 0.1888011 0.005720675 0.1950795 -1.859339
6 0.1868207 0.005539925 0.1900594 -1.819732
My problem is that the confidence intervals seem too large when I add them to the graph; they range from 0 to a few points above the predicted probability. I am guess that because the variables are scaled with a mean of zero that using the mean to generate the quantiles doesn't make sense? Is there another way to do it? I could have them without the confidence intervals, but I am sure that for my article they will be required.
My last question is that I'd like to make sure that the predicted probabilities are using all observed data, and not the mean of the other independent variables, but I can't be sure it is doing that so I thought someone with more of an eye for R code would help.
(edited) Picture of my plot