ma_lme4_formula_terms: Utility Functions for Working with 'lme4' Formula Objects

View source: R/ma_lme4_formula_terms.R

ma_lme4_formulaR Documentation

Utility Functions for Working with lme4 Formula Objects

Description

Utility functions for working with lme4 formula objects. The function ma_lme4_formula_terms decomposes an lme4 formula into several parts for further processing.

Usage

ma_lme4_formula_terms(formula)

ma_lme4_formula_design_matrices(formula, data, start_index=0, formula_terms=NULL,
        only_design_matrices=FALSE)

Arguments

formula

An R formula object

data

Data frame

start_index

Starting index for cluster identifiers

formula_terms

Optional argument with processed formula terms using the function ma_lme4_formula_terms

only_design_matrices

Logical indicating whether only design matrices should be created

Value

List with several entries

Examples

## Not run: 
#############################################################################
# EXAMPLE 1: Splitting a lme4 formula
#############################################################################

#*** formula for a multilevel model
formula <- y ~ I( miceadds::cwc(x, idcluster)) + z + I(z^2) + I( miceadds::gm(x, idcluster) ) + w +
                        ( x + I(x^2) | idcluster)  + (0 +  w | idcluster ) +
                        ( 0 + I(as.factor(f)) | idcluster)
miceadds::ma_lme4_formula_terms(formula)

#*** formula for a single level model
formula2 <- y ~ I( miceadds::cwc(x, idcluster)) + z + I(z^2) + I( miceadds::gm(x, idcluster) ) + w
miceadds::ma_lme4_formula_terms(formula2)

#############################################################################
# EXAMPLE 2: Design matrices for multilevel model
#############################################################################

data(data.ma07, package="miceadds")
dat <- data.ma07

formula <- x1 ~ x2 + I( miceadds::gm( x2, id2)) + I( miceadds::gm( x2, id3)) + y1 + z1 +
                    ( x2 | id2:id3 ) + ( 1 | id3 ) + ( 0 + x2 | id3 )
res <- miceadds::ma_lme4_formula_design_matrices(formula, data=dat)
str(res)

## End(Not run)

miceadds documentation built on May 29, 2024, 11:05 a.m.