my_data<-ToothGrowth
library("dplyr")
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
sample_n(my_data, 10)
##     len supp dose
## 1  33.9   VC  2.0
## 2  21.5   OJ  0.5
## 3  25.2   OJ  1.0
## 4  25.5   OJ  2.0
## 5  10.0   OJ  0.5
## 6  16.5   OJ  0.5
## 7  23.0   OJ  2.0
## 8  22.4   OJ  2.0
## 9  15.5   VC  1.0
## 10 27.3   OJ  1.0

We want to test the equality of variances between the two groups OJ and VC in the column “supp”.

Preleminary test to check F-test assumptions

F-test is very sensitive to departure from the normal assumption. You need to check whether the data is normally distributed before using the F-test.

Shapiro-Wilk test can be used to test whether the normal assumption holds. It’s also possible to use Q-Q plot (quantile-quantile plot) to graphically evaluate the normality of a variable. Q-Q plot draws the correlation between a given sample and the normal distribution.

If there is doubt about normality, the better choice is to use Levene’s test or Fligner-Killeen test, which are less sensitive to departure from normal assumption.

hypothesis: ho:equality of var h1:no eqaualaity of var

level of significance

alpha=0.05
res<-var.test(len~supp,data=my_data)
print(res)
## 
##  F test to compare two variances
## 
## data:  len by supp
## F = 0.6386, num df = 29, denom df = 29, p-value = 0.2331
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
##  0.3039488 1.3416857
## sample estimates:
## ratio of variances 
##          0.6385951
if(res$p.value<alpha)
{
  cat("reject ho")
}else
{
  cat("accept ho")
}
## accept ho