################################################################################ # Gamma example # ################################################################################ ################################################################################ # Data set.seed(4869) n <- 30 alpha <- 7/2 beta <- 2 #Chisq(7) y <- rgamma(n = n, shape = alpha, scale = beta) options(width = 60) round(y, 2) ################################################################################ # Likelihood function library(pracma) logL <- function(theta, y) { n <- length(y) alpha <- theta[1] beta <- theta[2] sum(dgamma(x = y, shape = alpha, scale = beta, log = TRUE)) } #At parameter values grad(f = logL, x0 = c(alpha, beta), y = y) #At MLEs – found later in the course grad(f = logL, x0 = c(2.661508, 2.874372), y = y) #At MLEs obs.Fisher.info <- hessian.mat <- hessian(f = logL, x0 = c(2.661508, 2.874372), y = y) -solve(obs.Fisher.info) # #