[R] Setting constraints in the glm package

Ravi Varadhan rvaradhan at jhmi.edu
Tue Oct 26 18:34:59 CEST 2010


We can further generalize this:

Suppose we want to constrain parameters such that :

b2 = a * b1

b3 = a * b1

We can do the following:

fit.a <- glm( y ~ I(x1 + a* x2 + a * x3),  data= ....   , ... )

For a fixed value of `a', we compute the log-likelihood of `fit.a'.  This is the profile likelihood in terms of a.  We then maximize this over `a' .  We can use, for example, `optimize' to accomplish this.

This is not contrived.  I have encountered this situation in a project.

Ravi.
____________________________________________________________________

Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619
email: rvaradhan at jhmi.edu


----- Original Message -----
From: David Winsemius <dwinsemius at comcast.net>
Date: Tuesday, October 26, 2010 11:21 am
Subject: Re: [R] Setting constraints in the glm package
To: "Viechtbauer Wolfgang (STAT)" <wolfgang.viechtbauer at maastrichtuniversity.nl>
Cc: "r-help at r-project.org" <r-help at r-project.org>, 'David Smith' <dreamworks1 at hotmail.co.uk>


>  On Oct 26, 2010, at 7:50 AM, Viechtbauer Wolfgang (STAT) wrote:
>  
>  >The constraint b1=b2 in a model such as b0 + b1 x1 + b2 x2 + b3 x3 
> implies that b0 + b1 (x1 + x2) + b3 x3, so just add x1 and x2 (call 
> this x12) and fit the model b0 + b1 x12 + b3 x3 and you have imposed 
> the constraint that b1=b2. To impose the constraint that b3=0, just 
> fit the model without variable x3 in it.
>  >
>  
>  It may be more convenient to do the addition within a formula without 
> first calculating x12 :
>  
>  glm( y ~ I(x1+x2), data= ....   , ... )
>  
>  And the offset argument is available for constraints of the form b3 = 
> <non-zero-constant>.
>  
>  -- 
>  David
>  
>  >Best,
>  >
>  >--
>  >Wolfgang Viechtbauer
>  >Department of Methodology and Statistics
>  
>  >----Original Message----
>  
>  >On Behalf Of David Smith Sent:
>  >Tuesday, October 26, 2010 12:24 To: r-help at r-project.org
>  >Subject: [R] Setting constraints in the glm package
>  >
>  >>Hi,
>  >>
>  >>I would like to set a constraint on the fixed effect estimates in a
>  >>GLM model, such as b1=b2. Is this possible in the glm package?
>  >>Similarly I would like to set some to equal zero too. I have tried
>  >>searching the information with this package, but I can't find
>  >>anything for this.
>  
>  ______________________________________________
>  R-help at r-project.org mailing list
>  
>  PLEASE do read the posting guide 
>  and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list