greta.glmer: Initialize the linear predictor for generalized linear effect...

Description Usage Arguments Value Examples

Description

greta.glmer creates the linear predictor $eta$ required for fitting generalized linear mixed models. The linear predictor has the form:

η = X β + Z γ,

where X is the fixed effects design matrix, β the fixed effects, Z the random effects design matrix and γ the random effects.

Usage

1
2
greta.glmer(formula, data, prior_intercept = NULL,
  prior_coefficients = NULL, prior_random_effects = NULL)

Arguments

formula

an lme4-style formula

data

the data set containing the variables described in formula

prior_intercept

a greta_array random variable that specifies the prior for the intercept β_0 for the fixed effects design matrix. If NULL, the distribution for the intercept is chosen as

p(β) ∝ const.

The intercept prior needs to have dimension 1.

prior_coefficients

a greta_array random variable that specifies the prior for the coefficientsβ for the fixed effects design matrix. If NULL, the distribution for the coefficients is chosen as

p(β_i) ~ N(0, σ),

and

p(σ) ~ Half-Cauchy(0, ∞).

The coefficients prior need to have the same dimensionalty as the number of columns of your fixed effects design matrix (without the intercept).

prior_random_effects

a greta_array random variable that specifies the prior for the random effects γ for the random effects design matrix. If NULL, the distribution for the random effects is chosen as

p(γ) ~ N(0, τ),

and

p(τ) ~ Inv-Wishart

If prior_random_effects is provided it needs to have the same dimensionalty as the number of columns of Z random effect design matrix. These are generally not trivial to construct. Calling glFormula(formula, data) creates the specified random effects matrix Z. From this the dimensionality of prior_random_effects can be inferred.

Value

Returns a list of class greta.glmer with the following elements:

predictor

the linear predictor η

X

the fixed effects design matrix

x.eta

the linear predictor

coef

the prior for the coefficients β

Z

the random effects design matrix

z.eta

the linear predictor

gamma

the prior for the random effects γ

Ztlist

a list of random effect terms used for initializing γ

grp.vars

the variables used for grouping

call

the function call used

formula

the formula used

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# create a random intercept model
greta.glmer(Sepal.Length ~ Sepal.Width + (1 | Species), iris)

# creates a random slope model
greta.glmer(Sepal.Length ~ Sepal.Width + (Sepal.Width | Species), iris)

# creates a random slope model with multiple random effect terms
greta.glmer(Sepal.Length ~ Sepal.Width + (Sepal.Width | Species) + (Petal.Width | Species),
            iris)

# creates a random slope model with strong regularizing prior
greta.glmer(Sepal.Length ~ Sepal.Width + (Sepal.Width | Species),
           iris,
           prior_random_effects = greta::normal(0, 1, dim=6))

# creates a random slope model with flat coefficient prior
greta.glmer(Sepal.Length ~ Sepal.Width + (Sepal.Width | Species),
           iris,
           prior_coefficients = greta::variable(dim=1))

# creates a random slope model with normal intercept prior
greta.glmer(Sepal.Length ~ Sepal.Width + (Sepal.Width | Species),
           iris,
           prior_intercept = greta::normal(0, 1))

dirmeier/greta.lme documentation built on May 8, 2019, 12:58 a.m.