1. Main Method Function: method.{METHOD_NAME}()
This is the core function that implements your statistical method. Here is the PET implementation as an example:
#' @title PET (Precision-Effect Test) Method
#'
#' @description
#' Implements the Precision-Effect Test for publication bias correction.
#' PET regresses effect sizes against standard errors to test for and correct
#' publication bias. The intercept represents the bias-corrected effect size
#' estimate.
#'
#' @param method_name Method name (automatically passed)
#' @param data Data frame with yi (effect sizes) and sei (standard errors)
#' @param settings List of method settings
#'
#' @return Data frame with PET results
#'
#' @export
method.PET <- function(method_name, data, settings = NULL) {
# Extract data
effect_sizes <- data$yi
standard_errors <- data$sei
# Input validation and error handling
if (length(effect_sizes) < 3)
stop("At least 3 estimates required for PET analysis", call. = FALSE)
if (stats::var(standard_errors) <= 0)
stop("No variance in standard errors", call. = FALSE)
# Implement the statistical method
pet_model <- stats::lm(effect_sizes ~ standard_errors,
weights = 1/standard_errors^2)
# Extract and process results
coefficients <- stats::coef(pet_model)
se_coefficients <- summary(pet_model)$coefficients[, "Std. Error"]
p_values <- summary(pet_model)$coefficients[, "Pr(>|t|)"]
# Main estimates
estimate <- coefficients[1] # Intercept = bias-corrected effect
estimate_se <- se_coefficients[1]
estimate_p <- p_values[1]
# Additional method-specific results
bias_coefficient <- coefficients[2]
bias_p_value <- p_values[2]
# Calculate confidence intervals
estimate_lci <- estimate - 1.96 * estimate_se
estimate_uci <- estimate + 1.96 * estimate_se
# Return standardized results
return(data.frame(
method = method_name,
estimate = estimate,
standard_error = estimate_se,
ci_lower = estimate_lci,
ci_upper = estimate_uci,
p_value = estimate_p,
BF = NA,
convergence = TRUE,
note = NA,
# Method-specific columns
bias_coefficient = bias_coefficient,
bias_p_value = bias_p_value
))
}Key Requirements for the Main Function:
Input Parameters:
method_name: Automatically passed by the frameworkdata: Data frame withyi(effect sizes),sei(standard errors), andni(sample sizes).settings: Optional list of method-specific settings
Output: Must return a data frame with these required columns:
method: Method nameestimate: Meta-analytic effect size estimatestandard_error: Standard error of the estimateci_lower: Lower confidence interval bound (95%)ci_upper: Upper confidence interval bound (95%)p_value: P-value for the estimateBF: Bayes factor for the estimateconvergence: Logical indicating successful convergencenote: Character string with notes
If your method does not provide certain values (e.g., Bayes factor),
use NA.
Error Handling:
- Include input validation and meaningful error messages
- Use
stop()withcall. = FALSEfor user-friendly errors - The framework handles errors automatically - your function can throw
errors. The package will catch the errors and attach them to an empty
output with
convergence = FALSEand the error message innote.