% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/add_riskscore.R
\name{add_riskscore}
\alias{add_riskscore}
\title{Add Risk Score to Dataset}
\usage{
add_riskscore(
  input,
  family = c("cox", "binary"),
  target = NULL,
  time = NULL,
  status = NULL,
  vars,
  new_var_name = "riskscore"
)
}
\arguments{
\item{input}{Data frame containing the variables for analysis.}

\item{family}{Character string specifying the model family: `"cox"` for Cox
proportional hazards regression or `"binary"` for logistic regression.
Default is `"cox"`.}

\item{target}{Character string specifying the target variable name. Required
when `family = "binary"`.}

\item{time}{Character string specifying the time-to-event variable name.
Required when `family = "cox"`.}

\item{status}{Character string specifying the event status variable name.
Required when `family = "cox"`.}

\item{vars}{Character vector of variable names to include in the model.}

\item{new_var_name}{Character string specifying the name for the new risk
score column. Default is `"riskscore"`.}
}
\value{
Data frame identical to `input` with an additional column containing
  risk scores (linear predictors for Cox models or predicted probabilities
  for logistic models).
}
\description{
Computes a risk score for each observation based on Cox proportional hazards
regression or binary logistic regression. The function fits the specified
model and returns the dataset with an added risk score column.
}
\examples{
set.seed(123)
input_data <- data.frame(
  time = rexp(100),
  status = rbinom(100, 1, 0.5),
  age = rnorm(100, 60, 10),
  score1 = rnorm(100),
  score2 = rnorm(100)
)
result <- add_riskscore(
  input_data,
  time = "time", status = "status",
  vars = c("age", "score1", "score2")
)
head(result$riskscore)
}
\author{
Dongqiang Zeng
}
