| aliases | R Documentation |
Consider the toy_iris dataset defined in the Examples, noting in particular the lines of code
u <- rnorm(10,sd=1) id_y <- gl(10,5) id_b <- rep(seq(10),5)
and the subsequent use of u[id_y] and u[id_b] in the expectations of Poisson draws. Suppose that we fit to a multivariate-response model with two Poisson responses to it. A fit by
fitmv(submodels = list(
list(yellow ~ 1+(1|id_y), family = poisson()),
list(blue ~ 1+(1|id_b), family = poisson())),
data = toy_iris)
does not match the data-generating algorithm, because the fit of the (1|id_y) and (1|id_b) random effects does not take into account that the latent values of these random effects are sampled from a single vector u of 10 latent values. One should rather fit a single random-effect variance and produce a single predicted vector for u, rather than two distinct vectors of predicted values.
Conversely, a fit such as
fitmv(submodels = list(
list(yellow ~ 1+(1|id_y), family = poisson()),
list(blue ~ 1+(1|id_y), family = poisson())),
data = toy_iris)
would fit a single random-effect variance and produce a single predicted vector, but the factor indices are incorrect in the second submodel.
We need a syntax such that a single variance and a single vector are fitted (as when the random-effect terms are identical in the two formulas), but where the factor indices are effectively id_y and id_b in the two submodels. The syntax of the proper fit in the Examples achieves this effect. The random effect is specified as
(1|id) where id is *not* an actual factor in the data but is an alias for the variable id_y in the first formula and id_b in the second one. This interpretation of the (1|id) term is specified by the argument
aliases=list(id=c("id_y","id_b")).
vignette("Multinomial-logit", package = "spaMM") for more examples.
# Toy data
set.seed(123)
ssize <- 50L
u <- rnorm(10,sd=1)
id_y <- gl(10,5)
id_b <- rep(seq(10),5)
yellow <- rpois(ssize, lambda=exp(1+u[id_y]))
blue <- rpois(ssize, lambda=exp(1+u[id_b]))
toy_iris <- data.frame(
id_y=id_y, id_b=id_b, yellow=yellow, blue=blue
)
# Fit
proper <- fitmv(submodels = list(
list(yellow ~ 1+(1|id), family = poisson()),
list(blue ~ 1+(1|id), family = poisson())),
data = toy_iris, aliases=list(id=c("id_y","id_b")))
ranef(proper) # single vector of 10 values
# Rows 1-50 and 51-100 of Z matrix show
# the distinct design of the two submodels:
get_matrix(proper,"ZA")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.