FLXMRlmer.RdThis is a driver which allows fitting of mixtures of linear models with random effects.
A formula which is interpreted relative to the formula
specified in the call to flexmix using
update.formula. Default is to use the original
flexmix model
formula.
A formula for specifying the random effects.
A logical indicating if the model should be estimated with weighted ML.
A list of control parameters. See
lmer for details.
Observations with a component-specific posterior smaller
than eps are omitted in the M-step for this component.
A character string indicating if the coefficients should
be fitted using either a linear model or the function
smooth.spline
Named logical vector of length 2 indicating if the variance of the random effects and the residuals are fixed over the components.
Additional arguments to be passed to smooth.spline.
FLXMRlmm allows only one random effect. FLXMRlmer allows
an arbitrary number of random effects if weighted = FALSE; a
certain structure of the model matrix of the random effects has to be
given for weighted ML estimation, i.e. where weighted = TRUE.
Returns an object of class FLXMRlmer and FLXMRlmm
inheriting from FLXMRglm and FLXMR, respectively.
For FLXMRlmer the weighted ML estimation is only correct if the
covariate matrix of the random effects is the same for each
observation. By default weighted ML estimation is made and the
condition on the covariate matrix of the random effects is checked. If
this fails, only estimation with weighted = FALSE is possible
which will maximize the classification likelihood.
id <- rep(1:50, each = 10)
x <- rep(1:10, 50)
sample <- data.frame(y = rep(rnorm(unique(id)/2, 0, c(5, 2)), each = 10) +
rnorm(length(id), rep(c(3, 8), each = 10)) +
rep(c(0, 3), each = 10) * x,
x = x,
id = factor(id))
fitted <- flexmix(.~.|id, k = 2, model = FLXMRlmm(y ~ x, random = ~ 1),
data = sample, control = list(tolerance = 10^-3),
cluster = rep(rep(1:2, each = 10), 25))
parameters(fitted)
#> Comp.1 Comp.2
#> coef.(Intercept) 2.41202513 8.160208
#> coef.x -0.00153039 2.966378
#> sigma2.Random 29.75108116 2.375748
#> sigma2.Residual 0.90276020 1.070790
fitted1 <- flexmix(.~.|id, k = 2, model = FLXMRlmer(y ~ x, random = ~ 1),
data = sample, control = list(tolerance = 10^-3),
cluster = rep(rep(1:2, each = 10), 25))
parameters(fitted1)
#> Comp.1 Comp.2
#> coef.(Intercept) 2.49561691 8.412487
#> coef.x -0.00153039 2.966378
#> sigma2.Random 29.74617499 2.306036
#> sigma2.Residual 0.90076516 1.070841
fitted2 <- flexmix(.~.|id, k = 2,
model = FLXMRlmm(y ~ 0 + x, random = ~ 1,
lm.fit = "smooth.spline"),
data = sample, control = list(tolerance = 10^-3),
cluster = rep(rep(1:2, each = 10), 25))
parameters(fitted2)
#> Comp.1 Comp.2
#> coef.knot1 0.0000000 0.0000000
#> coef.knot2 0.0000000 0.0000000
#> coef.knot3 0.0000000 0.0000000
#> coef.knot4 0.0000000 0.0000000
#> coef.knot5 0.1111111 0.1111111
#> coef.knot6 0.2222222 0.2222222
#> coef.knot7 0.3333333 0.3333333
#> coef.knot8 0.4444444 0.4444444
#> coef.knot9 0.5555556 0.5555556
#> coef.knot10 0.6666667 0.6666667
#> coef.knot11 0.7777778 0.7777778
#> coef.knot12 0.8888889 0.8888889
#> coef.knot13 1.0000000 1.0000000
#> coef.knot14 1.0000000 1.0000000
#> coef.knot15 1.0000000 1.0000000
#> coef.knot16 1.0000000 1.0000000
#> coef.nk 12.0000000 12.0000000
#> coef.min 1.0000000 1.0000000
#> coef.range 9.0000000 9.0000000
#> coef.coef1 2.4417892 10.8857902
#> coef.coef2 2.3488504 12.0203806
#> coef.coef3 2.1620595 14.2898087
#> coef.coef4 2.8830781 17.1939888
#> coef.coef5 2.2117649 19.9011672
#> coef.coef6 2.4765860 23.1571366
#> coef.coef7 1.7451901 26.0393170
#> coef.coef8 2.9541234 29.0638509
#> coef.coef9 2.2912061 31.5770079
#> coef.coef10 2.3295747 34.8978498
#> coef.coef11 2.4233764 36.8452776
#> coef.coef12 2.4703592 37.8191955
#> sigma2.Random 29.7548244 2.3786241
#> sigma2.Residual 0.8650385 1.0448569