var1.chisq: One-Sample Chi-Square Test for Variance

View source: R/var1_chisq.R

var1.chisqR Documentation

One-Sample Chi-Square Test for Variance

Description

Given an univariate sample x, it tests

H_0 : σ_x^2 ≤ft\lbrace =,≥q,≤q \right\rbrace σ_0^2 \quad vs\quad H_1 : σ_x^2 ≤ft\lbrace \neq,<,>\right\rbrace σ_0^2

.

Usage

var1.chisq(x, var0 = 1, alternative = c("two.sided", "less", "greater"))

Arguments

x

a length-n data vector.

var0

hypothesized variance σ_0^2.

alternative

specifying the alternative hypothesis.

Value

a (list) object of S3 class htest containing:

statistic

a test statistic.

p.value

p-value under H_0.

alternative

alternative hypothesis.

method

name of the test.

data.name

name(s) of provided sample data.

References

\insertRef

snedecor_statistical_1996SHT

Examples

## CRAN-purpose small example
x = rnorm(10)
var1.chisq(x, alternative="g") ## Ha : var(x) >= 1
var1.chisq(x, alternative="l") ## Ha : var(x) <= 1
var1.chisq(x, alternative="t") ## Ha : var(x) =/=1


## empirical Type 1 error 
niter   = 1000
counter = rep(0,niter)  # record p-values
for (i in 1:niter){
  x = rnorm(50)  # sample x from N(0,1)
  
  counter[i] = ifelse(var1.chisq(x,var0=1)$p.value < 0.05, 1, 0)
}

## print the result
cat(paste("\n* Example for 'var1.chisq'\n","*\n",
"* number of rejections   : ", sum(counter),"\n",
"* total number of trials : ", niter,"\n",
"* empirical Type 1 error : ",round(sum(counter/niter),5),"\n",sep=""))



kisungyou/SHT documentation built on Oct. 15, 2022, 3:18 p.m.