Replaces the coefficients in a fitted model object. This is used for simulation-based inference (MVN simulation) where we draw coefficient vectors from a multivariate normal distribution and need to compute predictions using each draw.
Usage
set_coef(model, new_coefs)
# Default S3 method
set_coef(model, new_coefs)
# S3 method for class 'orm'
set_coef(model, new_coefs)
# S3 method for class 'lrm'
set_coef(model, new_coefs)
# S3 method for class 'rms'
set_coef(model, new_coefs)
# S3 method for class 'robcov_vglm'
set_coef(model, new_coefs)
# S3 method for class 'vglm'
set_coef(model, new_coefs)Details
This function creates a shallow copy of the model and replaces its
coefficients. The modified model can then be passed to predict() or
soprob_markov() to compute predictions under the simulated coefficients.
Supported model classes:
orm,lrm,rms(S3): Modifies$coefficientsvglm(S4): Modifies@coefficientsslotrobcov_vglm: Modifies$coefficients
Note: Prediction functions (predict.orm, predict.vglm) recompute
linear predictors from the design matrix and coefficients, so we only need
to replace the coefficients - not any stored linear predictors.
See also
get_vcov_robust() for obtaining robust covariance matrices
Examples
trial <- sim_markov("actt2", n_patients = 40, follow_up_time = 6, seed = 1)
markov_data <- prepare_markov_data(trial, absorbing_state = 8)
fit <- rms::orm(
y ~ time + tx + yprev,
data = markov_data,
x = TRUE,
y = TRUE,
opt_method = "LM",
scale = TRUE
)
new_coefs <- coef(fit)
new_coefs["tx"] <- new_coefs["tx"] - 0.1
fit_shifted <- set_coef(fit, new_coefs)
coef(fit_shifted)["tx"]
#> tx
#> -0.2647912
