# Jackknife standard errors for estimates of gamma distribution parameters # Inputs: vector of data values (data) # Outputs: vector with two components, giving standard errors in shape and # scale parameters gamma.jackknife <- function(data) { n <- length(data) # Prepare a matrix to store the re-estimates on partial data jackknifed.ests <- matrix(NA,nrow=2,ncol=n) rownames(jackknifed.ests) = c("a","s") # Omit each point in turn, and do estimation on the rest for (omitted.point in 1:n) { # Presumes gamma.est() exists in this environment and takes a data vector fit <- gamma.est(data[-omitted.point]) # Presumes that gamma.est returns a list of two numbers named "a" and "s" jackknifed.ests["a",omitted.point] <- fit$a jackknifed.ests["s",omitted.point] <- fit$s } # Take the variance of each row of the re-estimates variance.of.ests <- apply(jackknifed.ests,1,var) # Scale up the variances to get the jackknife variance jackknifed.vars <- ((n-1)^2/n)*variance.of.ests # Standard error is the square root of variance jackknifed.stderrs <- sqrt(jackknifed.vars) return(jackknifed.stderrs) }