Columbine Caroline Waring
2010-Nov-16 11:56 UTC
[R] Offset in glm poisson using R vs Exposure in Stata
R-helpers, I am hoping to find someone who uses both R and program Stata for GLMs. I am a beginner R user, finding my own way through; learning code etc. at the same time as learning the statistics I need to complete my project. What I have is the code from Stata and am trying to reproduce the same analysis in R - my program of choice. . glm count md ms rf sg, family(poisson) exposure(effort) eform I am lost at the point of finding the equivalent code for 'exposure'. Having looked at a few forums and 'googled'. I thought 'offset', used as offset=(log(Eff)) or the equivalent +offset(log(Eff)) would produce the desired effect. Incidentally my code was: glm(Count~md+ms+rf+sg+offset(Eff),family=poisson,data=DepthHabGen) (Making use of glm{stats}) However, offset does not seem to be equivalent to 'exposure' in Stata. As coefficients and log likelhood estimates differ. So I asked the following questions: 1. Do both programs produce the same results without 'exposure' i.e. glm models Yes, log likelihoods and coefficients are the same. 2. How about using the unintuitive non logged " offset=Eff" ? Coefficients and log likelihoods still differ. So now I defer to those with more experience, does anyone know how to produce the equivalent of Stata's glm 'exposure' in R? Thank you in advance, Columbine [[alternative HTML version deleted]]
Columbine Caroline Waring <caquilegia <at> hotmail.com> writes:> I am hoping to find someone who uses both R and program Stata for GLMs.[snip]> What I have is the code from Stata and am trying to reproduce the sameanalysis in R - my program of choice.> > . glm count md ms rf sg, family(poisson) > exposure(effort) eform > > I am lost at the point of finding the equivalent code for 'exposure'. > > Having looked at a few forums and 'googled'. I thought 'offset', used asoffset=(log(Eff)) or the> equivalent +offset(log(Eff)) would produce the desired effect. > > Incidentally my code was:glm(Count~md+ms+rf+sg+offset(Eff),family=poisson,data=DepthHabGen)> > (Making use of glm{stats}) >Based on your discussion above did you mean glm(count~md+ms+rf+sg+offset(log(Eff)), family=poisson,data=DepthHabGen) ? is this just a typo ? according to http://www.stata.com/help.cgi?glm exposure(varname) include ln(varname) in model with coefficient constrained to 1 offset(varname) include varname in model with coefficient constrained to 1> However, offset does not seem to be equivalent to 'exposure' in Stata. Ascoefficients and log likelhood> estimates differ. > > So I asked the following questions: > > 1. Do both programs produce the same results without > 'exposure' i.e. glm models > > Yes, log likelihoods and coefficients are the same. > > 2. How about using the unintuitive non logged " offset=Eff" ? > > Coefficients and log likelihoods still differ.You're not doing anything obviously wrong. Are you sure your "effort" and "Eff" variables are the same, i.e. nothing got mangled moving to R? I don't use Stata, perhaps someone else can try. Posting a small reproducible example would be helpful.