# [R] smoothing binary data

Bill Oliver wloliver at qwest.net
Tue Dec 12 20:24:43 CET 2000

```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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```