[R] Simon Wood GAMsetup

Simon Wood s.wood at bath.ac.uk
Wed Oct 1 14:35:59 CEST 2008


Michela, 

Thanks for the email. I'm still not completely clear what parts of H you need. 
Are you just wanting to extract a model matrix for a smooth (i.e. the matrix 
of basis functions evaluated at the covariate values), or do you need other 
things, like the smoothing penalty matrix, as well?

Since version 1.0 mgcv uses an object oriented approach to setting up 
smoothing bases, using `smooth constructor functions'. For example:

x <- runif(20)
sm <- smooth.construct2(s(x,bs="cr"),data=data.frame(x=x),knots=NULL)
sm$X   ## model matrix for "cr" smooth of x

... not sure if this gives all you need. Let me know.

best,
Simon


On Wednesday 01 October 2008 08:44, Michela Leone wrote:
> Dear Simon, Thank you for your quick reply!
>
> I used to perform the GAMsetup in the following manner:
>
> GAMsetup sintax:
>
> x.summer: vector used for construct the spline
>
> knots<-14
>
> N<-length(x.summer)
>
> x<-array(x.summer,dim=c(1,N))
>
> G<-list(m=1,n=N,nsdf=0,df=knots+1,dim=1,s.type=0,by=0,by.exists=FALSE,p.ord
>er=0,x=x,n.knots=knots,fit.method="mgcv")
>
> H<-GAMsetup(G)
>
> with the new version mgcv 1.4.1 gam.setup this does no longer work and
> gives me the following error:
>
> Error in gam.setup(G) : First argument is no sort of formula!
>
> What is the correct new syntax?
>
> I also tried to obtain H with gam function under mgcv and I thought that
> with the gam function I could obtain H using s(). Is this wrong?
>
> e.g.
>
> mod_spline<-gam(yy~s(x.summer,k=16,bs="cr",fx=FALSE,by=NA,m=1),sp=c(0.001),
>data=dstime,family=poisson,fit.method="mgcv")
>
>
> H<-predict.gam(mod_spline,type="lpmatrix")
>
> H<-H[,2:16]
>
> I presume that the vectors obtained using the predict.gam() are different
> from the ones obtained using GAM.setup().
>
> Thank for your help.
>
> Looking forward to hearing from you.
>
> Michela
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html and provide commented, minimal,
> self-contained, reproducible code.

-- 
> 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