Skip to contents

This function computes a threshold for indirect or direct effect estimates that controls the false discovery rate according to estimates made using real and synthetic null data, against the null hypotheses that effects are zero. It computes the proportion of synthetic null estimates that are among the top K largest effects (in magnitude) as an estimate of the FDR.

Usage

fdr_summary(contrast, effect = "indirect_overall", q_value = 0.15)

Arguments

contrast

A data.frame summarizing the differences between outcomes across hypothetical treatments, typically as output by null_contrast. Each row is one outcome in one hypothetical scenario.

effect

Either "indirect_overall" (the default), "indirect_pathwise", or "direct_effect" specifying the type of effect that we want to select.

q_value

The target for false discovery rate control. The last time the estimated FDR is above this threshold is smallest magnitude of effect size that we will consider.

Value

fdr A data.frame specifying, for each candidate effect, whether it should be selected.

Examples

# example with null data - notice synthetic data has larger effect.
exper <- demo_joy() |>
    mediation_data("PHQ", "treatment", starts_with("ASV"))
multimedia(exper) |>
    estimate(exper) |>
    null_contrast(exper) |>
    fdr_summary("direct_effect")
#> Fitting the nullified model...
#> Generating synthetic data...
#> Fitting the full model on synthetic data...
#> Estimating effects on real and synthetic data...
#> Warning: There was 1 warning in `summarise()`.
#>  In argument: `ix = max(.data$rank)`.
#> Caused by warning in `max()`:
#> ! no non-missing arguments to max; returning -Inf
#> # A tibble: 2 × 6
#>   source    outcome direct_effect  rank fdr_hat keep 
#>   <chr>     <chr>           <dbl> <int>   <dbl> <lgl>
#> 1 synthetic PHQ             0.398     1     1   FALSE
#> 2 real      PHQ            -0.298     2     0.5 FALSE

multimedia(exper) |>
    estimate(exper) |>
    null_contrast(exper, "M->Y", indirect_overall) |>
    fdr_summary("indirect_overall")
#> Fitting the nullified model...
#> Generating synthetic data...
#> Fitting the full model on synthetic data...
#> Estimating effects on real and synthetic data...
#> Warning: There was 1 warning in `summarise()`.
#>  In argument: `ix = max(.data$rank)`.
#> Caused by warning in `max()`:
#> ! no non-missing arguments to max; returning -Inf
#> # A tibble: 2 × 6
#>   source    outcome indirect_effect  rank fdr_hat keep 
#>   <chr>     <chr>             <dbl> <int>   <dbl> <lgl>
#> 1 synthetic PHQ             -0.120      1     1   FALSE
#> 2 real      PHQ             -0.0447     2     0.5 FALSE

# example with another dataset - synthetic effect is smaller.
exper <- demo_spline(tau = c(2, 1)) |>
    mediation_data(starts_with("outcome"), "treatment", "mediator")
multimedia(exper) |>
    estimate(exper) |>
    null_contrast(exper) |>
    fdr_summary("direct_effect")
#> Fitting the nullified model...
#> Generating synthetic data...
#> Fitting the full model on synthetic data...
#> Estimating effects on real and synthetic data...
#> # A tibble: 4 × 6
#>   source    outcome   direct_effect  rank fdr_hat keep 
#>   <chr>     <chr>             <dbl> <int>   <dbl> <lgl>
#> 1 real      outcome_1      -1.72        1   0     TRUE 
#> 2 real      outcome_2      -0.847       2   0     FALSE
#> 3 synthetic outcome_2       0.0259      3   0.333 FALSE
#> 4 synthetic outcome_1      -0.00569     4   0.5   FALSE

multimedia(exper) |>
    estimate(exper) |>
    null_contrast(exper, "M->Y", indirect_overall) |>
    fdr_summary("indirect_overall")
#> Fitting the nullified model...
#> Generating synthetic data...
#> Fitting the full model on synthetic data...
#> Estimating effects on real and synthetic data...
#> # A tibble: 4 × 6
#>   source    outcome   indirect_effect  rank fdr_hat keep 
#>   <chr>     <chr>               <dbl> <int>   <dbl> <lgl>
#> 1 real      outcome_2          1.01       1   0     TRUE 
#> 2 real      outcome_1          0.772      2   0     FALSE
#> 3 synthetic outcome_2         -0.0213     3   0.333 FALSE
#> 4 synthetic outcome_1         -0.0183     4   0.5   FALSE