dina: Estimate heterogeneous treatment effects via DINA (data-frame...

View source: R/dina_df.R

dinaR Documentation

Estimate heterogeneous treatment effects via DINA (data-frame interface)

Description

dina() is the high-level user-facing wrapper around dina_fit(). It accepts a data frame plus column-name arguments, matching the conventions used elsewhere in the forestsearch package, and extracts the covariate matrix, response, and treatment indicator before dispatching to dina_fit().

Usage

dina(
  df,
  outcome,
  treatment,
  covariates,
  family = c("gaussian", "binomial", "poisson", "cox"),
  status = NULL,
  ...
)

Arguments

df

data frame (or tibble / data.table) containing the outcome, treatment, and covariate columns.

outcome

character(1); the name of the response column in df. For family = "cox" this is the event/censoring time column.

treatment

character(1); the name of the binary treatment indicator column in df. Values must be 0/1 or logical.

covariates

character vector of length ⁠>= 1⁠; the names of the covariate columns in df. All must be numeric.

family

one of "gaussian", "binomial", "poisson", "cox".

status

character(1) or NULL; for family = "cox" only, the name of the event indicator column in df (1 = event, 0 = censored). Ignored for non-Cox families.

...

further arguments forwarded to dina_fit().

Details

All other arguments are forwarded to dina_fit() via ..., including propensity_method, baseline_method, cross_fitting, n_folds, cens_type, cens_params, n_grid, eps, and seed. See dina_fit() for their full documentation.

Covariate columns must be numeric (or integer). Convert factors to dummy variables (e.g., with stats::model.matrix()) before calling if needed. Rows with any NA value in the referenced columns are rejected with an error; use stats::na.omit() or impute beforehand.

Value

An object of class "dina", as returned by dina_fit(). The ⁠$call⁠ component is overwritten with the original dina() call so that print() and summary() show the high-level invocation rather than the internal matrix-based dispatch.

See Also

dina_fit() for the underlying matrix-based estimator; dina_bagged() for the bagged version with infinitesimal-jackknife variance.

Examples

set.seed(1)
n <- 400
df_demo <- data.frame(
  y         = NA,
  w         = stats::rbinom(n, 1, 0.5),
  x1        = stats::runif(n, -1, 1),
  x2        = stats::runif(n, -1, 1),
  x3        = stats::runif(n, -1, 1)
)
tau_x      <- 0.5 + 0.8 * df_demo$x1 - 0.3 * df_demo$x2
df_demo$y  <- 1 + df_demo$x1 + df_demo$w * tau_x + stats::rnorm(n)

fit <- dina(
  df         = df_demo,
  outcome    = "y",
  treatment  = "w",
  covariates = c("x1", "x2", "x3"),
  family     = "gaussian",
  seed       = 1L
)
coef(fit)
confint(fit)


forestsearch documentation built on Nov. 15, 2026, 9:06 a.m.