random(f, df = NULL, lambda = 0, intercept = TRUE)
gam.random(f, y, w, df = sum(non.zero), lambda = 0, intercept=TRUE, xeval)
gam.random
during backfittinglambda
below) is found
such that df=tr(S)
, where S
is the implicit smoother
matrix. Values for df
should be greater than 0
and less
than the number of levels of f
. If both df
and lambda
are
supplied, the latter takes precedence. Note that df
is not
necessarily an integer.intercept=TRUE
(the default) then the estimated level effects
are centered to average zero, otherwise they are left alone.
gam.random
produces a
prediction at xeval
.random
returns the vector f
, endowed with a number of
attributes. The vector itself is used in computing the means in backfitting,
while the attributes are needed for the backfitting algorithms
general.wam
.
Note that random
itself does no smoothing; it simply sets things up
for gam
. One important attribute is named call
. For example,
random(f, lambda=2)
has a call component
gam.random(data[["random(f, lambda = 2)"]], z, w, df = NULL, lambda = 2, intercept = TRUE)
.
This is an expression that gets evaluated repeatedly in general.wam
(the backfitting algorithm). gam.random
returns an object with components
lambda
used in the fitgam.random
is evaluated with an xeval
argument, it returns a
vector of predictions.lambda=0
, it simply computes the mean of the response at
each level of f
. With lambda>0
, it returns a shrunken
mean, where the j'th level is shrunk by nj/(nj+lambda)
, with
nj
being the number of observations (or sum of their weights)
at level j
. Using such smoother(s) in gam is formally
equivalent to fitting a mixed-effect model by generalized least squares.lo
, s
, bs
, ns
, poly
# fit a model with a linear term in Age and a random effect in the factor Level
y ~ Age + random(Level, lambda=1)
Run the code above in your browser using DataLab