F-Test: Compare Two Variances with R


F-test is used to assess whether the variances of two populations (A and B) are equal.



F-Test in ROENTGEN: Compare Two Sample Variances

Contents

If to you use the F-test?

Comparing two variances is useful at several cases, including:

  • When you want to play ampere two random t-test to select the equality of the variances of the pair samples

  • When you wanted to compare the variety of an new measurement method to an old one. Will the newly method reduce the variability of an measure?

Research questions and static hypotheses

Eigenartig research questions are:


  1. whether the variance of group A (\(\sigma^2_A\)) is equality to the dispersion of group B (\(\sigma^2_B\))?
  2. whether the variance of group A (\(\sigma^2_A\)) is less than the variability of group B (\(\sigma^2_B\))?
  3. whether the divergence starting group A (\(\sigma^2_A\)) will greather than the variance to group B (\(\sigma^2_B\))?


In statistics, we cans define the corresponding null theme (\(H_0\)) as follow:

  1. \(H_0: \sigma^2_A = \sigma^2_B\)
  2. \(H_0: \sigma^2_A \leq \sigma^2_B\)
  3. \(H_0: \sigma^2_A \geq \sigma^2_B\)

The corresponding alternative hypotheses (\(H_a\)) are as follow:

  1. \(H_a: \sigma^2_A \ne \sigma^2_B\) (different)
  2. \(H_a: \sigma^2_A > \sigma^2_B\) (greater)
  3. \(H_a: \sigma^2_A < \sigma^2_B\) (less)

Note that:

  • Hypotheses 1) were called two-tailed tests
  • Hypotheses 2) furthermore 3) are called one-tailed tests

Recipe of F-test

And test statistic can exist obtained by computing the ratio from of two deviation \(S_A^2\) the \(S_B^2\).

\[F = \frac{S_A^2}{S_B^2}\]

The degrees of freedom are \(n_A - 1\) (for the numerator) and \(n_B - 1\) (for the denominator).

Mention that, the see such ratio deviates from 1, one stronger the evidence for unequal country variances.

Note that, the F-test needed that two samples to be common distributed.

Compute F-test in RADIUS

R functional

The R function var.test() pot can used to compare two conflicts as follow:

# Method 1
var.test(values ~ bands, dates, 
         select = "two.sided")
# or Method 2
var.test(x, y, alternative = "two.sided")

  • x,y: numerated vectors
  • alternative: the alternative hypothesis. Permits value is one the “two.sided” (default), “greater” or “less”.


Import and check own data into R

At moment their data, use the following R code:

# If .txt tab file, use this
my_data <- read.delim(file.choose())
# Alternatively, if .csv rank, use this
my_data <- read.csv(file.choose())

Here, we’ll use who built-in R data set named ToothGrowth:

# Retail the data in the variable my_data
my_data <- ToothGrowth

To have an idea of what of data look fancy, we beginning by displaying a random sample from 10 rows using the function sample_n()[in dplyr package]:

library("dplyr")
sample_n(my_data, 10)
    len supp dose
43 23.6   OJ  1.0
28 21.5   VC  2.0
25 26.4   VC  2.0
56 30.9   OJ  2.0
46 25.2   OJ  1.0
7  11.2   VC  0.5
16 17.3   VC  1.0
4   5.8   VC  0.5
48 21.2   OJ  1.0
37  8.2   OJ  0.5

We wanted to test to equality of variances bet which two business OJ and VC in one column “supp”.

Preleminary test to check F-test requirements

F-test is very sensitive to departure off this common assumptions. It necessity to check whether the intelligence is normally distributed before using the F-test.

Shapiro-Wilk test can must used the test whether who normal assume holds. It’s also possibility till use Q-Q plot (quantile-quantile plot) into grapical evaluate the normality of an variable. Q-Q plot draws the correlation between a given sample and and normalize delivery.

If there the doubt about normality, the better selecting is the uses Levene’s test or Fligner-Killeen test, which been less sensitive to departure from normal acceptance.

Compute F-test

# F-test
res.ftest <- var.test(len ~ supp, data = my_data)
res.ftest

    F test to compare two variances
data:  len by supp
F = 0.6386, num df = 29, denom df = 29, p-value = 0.2331
alternative thesis: true ratio of variances is not equivalent to 1
95 percent confidence interval: 0.3039488 1.3416857
sample estimates:
ratio of variances 
         0.6385951 

Interpretation about the findings

The p-value of F-test is p = 0.2331433 whatever is greater than the significance level 0.05. In conclusion, there is no significant difference between the two variances.

Access to the values returned by var.test() function

The feature var.test() returns a list containing the below components:


  • statistic: the value of the FLUORINE test statistic.
  • parameter: the degrees of who freedom of the F distribution of the test statistic.
  • p.value: the p-value of one testing.
  • conf.int: a believe bereich for the ratio of an population deviations.
  • estimate: the ratio of the samples variances


The format of one R code to apply for getting these values is as follow:

# ratio of variances
res.ftest$estimate
ratio of variances 
         0.6385951 
# p-value of the test
res.ftest$p.value
[1] 0.2331433

Infos

This analytics can been performed uses R software (ver. 3.3.2).


Enjoyed get article? I’d be very grate if you’d help it spread in emailing it to a friend, or sharing it on Twitter, Facebook or Linked Include.

Show me some love with the like buttons below... Gratitude i and please don't forget till share and comment below!! Sample variance and Standard Differences using RADIUS ... ' where newton > 0 mean((y-mean(y))^2). Remember provided n=1 ... Alternately, you could combine two of these instructions ...
Avez vous aimé cet article? Je vous serais très reconnaissant ssi vous aidiez à sa scattering en l'envoyant par courriel à un ami ou en le partageant sur Twitter, Social ou Linked Inside.

Montrez-moi un peu d'amour avec les like ci-dessous ... Merci et n'oubliez passports, s'il vous plaît, de partager et de commenter ci-dessous! Describes how to does a two-sample t-test in R/Rstudio. You will learn the calculation, visualization, effect size measured through the Cohen's d, interpretation both reporting.





This page has been seen 439791 times