R语言中plot()无法修改带标准粗糙度惩罚的饱和B样条基绘图线条颜色的原因
基于粗糙度惩罚的饱和B样条计算可视化问题
目前正基于标准粗糙度惩罚方法开展饱和B样条基的相关计算工作:
- 预期达成的可视化效果:可通过参数调整区分不同曲线颜色的温度平滑B样条拟合图
- 实际遇到的异常:调用
plot()函数传入颜色参数后,始终无法修改对应线条的颜色,和预期效果存在明显偏差
问题说明
已完成B样条基构建、粗糙度惩罚设置、GCV交叉验证选取最优平滑参数的全流程计算,但在最终可视化环节,颜色参数设置无法生效,无法定位问题根因,需要对应的排查方向和解决方案。
可复现R代码
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)
内容的提问来源于stack exchange,提问作者Chaeeun Lee
相关产品推荐
相关产品推荐

