ml_spline: Spline-Based Nonlinear Time Trend in Longitudinal...

View source: R/ml_spline.R

ml_splineR Documentation

Spline-Based Nonlinear Time Trend in Longitudinal Meta-Analysis

Description

Fits a natural cubic spline meta-regression over follow-up time using the pooled time-point estimates from ml_meta(). Produces a smooth pooled trajectory with simultaneous pointwise confidence bands and tests for nonlinearity.

Usage

ml_spline(meta_obj, df = 3L, n_pred = 200L, alpha = NULL, test_linear = TRUE)

Arguments

meta_obj

Output from ml_meta().

df

Degrees of freedom for the natural cubic spline. Default 3. A value of 1 recovers a linear fit.

n_pred

Number of prediction points for the smooth curve. Default 200.

alpha

Confidence level (inherits from meta_obj if NULL).

test_linear

Logical. If TRUE, performs an F-test of nonlinearity (spline df > 1 vs linear fit). Default TRUE.

Details

The spline is fit by weighted least squares on the ml_meta() estimates, using 1 / se^2 as weights (i.e., inverse squared SE weighting to reflect the precision of each time-point estimate). This is a second-stage model.

For a fully joint spline model at the individual-effect level, users should call metafor::rma.mv() directly with mods = ~ ns(time, df). This function is primarily intended for visualisation and trajectory testing.

Value

Object of class ml_spline with elements:

pred

data.frame with time, fit, ci_lb, ci_ub for the smooth prediction grid.

coef

Spline coefficient estimates.

vcov

Coefficient covariance matrix.

r_squared

Weighted R-squared of the spline fit.

p_nonlinear

p-value for nonlinearity test (if requested).

df

Spline degrees of freedom used.

meta_obj

The original ml_meta object (for plotting).

See Also

ml_meta(), ml_plot()

Examples

dat  <- sim_longitudinal_meta(k = 10, times = c(0, 6, 12, 24), seed = 3)
meta <- ml_meta(dat, yi = "yi", vi = "vi", study = "study", time = "time")
spl  <- ml_spline(meta, df = 2)
print(spl)
plot(spl)


metaLong documentation built on March 31, 2026, 1:07 a.m.