# MAXIMUM LIKELIHOOD ESTIMATION FOR POISSON DATA WITH ZEROS UNOBSERVED. # # Implements the three methods discussed in lecture. For all three functions, # the arguments are the vector of observations, the number of iterations to # do, and the initial guess (defaulting to the sample mean). The result is # the vector of values found after each of the iterations - the last of which # is the final guess at the MLE. # SIMPLE ITERATION. nzp.simple <- function (n, r, m0=mean(n)) { mean.n <- mean(n) mvec <- rep(0,r) m <- m0 for (i in 1:r) { m <- mean.n * (1 - exp(-m)) mvec[i] <- m } mvec } # NEWTON-RAPHSON ITERATION. nzp.newton <- function (n, r, m0=mean(n)) { mean.n <- mean(n) mvec <- rep(0,r) m <- m0 for (i in 1:r) { e <- exp(-m) m <- m - (mean.n/m - 1/(1-e)) / (e/(1-e)^2 - mean.n/m^2) mvec[i] <- m } mvec } # THE METHOD OF SCORING. nzp.mos <- function (n, r, m0=mean(n)) { mean.n <- mean(n) mvec <- rep(0,r) m <- m0 for (i in 1:r) { e <- exp(-m) m <- m - (mean.n/m - 1/(1-e)) / ((e/(1-e) - 1/m) / (1-e)) mvec[i] <- m } mvec }