Skip to contents

Estimates the treatment effect across many reasonable model specifications to assess robustness. Combines covariate sets x sample filters x model families. Cross-references specr (specr::specr) as the canonical modern implementation with built-in plotting; use specr directly when you want the published specification-curve plot.

Usage

specification_curve(
  data,
  outcome,
  treatment,
  covariate_sets,
  sample_filters = NULL,
  model_types = NULL,
  alpha = 0.05
)

Arguments

data

Analysis data.frame.

outcome

Outcome variable name.

treatment

Treatment variable name.

covariate_sets

List of character vectors (one per spec).

sample_filters

Optional. Accepted shapes (for Python<->R parity): (a) list(list(name = "...", fn = function(df) ...), ...) (R native), (b) list(c("name", fn), ...) or list(list("name", fn), ...) (Python list[tuple[str, callable]] shape — positional pair). Default: full sample only.

model_types

Character vector of model families: "ols", "logistic", "robust". Default c("ols").

alpha

Significance level. Default 0.05.

Value

A morie_spec_curve named-list.

Examples

set.seed(1)
df <- data.frame(d = rnorm(80), x1 = rnorm(80), x2 = rnorm(80))
df$y <- 0.4 * df$d + 0.3 * df$x1 + rnorm(80)
res <- specification_curve(df, "y", "d",
                           covariate_sets = list(character(0), "x1",
                                                 c("x1", "x2")))
str(res, max.level = 1)
#> List of 9
#>  $ estimates      : num [1:3] 0.487 0.556 0.59
#>  $ ses            : num [1:3] 0.121 0.125 0.125
#>  $ p_values       : num [1:3] 1.39e-04 2.88e-05 1.11e-05
#>  $ specifications :List of 3
#>  $ median_estimate: num 0.556
#>  $ iqr_lower      : num 0.521
#>  $ iqr_upper      : num 0.573
#>  $ pct_significant: num 100
#>  $ pct_same_sign  : num 100
#>  - attr(*, "class")= chr [1:2] "morie_spec_curve" "list"