我想使用 P(见下文)在 (0, 10) 上的 100 个相等点处估计 X 和 Y(来自数据 m)之间的关系。我如何使用 R 来做到这一点?
> m
X Y
1 0.5 6.0
2 1.5 5.0
3 2.5 6.7
4 3.5 7.1
5 4.5 6.1
6 5.5 8.1
7 6.5 8.0
8 7.5 7.9
9 8.5 8.0
10 9.5 6.0
(1)
P=function(x,X,Y,sigma){
# x = point to evaluate our estimate.
# X = vector of observation X values
# Y = vector of observation Y values
# sigma = standard deviation.
weights = rep(0,length(X))
sumweights = 0
smooth = 0
for(i in 1:length(X)){
weights[i] = dnorm(x,mean=X[i],sd=sigma)
sumweights = sumweights + weights[i]
smooth = smooth + weights[i]*Y[i]
}
return( smooth/sumweights )
}