| observe_treatment | R Documentation |
Evaluates one formula per modeled group against every row of data and
draws that row's exposure from the resulting probabilities, so the formulas
are the propensity model. One group is always implicit: it is listed last and
takes the remaining probability, which makes it the reference category of the
logit link.
observe_treatment(
data,
formulas,
link = c("identity", "logit"),
labels = NULL,
name = "treatment",
seed = NULL,
envir = parent.frame()
)
data |
Base |
formulas |
Character vector of at least one formula, each an expression
over the columns of |
link |
Scale the formulas are stated on, one of |
labels |
Optional atomic vector of group labels, one per formula plus
one for the implicit final group. Defaults to |
name |
Name of the exposure variable, which must not already exist in
|
seed |
Optional random seed. A single number, or |
envir |
Environment the formulas are evaluated in after the data columns. Defaults to the caller's environment. |
A simulab_sim base data.frame with the columns of data followed
by the exposure variable named by name, one row per input row. The
component probabilities, reached with
as.data.frame(x, what = "probabilities"), holds one row per observation
and group, with columns observation, group and probability.
data <- data.frame(id = 1:100, severity = stats::rnorm(100))
result <- observe_treatment(
data, formulas = "-0.5 + 0.8 * severity", link = "logit", seed = 1
)
head(result)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.