Skip to contents

compare_coefficients() binds an original data set to its balanced/bootstrapped counterpart, labels each with a Dataset factor, and fits a grouped standardised major axis (SMA) model to test whether the slope or the elevation (intercept) differs between groups, and whether that coefficient differs from a user‑supplied reference value.

Usage

compare_coefficients(
  original,
  balanced,
  var_x,
  var_y,
  which_coefficient = c("slope", "intercept"),
  model_type = c("power", "exp", "linear"),
  test_value = NA
)

Arguments

original

Data frame with the unscaled data.

balanced

Data frame with the balanced data (e.g. balanced_scaling(... )$first_boot).

var_x, var_y

Unquoted column names for the predictor and response.

which_coefficient

"slope" (default) or "intercept".

model_type

"power" (default), "exp", or "linear".

test_value

Numeric; value to compare the chosen coefficient against (optional).

Value

A "sma.summary" object (see smatr::sma()).

References

Simovic, M., & Michaletz, S.T. (2025). Harnessing the Full Power of Data to Characterise Biological Scaling Relationships. Global Ecology and Biogeography, 34(2). https://doi.org/10.1111/geb.70019 Warton, D.I., Duursma, R.A., Falster, D.S., & Taskinen, S. (2012). smatr 3 – an R package for estimation and inference about allometric lines. Methods in Ecology and Evolution, 3(2), 257–259. https://doi.org/10.1111/j.2041-210X.2011.00153.x

Author

Simovic, M. milos.simovic@botany.ubc.ca; Michaletz, S.T. sean.michaletz@ubc.ca

Examples

if (requireNamespace("smatr", quietly = TRUE)) {
  data(xylem_scaling_simulation_dataset)

  bal <- balanced_scaling(
    data        = xylem_scaling_simulation_dataset,
    var_x       = L,
    var_y       = DAVG,
    min_per_bin = 100,
    n_boot      = 1,
    seed        = 1,
    model_type  = "power"
  )$first_boot

  #Compare slopes between balanced and imbalanced datasets

  compare_coefficients(
    original  = xylem_scaling_simulation_dataset,
    balanced  = bal,
    var_x     = L,
    var_y     = DAVG,
    which_coefficient = "slope",
    model_type        = "power"
  )

  #Test if balancing data results in better agreement with WBE model

  compare_coefficients(
    original  = xylem_scaling_simulation_dataset,
    balanced  = bal,
    var_x     = L,
    var_y     = DAVG,
    which_coefficient = "slope",
    model_type        = "power",
    test_value        = 0.25
  )
}
#> Call: smatr::sma(formula = fmla, data = combined, log = "", method = "SMA", 
#>     slope.test = slope_test, elev.test = elev_test) 
#> 
#> Fit using Standardized Major Axis 
#> 
#> ------------------------------------------------------------
#> Results of comparing lines among groups.
#> 
#> H0 : slopes are equal.
#> Likelihood ratio statistic : 256500 with 1 degrees of freedom
#> P-value : < 2.22e-16 
#> ------------------------------------------------------------
#> 
#> Coefficients by group in variable "Dataset"
#> 
#> Group: Balanced 
#>             elevation     slope
#> estimate    0.9566411 0.2294432
#> lower limit 0.9562315 0.2291341
#> upper limit 0.9570507 0.2297526
#> 
#> H0 : variables uncorrelated.
#> R-squared : 0.2698124 
#> P-value : < 2.22e-16 
#> 
#> Group: Original 
#>             elevation     slope
#> estimate     0.773043 0.5041909
#> lower limit  0.772178 0.5028917
#> upper limit  0.773908 0.5054936
#> 
#> H0 : variables uncorrelated.
#> R-squared : 0.2341062 
#> P-value : < 2.22e-16 
#> 
#> 
#> Call: smatr::sma(formula = fmla, data = combined, log = "", method = "SMA", 
#>     slope.test = slope_test, elev.test = elev_test) 
#> 
#> Fit using Standardized Major Axis 
#> 
#> ------------------------------------------------------------
#> Results of comparing lines among groups.
#> 
#> H0 : slopes are equal.
#> Likelihood ratio statistic : 256500 with 1 degrees of freedom
#> P-value : < 2.22e-16 
#> ------------------------------------------------------------
#> 
#> H0 : common slope not different from 0.25 
#> Likelihood ratio statistic = 264100 with 2 degrees of freedom under H0
#> P-value : < 2.22e-16 
#> 
#> Coefficients by group in variable "Dataset"
#> 
#> Group: Balanced 
#>             elevation     slope
#> estimate    0.9566411 0.2294432
#> lower limit 0.9562315 0.2291341
#> upper limit 0.9570507 0.2297526
#> 
#> H0 : variables uncorrelated.
#> R-squared : 0.2698124 
#> P-value : < 2.22e-16 
#> 
#> H0 : slope not different from 0.25 
#> Test statistic: r= -0.1 with 1544054 degrees of freedom under H0
#> P-value : < 2.22e-16 
#> 
#> Group: Original 
#>             elevation     slope
#> estimate     0.773043 0.5041909
#> lower limit  0.772178 0.5028917
#> upper limit  0.773908 0.5054936
#> 
#> H0 : variables uncorrelated.
#> R-squared : 0.2341062 
#> P-value : < 2.22e-16 
#> 
#> H0 : slope not different from 0.25 
#> Test statistic: r= 0.6559 with 441902 degrees of freedom under H0
#> P-value : < 2.22e-16 
#> 
#>