[R] GAM function in mgcv package

Gavin Simpson gavin.simpson at ucl.ac.uk
Wed Oct 27 09:51:50 CEST 2010


On Wed, 2010-10-27 at 12:54 +1000, Lorenzo Cattarino wrote:
> Hi R-users

> I am trying to use the GAM function of the mgcv package. But I am having
> problem trying to specify the k parameter.

Is there a specific reason to supply k?

> Although I managed to run some models by giving to the parameter some
> (random) value, and it is explained by Wood (2006) that it does not seem
> to "really" affect the final result, I would like to grasp better its
> meaning.

k is a parameter controlling the starting complexity of the smooth.
gam() penalises this smoother using GCV or ML or REML estimation
(depending on 'method' argument), to automatically choose the degree of
smoothness in the fitted model.

If you want to fix the complexity, then you need to specify the argument
'fx' in your smooths:

m1 <- gam(y ~ s(x, k = 10), data = foo)

is a model where the starting dimensionality of the smooth matrix is 10,
and which will be penalised back to some optimal level of smoothing
using GCV. (I've probably mis-remembered exactly what k is here [at
home] and without referring back to the help, but hopefully you get the
idea.)

If I want to fix the smoothness, and not allow any smoothness selection,
then

m2 <- gam(y ~ s(x, k = 10, fx = TRUE), data = foo)

See the help for s() (via ?s ) for further details.

HTH

G

> I understand that is the 'basis dimension'. Is that refer to the order
> of the function used as smother (i.e. for a cubic regression spline it
> is 3)? Also it shouldn't be bigger than the number of unique covariate
> values. But what is the minimum value it can get? I think it has to do
> with the penalty (i.e. the integrated square of the second order
> derivative of the smoother function) and the penalty order (m).
> 
>  
> 
> I would very much appreciate any help or examples you might give to fill
> in some of my (many) knowledge gaps
> 
>  
> 
> Thanks 
> 
>  
> 
> Lorenzo   
> 
> 
> 	[[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.

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list