Skip to content

Instantly share code, notes, and snippets.

@bbolker
Created March 7, 2022 19:29
Show Gist options
  • Select an option

  • Save bbolker/d06320f8c7c3c6d812a86f25e57fbab6 to your computer and use it in GitHub Desktop.

Select an option

Save bbolker/d06320f8c7c3c6d812a86f25e57fbab6 to your computer and use it in GitHub Desktop.
library(emdbook)
set.seed(101)
dd <- rgamma(5, shape = 1, scale = 1)
ff <- function(x,y) -sum(dgamma(dd,shape=x, scale=y, log = TRUE))
ifun <- function(...) {
image(cc$x, cc$y, cc$z, ...)
contour(cc$x, cc$y, cc$z, level = min(cc$z) + 1.92, add = TRUE, label = "")
}
png("gamma_lik.png", width = 800, height = 400)
par(mfrow=c(1,2), las = 1, bty = "l")
cc <- curve3d(ff, xlim = c(0.1, 5.5), ylim = c(0.1,2.25), sys3d = "none", n = 101)
ifun(xlab = "shape", ylab = "scale")
points(1,1, pch=16)
cc <- curve3d(ff(exp(x), exp(y-x)),
xlim = log(c(0.3,8)), ylim = log(c(0.3,2.5)), sys3d = "none", n = 101)
ifun(xlab = "log(shape)", ylab = "log(mean)")
points(0,0, pch=16)
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment