Scale by Median
scale_by_median.Rd
Transform selected columns in a data frame into z-scores centered around the median using median absolute deviation (MAD). This transformation is recommended when using range size and evolutionary distinctiveness for geographic and phylogenetic dimensions of rarity.
Value
A data frame where the selected columns have been scaled to z-scores based on the median and MAD.
Details
This function calculates z-scores as:
$$z = (x - \text{median}(x)) / \text{MAD}(x)$$
where MAD is computed as the median of absolute deviations from the median,without applying the standard consistency constant.
If columns_chosen
is NULL
, all columns except "species_name"
are scaled.
See also
prepare_gdrarity_axes()
where it is applied internally.
Author
Alivia G Nytko, anytko@vols.utk.edu
Examples
# Create dataframe of pine species with range sizes and evolutionary distinctiveness
pine_names <- c("Pinus_banksiana", "Pinus_cembra", "Pinus_nigra", "Pinus_pinaster",
"Pinus_pinea", "Pinus_ponderosa", "Pinus_strobus", "Pinus_sylvestris", "Pinus_uncinata")
evol_dist_values <- runif(n = 9, min = -50, max = 50)
range_values <- runif(n = 9, min = -20000, max = 20000)
pine_data <- data.frame(species_name = pine_names, range_size = range_values, evol_dist = evol_dist_values)
# Apply median scaling to all columns except species_name
transform_all <- scale_by_median(data_frame = pine_data)
print(transform_all)
#> species_name range_size evol_dist
#> 1 Pinus_banksiana 0.01035741 0.09593961
#> 2 Pinus_cembra -3.12878817 1.59802104
#> 3 Pinus_nigra -2.57155004 0.00000000
#> 4 Pinus_pinaster -1.00000000 -1.29524563
#> 5 Pinus_pinea 0.00000000 -1.23479241
#> 6 Pinus_ponderosa 1.90583567 -1.00000000
#> 7 Pinus_strobus 0.52071923 0.75267739
#> 8 Pinus_sylvestris -0.67693971 -2.63169666
#> 9 Pinus_uncinata 1.07995383 0.58976869