I'm trying to figure out a good way to smooth binary data. The ideal approach appears to be the "sm.logit" function in library "sm", but I haven't had success with it. Below, is some code illustrating what I've come up with so far, but I'm hoping there is a better approach. I'm using R 1.2 (development) under Windows 98. -Bill library(MASS) data(birthwt) attach(birthwt) # This doesn't work for me, no matter what h equals # Maybe I'm doing something wrong library(sm) sm.logit(age,low,h=3) # This "works", but controlling the degree of smoothing # is problematic library(gss) logit.fit <- gssanova(low ~ age,family="binomial") est <- predict(logit.fit,data.frame(age=age)) plot(lowess(age,1-1/(1+exp(est))),xlab="Age", ylab="Low Birth Weight",ylim=c(0,1),type='l') rug(jitter(age[low==0],amount=1)) rug(jitter(age[low==1], amount = 1), side = 3) -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 Formula: low ~ s(age) Estimated degrees of freedom: 4.236948 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 ______________________________________________________________________> 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._