[R-sig-eco] GAM - Cyclic splines

Gavin Simpson ucfagls at gmail.com
Thu Jan 22 21:14:19 CET 2015


To the best of my knowledge this works as per mgcv::gam and mgcv::gamm (as
the only code in **gamm4** is that to fit the GAMM via **lme4** and nothing
else, so leveraging existing code in **mgcv**).

Whilst it would help to give more informative names than X1 and X2, and so
on to your variables, I think the following should work, for the `bs =
"cc"` term:

Model <- gamm4(Y ~ s(X1, k=5, bs="cc") + s(X2, bs="cr") + offset(log(X3)),
              random = ~(1 | X4), data = data, family = poisson,
              knots = list(X1 = c(1, 366)))

Not sure why you want c(0, 366) as wouldn't that be 367 days?

Anyway, you pass knots a list with components named as per the variables
used in the smooth terms. If you don't supply knots for a smooth term, the
default locations are used. In the case of cyclic cubic splines, one can
simply get by with passing the end points of the knots as I did above, and
the remaining knots (as determined by k) are distributed evenly across the
interior of the stated two boundary knots.

I don't see why, if suitably fitted, predictions for day 1 or day 366
should differ markedly. Were you predicting at the same values of X2, X3,
and X4 when you compared the outputs?

HTH

G

On 22 January 2015 at 13:40, SamiC <samantha.cox at plymouth.ac.uk> wrote:

> Hi,
>
> I am trying to use cyclic splines in gamm4 to model year day.  I have data
> running from say day 6 to day 300 but I want to specify the outer limits of
> the data are at 0 and 366.  I dont want to fix the inner position of the
> knots however (I allow for a total of 5 knots).  Is there a way to do this?
> I also have other explanatory variables in the model that are not cyclic.
>
> Example:
> Model<-gamm4(Y~s(X1,fx=FALSE,k=5,bs="cc")+s(X2,fx=FALSE, k=5,
> bs='cr')+offset(log(X3)),random=~(1|X4),data=data,family=poisson)
>
> Finally when I try to plot the predictions on the response scale the values
> predicted at 0 and 366 are vastly different and do not match, as when
> outputs using plot(Model$gam,se=TRUE).
>
> Any help on this would be much appreciated.
>
> Cheers
>
> Sam
>
>
>
> --
> View this message in context:
> http://r-sig-ecology.471788.n2.nabble.com/GAM-Cyclic-splines-tp7579269.html
> Sent from the r-sig-ecology mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>



-- 
Gavin Simpson, PhD

	[[alternative HTML version deleted]]



More information about the R-sig-ecology mailing list