I'm having trouble plotting random intercepts from a clmm()
model with 4 random effects in 31 countries.
I tried following this SO post: In R, plotting random effects from lmer (lme4 package) using qqmath or dotplot: how to make it look fancy? However, I cannot get the confidence intervals to show up. I've managed to use dotchart
to plot the intercepts by country.
library(ggplot2)
library(ordinal)
# create data frame with intercepts and variances of all random effects
# the first column are the grouping factor, followed by 5 columns of intercepts,
# columns 7-11 are the variances.
randoms <- as.data.frame(ranef(nodual.logit, condVar = F))
var <- as.data.frame(condVar(nodual.logit))
df <- merge(randoms, var, by ="row.names")
# calculate the CI
df[,7:11] <- (1.96*(sqrt(df[,7:11])/sqrt(length(df[,1]))))
# dot plot of intercepts and CI.
p <- ggplot(df,aes(as.factor(Row.names),df[,2]))
p <- p + geom_hline(yintercept=0) +
geom_errorbar(aes(xmax=df[,2]+df[,7], xmin=df[,2]-df[,7]), width=0, color="black") +
geom_point(aes(size=2))
p <- p + coord_flip()
print(p)
Error: Discrete value supplied to continuous scale
Here is another way I tried to plot them:
D <- dotchart(df[,2], labels = df[,1])
D <- D + geom_errorbarh(aes(xmax=df[,2]+df[,7], xmin=df[,2]-df[,7],))
Error in dotchart(df[, 2], labels = df[, 1]) + geom_errorbarh(aes(xmax = df[, : non-numeric argument to binary operator