View source: R/negbin_helpers.R
| lgspline_negbin | R Documentation |
Convenience wrapper that calls lgspline with the correct
family, weight, dispersion, score, and unconstrained-fit functions for
NB2 regression. All standard lgspline arguments (knots, penalties,
constraints, parallel, correlation structures, etc.) are passed through.
lgspline_negbin(formula, data, ...)
formula |
Formula specifying the model. The response should be non-negative integer counts. |
data |
Data frame. |
... |
Additional arguments passed to |
Internally sets:
family = negbin_family()
unconstrained_fit_fxn = unconstrained_fit_negbin
glm_weight_function = negbin_glm_weight_function
qp_score_function = negbin_qp_score_function
dispersion_function = negbin_dispersion_function
schur_correction_function = negbin_schur_correction
need_dispersion_for_estimation = TRUE
estimate_dispersion = TRUE
standardize_response = FALSE
A formula interface is needed, e.g. lgspline_negbin(t, y) won't work,
unlike for ordinary lgspline.
When a correlation structure is supplied via Vhalf/VhalfInv,
the model is fitted through the GEE Path 1b machinery in get_B.
The dispersion function uses VhalfInv to whiten Pearson
residuals for a better moment-based initialization of \theta,
which stabilizes the profile MLE under moderate to strong correlation.
The score function handles the whitened design consistently with the
Weibull AFT GEE convention.
An object of class "lgspline".
lgspline_cox for Cox PH,
lgspline_weibull for Weibull AFT,
negbin_family, unconstrained_fit_negbin
set.seed(1234)
N <- 300
t <- rnorm(N)
mu <- exp(1 + 0.5 * sin(2 * t))
y <- rnbinom(N, size = 3, mu = mu)
df <- data.frame(response = y, predictor = t)
fit <- lgspline_negbin(
response ~ spl(predictor),
data = df,
K = 2,
opt = FALSE,
wiggle_penalty = 1e-2
)
print(summary(fit))
plot(fit, show_formulas = TRUE,
custom_response_lab = 'Count')
points(t, mu, col = 'grey', cex=0.67)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.