predict.risk_mod: Predict Method for Risk Model Fits

View source: R/generic.R

predict.risk_modR Documentation

Predict Method for Risk Model Fits

Description

Obtains predictions from risk score models.

Usage

## S3 method for class 'risk_mod'
predict(
  object,
  newx = NULL,
  type = c("link", "response", "score"),
  target_prevalence = NULL,
  study_prevalence = NULL,
  ...
)

Arguments

object

An object of class "risk_mod", usually a result of a call to risk_mod().

newx

Optional matrix of new values for X for which predictions are to be made. If ommited, the fitted values are used.

type

The type of prediction required. The default ("link") is on the scale of the predictors (i.e. log-odds); the "response" type is on the scale of the response variable (i.e. risk probabilities); the "score" type returns the risk score calculated from the integer model.

target_prevalence

Optional numeric scalar. If provided (and type = "response"), predicted probabilities are recalibrated to this target outcome prevalence via prevalence_adjust() before being returned. Useful when applying a model fit on one population (e.g. a case-control or enriched study sample) to a target population with a different outcome prevalence.

study_prevalence

Optional numeric scalar giving the outcome prevalence in the sample used to fit object. Only used when target_prevalence is provided. Defaults to mean(object$y), the prevalence observed in the model's training data.

...

Additional arguments.

Value

Numeric vector of predicted values.

Examples

y <- breastcancer[[1]]
X <- as.matrix(breastcancer[,2:ncol(breastcancer)])
mod <- risk_mod(X, y, lambda0 = 0.01)
predict(mod, type = "link")[1]
predict(mod, type = "response")[1]
predict(mod, type = "score")[1]
predict(mod, type = "response", target_prevalence = 0.10)[1]

riskscores documentation built on Aug. 24, 2026, 5:07 p.m.