Skip to content

Instantly share code, notes, and snippets.

@wkmor1
Last active December 19, 2015 20:59
Show Gist options
  • Save wkmor1/6017380 to your computer and use it in GitHub Desktop.
Save wkmor1/6017380 to your computer and use it in GitHub Desktop.
plot variance components from a GLMM fit in JAGS
plot.vc <-
function (model, comps, ylabs) {
vc <- matrix(F, ncol=5, nrow=length(comps))
row.names(vc) <- comps
for (i in comps) {
vc[i, ] <- quantile(
eval(parse(text=sprintf('model$BUGSoutput$sims.list$%s', i))),
prob = c(0.025, 0.1587, .5, 0.8413, 0.975))
}
plot.new()
plot.window(xlim=c(0, max(vc) * 1.1), ylim=c(0, length(comps)))
abline(v=0, col='grey75')
segments(vc[, 1], seq_len(length(comps)) - .5, vc[, 5], lwd=2)
segments(vc[, 2], seq_len(length(comps)) - .5, vc[, 4], lwd=4)
points(vc[,3], 1:length(comps) - .5, pch=21, cex=1.2, bg='black')
axis(side=1)
mtext(side=1, text='Standard deviation', line=2.5, cex=.8)
axis(side=2, at=seq_len(length(comps)) - .5, labels=ylabs, las=1, cex.axis=.8)
box()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment