I am using the book "Generalized Linear Models and Extension" by Hardin and Hilbe (second edition, 2007) at the moment. The authors suggest that instead of OLS models, "the log link is generally used for response data that take only positive values on the continuous scale". Of course they also suggest residual plots to check whether a "normal" linear model using an identity link can still be used.
I am trying to replicate in R what they do in the book in STATA. Indeed, I have no problems in STATA with the log link. However, when calling the same model using R's glm-function, but specifying family=gaussian(link="log")
I am asked to provide starting values. When I set them all equal to zero, I always get the message that the algorithm did not converge. Picking other values the message is sometimes the same, but more often I get:
Error in glm.fit(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, :
NA/NaN/Inf in 'x'
As I said, in STATA I can run these models without setting starting values and without errors. I tried many different models, and different datasets, but the problem is always the same (unless I only include one single independent variable). Could anyone tell me why this is the case, or what I do wrong, or why the suggested models from the book might not be appropriate? I'd appreciate any help, thanks!
Edit: As an example which reproduces the error consider the dataset which can be downloaded here. With this dataset loaded, I run the following model:
mod <- glm(betaplasma ~ age + vituse, family=gaussian(link="log"), data=data2, start=c(0,0,0))
This produces the the warning message that the algorithm did not converge.
Edit2: I was asked to also provide the STATA output for that model. Here it is:
. glm betaplasma age vituse, link(log)
Iteration 0: log likelihood = -2162.1385
Iteration 1: log likelihood = -2096.4765
Iteration 2: log likelihood = -2076.2465
Iteration 3: log likelihood = -2076.2244
Iteration 4: log likelihood = -2076.2244
Generalized linear models No. of obs = 315
Optimization : ML Residual df = 312
Scale parameter = 31384.51
Deviance = 9791967.359 (1/df) Deviance = 31384.51
Pearson = 9791967.359 (1/df) Pearson = 31384.51
Variance function: V(u) = 1 [Gaussian]
Link function : g(u) = ln(u) [Log]
AIC = 13.20142
Log likelihood = -2076.224437 BIC = 9790173
------------------------------------------------------------------------------
| OIM
betaplasma | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
age | .0056809 .0032737 1.74 0.083 -.0007354 .0120972
vituse | -.273027 .0650773 -4.20 0.000 -.4005762 -.1454779
_cons | 5.467577 .2131874 25.65 0.000 5.049738 5.885417
------------------------------------------------------------------------------
glm
may well be more fragile than Stata's glm-fitting code, but I have used a log link successfully many times in the past. Can you post a reproducible example [ tinyurl.com/reproducible-000 ] ? – Mayweed