vartest: Calibrated variance test between two or more independent...

Description Usage Arguments Details Value Note See Also Examples

View source: R/vartest.R

Description

Tests the equality of variance for continuous independent samples using the Welch corrected versions of the Fisher's variance test

Usage

1
vartest(x, y, ...)

Arguments

x, y

the two continuous variables for the two samples variance test.

...

other parameters such as alternative which indicates the alternative hypothesis as one of "two.sided", "greater" or "less", or data and formula to include a dataset with a formula from the command vartest(x~y,data=dataset) with dataset the name of the data.

Details

For the two sample variance test, the null hypothesis is: H0 var(X)=var(Y) where var represents the variance. The alternative is specified by the alternative argument. The test uses the Welch correction for the variables (x_i-mean(x))^2, (y_i-mean(y))^2 and is asymptotically calibrated in the sense that the rejection probability under the null hypothesis is asymptotically equal to the level of the test. The test can be applied to more than two groups and it will test if all groups have the same variance.

Value

Returns the result of the test with its corresponding p-value and the value of the test statistic. In the two sample case, the function also returns the estimated value of the ratio of the two variances.

Note

The function can also be called using formulas: type vartest(x~y,data) with x the quantitative variable and y a factor variable with two or more levels. For more than two groups, only the formula is valid.

See Also

cortest, indeptest, mediantest, wilcoxtest.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#Application on the Evans dataset
data(Evans)
#Description of this dataset is available in the lbreg package
with(Evans,var.test(CHL[CDH==0],CHL[CDH==1]))
with(Evans,vartest(CHL[CDH==0],CHL[CDH==1]))
vartest(CHL~CDH,data=Evans) #using formulas

#Similar pvalues between var.test and vartest

#Simulated data
n=60
M=10000 #number of replications
testone=function(n){
X=rnorm(n,0,1)
Y=rchisq(2*n,df=2)/2
list(test1=vartest(X,Y)$p.value,test2=var.test(X,Y)$p.value) #var.test is the standard Fisher test
}
res1=res2=rep(NA,M)
# Replications to check if the the corrected Fisher test and the standard test are well calibrated
for (i in 1:M)
{
result=testone(n)
res1[i]=result$test1
res2[i]=result$test2
}
mean(res1<0.05)  #0.0515
mean(res2<0.05)  #0.1509

obouaziz/robusTest0 documentation built on Dec. 22, 2021, 4:13 a.m.