nlregress: Flexible nonlinear-shape regression

View source: R/advanced-models.R

nlregressR Documentation

Flexible nonlinear-shape regression

Description

Fits flexible nonlinear predictor shapes without requiring users to construct spline bases manually.

Usage

nlregress(y,
  x,
  covariates = NULL,
  data = NULL,
  spline = c("natural",
    "bspline",
    "polynomial",
    "linear"),
  df = 4,
  degree = 3,
  knots = NULL,
  boundary_knots = NULL,
  family = c("gaussian",
    "binomial",
    "poisson"),
  event = NULL,
  robust = FALSE,
  diagnosis = FALSE,
  level = 0.95,
  digits = 3,
  p_digits = 3,
  show = TRUE,
  console = FALSE)

Arguments

y

Outcome variable.

x

Numeric predictor whose functional form is modeled flexibly.

covariates

Optional additional covariates, including vars(...).

data

Data frame or active data.

spline

Natural spline, B-spline, raw polynomial, or linear form.

df

Spline degrees of freedom when knots are not supplied.

degree

B-spline/polynomial degree.

knots

Optional internal knots.

boundary_knots

Optional two boundary knots.

family

Gaussian, binomial, or Poisson model.

event

Event category for binary binomial/Poisson outcomes.

robust

Request robust covariance when available.

diagnosis

Logical; if TRUE, append diagnostics appropriate to the selected family: linear-model diagnostics for Gaussian models, calibration/influence diagnostics for binomial models, and dispersion/goodness-of-fit diagnostics for Poisson models. Default FALSE.

level, digits, p_digits, show, console

Confidence, formatting and display controls.

Details

The fitted model is stored as the active model and can be used immediately by margins(), predict() and lincom().

Value

An R4VN result object, invisibly.

See Also

qregress, margins

Examples

d <- data.frame(
  age = seq(20, 75, by = 5),
  bmi = c(20, 21, 22, 24, 23, 25, 26, 27, 29, 28, 30, 31),
  sex = factor(rep(c("Female", "Male"), 6)),
  y = c(48, 52, 55, 61, 60, 66, 69, 73, 78, 80, 85, 89),
  outcome = c(0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1)
)
nlregress(y, age, data = d, spline = "natural", df = 3, show = FALSE)
nlregress(y, age, covariates = vars(sex, bmi), data = d,
          spline = "natural", knots = c(35, 50), show = FALSE)
nlregress(outcome, age, data = d, family = "binomial", event = 1,
          show = FALSE)
nlregress(y, age, data = d, spline = "bspline", df = 4, diagnosis = TRUE, show = FALSE)
nlregress(y, age, data = d, spline = "polynomial", degree = 2, show = FALSE)

R4VN documentation built on Sept. 30, 2026, 5:13 p.m.