get_nested_categories {gpboost}R Documentation

Auxiliary function to create categorical variables for nested grouped random effects

Description

Auxiliary function to create categorical variables for nested grouped random effects

Usage

get_nested_categories(outer_var, inner_var)

Arguments

outer_var

A vector containing the outer categorical grouping variable within which the inner_var is nested in. Can be of type integer, double, or character.

inner_var

A vector containing the inner nested categorical grouping variable

Value

A vector containing a categorical variable such that inner_var is nested in outer_var

Author(s)

Fabio Sigrist

Examples


# Fit a model with Time as categorical fixed effects variables and Diet and Chick
#   as random effects, where Chick is nested in Diet using lme4
chick_nested_diet <- get_nested_categories(ChickWeight$Diet, ChickWeight$Chick)
fixed_effects_matrix <- model.matrix(weight ~ as.factor(Time), data = ChickWeight)
mod_gpb <- fitGPModel(X = fixed_effects_matrix, 
                      group_data = cbind(diet=ChickWeight$Diet, chick_nested_diet), 
                      y = ChickWeight$weight, params = list(std_dev = TRUE))
summary(mod_gpb)
# This does (almost) the same thing as the following code using lme4:
# mod_lme4 <-  lmer(weight ~ as.factor(Time) + (1 | Diet/Chick), data = ChickWeight, REML = FALSE)
# summary(mod_lme4)


[Package gpboost version 1.4.0.1 Index]