In: Statistics and Probability
Run the following R code (copy and paste) to create some data: out1 <- rep( c(0,0,1), 3 ) out2 <- rep( c(1,0,1), 3 ) counts <- c(18,17,15,20,10,20,25,13,12)
This is a variation on the data in the first example on the “glm” help page in R. The counts variable is our response variable and will be modeled as a Poisson variable, the out1 predictor variable will measure the difference between outcomes 2 (baseline) and 3, and out2 will measure the difference between outcomes 3 and 1.
Fit a Poisson regression to this data using maximum likelihood (use the “optim” function or the “mle” function from the stats4 package or the SAS equivalent) where λ = e β0+β1×out1+β2×out2.
You can get the negative log likelihood using code like: -sum(dpois(count,lambda,log=TRUE)) You can check your parameter estimates by using the “glm” function on the same data (see the help page for “glm”)