[R] gamm
Simon Wood
sw283 at maths.bath.ac.uk
Wed Jul 19 23:13:20 CEST 2006
Sorry for the delay replying: I was on holiday, but have foolishly come
back.
> I am a bit confused about gamm in mgcv. Consulting Wood (2006) or
> Ruppert et al. (2003) hasn't taken away my confusion.
>
> In this code from the gamm help file:
>
> b2<-gamm(y~s(x0)+s(x1)+s(x2)+s(x3),family=poisson,random=list(fac=~1))
>
> Am I correct in assuming that we have a random intercept here....but
> that the amount of smoothing is also changing per level of the factor??
> Or is it only the intercept that is changing?
>
- the degree of smoothing is the same for each level of `fac' but there is
a different intercept for each level of `fac': these intercepts are
assumed Normally distributed. i.e. all `s()' terms apply to all data,
they are not nested within groups.
> And where can I find some explanation on the magic output below?
mgcv::gamm is basically a wrapper that turns a GAMM into the sort of model
that nlme::lme or MASS::glmmPQL expects to see.... `gamm' returns an
object with two parts - the `lme' part is the object that was returned by
glmmPQL or lme; the `gam' part is an object with most of the attributes of
a `gam' object (all those that can be reconstructed from an lme/glmmPQL
fitted model object).
So the `lme' object contains a bunch of opaque stuff that results from
turning the original GAMM into something that lme/glmmPQL can work with...
further detail below.
>
> summary(b2$lme)
> Random effects:
- The output starting here relates to the random components of the 4
smooths in the model. Each smooth starts with 10 degrees of freedom, but
one of these is lost to the GAM centering constraint that ensures additive
identifiability, and one is treated as a fixed effect (see Wood, 2006, for
details), so each smooth have 8 random coefficients. Each of these
coefficients is treated as having the same variance (after some
preparatory reparameterization), but this variance (which plays the role
of a smoothing parameter) is unknown and is estimated as part of model
estimation.
[Note that g.1 to g.4 below are dummy grouping factors, each having
only one level - they force the smooths to apply to all the data, rather
than being nested within, e.g. the levels of `fac'].
> Formula: ~Xr.1 - 1 | g.1
> Structure: pdIdnot
> Xr.11 Xr.12 Xr.13 Xr.14 Xr.15 Xr.16 Xr.17 Xr.18
> StdDev: 1.680679 1.680679 1.680679 1.680679 1.680679 1.680679 1.680679 1.680679
> Formula: ~Xr.2 - 1 | g.2 %in% g.1
> Structure: pdIdnot
> Xr.21 Xr.22 Xr.23 Xr.24 Xr.25 Xr.26 Xr.27 Xr.28
> StdDev: 1.57598 1.57598 1.57598 1.57598 1.57598 1.57598 1.57598 1.57598
> Formula: ~Xr.3 - 1 | g.3 %in% g.2 %in% g.1
> Structure: pdIdnot
> Xr.31 Xr.32 Xr.33 Xr.34 Xr.35 Xr.36 Xr.37 Xr.38
> StdDev: 20.06377 20.06377 20.06377 20.06377 20.06377 20.06377 20.06377 20.06377
> Formula: ~Xr.4 - 1 | g.4 %in% g.3 %in% g.2 %in% g.1
> Structure: pdIdnot
> Xr.41 Xr.42 Xr.43 Xr.44 Xr.45
> StdDev: 0.0001063304 0.0001063304 0.0001063304 0.0001063304 0.0001063304
> Xr.46 Xr.47 Xr.48
> StdDev: 0.0001063304 0.0001063304 0.0001063304
- that's the random component information relating to the smooths done
with. What follows is the information realting to the random intercept.
Note that the rather complicated Formula is really equivalent to
~1|fac
since the g.j are degenerate.
> Formula: ~1 | fac %in% g.4 %in% g.3 %in% g.2 %in% g.1
> (Intercept) Residual
> StdDev: 0.6621173 1.007227
> Variance function:
> Structure: fixed weights
> Formula: ~invwt
- What follows is information about the fixed effects. In this case there
is one fixed effect for each smooth, and an overall intercept:
`X(Intercept)'.
> Fixed effects: y.0 ~ X - 1
> Value Std.Error DF t-value p-value
> X(Intercept) 2.0870364 0.3337787 392 6.252755 0.0000
> Xs(x0)Fx1 -0.0000325 0.1028794 392 -0.000316 0.9997
> Xs(x1)Fx1 0.3831694 0.0957323 392 4.002509 0.0001
> Xs(x2)Fx1 1.4584330 0.3909237 392 3.730736 0.0002
> Xs(x3)Fx1 -0.0123951 0.0143162 392 -0.865809 0.3871
> Correlation:
>
Hope that's some use.
Simon
>- Simon Wood, Mathematical Sciences, University of Bath, Bath BA2 7AY
>- +44 (0)1225 386603 www.maths.bath.ac.uk/~sw283/
More information about the R-help
mailing list