[R] Forcing a variableinto a model using stepAIC
ccleland at optonline.net
Fri May 22 16:19:49 CEST 2009
On 5/22/2009 9:58 AM, Laura Bonnett wrote:
> Dear All,
> I am attempting to use forward and/or backward selection to determine
> the best model for the variables I have. Unfortunately, because I am
> dealing with patients and every patient is receiving treatment I need
> to force the variable for treatment into the model. Is there a way to
> do this using R? (Additionally, the model is stratified by
> randomisation period). I know that SAS can be used to do this but my
> SAS coding is poor and consequently it would be easier for me to use
> R, especially given the fractional polynomial transformations!
> Currently the model is as follows (without treatment).
> Thank you for your help,
See the scope argument to stepAIC in the MASS package. You can
specify a formula in the 'lower' component of scope which includes the
treatment variable. That will force the treatment variable to remain in
every model examined in the stepwise search.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894
More information about the R-help