################################################################################# # Bayesian model selection and statistical modeling # Chapman & Hall/CRC Taylor and Francis Group # # Chapter2: Section2.8.2 # # Smoothing parameter selection # # Author : Tomohiro Ando # ################################################################################ # Data generation n <- 50 x <- sort(runif(n,-1,1)) z <- 0.3*cos(pi*x)+0.5*sin(2*pi*x) y <- z+rnorm(n,0,0.2) # Design matrix X <- cbind(x^1,x^2,x^3,x^4,x^5,x^6,x^7,x^8,x^9,x^10,x^11,x^12,x^13,x^14,x^15) # Models A <- 10^-6*diag(1,ncol(X)) #Model 1 #A <- 10^-3*diag(1,ncol(X)) #Model 2 #A <- 10^-1*diag(1,ncol(X)) #Model 3 #A <- 10^1*diag(1,ncol(X)) #Model 4 # Plot library(akima) B <- solve(t(X)%*%X+A)%*%t(X)%*%y yhat <- X%*%matrix(B,ncol=1) plot(x,y) lines(x,yhat,lty=2) lines(x,z,lty=1)