我有数据(x
和y
值)的散点图。我想计算加权平均值和标准偏差作为 X 的函数。对于我的每个点,我想计算每个值与预测值之间的标准偏差数。我目前正在使用包中的loess.sd
函数,msir
因为它会为我计算 sd。有谁知道我如何获得每个数据点的预测标准差?或者也许有替代或更好的方法来解决这个计算?提前致谢。
我当前的代码:
#... scatter plot of data
plot(xy,ylim=c(0,50),pch=20)
#loess +- 1 sd
std_loess = loess.sd(xy, nsigma =1,span=0.3)
# ... add weighted average to plot
lines(std_loess$x,std_loess$y,col="firebrick2")
# .... add weighted sd to plot
lines(std_loess$x,std_loess$y,col="firebrick2")
#.... get observed data points
lines(std_loess$x,std_loess$upper,col="dodgerblue2")
# ... get expected value for each data point
obs = xy[,2]
# ... get predicted sd for each data point
expected = predict(std_loess$model,data.frame(xy))
# ...get predicted sd for each data point
exp_sd = ??????????????????
# ...get predicted sd for each data point
sd_away = (obs - expected) / exp_sd