0
我有散點圖的數據(x
和y
值)。我想計算加權平均值和標準差作爲X的函數。對於我的每一個點,我都希望計算每個值與預測值之間的標準偏差數。我目前使用msir
包中的loess.sd
函數,因爲它會爲我計算sd。有誰知道我怎麼能得到每個數據點的預測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