Learn R Programming

splineplot (version 0.2.1)

extract_spline_data: Extract Spline Data

Description

Extract predictions and confidence intervals from fitted models

Usage

extract_spline_data(
  fit,
  data,
  xvar,
  refx,
  model_info,
  term_index = 1,
  log_scale = FALSE,
  ci_level = 0.95
)

Value

Data frame with predictions

Arguments

fit

Fitted model object

data

Data frame

xvar

Variable name

refx

Reference value

model_info

Model information list

term_index

Which smooth term to use (for multiple s() terms)

log_scale

Whether to use log scale

ci_level

Confidence level

Examples

Run this code
# Create sample data
set.seed(123)
n <- 100
x <- rnorm(n, mean = 50, sd = 10)
y <- rbinom(n, 1, plogis(-0.05*(x - 50)))
dat <- data.frame(x = x, y = y)

# Fit GLM with splines
library(splines)
fit <- glm(y ~ ns(x, df = 4), family = binomial(), data = dat)

# Extract spline data
model_info <- list(type = "glm", family = "binomial", ylabel = "Odds Ratio")
df <- extract_spline_data(fit, dat, "x", refx = 50, model_info,
                          log_scale = FALSE, ci_level = 0.95)
head(df)

Run the code above in your browser using DataLab