Using MEXGB

MEXGB combines flexible fixed effects with subject-specific random effects. The Gaussian model assumes independent residuals conditional on these effects.

library(MEXGB)
set.seed(10)
d <- simLong(8, 6, time_points = 4, rho_W = 0)
X <- as.matrix(d[paste0("Var", 1:6)])
Z <- as.matrix(d[c("RandomIntercept", "RandomSlope")])
fit <- MEXGB(X, d$Y, d$id, Z, time = d$time,
             ntree = 10, iter = 2, inner = 2, crossfit = 2,
             linear = FALSE, screen = "none", verbose = FALSE)
fit
#> Mixed Effect Extreme Gradient Boosting (MEXGB)
#>   family: gaussian 
#>   individuals: 8  observations: 32 
#>   random effects: 2  selected boosting rounds: 20 
#>   EM iterations: 2 (not converged) 
#>   estimated random-effect covariance:
#>         [,1]    [,2]
#> [1,]  4.5076 -2.5428
#> [2,] -2.5428  5.5014
#>   estimated residual variance: 5.5826
head(predict(fit, X, Z, d$id, d$time))
#> [1] -0.8722626 -1.0332720 -1.0848488 -1.4530335 -0.9563522 -2.1997995

The small iteration budget illustrates the interface, not convergence or model accuracy. For a substantive analysis increase the budget and inspect diagnostics.

For unseen subjects, random effects are zero but population coefficients of Z are retained:

head(predict(fit, X, Z, d$id + 100, d$time))
#> [1] -2.215145 -2.298764 -2.272950 -2.563744 -2.096710 -2.861704
summary(fit)
#>       var   rel.inf
#> Var5 Var5 37.472872
#> Var3 Var3 27.813755
#> Var1 Var1 23.299268
#> Var2 Var2  7.872080
#> Var6 Var6  3.542026

Use family = "binomial" with a numeric 0/1 outcome or family = "cox" with a two-column matrix of positive observed times and 0/1 status (1 means event). Right-censored survival::Surv inputs are also supported. Start-stop and interval censoring are not. Cox rows represent clustered event times rather than repeated time-varying records for one terminal event. type = "survival" returns a matrix of conditional survival probabilities for requested times.

For nonlinear links, zero-random-effect predictions are not marginal predictions integrated over the random-effects distribution. The Cox update uses a Poisson working approximation. Failed Laplace optimizations warn, retain the PQL update, and appear in laplace_diagnostics.

Evaluation

Within-subject folds tune predictions for additional observations of represented subjects. They are not subject-held-out validation or temporal validation. Adaptive choices share these folds; evaluate final performance on an independent test set or with nested validation tailored to the task. Never report the training predictions above as external validation performance.

Simulation

simLong() generates Gaussian, binary or clustered event-time data. Binary and survival discrimination targets are solved on a finite pilot; achieved pilot values do not guarantee exact population or realised-sample discrimination. Survival censoring rates are calibrated on the realised sample. Gaussian simulations with nonzero rho_W include residual serial correlation beyond that modelled by MEXGB and can be used to study misspecification.