# [R] gam and ordination (vegan and labdsv surf and ordisurf)

Gavin Simpson gavin.simpson at ucl.ac.uk
Thu Nov 20 16:23:40 CET 2008

```On Thu, 2008-11-20 at 09:45 -0500, stephen sefick wrote:
> #for instance this
> ordisurf(bug.4, env.savannah[,"TSS"]+env.savannah[,"TIN.TP"])
>
> This is mod1?

Hi Stephen,

Yes, but it is mod1 expressed as

## the sum of TSS and TIN.TP
y <- env.savannah[,"TSS"]+env.savannah[,"TIN.TP"]

## sites scores from bug.4 on axes 1 and 2
scr <- scores(bug.4, choices = 1:2, display = "sites")
x1 <- scr[, 1]
x2 <- scr[, 2]

## GAM model fitted in ordisurf
## ... from defaults in ordisurf
mod1 <- gam(y ~ s(x1, x2), ...)

So it is fitting a model of a 2-D smooth in the axis scores of bug.4 as
predictors to the response y. In your case the response y is TSS +
TIN.TP, which may not make sense.

So lets start with sum dummy data

dat <- data.frame(height = rnorm(100), totalN = rnorm(100),
axis1 = runif(100, -4, 4), axis2 = runif(100, -4, 4))

The model you fitted via ordisurf was equivalent to:

mod1 <- gam(height + totalN ~ s(axis1, axis2), data = dat)

which is the same as

resp <- with(dat, height + totalN)
mod2 <- gam(resp ~ s(axis1, axis2), data = dat)

So we added totalN concentration to height which doesn't make sense. And
I suspect doesn't make sense for your variables (TSS == total suspended
solids? TIN.TP something to do with total inorganic N and total P?)
either.

The point is that the model is a single response, /predicted/ by a 2-d
smooth of the two sets of axis scores if 'thinplate = TRUE'. If
'thinplate = FALSE' then it is an additive model of two seperate smooths
applied to the axis scores independently. In either case, the only
things that get smoothed are the axis scores. What you supply as 'y' in
the call to ordisurf (your env.savannah[,"TSS"]+env.savannah[,"TIN.TP"])
is the *univariate* response.

>   I am new to gam models, and will buy Simon's book when
> I have the funds.

When you get the funds, make sure you grab the discount code off the R
Project website book section. Should save you 20% IIRC.

> thanks for being patient

You're welcome,

Hope this explains things?

G

>
> Stephen Sefick
> (I will send you data off list if you wish with reproduvible code, but
> I believe that it is too large for posting to the list.)
>
> On Thu, Nov 20, 2008 at 8:52 AM, Gavin Simpson <gavin.simpson at ucl.ac.uk> wrote:
> > [Have CC'd Jari here as lead author and maintainer of vegan]
> >
> > Hi Stephen,
> >
> > On Thu, 2008-11-20 at 07:41 -0500, stephen sefick wrote:
> >> I have a general question about using thin plate splines in the surf
> >> and ordisurf routines.  My rudimentary knowledge of a gam is that with
> >> each predictive variable there is a different smooth for each one and
> >> then they are added together with no real interaction term (because
> >> they don't handle this well?).
> >
> > If this is really about ordisurf then what you write is not really
> > accurate. The model ordisurf fits is not additive, given the defaults.
> > By default ordisurf fits a smooth of Ax1 and Ax2 together, not separate
> > smooths of Ax1 and Ax2 which then sum up to predict the response (plus
> > the intercept of course, if one is included in the model).
> >
> > In mgcv::gam the default model fitted by ordisurf is of the form
> >
> > mod1 <- gam(y ~ s(Ax1, Ax2), data = X, ...)
> >
> > whilst you seem to be describing the following additive model
> >
> > mod2 <- gam(y ~ s(Ax1) + s(Ax2), data = X, ...)
> >
> > Simon Wood's GAM book goes on to explain that given the thinplate
> > regression spline bases used in this example, mod2 is not actually
> > nested in mod1. To compare nested models then we need to replace mod1 by
> >
> > mod3 <- gam(y ~ s(Ax1) + s(Ax2) + s(Ax1, Ax2), data = X, ...)
> >
> > In the case or ordisurf, to my mind mod1 is the correct model to fit as
> > one is often interested in the configuration (i.e. the two axes
> > together) and not the individual axes per se.
> >
> > The smooths in mod1 are isotropic and useful when Var1 and Var2 (in
> > s(Var1, Var2) ) are on the same scale and we expect the same degree of
> > smoothness to apply to both covariates. mgcv provides tensor product
> > terms via te() (instead of s() ) for situations where isotropy is not
> > appropriate, but these are not available in ordisurf.
> >
> > You can get mod2 in ordisurf by specifying 'thinplate = FALSE'. Looking
> > at ordisurf now, I'm not sure thinplate is the correct name for this -
> > whether thinplate is FALSE or TRUE, thinplate regression splines are
> > used in the model fit, all thinplate controls is whether a model of the
> > form mod1 or mod2 is computed.
> >
> >>   Now,  If I have two variables that
> >> have a high D^2 score and a low GCV score (I am thinking of this as a
> >> goodness of fit which may be wrong) I would like to add these together
> >> to produce one surface fitted to the ordination.  Is this possible?
> >> Am I going down the right track?  Any help is greatly appreciated.
> >
> > It isn't clear what you want to do (to me at least). ordisurf certainly
> > doesn't do this as you provide the response (argument 'y') and an
> > ordination (plus which axes to use) and fits a model like mod1. So you
> > provide only the *univariate* response.
> >
> > So what do you mean by "two variables"? Have you used ordisurf on your
> > var1 and your var2 separately and now want to combine them? If so, that
> > doesn't make sense (with ordisurf at least) as your "two variables" are
> > responses. The only predictor variables ordisurf knows about are
> > ordination axes.
> >
> > If you want to fit a multivariate response with smooth functions of the
> > predictors, take a look at Thomas Yee's VGAM package - coincidentally
> > there is a nice article by Thomas in the current R News on VGAM.
> >
> > If this is not what you meant, perhaps an example might help elucidate
> > things? At least up to the part you want help with.
> >
> > HTH
> >
> > G
> >
> > --
> > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
> >  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
> > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
> >
> >
>
>
>
--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

```