[R] Displaying smooth bases - mgcv package

Simon Wood s.wood at bath.ac.uk
Wed May 19 20:38:19 CEST 2010



On Wednesday 19 May 2010 15:08, Joris Meys wrote:
> Dear all,
>
> for demonstration purposes I want to display the basis functions used by a
> thin plate regression spline in a gamm model. I've been searching the help
> files, but I can't really figure out how to get the plots of the basis
> functions. Anybody an idea?
>
> Some toy code :
>
> require(mgcv)
> require(nlme)
>
> x1 <- 1:1000
> x2 <- runif(1000,10,500)
>
> fx1 <- -4*sin(x1/50)
> fx2 <- -10*(x2)^(1/4)
> y <- 60+ fx1 + fx2 + rnorm(1000,0,5)
>
> test <- gamm(y~s(x1)+s(x2))
>
> plot(test$gam)
>

## plots basis functions in space of identifiability constraints, set
## absorb.cons=FALSE for original basis functions
um <- smoothCon(s(x1),data=data.frame(x1=sort(x1)),
          knots=NULL,absorb.cons=TRUE)
X <- um[[1]]$X
plot(sort(x1),X[,1],ylim=range(X),type="l")
for (i in 2:ncol(X)) lines(sort(x1),X[,i],col=i)

best,
Simon






> This gives me the conditional estimates, but not the basis functions for
> the different splines. I'd like to have the basis functions for s(x1) and
> s(x2).
>
> Cheers
> Joris

-- 
> Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK
> +44 1225 386603  www.maths.bath.ac.uk/~sw283



More information about the R-help mailing list