黄土线绘制不正确 [英] loess line not plotting correctly

查看:75
本文介绍了黄土线绘制不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将黄土平滑度和置信度限制拟合到残差散点图时,我遇到了麻烦.

I'm having trouble fitting a loess smooth plus confidence limits to a scatterplot of residuals.

我的模型是身高〜体重+胸围.为了检查胸围的线性度,我拟合了没有胸围的模型(即身高〜体重),并针对胸围绘制了该模型的残差.到目前为止,一切都很好.然后,我尝试使用loess()predict()绘制一条黄土线以及置信度限制.结果看起来像这样(在图片中,我仅绘制了中心线,但CI线看起来相同):

My model is height ~ weight + chest circumference. To check linearity of chest circumference, I've fitted a model without chest circumference (i.e. height ~ weight), and plotted the residuals of this model against chest circumference. So far so good. I then tried to use loess() and predict() to plot a loess line, plus confidence limits. The result looks like this (in the picture I've only plotted the central line, but the CI lines look the same):

散点图中的黄土问题

这些点是正确的(当我将黄土拟合点绘制为看起来正确的点时),但是由于某种原因,该线并未按照我的期望绘制.我的代码如下:

The points are correct (when I plot the loess fit as points it looks right), but for some reason the line is not being drawn how I expect. My code is below:

# bf.red = data set; mod.nch = model; chestc = chest circumference;
# loess = loess model; lo.pred = predict loess

plot(bf.red$chestc           #Chest circumference
 ,residuals(mod.nch))    #Residuals from height ~ weight model

loess <- loess(mod.nch$residuals ~ bf.red$chestc)
lo.pred <- predict(loess, se=T)

lines(bf.red$chestc,lo.pred$fit,pch=2) #Main line
lines(bf.red$chestc,lo.pred$fit+2*lo.pred$s, lty=2) #rough & ready CI
lines(bf.red$chestc,lo.pred$fit-2*lo.pred$s, lty=2)

希望可以为您提供帮助.非常感谢,

Hope you can help. Many thanks,

垫子

推荐答案

lines以它们出现的顺序连接点, 有时是不可取的. 您可以对它们进行如下排序:

lines connects the points in the order in which they appear, which is sometimes undesirable. You can sort them as follows:

i <- order(bf.red$chestc)
lines(bf.red$chestc[i], lo.pred$fit[i])
...

这篇关于黄土线绘制不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆