Re: GeneralizedLinearModelFit and offsert for poisson
- To: mathgroup at smc.vnet.net
- Subject: [mg113044] Re: GeneralizedLinearModelFit and offsert for poisson
- From: Darren Glosemeyer <darreng at wolfram.com>
- Date: Tue, 12 Oct 2010 04:24:47 -0400 (EDT)
On 10/9/2010 5:33 AM, Ester Vilapriny=F3 wrote: > Hello, I would like to solve a poisson regression with the > GeneralizedLinearModelFit function. > I have a matrix with the following form: > > {{x11,x12, x13, y1}, > {x21,x22, x23, y2}, > ... > } > > The GeneralizedLinearModelFit for an exponential family Poisson will retu= rn > e^(b0+b1 f1+ b2 f2+ b3 f3) > Can I fix that b3==1? > > In my case y refers to death counts and x3 to population. In other > programs such as Stata this would be solved by offset(x3). I tried to > solve this using LinearOffsetFunction but I did not succeed with the > following steps: 1) created a new matrix for data == {{x11,x12, > y1},{x21,x22, y2},...}. 2) Create a function that will return the offset > for each input f[x1_,x2_]:==x3 3) > GeneralizedLinearModelFit[data,{x1,x2},{x1,x2},ExponentialFaily->"Poisson= ", > LinearOffsetFunction->(f[#1,#2]&)]. Why it does not work? > > Thanks! > > > The slots (#1, #2, etc.) refer to the predictor variables and LinearOffsetFunction is a function of the predictors, so you will want to include x3 as a predictor variable but not a basis function. Then you can define the offset as #3& to get b3==1. Here is an example: In[1]:== data == Flatten[ Table[{x1, x2, x3, RandomInteger[PoissonDistribution[Exp[.4 + .8 x1 + .15 x2 + x3]]]}, {x1, .1, .5, .05}, {x2, .1, .5, .05}, {x3, .1, .5, .05}], 2]; In[2]:== GeneralizedLinearModelFit[data, {x1, x2}, {x1, x2, x3}, ExponentialFamily -> "Poisson", LinearOffsetFunction -> (#3 &)] // Normal // InputForm Out[2]//InputForm== E^(0.541887051809523 + 0.6416041403513674*x1 - 0.14021042180307658*x2 + x3) Darren Glosemeyer Wolfram Research