data(Orthodont)
# are there cluster-constant covariates?
find_ccc(Orthodont, "Subject")
# \donttest{
# fit initial model
mod <- glmermboost(distance ~ age + Sex + (1 |Subject),
data = Orthodont, family = gaussian,
control = boost_control(mstop = 100))
# let mermboost do the cluster-sensitive cross-validation for you
norm_cv <- mer_cvrisk(mod, no_of_folds = 10)
opt_m <- mstop(norm_cv)
# fit model with optimal stopping iteration
mod_opt <- glmermboost(distance ~ age + Sex + (1 |Subject),
data = Orthodont, family = gaussian,
control = boost_control(mstop = opt_m))
# use the model as known from mboost
# in additional, there are some methods knwon from lme4
ranef(mod_opt)
VarCorr(mod_opt)
# }
#######################
set.seed(123)
# Parameters
n_groups <- 10 # Number of groups
n_per_group <- 50 # Number of observations per group
beta_fixed <- c(0.5, -0.3, 0.7) # Fixed effects for intercept, covariate1, covariate2
sigma_random <- 1 # Random effect standard deviation
# Simulate random effects (group-specific)
group_effects <- rnorm(n_groups, mean = 0, sd = sigma_random)
# Simulate covariates
covariate1 <- rnorm(n_groups * n_per_group)
covariate2 <- rnorm(n_groups * n_per_group)
# Simulate data
group <- rep(1:n_groups, each = n_per_group)
random_effect <- group_effects[group]
# Linear predictor including fixed effects and random effects
linear_predictor <- beta_fixed[1] + beta_fixed[2] * covariate1 +
beta_fixed[3] * covariate2 + random_effect
prob <- plogis(linear_predictor) # Convert to probabilities
# Simulate binomial outcomes
y <- rbinom(n_groups * n_per_group, size = 1, prob = prob)
# Combine into a data frame
sim_data <- data.frame(group = group, y = y,
covariate1 = covariate1,
covariate2 = covariate2)
sim_data$group <- as.factor(sim_data$group)
# \donttest{
mod3 <- glmermboost(y ~ covariate1 + covariate2 + (1 | group),
data = sim_data, family = binomial())
bin_cv <- mer_cvrisk(mod3, no_of_folds = 10)
mstop(bin_cv)
# }
Run the code above in your browser using DataLab