pvalueschamm: Calculate the p_values matrix or matrices (two or more) for...

View source: R/cmahalanobis.R

pvalueschammR Documentation

Calculate the p_values matrix or matrices (two or more) for each factor inside variable or variables (two or more), using Hamming distances as a base.

Description

Using the Hamming distance for the distances calculation, this function takes a dataframe, a variable or variables (two or more), a p_value method such as "bootstrap" and "permutation" and returns the p_values matrix or matrices (two or more) between each pair of factors.

Usage

pvalueschamm(
  dataset,
  formula,
  pvalue.method = "permutation",
  seed = NULL,
  min_group_size = 3,
  num_replicas = 1000,
  automatic_encoding = FALSE,
  na_removal = FALSE,
  grouping_stat = "median"
)

Arguments

dataset

A dataframe.

formula

A variable or variables (two or more) with factors which you want to calculate the Hamming distances matrix or matrices (two or more).

pvalue.method

A p_value method used to calculate the matrix or matrices (two or more), the default value is "permutation". Another method is "bootstrap".

seed

Optionally, set a seed for "bootstrap" and "permutation".

min_group_size

Minimum group size to maintain. The default value is 3, therefore groups, inside variables, with less than 3 observations will be discarded.

num_replicas

Number of permutations or bootstraps trials, the default value is 1000.

automatic_encoding

Logical, if TRUE, names inside factor variables will be transformed in numbers with ordinal order (1,2,....).

na_removal

Logical, if TRUE, missing value removal on rows is performed.

grouping_stat

When a factor variable is specified, calculate the specified grouping statistic for each factor. Available methods are: mean (arithmetic mean), median and SDS (standard deviations). Then, we find p-values with the resulting distances.

Value

A list containing a matrix or matrices (two or more) of p_values.

Note

This function leverages on an early stopping procedure in which the resulting matrix is printed also if the specified number of replicas is not reached; if every 500 replicas the maximum difference between each p_value does not exceed 0.0001, the function will print the entire matrix, else it continues.

Examples


pvalueschamm(CO2, ~Plant + Type,
   pvalue.method = "permutation",
   seed = 122,
   num_replicas = 50,
   grouping_stat = 'median', 
   automatic_encoding = TRUE)
   
   
pvalueschamm(airquality, ~Ozone,
   pvalue.method = 'bootstrap',
   na_removal = TRUE, num_replicas = 50)


cmahalanobis documentation built on Aug. 31, 2026, 5:07 p.m.