Learn R Programming

rethinking (version 1.59)

glimmer: glm/glmer formulas to map/map2stan formulas

Description

Converts a glm or glmer model formula into a formula list of the kind used by map and map2stan

Usage

glimmer( formula , data , family=gaussian , prefix=c("b_","v_") , 
    default_prior="dnorm(0,10)" , ... )

Arguments

formula

A formula of the sort used by glm or glmer

data

A data frame or list containing the data

family

Name of family, as in glm/glmer. Recognizes gaussian, binomial, and poisson with arbitrary links

prefix

Text prefixes for fixed and varying effects parameters

default_prior

Text of default prior for regression parameters

...

Additional parameters to pass to map2stan

Value

Returns an invisible list with two slots:

f

list of formulas, suitable for passing to map2stan

d

list of data, suitable for passing to map2stan

Details

This function parses and converts a glmer-style mixed model formula into a list of formulas appropriate for map2stan input. Interactions are pre-multiplied, and factors are automatically converted into a series of dummy variables. In the absence of varying effects in the input formula, the resulting formula list will also be suitable for map input in most cases.

The function glmer is provided by package lme4, but it is not required for glimmer to work.

See Also

map2stan

Examples

Run this code
# NOT RUN {
library(rethinking)
data(UCBadmit)

# varying intercepts
f3 <- cbind(admit,reject) ~ (1|dept) + applicant.gender
m3 <- glimmer( f3 , UCBadmit , binomial )
m3s <- map2stan( m3$f , data=m3$d )

# varying intercepts and slopes
f4 <- cbind(admit,reject) ~ (1+applicant.gender|dept) + applicant.gender
m4 <- glimmer( f4 , UCBadmit , binomial )
m4s <- map2stan( m4$f , data=m4$d )
# }

Run the code above in your browser using DataLab