gcv选择局部多项式的带宽
K <- function(x) {
0.75 * (1 - x^2) * (abs(x) <= 1)
}
gcvhLL <- function(h,x,y) {
n <- length(x)
S <- matrix(NA,nrow = n,ncol = n)
GCVh <- 0
for (ii in 1:n) {
u=x-x[ii]
Kh=K(u/h)
s1=t(Kh)%%u
s2=t(Kh)%%(u^2)
if(s2 < 0) s2=s2+0.0002
s=sum(Kh*(s2-s1u))
if(s<0.0001) s=s+0.001
weight=as.vector(Kh(s2-s1u)/s)
GCVh=GCVh+(y[ii]-weight%%y)^2
S[ii, ]=weight
}
I=diag(n)
S1=I-S
trace=0
for (j in 1:n) trace=trace + S1[j, j]
GCVh=(GCVh/n)/(trace/n)^2
return(GCVh)
}
选择带宽的函数
gcvbandLL <- function(x,y,c=1.1) {
x <- as.vector(x)
y <- as.matrix(y)
n <- dim(y)[1]
tmp <- range(x)
hmin <- 2*(tmp[2] - tmp[1])/n
hmax <- 0.5*(tmp[2]-tmp[1])
h <- hmin
IUP <- 0
H <- vector()
H[0]

文章详细介绍了使用GCV(GeneralizedCrossValidation)方法在局部多项式和核估计中选择带宽的过程,包括gcvhLL和gcvbandLL函数用于多项式,以及gcvhNW和gcvbandNW函数用于核估计。文中给出了具体的计算步骤和示例,展示了如何通过比较不同带宽下模型性能来确定最优带宽值。
最低0.47元/天 解锁文章
561

被折叠的 条评论
为什么被折叠?



