0

我试图在具有连续预测变量的二元结果变量的散点图上拟合一条黄土线。

这是我正在使用的代码:

    lw1<-loess(y~x, data=df) 
    plot(y~x, data=df, pch=19, cex=0.1)
    lines(df$x, lw1$fitted, col='blue')

这是我得到的图表:!https://bitbucket.org/heatherjbaldwin/akos_open/src/ec2a78d093e6cdf988434c03c1b7c7df145892ba/loessgraph1.png?at=master

我还尝试订购 x 变量:

    j<-order(df$x)
    lines(df$x[j], lw1$fitted, col='blue')

并得到这张图:!https://bitbucket.org/heatherjbaldwin/akos_open/src/ec2a78d093e6cdf988434c03c1b7c7df145892ba/loessgraph2%28ordered_x%29.png?at=master

这是数据:https ://bitbucket.org/heatherjbaldwin/akos_open/src/ec2a78d093e6cdf988434c03c1b7c7df145892ba/loesscurvedata.txt?at=master

任何帮助深表感谢。

4

1 回答 1

1

使用ggplot2loess平滑我得到这个:

ggplot(data=dat,aes(x,y)) + 
     geom_line() + 
     geom_smooth(method='loess')

在此处输入图像描述

但我认为你在这里寻找分类器

于 2014-02-14T11:27:06.247 回答