Compute Difference in Average Treatment Effects or Relative Risk Ratio Between Two Subgroups
compute_difference.Rd
This function calculates either the difference in average treatment effects (ATE) or the relative risk ratio (RRR) between two independent subgroups. Each subgroup is represented as a list that includes the estimated effect (theta) and the standard error (std.error) of the effect. The result includes both a data frame and an interpretation string formatted for easy use with `glue::glue` in Quarto documents etc. The subgroups are expected to be outputs from the `lmtp::lmtp_contrast()` function.
Arguments
- group1
A list containing the estimated effect and standard error of subgroup 1. Expected structure: list(vals = data.frame(theta = x, std.error = y)).
- group2
A list containing the estimated effect and standard error of subgroup 2. Expected structure: list(vals = data.frame(theta = x, std.error = y)).
- type
A character string specifying the type of calculation. "RD" for risk difference (default), "RR" for relative risk ratio.
Value
A list containing: - `results`: A data frame with columns `mean_difference`, `std_error`, `conf_low`, and `conf_high` for type "RD", or `rrr`, `std_error_log`, `conf_low`, and `conf_high` for type "RR", each rounded to 4 decimal places. Suitable for direct use in reporting. - `interpretation`: A string providing a formatted interpretation of the results.
Examples
group1 <- list(vals = data.frame(theta = 100, std.error = 10))
group2 <- list(vals = data.frame(theta = 90, std.error = 5))
output_rd <- compute_difference(group1, group2)
#> Error in glue("the difference in average treatment effects is {results$mean_difference} with a standard error of {results$std_error} and a 95% ci of [{results$conf_low}, {results$conf_high}]."): could not find function "glue"
cat(output_rd$interpretation) # Print the interpretation for risk difference
#> Error in eval(expr, envir, enclos): object 'output_rd' not found
group1 <- list(vals = data.frame(theta = 3.19, std.error = 0.393))
group2 <- list(vals = data.frame(theta = 1.23, std.error = 0.228))
output_rr <- compute_difference(group1, group2, type = "RR")
#> Error in glue("the difference in the relative risk ratio between the focal group and the reference group is {results$rrr} with a standard error of {results$std_error_log} and a 95% ci of [{results$conf_low}, {results$conf_high}]."): could not find function "glue"
cat(output_rr$interpretation) # Print the interpretation for relative risk ratio
#> Error in eval(expr, envir, enclos): object 'output_rr' not found