fdaLm {fdaMixed} | R Documentation |
Linear mixed-effects model for functional data
Description
Fits variance and smoothing parameters, and possibly also Box-Cox transformation, by maximum restricted likelihood. Estimate fixed parameters, predict random effects, and predict serial correlated effect at point of maximum restricted likelihood. Linear models for fixed and random effects may be global or marginal over sample times.
Usage
fdaLm(formula, data, design, boxcox = NULL, G = 1, lambda = 1, nlSearch
= TRUE, K.order = 1, D.order = NULL, Fleft = "tied", Fright = "tied",
left = NULL, right = NULL)
Arguments
formula |
A multiple formula of the type |
data |
An optional data frame containing the variables. See details below. |
design |
An optional data frame containing the design variables in the specification of the fixed and the random effects. See details below. |
boxcox |
The power parameter in the scale invariant Box-Cox transformation.
If |
G |
Variance of the random effects. Present implementation only allows
for independent random effects, i.e. |
lambda |
Start value for the |
nlSearch |
If |
K.order |
The order of the K-operator. |
D.order |
The requested order of derivatives of the prediction of the serial
correlated effect |
Fleft |
Specification of the |
Fright |
Similarly for the |
left |
Left limit of the sampling interval. If |
right |
Right limit of the sampling interval. If |
Details
The response variable Y
is taken from the data frame
data
(subsidiary the parent environment). If there is more
than one sample, then the responses must be stacked sample-wise on top
of each other. The sample identifier id
is sought for in both
data frames data
and design
(subsidiary the parent
environment). The primarily function of the identifier is to decide
the number of samples. But if id
is present in both data
frames, and if there is more that one sample, then this variable is
also used to match the reponse vector to the design variables
(i.e. these need not appear in the same order).
The design variables fixed
and random
for the fixed and
the random effects are taken from the data frame design
(subsidiary the parent environment), subsidiary from the data frame
data
(subsidiary the parent environment).
If the number of observations in the design variables equal the total number of response observations, then a global ANOVA is performed. If the number of observations in the design variables equal the number of sample points, then a marginal ANOVA is performed.
Value
A list with components
logLik |
Minus twice the log restricted likelihood taken at the estimates. |
ANOVA |
Specifies whether fixed and random effects were estimated
globally ( |
nlSearch |
Specifies whether non-linear optimization was
performed ( |
counts |
Number of computations of the negative log likelihood. |
boxcoxHat |
Maximum restricted likelihood estimate for the power
parameter in the scale invariant Box-Cox transformation. Equal to
|
Ghat |
Maximum restricted likelihood estimate for the variance matrix of the random effects. |
lambdaHat |
Maximum restricted likelihood estimate for the lambda parameter describing the L-operator. |
sigma2hat |
Maximum restricted likelihood estimate for the noise variance. |
betaHat |
For global ANOVA a vector with estimate for the fixed effect. For marginal ANOVA a matrix with estimate for the fixed effects. |
uBLUP |
For global ANOVA a vector with prediction of the random effect. For marginal ANOVA a matrix with predictions of the random effects. |
xBLUP |
Array with predictions of serial correlated effects. The
dimension is (sample length,sample numbers,1+ |
condRes |
Matrix of conditional residuals. The dimension is (sample length,sample numbers). |
betaVar |
Variance matrix of fixed effect estimate. |
Note
If the real value of the left most eigenvalues are non-positive, and if the real value of the right most eigenvalues are non-negative, then the underlying algorithm is numerical stable. This will always be the situation for the present restriction of the L-operator.
If lambda
has length=1, then it may also be interpreted as the
smoothing parameter in the penalized likelihood framework.
If D.order
is chosen larger than K.order
, this number of
derivaties are also computed during the non-linear optimization. This
might slow down the computation speed a little bit.
Author(s)
Bo Markussen <bomar@math.ku.dk>
See Also
See also findRoots
and dataTrans
.
Examples
# ---------------------
# Using a fixed effect
# ---------------------
x <- seq(0,2*pi,length.out=200)
y.true <- sin(x)+x
y.obs <- y.true + rnorm(200)
est0 <- fdaLm(y.obs~0,Fright="open",right=2*pi)
est1 <- fdaLm(y.obs~0+x,Fright="open",right=2*pi)
plot(x,y.obs,main="Estimating the sum of a line and a curve")
lines(x,y.true,lty=2)
lines(x,est0$xBLUP[,1,1],col=2)
lines(x,est1$betaHat*x+est1$xBLUP[,1,1],col=3)
legend("topleft",c("True curve","Smooth","Line + smooth"),col=1:3,lty=c(2,1,1))
# --------------------------
# Including a random effect
# --------------------------
# Build data frame
test.frame <- data.frame(y=rnorm(50),sample=factor(rep(1:5,each=10)),
x=rep(0:9,times=5),
f=factor(rnorm(50) < 0,labels=c("a","b")),
j=factor(rnorm(50) < 0,labels=c("A","B")))
test.frame$y <- test.frame$y + 2 +
3*(test.frame$f=="a")*test.frame$x + 5*(test.frame$f=="b")*test.frame$x +
(-10)*(test.frame$j=="A") + 10*(test.frame$j=="B")
# This is the model 'y|sample ~ f:x|j' with intercept=2, slopes (3,5),
# and random effects (-10,10)
est <- fdaLm(y|sample ~ f:x|0+j,data=test.frame)
print(est)