p_var.test: p-value from variance test simulation

View source: R/p_var.test.R

p_var.testR Documentation

p-value from variance test simulation

Description

Generates one or or more sets of continuous data group-level data to perform a variance test, and return a p-value. When two-samples are investigated the var.test function will be used, otherwise functions from the EnvStats package will be used.

Usage

p_var.test(
  n,
  vars,
  n.ratios = rep(1, length(vars)),
  sigma2 = 1,
  two.tailed = TRUE,
  alternative = NULL,
  test = "Levene",
  correct = TRUE,
  gen_fun = gen_var.test,
  return_analysis = FALSE,
  ...
)

gen_var.test(n, vars, n.ratios = rep(1, length(vars)), ...)

Arguments

n

sample size per group, assumed equal across groups

vars

a vector of variances to use for each group; length of 1 for one-sample tests

n.ratios

allocation ratios reflecting the sample size ratios. Default of 1 sets the groups to be the same size (n * n.ratio)

sigma2

population variance to test against in one-sample test

two.tailed

logical; should a two-tailed or one-tailed test be used? For one-tailed tests relevant alternative arguments are set to 'greater'

alternative

character vector passed to alternative analysis function (most commonly, 'two.tailed', 'greater', 'less'). When used, ignores the value of two.tailed

test

type of test to use in multi-sample applications. Can be either 'Levene' (default), 'Bartlett', or 'Fligner'

correct

logical; use correction when test = 'Bartlett'?

gen_fun

function used to generate the required discrete data. Object returned must be a matrix with k rows and k columns of counts. Default uses gen_var.test. User defined version of this function must include the argument ...

return_analysis

logical; return the analysis object for further extraction and customization?

...

additional arguments to be passed to gen_fun. Not used unless a customized gen_fun is defined

Value

a single p-value

Author(s)

Phil Chalmers rphilip.chalmers@gmail.com

See Also

gen_var.test

Examples


# one sample
p_var.test(100, vars=10, sigma2=9)

# return analysis object
p_var.test(100, vars=10, sigma2=9, return_analysis = TRUE)

# three sample
p_var.test(100, vars=c(10, 9, 11))
p_var.test(100, vars=c(10, 9, 11), test = 'Fligner')
p_var.test(100, vars=c(10, 9, 11), test = 'Bartlett')


  # power to detect three-group variance differences
  p_var.test(n=100, vars=c(10,9,11)) |> Spower()

  # sample size per group to achieve 80% power
  p_var.test(n=interval(100, 2000), vars=c(10,9,11)) |> Spower(power=.80)



Spower documentation built on Oct. 16, 2026, 9:08 a.m.