# Introduction to metacor

# metacor: Meta-analysis with correlated data

The `metacor` package provides tools for conducting meta-analyses when your effect sizes involve pre-post correlations, missing SDs, and flexible imputation methods. It is especially useful for single-group or controlled designs with incomplete data.

## Main Features

- Calculates multiple effect sizes (SMDpre, SMDchange, ScMDpooled, etc.)
- Handles missing correlations and SDs with advanced imputation methods
- Produces detailed imputation reports (Word)
- Flexible for intervention-only or control-intervention designs

## Quick Start Example

Let’s illustrate a simple workflow with example data:

    library(metacor)

    # Example dataset (for pre/post design only)
    df <- data.frame(
      study_name = c("Study1", "Study2", "Study3", "Study4","Study5", "Study6", "Study7", "Study8", "Study9"),
      p_value_Int = c(1.038814e-07, NA, NA, NA, NA, 2.100000e-02, NA, NA, NA),
      n_Int = c(10, 10, 10, 10, 15, 15, 10, 10, 10),
      meanPre_Int = c(8.17, 10.09, 10.18, 9.85, 9.51,7.70, 10.00,  11.53, 11.20),
      meanPost_Int = c(10.12, 12.50, 12.56,10.41, 10.88, 9.20, 10.80,13.42,12.00),
      sd_pre_Int = c(1.83,0.67,0.66,0.90,0.62, 0.90, 0.70, 0.60, 1.90),
      sd_post_Int = c(1.85, 0.72, 0.97, 0.67, 0.76, 1.10, 0.70,0.80,1.80),
      upperCI_Int = c(NA, NA,NA, NA,NA, NA,NA, NA, NA),
      lowerCI_Int = c(NA, NA,NA, NA,NA, NA,NA, NA, NA))

    results <- metacor_dual(df,
                            digits = 3,
                            method = "both",
                            apply_hedges = TRUE,
                            add_to_df = TRUE,
                            SMD_method = "SMDpre",
                            MeanDifferences = TRUE,
                            impute_method = "cv",
                            verbose = TRUE,
                            report_imputations = TRUE,
                            custom_sd_diff_int = NULL,
                            custom_sd_diff_con = NULL,
                            single_group = TRUE)
    #> Imputed sd_diff_int at row 2 using 'cv' (global median): 0.7200
    #> Imputed sd_diff_int at row 3 using 'cv' (global median): 0.7111
    #> Imputed sd_diff_int at row 4 using 'cv' (global median): 0.1673
    #> Warning in metacor_dual(df, digits = 3, method = "both", apply_hedges = TRUE, : Row 4: Imputed sd_diff_int = 0.1673 gives r_int = 1.0207 (outside [-0.9999, 0.9999]).
    #> Suggested sd_diff_int range: [0.2303, 1.5700].
    #>  r_int not assigned.
    #> Imputed sd_diff_int at row 5 using 'cv' (global median): 0.4093
    #> Warning in metacor_dual(df, digits = 3, method = "both", apply_hedges = TRUE, : Row 6: Imputed sd_diff_int = 2.2349 gives r_int = -1.5024 (outside [-0.9999, 0.9999]).
    #> Suggested sd_diff_int range: [0.2005, 2.0000].
    #>  r_int not assigned.
    #> Imputed sd_diff_int at row 7 using 'cv' (global median): 0.2390
    #> Imputed sd_diff_int at row 8 using 'cv' (global median): 0.5647
    #> Imputed sd_diff_int at row 9 using 'cv' (global median): 0.2390

## Imputation and Reporting

If your dataset has missing values for correlations or SD differences, metacor_dual() will automatically perform imputations based on the method you choose (e.g., “direct”, “mean”, “cv”). You can also request a Word report with all imputations performed by setting the argument report_imputations = TRUE.

    result <- metacor_dual(df, report_imputations = TRUE)
    #> Warning in metacor_dual(df, report_imputations = TRUE): Row 6: Imputed sd_diff_int = 2.2349 gives r_int = -1.5024 (outside [-0.9999, 0.9999]).
    #> Suggested sd_diff_int range: [0.2005, 2.0000].
    #>  r_int not assigned.

The report will be saved as imputation_report.docx in your working directory.

## Advanced Usage

You can customise the imputation methods and other arguments. For more details, see the documentation:

    ?metacor_dual

## References

Fu, R., Vandermeer, B. W., Shamliyan, T. A., O’Neil, M. E., Yazdi, F., Fox, S. H., & Morton, S. C. (2013). Handling Continuous Outcomes in Quantitative Synthesis. Methods Guide for Comparative Effectiveness Reviews. AHRQ Publication No. 13-EHC103-EF. Link

## Session info

    sessionInfo()
    #> R version 4.3.1 (2023-06-16)
    #> Platform: aarch64-apple-darwin20 (64-bit)
    #> Running under: macOS 26.1
    #>
    #> Matrix products: default
    #> BLAS:   /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib
    #> LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0
    #>
    #> locale:
    #> [1] C/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
    #>
    #> time zone: Europe/London
    #> tzcode source: internal
    #>
    #> attached base packages:
    #> [1] stats     graphics  grDevices utils     datasets  methods   base
    #>
    #> other attached packages:
    #> [1] metacor_1.2.1
    #>
    #> loaded via a namespace (and not attached):
    #>  [1] vctrs_0.6.5       zip_2.3.3         cli_3.6.5         knitr_1.50
    #>  [5] rlang_1.1.6       xfun_0.52         stringi_1.8.7     textshaping_1.0.1
    #>  [9] jsonlite_2.0.0    glue_1.8.0        openssl_2.3.3     askpass_1.2.1
    #> [13] htmltools_0.5.8.1 ragg_1.4.0        sass_0.4.9        rmarkdown_2.29
    #> [17] evaluate_1.0.4    jquerylib_0.1.4   fastmap_1.2.0     yaml_2.3.10
    #> [21] lifecycle_1.0.4   stringr_1.5.1     compiler_4.3.1    officer_0.6.10
    #> [25] rstudioapi_0.17.1 systemfonts_1.2.3 digest_0.6.37     R6_2.6.1
    #> [29] magrittr_2.0.3    bslib_0.9.0       uuid_1.2-1        tools_4.3.1
    #> [33] xml2_1.3.8        cachem_1.1.0

…