📉 RCSAnalysis - Restricted Cubic Spline Analysis

Nonlinear dose-response | P-for-nonlinearity | Inflection points | Continuous forest plot

1. Data Input

2. Model Type

3. Variable Selection

4. RCS Options


Downloads







How to Use RCS Analysis

What is Restricted Cubic Spline?

Restricted Cubic Spline (RCS) is a flexible method for modeling nonlinear relationships in regression analysis. It fits piecewise cubic polynomials joined at knot points, with the constraint that the function is linear beyond the boundary knots. This makes it one of the most popular methods in epidemiology for dose-response analysis.

Workflow
  • Step 1: Load data and select the exposure variable (continuous).
  • Step 2: Choose outcome type: Linear (continuous Y), Logistic (binary Y), or Cox (survival data).
  • Step 3: Select outcome variable(s) and optional covariates for adjustment.
  • Step 4: Set number of knots (default 4) and reference value (default median).
  • Step 5: Run analysis and review the RCS curve, P-for-nonlinearity, inflection points, and forest plot.
Number of Knots
  • 3 knots: Minimal flexibility, suitable for simple nonlinear patterns.
  • 4 knots (default): Good balance between flexibility and parsimony. Recommended for most analyses.
  • 5 knots: More flexible, can capture complex curves. Recommended for large datasets.
  • 6 knots: Maximum flexibility, but may overfit with small samples.
  • 7 knots: For very large datasets with complex dose-response shapes. Rarely needed; requires sufficient unique values in the exposure variable.
P for Nonlinearity
  • Overall P: Tests the overall association between exposure and outcome (linear + nonlinear).
  • P for Nonlinearity: Tests whether the nonlinear component is significant. If P < 0.05, the relationship is significantly nonlinear.
  • The P-for-nonlinearity is computed using the Wald test on the nonlinear spline terms (jointly testing that all nonlinear coefficients = 0).
Inflection Points
  • Turning Point: Where the first derivative of the RCS curve is zero - the local minimum or maximum of the dose-response. This is the most clinically meaningful inflection, indicating the exposure value with lowest (or highest) risk.
  • Reference Crossing: Where the effect measure (HR/OR) crosses the reference value (1.0). These indicate thresholds where the exposure changes from protective to harmful (or vice versa).
  • Curvature Inflection: Where the second derivative of the RCS curve is zero - the curve changes from convex to concave (or vice versa). Computed on the log-HR/log-OR scale for numerical stability, with boundary 10% excluded to avoid edge noise.
  • All three types of inflection points are automatically identified and can help identify clinically meaningful thresholds.
Forest Plot

The continuous forest plot displays the effect estimate (HR/OR) with 95% CI at multiple points along the exposure range. Points near inflection points are highlighted in red, significant points (CI excludes reference) in dark blue, and non-significant points in gray.

Demo Data

Simulated survival study (n=500) with a U-shaped nonlinear age effect on mortality. The true minimum risk is around age 55. The dataset includes: age (exposure), sex, bmi (covariates), time/status (survival outcome), biomarker (continuous outcome), and outcome (binary outcome).

Reference

Harrell FE. Regression Modeling Strategies: With Applications to Linear Models, Logistic Regression, and Survival Analysis. 2nd ed. Springer; 2015. (rms package)

Effect Measure Interpretation
  • Cox Regression: Y-axis shows HR (Hazard Ratio) relative to the reference value. HR=1 at the reference. The curve shows how risk changes across exposure levels.
  • Logistic Regression: Y-axis shows OR (Odds Ratio) relative to the reference value. OR=1 at the reference.
  • Linear Regression (OLS): Y-axis shows the difference in predicted Y from the reference value. At the reference, the difference = 0. The curve shows how the outcome changes (in its original units) relative to the reference level — not the absolute predicted value.
九方思乐 · math81.com · 粤ICP备2026092768号