【发布时间】:2021-06-26 23:22:56
【问题描述】:
我正在使用标准粗糙度惩罚在饱和 B 样条基础上工作。
但我的情节是这样的:
我不知道为什么我的plot() 函数不能改变线条的颜色。下面是我的代码,您能告诉我解决方案的原因吗?提前谢谢!
library('fda')
data(CanadianWeather)
temp = CanadianWeather$dailyAv[,,1]
precip = CanadianWeather$dailyAv[,,2]
daytime = (1:365)-0.5
day5 = seq(0,365,5)
dayrng = c(0,365)
knots = day5
norder = 4
nbasis = length(knots) + norder - 2
plot(create.bspline.basis(dayrng,nbasis=12,norder))
bbasis = create.bspline.basis(dayrng,nbasis,norder, knots)
in.mat = inprod(bbasis,bbasis)
image(in.mat)
bbasis = create.bspline.basis(dayrng,nbasis=21,norder=4)
lambda = 1e6
curv.Lfd = int2Lfd(2)
curv.fdPar = fdPar(bbasis,curv.Lfd,lambda)
tempSmooth1 = smooth.basis(daytime,temp,curv.fdPar)
plot(tempSmooth1$fd)
lambda = 1e1
curv.fdPar$lambda = lambda
tempSmooth = smooth.basis(daytime,temp,curv.fdPar)
lambdas = 10^seq(-4,4,by=0.5)
mean.gcv = rep(0,length(lambdas))
for(ilam in 1:length(lambdas)){
curv.fdPari = curv.fdPar
curv.fdPari$lambda = lambdas[ilam]
tempSmoothi = smooth.basis(daytime,temp,curv.fdPari)
mean.gcv[ilam] = mean(tempSmoothi$gcv)
}
plot(lambdas,mean.gcv,type='b',log='x')
best = which.min(mean.gcv)
lambdabest = lambdas[best]
curv.fdPar$lambda = lambdabest
tempSmooth = smooth.basis(daytime,temp,curv.fdPar)
plot(tempSmooth)
tempfd = tempSmooth$fd
mtempfd = mean(tempfd)
plot(tempfd, col = 4)
lines(mtempfd,lwd = 2,col = 2)
【问题讨论】:
标签: r plot functional-programming smoothing