[R] smoothing binary data

Bill Oliver wloliver at qwest.net
Thu Dec 14 19:26:44 CET 2000

Thank you *very* much for your help. The package (mgcv) you have written is
wonderful. Following your suggestion, I'm using the code below to produce
the plot I was trying to generate. However, the default plot your package
generates is better. -Bill


b<-gam(low~s(age,4|f),family=binomial()) # 4 knot regression spline

x <- as.numeric(b$x); ord <- order(x)
x <- x[ord]; y <- fitted(b)[ord]
plot(x,y,xlab="Age of Mother (yrs)",
     ylab="Prob. of Low Birth Weight",ylim=c(0,1),type='l')
rug(jitter(age[low==1], amount = 1), side = 3)

----- Original Message -----
From: "Simon Wood" <snw at mcs.st-and.ac.uk>
To: "Bill Oliver" <wloliver at qwest.net>
Cc: <r-help at stat.math.ethz.ch>
Sent: Thursday, December 14, 2000 3:35 AM
Subject: Re: [R] smoothing binary data

You could also try the gam function in package mgcv (latest version
0.3-2). The following uses a penalized regression spline and chooses the
degrees of freedom by GCV:

> library(MASS)
> data(birthwt)
> attach(birthwt)
> library(mgcv)
> gam(low~s(age),family=binomial())

Family: binomial
Link function: logit

low ~ s(age)

Estimated degrees of freedom:

Alternatively, if you want more control over the degrees of freedom then
you could use an un-penalized regression spline (although these don't
give such "nice" smooths):

> b<-gam(low~s(age,4|f),family=binomial()) # 4 knot regression spline
> plot(b)


> Simon Wood  snw at st-and.ac.uk  http://www.ruwpa.st-and.ac.uk/simon.html
> The Mathematical Institute, North Haugh, St. Andrews, Fife KY16 9SS UK
> Direct telephone: (0)1334 463799          Indirect fax: (0)1334 463748

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list