*! ml_spline.sthlp metaLong for Stata 14.1

ml_spline — Restricted Cubic Spline Time Trend for Longitudinal Meta-Analysis

Syntax

ml_spline ,
metafile(filename)
[df()
npred()
alpha()
nolineartest
plot
saving()
replace]

Description

ml_spline fits a second-stage restricted cubic spline (RCS) meta-regression
using the pooled time-point estimates produced by ml_meta as the outcome.
Precision weights (1/se²) reflect the reliability of each pooled estimate.
The command uses Stata's built-in mkspline to construct the RCS basis.

The result is a smooth predicted trajectory with pointwise confidence bands,
suitable for overlaying on the observed pooled estimates in metalong_plot.
An optional F-test for nonlinearity compares the spline to a simple linear fit.

Options

metafile(filename) specifies the path to the results dataset
saved by ml_meta. Required.

df() specifies the degrees of freedom for the restricted
cubic spline. Default is 3. A value of 1 recovers a linear weighted regression.
The number of internal knots equals df − 1, placed at quantiles of the observed
time distribution.

npred() specifies the number of equally-spaced prediction
points spanning the observed time range. Default is 100.

alpha() sets the significance level for confidence bands.
Default is 0.05.

nolineartest suppresses the nonlinearity F-test (spline vs linear).

plot draws a quick preview twoway plot of the spline. For a fully
annotated combined figure use metalong_plot.

saving() saves the prediction dataset to filename.dta.
This file is required by metalong_plot when the splinefile() option is used.

replace allows overwriting an existing saving() file.

Saved prediction dataset columns

time Prediction grid time value

theta_hat Spline predicted pooled effect

se_hat Standard error of prediction

ci_lb Lower confidence bound

ci_ub Upper confidence bound

Returned r() values

r(r_squared) Weighted R² of the spline fit

r(p_nonlinear) Nonlinearity F-test p-value; missing if df=1

r(df) Spline degrees of freedom used

r(alpha) Confidence level used

Statistical details

The spline is fitted by weighted least squares:

min_β Σ wt_t (theta_t − X_t β)², wt_t = 1/se_t²

where X_t is the RCS design matrix evaluated at time t. Knot positions are
placed at the (1/(df))-th, (2/(df))-th, …, ((df−1)/df)-th quantiles of
the observed time distribution.

Confidence bands use the standard error of prediction from the fitted weighted
regression model, with a t(n_obs − df − 1) critical value.

The nonlinearity test compares the weighted R² of the spline model to that of
a simple weighted linear regression via an F-statistic with (df − 1) and
(n_obs − df − 1) degrees of freedom.

Example

. sim_longmeta, k(20) times(0 6 12 18 24) seed(3) clear

. ml_meta yi vi, study(study) time(time) saving(meta_res) replace

. ml_spline, metafile(meta_res) df(3) npred(200) ///

saving(spline_res) replace

. display r(r_squared)

. display r(p_nonlinear)

. ml_plot, metafile(meta_res) splinefile(spline_res) ///

title("Spline trend") saving(fig.gph) replace

See also

ml_meta, metalong_plot, mkspline, metalong