balancR
is an R package which provides tools for
balancing imbalanced data in scaling analyses using bootstrapping, and
for comparing regression coefficients (slopes and intercepts) between
original and balanced samples.
library(balancR)
Balance an imbalanced, log-normally distributed dataset, fit an SMA model to both imbalanced and balanced datasets, and compare slopes:
# Simulated imbalanced dataset
library(balancR)
set.seed(123)
df <- data.frame(x = rlnorm(1000, meanlog = 3, sdlog = 1), y = rlnorm(1000, meanlog = 2, sdlog = 1))
# Create balanced sample and fit with SMA model
bal <- balanced_scaling(data = df, var_x = x, var_y = y, min_per_bin = 10, n_boot = 1, seed = 1, model_type = "power" )$first_boot
# Compare slopes between balanced and imbalanced datasets
compare_coefficients(original = df, balanced = bal, var_x = x, var_y = y, which_coefficient = "slope", model_type = "power")