[R] using GAM to assess the linearity in logistic regression

John Fox jfox at mcmaster.ca
Sat Apr 2 15:08:37 CEST 2005


Dear ronggui,

There are several approaches you can take, one of which is to fit a GAM and
simply look to see whether the relationships appear linear on the logit
scale. As well, you could compare the fit of the GAM with semiparametric
models in which each smooth term in turn is replaced by a linear term; see
?anova.gam in the mcgv or gam package and the on-line appendix on
nonparametric regression to my R and S-PLUS Companion to Applied Regression
(at
http://socserv.socsci.mcmaster.ca/jfox/Books/Companion/appendix-nonparametri
c-regression.pdf, and slightly out of date).

Another approach is to fit the linear logit model with glm() and examine
component+residual (partial-residual) plots via the cr.plots() function or
the ceres.plots() function, both in the car package. 

If nonlinearity in, say, x is correctable by a power transformation, you can
get an approximate score test for the need to transform x by adding the
"constructed variable" I(x*log(x)) to the model and examining its Wald
statistic; an added-variable plot (av.plots in car) for the constructed
variable shows leverage and influence on the decision to transform x. You
can also compute a suggested power transformation as p = 1 - b/g, where b is
the coefficient of x in the *original* model and g that of the constructed
variable. Details are in the R and S-PLUS Companion. Some further examples
are in lecture notes at
http://socserv.socsci.mcmaster.ca/jfox/Courses/soc740/lecture-11.pdf.

If x is quantitative but discrete, refitting the logit model replacing x
with as.factor(x) and comparing via anova() to the original model gives a
test of nonlinearity.

I hope this helps,
 John

--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
-------------------------------- 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of ronggui
> Sent: Friday, April 01, 2005 10:19 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] using GAM to assess the linearity in logistic regression
> 
> as agresti(2002) points out that we had better to screen the 
> data to see if the the logit(pi) and the predictor has linear 
> realtionship in logistic regressin.and i find some materials  
> in MASS and the refernce of s-plus.but it is a bit  simple 
> and i can not exactly master the means to assess the 
> linearity in logistic regression. so anyone suggest some materials?
> 
> i am not familiar with GAM,but i think thers maybe some 
> materials can let me use GAM to assess the linearity in 
> logistic regression without master GAM model. is it right?
> 
> thank you!
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html




More information about the R-help mailing list