library( fields) set.seed(123) x<- matrix( runif( 400,-1,1), ncol=4) true<- exp( -2*(x[,1]**2 + x[,2]**2)) + ((1+x[,3])**2)*(1-x[,3])**3 + x[,4] y<- true+ rnorm(100)*.1 p12<- p3<- p4<- rep( 0,100) hold<- rep( 0,100) NBACK<- 25 for( k in 1:NBACK ){ p12<- Tps( x[,1:2], y - p3- p4)$fitted.values p3<- sreg( x[,3], y- p12- p4)$fitted.values ytemp<- y- p12 -p3 p4<- lm(ytemp~ x[,4])$fitted.values test<- p12 + p3 + p4 cat(k, mean(abs( hold- test)), fill=TRUE) hold<- test } tps.obj<- Tps( x[,1:2], y - p3- p4) sreg.obj<- sreg( x[,3], y- p12- p4) ytemp<- y- p12 -p3 lm.obj<- lm(ytemp~ x[,4]) set.panel(2,2) phat<- p12+ p3 +p4 plot( phat, y) plot( phat, y-phat) surface( tps.obj) plot( sreg.obj$x, sreg.obj$y) lines( sreg.obj$predicted)