# Link functions and fitting models to data with mle2 in bbmle

I'm fitting models to data with the mle2() function in the bbmle package.

In an example problem (reproducible code below) I am fitting a count response variable to a single predictor with a linear relationship (polar bears, PB, and fraction of coastline filled with sea ice, Ice). I created a simulated dataset by sampling from a Poisson distribution for polar bears using a linear function of sea ice and an intercept and then fit the model with mle2(). Since this is a linear model I can fit the same model with glm(), of course. The two approaches (glm and mle2) provide identical results only if one uses the identity link function, rather than the (canonical) log link (or any other link).

My question is: should I be using a log link in the mle2() fitting (and appropriate link functions for other distributions) when using mle2()?

I understand that fitting non-Gaussian glm() models often uses iterated weighted least squares, and that canonical link functions often translate the expected value of the linear model onto the -infinity to +infinity range (e.g. a log link takes a distribution that ranges from 0 to +infinity and translates it to -infinity to +infinity), and so I can see how a link function would aid in the fitting process. However, I wouldn’t have thought there was anything wrong with the mle2() fit, which is equivalent to using the identity link. But given that using glm() with the canonical link and mle2() produce different answers I'm uncertain about which one is preferred and why. Thank you. marm

## Reproducible example

require(bbmle)
set.seed(67)
Ice=runif(20,0,1); PB=rpois(20,lambda=20+50*Ice);plot(PB~Ice)
d=data.frame(PB=PB,Ice=Ice)
F1=mle2(PB~dpois(lambda=c0+c1*Ice),start=list(c0=10,c1=30),data=d);summary(F1)

F3=glm(PB~Ice,family=poisson(link=identity),data=d);summary(F3) #gives identical results to F1
F4=glm(PB~Ice,family=poisson,data=d);summary(F4) #canonical link - gives different results for predicted values (and obviously for coefs)
points(predict(F3)~Ice,col="blue") #predicted values from identity link or mle2() fit
points(predict(F4,type="response")~Ice,col="red") #predicted values from canonical link - curvature due to log link is apparent in differences from F3 predictions

• I see that this question (and answers) provides a partial answer to the question, so I wanted to link to it: stats.stackexchange.com/questions/203355/… – Marm Kilpatrick May 23 '18 at 1:59
• See this thread for further insights. stats.stackexchange.com/questions/141181/…. Also, the glmx package in R allows you to perform goodness-of-link tests. – Isabella Ghement May 23 '18 at 2:32
• Is your goal to reproduce the output of glm using a different R function? Or are you asking how/why to select a particular link function for this data analysis? – AdamO Jun 4 '18 at 19:45
• My goal was to understand when/whether a link function (other than an identity link) is really needed - i.e. is there something incorrect about using an identity link? - or if non-identity links are more a mathematical/statistical convenience that is helpful, for example, in constraining the response range, or in fitting a non-linearity in the response-predictor relationship. – Marm Kilpatrick Jun 5 '18 at 20:10
• The answer of this question shows how to code a log link Poisson model using mle2: stackoverflow.com/questions/45300955/… That should solve the discrepancy! – Tom Wenseleers Apr 27 '19 at 14:59