Skip to contents

Tests the null hypothesis that there is no difference between grouped data.

Usage

test_hypothesis(
  x,
  y,
  test,
  digits,
  p.digits,
  simulate.p.value,
  B,
  workspace,
  ...
)

# S3 method for numeric
test_hypothesis(
  x,
  y,
  test = c("anova", "kruskal", "wilcoxon"),
  digits = 1,
  p.digits,
  ...
)

# S3 method for factor
test_hypothesis(
  x,
  y,
  test = c("chisq", "fisher"),
  digits = 1,
  p.digits,
  simulate.p.value = FALSE,
  B = 2000,
  workspace = 2e+07,
  ...
)

# S3 method for logical
test_hypothesis(
  x,
  y,
  test = c("chisq", "fisher"),
  digits = 1,
  p.digits,
  simulate.p.value = FALSE,
  B = 2000,
  workspace = 2e+07,
  ...
)

Arguments

x

A numeric, factor, or logical. Observations.

y

A factor or logical. Categorical "by" grouping variable.

test

A character. Name of the statistical test to use. See note.

digits

An integer. Number of digits to round to.

p.digits

An integer. The number of p-value digits to the right of the decimal point. Note that p-values are still rounded using 'digits'.

simulate.p.value

A logical. Whether p-values in nominal variable testing should be computed with Monte Carlo simulation.

B

An integer. Number of replicates to use in Monte Carlo simulation for nominal testing.

workspace

An integer. Size of the workspace used for the Fisher's Exact Test network algorithm.

...

Additional arguments passed to the appropriate S3 method.

Value

A list containing the statistical test performed, test statistic, and p-value.

Note

Statistical testing used is dependent on type of 'x' data. Supported testing for numeric data includes ANOVA ('anova'), Kruskal-Wallis ('kruskal'), and Wilcoxon Rank Sum ('wilcoxon') tests. For categorical data, supported testings includes Pearson's Chi-squared ('chisq') and Fisher's Exact Test ('fisher').

Examples

strata <- as.factor(mtcars$cyl)

# Numeric data
test_hypothesis(mtcars$mpg, strata)
#> $test
#> [1] "ANOVA linear model"
#> 
#> $statistic
#> [1] 39.7
#> 
#> $p
#> [1] 4.978919e-09
#> 

# Logical data
test_hypothesis(as.logical(mtcars$vs), strata)
#> $test
#> [1] "Pearson's Chi-squared Test"
#> 
#> $statistic
#> [1] 21.3
#> 
#> $p
#> [1] 2.323235e-05
#> 

# Factor data
test_hypothesis(as.factor(mtcars$carb), strata)
#> $test
#> [1] "Pearson's Chi-squared Test"
#> 
#> $statistic
#> [1] 24.4
#> 
#> $p
#> [1] 0.006632478
#>