m1 <- "Estimated NCS for different values of the smoothing parameter (k)"
n <- 300
t <- round(runif(n),digits=2)
y <- cos(4*pi*t) + rnorm(n)
ss <- splinek(t)
N <- ss$N
M <- ss$K
lambda <- c(0.002,0.02,0.2,2,20)
plot(t,y,xlim=range(t),ylim=range(y),cex=0.3,lwd=3,xlab="",ylab="",main=m1)
for(i in 1:length(lambda)){
h <- solve(t(N)%*%N + lambda[i]*M)%*%t(N)%*%y
sa <- ncs.graph(t,h,1000)
par(new=TRUE)
plot(sa[,1],sa[,2],xlim=range(t),ylim=range(y),type="l",xlab="t",ylab="",col=i)
}
legend(min(t),max(y),bty="n",col=1:length(lambda),legend=paste("k = ",lambda),lty=1)
Run the code above in your browser using DataLab