Reputation: 870
I'm trying to fit a loess line on a scatterplot of a binary outcome variable with a continuous predictor variable.
Here is the code I am using:
lw1<-loess(y~x, data=df)
plot(y~x, data=df, pch=19, cex=0.1)
lines(df$x, lw1$fitted, col='blue')
and this is the graph I get: !https://bitbucket.org/heatherjbaldwin/akos_open/src/ec2a78d093e6cdf988434c03c1b7c7df145892ba/loessgraph1.png?at=master
I also tried ordering the x variable:
j<-order(df$x)
lines(df$x[j], lw1$fitted, col='blue')
And get this graph: !https://bitbucket.org/heatherjbaldwin/akos_open/src/ec2a78d093e6cdf988434c03c1b7c7df145892ba/loessgraph2%28ordered_x%29.png?at=master
Here is the data: https://bitbucket.org/heatherjbaldwin/akos_open/src/ec2a78d093e6cdf988434c03c1b7c7df145892ba/loesscurvedata.txt?at=master
Any help is much appreciated.
Upvotes: 0
Views: 2733
Reputation: 121578
Using ggplot2
and a loess
smoother I get this :
ggplot(data=dat,aes(x,y)) +
geom_line() +
geom_smooth(method='loess')
But I think your a looking for a classifier here.
Upvotes: 1