<?xml version="1.0" encoding="UTF-8" ?>
<!-- RSS generated by PHPBoost on Sat, 18 Apr 2026 19:25:47 +0200 -->

<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Easy Guides]]></title>
		<atom:link href="https://www.sthda.com/english/syndication/rss/wiki/45" rel="self" type="application/rss+xml"/>
		<link>https://www.sthda.com</link>
		<description><![CDATA[Last articles of the category: Comparing Variances in R]]></description>
		<copyright>(C) 2005-2026 PHPBoost</copyright>
		<language>en</language>
		<generator>PHPBoost</generator>
		
		
		<item>
			<title><![CDATA[Comparing Variances in R]]></title>
			<link>https://www.sthda.com/english/wiki/comparing-variances-in-r</link>
			<guid>https://www.sthda.com/english/wiki/comparing-variances-in-r</guid>
			<description><![CDATA[<!-- START HTML -->

  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">
<p><br/></p>
<p>Previously, we described the <a href="https://www.sthda.com/english/english/wiki/r-basics-quick-and-easy">essentials of R programming</a> and provided quick start guides for <a href="https://www.sthda.com/english/english/wiki/importing-data-into-r">importing data</a> into <strong>R</strong>. Additionally, we described how to compute <a href="https://www.sthda.com/english/english/wiki/descriptive-statistics-and-graphics">descriptive or summary statistics</a>, <a href="https://www.sthda.com/english/english/wiki/correlation-analyses-in-r">correlation analysis</a>, as well as, how to <a href="https://www.sthda.com/english/english/wiki/comparing-means-in-r">compare sample means</a> using R software.</p>
<br/>
<div class="block">
This chapter contains articles describing <strong>statistical tests</strong> to use for <strong>comparing variances</strong>.
</div>
<p><br/></p>
<div id="how-this-chapter-is-organized" class="section level1">
<h1><span class="header-section-number">1</span> How this chapter is organized?</h1>
<br/>
<div class="block">
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/f-test-compare-two-variances-in-r">F-Test: Compare Two Variances in R</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/compare-multiple-sample-variances-in-r">Compare Multiple Sample Variances in R</a></li>
</ul>
</div>
<p><br/></p>
<p>
 <img src="https://www.sthda.com/english/sthda/RDoc/images/comparing-variances.png" alt="Comapring variances in R" /> <br/></p>
<hr/>
</div>
<div id="f-test-compare-two-variances-in-r" class="section level1">
<h1><span class="header-section-number">2</span> F-Test: Compare two variances in R</h1>
<ul>
<li>What is F-test?</li>
<li>When to you use the F-test?</li>
<li>Research questions and statistical hypotheses</li>
<li>Formula of F-test</li>
<li>Compute F-test in R</li>
</ul>
<p><br/> <img src="https://www.sthda.com/english/sthda/RDoc/images/f-test.png" alt="F-Test in R: Compare Two Sample Variances" /> <br/></p>
<p><span class="success">Read more: —> <a href="https://www.sthda.com/english/english/wiki/f-test-compare-two-variances-in-r">F-Test: Compare Two Variances in R</a>.</span></p>
</div>
<div id="compare-multiple-sample-variances-in-r" class="section level1">
<h1><span class="header-section-number">3</span> Compare multiple sample variances in R</h1>
<p>This article describes <strong>statistical tests</strong> for comparing the <strong>variances</strong> of two or more samples.</p>
<ul>
<li>Compute <strong>Bartlett’s test</strong> in R</li>
<li>Compute <strong>Levene’s test</strong> in R</li>
<li>Compute <strong>Fligner-Killeen</strong> test in R</li>
</ul>
<p><br/> <img src="https://www.sthda.com/english/sthda/RDoc/images/multiple-variances-test.png" alt="Compare Multiple Sample Variances in R" /> <br/></p>
<p><span class="success">Read more: —> <a href="https://www.sthda.com/english/english/wiki/compare-multiple-sample-variances-in-r">Compare Multiple Sample Variances in R</a>.</span></p>
</div>
<div id="see-also" class="section level1">
<h1><span class="header-section-number">4</span> See also</h1>
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/r-basics-quick-and-easy">R Basics</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/import-and-export-data-using-r">Import and Export Data using R</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/preparing-and-reshaping-data-in-r-for-easier-analyses">Preparing and Reshaping Data in R for Easier Analyses</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/data-manipulation-in-r">Data Manipulation in R</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/data-visualization">Data visualization</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/descriptive-statistics-and-graphics">Descriptive Statistics and Graphics</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/correlation-analyses-in-r">Correlation Analyses in R</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/comparing-means-in-r">Comparing Means in R</a></li>
</ul>
</div>
<div id="infos" class="section level1">
<h1><span class="header-section-number">5</span> Infos</h1>
<p><span class="warning"> This analysis has been performed using <strong>R statistical software</strong> (ver. 3.2.4). </span></p>
</div>
<script>jQuery(document).ready(function () {
    jQuery('#rdoc h1').addClass('wiki_paragraph1');
    jQuery('#rdoc h2').addClass('wiki_paragraph2');
    jQuery('#rdoc h3').addClass('wiki_paragraph3');
    jQuery('#rdoc h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->

<!-- END HTML -->]]></description>
			<pubDate>Tue, 23 Jun 2020 20:38:03 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[F-Test: Compare Two Variances in R]]></title>
			<link>https://www.sthda.com/english/wiki/f-test-compare-two-variances-in-r</link>
			<guid>https://www.sthda.com/english/wiki/f-test-compare-two-variances-in-r</guid>
			<description><![CDATA[<!-- START HTML -->

  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">
<br/>
<div class="block">
<strong>F-test</strong> is used to assess whether the <strong>variances</strong> of two populations (A and B) are equal.
</div>
<p><br/></p>
<p><br/> <img src="https://www.sthda.com/english/sthda/RDoc/images/f-test.png" alt="F-Test in R: Compare Two Sample Variances" /> <br/></p>
<p><strong>Contents</strong></p>
<div id="TOC">
<ul>
<li><a href="#when-to-you-use-f-test">When to you use the F-test?</a></li>
<li><a href="#research-questions-and-statistical-hypotheses">Research questions and statistical hypotheses</a></li>
<li><a href="#formula-of-f-test">Formula of F-test</a></li>
<li><a href="#compute-f-test-in-r">Compute F-test in R</a><ul>
<li><a href="#r-function">R function</a></li>
<li><a href="#import-and-check-your-data-into-r">Import and check your data into R</a></li>
<li><a href="#preleminary-test-to-check-f-test-assumptions">Preleminary test to check F-test assumptions</a></li>
<li><a href="#compute-f-test">Compute F-test</a></li>
<li><a href="#interpretation-of-the-result">Interpretation of the result</a></li>
<li><a href="#access-to-the-values-returned-by-var.test-function">Access to the values returned by var.test() function</a></li>
</ul></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>
<div id="when-to-you-use-f-test" class="section level2">
<h2>When to you use the F-test?</h2>
<p>Comparing two variances is useful in several cases, including:</p>
<ul>
<li><p>When you want to perform a <a href="unpaired-two-samples-t-test-in-r">two samples t-test</a> to check the equality of the variances of the two samples</p></li>
<li><p>When you want to compare the variability of a new measurement method to an old one. Does the new method reduce the variability of the measure?</p></li>
</ul>
</div>
<div id="research-questions-and-statistical-hypotheses" class="section level2">
<h2>Research questions and statistical hypotheses</h2>
<p>Typical research questions are:</p>
<br/>
<div class="question">
<ol style="list-style-type: decimal">
<li>whether the variance of group A (<span class="math inline">\(\sigma^2_A\)</span>) <em>is equal</em> to the variance of group B (<span class="math inline">\(\sigma^2_B\)</span>)?</li>
<li>whether the variance of group A (<span class="math inline">\(\sigma^2_A\)</span>) <em>is less than</em> the variance of group B (<span class="math inline">\(\sigma^2_B\)</span>)?</li>
<li>whether the variance of group A (<span class="math inline">\(\sigma^2_A\)</span>) <em>is greather than</em> the variance of group B (<span class="math inline">\(\sigma^2_B\)</span>)?</li>
</ol>
</div>
<p><br/></p>
<p>In statistics, we can define the corresponding <em>null hypothesis</em> (<span class="math inline">\(H_0\)</span>) as follow:</p>
<ol style="list-style-type: decimal">
<li><span class="math inline">\(H_0: \sigma^2_A = \sigma^2_B\)</span></li>
<li><span class="math inline">\(H_0: \sigma^2_A \leq \sigma^2_B\)</span></li>
<li><span class="math inline">\(H_0: \sigma^2_A \geq \sigma^2_B\)</span></li>
</ol>
<p>The corresponding <em>alternative hypotheses</em> (<span class="math inline">\(H_a\)</span>) are as follow:</p>
<ol style="list-style-type: decimal">
<li><span class="math inline">\(H_a: \sigma^2_A \ne \sigma^2_B\)</span> (different)</li>
<li><span class="math inline">\(H_a: \sigma^2_A > \sigma^2_B\)</span> (greater)</li>
<li><span class="math inline">\(H_a: \sigma^2_A < \sigma^2_B\)</span> (less)</li>
</ol>
<div class="notice">
<p>Note that:</p>
<ul>
<li>Hypotheses 1) are called <strong>two-tailed tests</strong></li>
<li>Hypotheses 2) and 3) are called <strong>one-tailed tests</strong></li>
</ul>
</div>
</div>
<div id="formula-of-f-test" class="section level2">
<h2>Formula of F-test</h2>
<p>The test statistic can be obtained by computing the ratio of the two variances <span class="math inline">\(S_A^2\)</span> and <span class="math inline">\(S_B^2\)</span>.</p>
<p><span class="math display">\[F = \frac{S_A^2}{S_B^2}\]</span></p>
<p>The degrees of freedom are <span class="math inline">\(n_A - 1\)</span> (for the numerator) and <span class="math inline">\(n_B - 1\)</span> (for the denominator).</p>
<p><span class="success">Note that, the more this ratio deviates from 1, the stronger the evidence for unequal population variances.</span></p>
<p><span class="error">Note that, the F-test requires the two samples to be <a href="normality-test-in-r">normally distributed</a>. </span></p>
</div>
<div id="compute-f-test-in-r" class="section level2">
<h2>Compute F-test in R</h2>
<div id="r-function" class="section level3">
<h3>R function</h3>
<p>The R function <strong>var.test</strong>() can be used to compare two variances as follow:</p>
<pre class="r"><code># Method 1
var.test(values ~ groups, data, 
         alternative = "two.sided")
# or Method 2
var.test(x, y, alternative = "two.sided")</code></pre>
<br/>
<div class="block">
<ul>
<li><strong>x,y</strong>: numeric vectors</li>
<li><strong>alternative</strong>: the alternative hypothesis. Allowed value is one of “two.sided” (default), “greater” or “less”.</li>
</ul>
</div>
<p><br/></p>
</div>
<div id="import-and-check-your-data-into-r" class="section level3">
<h3>Import and check your data into R</h3>
<p>To import your data, use the following R code:</p>
<pre class="r"><code># If .txt tab file, use this
my_data <- read.delim(file.choose())
# Or, if .csv file, use this
my_data <- read.csv(file.choose())</code></pre>
<p>Here, we’ll use the built-in R data set named <a href="r-built-in-data-sets#toothgrowth">ToothGrowth</a>:</p>
<pre class="r"><code># Store the data in the variable my_data
my_data <- ToothGrowth</code></pre>
<p>To have an idea of what the data look like, we start by displaying a random sample of 10 rows using the function <strong>sample_n</strong>()[in <strong>dplyr</strong> package]:</p>
<pre class="r"><code>library("dplyr")
sample_n(my_data, 10)</code></pre>
<pre><code>    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</code></pre>
<p><span class="question">We want to test the equality of variances between the two groups OJ and VC in the column “supp”.</span></p>
</div>
<div id="preleminary-test-to-check-f-test-assumptions" class="section level3">
<h3>Preleminary test to check F-test assumptions</h3>
<p>F-test is very sensitive to departure from the normal assumption. You need to check whether the data is <a href="normality-test-in-r">normally distributed</a> before using the F-test.</p>
<p>Shapiro-Wilk test can be used to test whether the normal assumption holds. It’s also possible to use <a href="qq-plots-quantile-quantile-plots-r-base-graphs"><strong>Q-Q plot</strong> (quantile-quantile plot)</a> to graphically evaluate the normality of a variable. <a href="qq-plots-quantile-quantile-plots-r-base-graphs">Q-Q plot</a> draws the correlation between a given sample and the normal distribution.</p>
<p>If there is doubt about normality, the better choice is to use <strong>Levene’s test</strong> or <strong>Fligner-Killeen test</strong>, which are less sensitive to departure from normal assumption.</p>
</div>
<div id="compute-f-test" class="section level3">
<h3>Compute F-test</h3>
<pre class="r"><code># F-test
res.ftest <- var.test(len ~ supp, data = my_data)
res.ftest</code></pre>
<pre><code>
    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 </code></pre>
</div>
<div id="interpretation-of-the-result" class="section level3">
<h3>Interpretation of the result</h3>
<p><pan class = "success">The p-value of <strong>F-test</strong> is p = 0.2331433 which is greater than the significance level 0.05. In conclusion, there is no significant difference between the two variances.</span></p>
</div>
<div id="access-to-the-values-returned-by-var.test-function" class="section level3">
<h3>Access to the values returned by var.test() function</h3>
<p>The function <strong>var.test</strong>() returns a list containing the following components:</p>
<br/>
<div class="block">
<ul>
<li><strong>statistic</strong>: the value of the F test statistic.</li>
<li><strong>parameter</strong>: the degrees of the freedom of the F distribution of the test statistic.</li>
<li><strong>p.value</strong>: the p-value of the test.</li>
<li><strong>conf.int</strong>: a confidence interval for the ratio of the population variances.</li>
<li><strong>estimate</strong>: the ratio of the sample variances</li>
</ul>
</div>
<p><br/></p>
<p>The format of the <strong>R</strong> code to use for getting these values is as follow:</p>
<pre class="r"><code># ratio of variances
res.ftest$estimate</code></pre>
<pre><code>ratio of variances 
         0.6385951 </code></pre>
<pre class="r"><code># p-value of the test
res.ftest$p.value</code></pre>
<pre><code>[1] 0.2331433</code></pre>
</div>
</div>
<div id="infos" class="section level2">
<h2>Infos</h2>
<p><span class="warning"> This analysis has been performed using <strong>R software</strong> (ver. 3.3.2). </span></p>
</div>
<script>jQuery(document).ready(function () {
    jQuery('#rdoc h1').addClass('wiki_paragraph1');
    jQuery('#rdoc h2').addClass('wiki_paragraph2');
    jQuery('#rdoc h3').addClass('wiki_paragraph3');
    jQuery('#rdoc h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src  = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->

<!-- END HTML -->]]></description>
			<pubDate>Tue, 23 Jun 2020 20:37:09 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Compare Multiple Sample Variances in R]]></title>
			<link>https://www.sthda.com/english/wiki/compare-multiple-sample-variances-in-r</link>
			<guid>https://www.sthda.com/english/wiki/compare-multiple-sample-variances-in-r</guid>
			<description><![CDATA[<!-- START HTML -->

  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">

<div id="TOC">
<ul>
<li><a href="#statistical-tests-for-comparing-variances">Statistical tests for comparing variances</a></li>
<li><a href="#statistical-hypotheses">Statistical hypotheses</a></li>
<li><a href="#import-and-check-your-data-into-r">Import and check your data into R</a></li>
<li><a href="#compute-bartletts-test-in-r">Compute Bartlett’s test in R</a></li>
<li><a href="#compute-levenes-test-in-r">Compute Levene’s test in R</a></li>
<li><a href="#compute-fligner-killeen-test-in-r">Compute Fligner-Killeen test in R</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<p><br/></p>
<p>This article describes <strong>statistical tests</strong> for comparing the <strong>variances</strong> of two or more samples. Equal variances across samples is called <strong>homogeneity</strong> of <strong>variances</strong>.</p>
<p>Some statistical tests, such as <a href="https://www.sthda.com/english/english/wiki/unpaired-two-samples-t-test-in-r">two independent samples T-test</a> and <a href="https://www.sthda.com/english/english/wiki/one-way-anova-test-in-r">ANOVA test</a>, assume that variances are equal across groups. The <strong>Bartlett’s test</strong>, <strong>Levene’s test</strong> or <strong>Fligner-Killeen’s test</strong> can be used to verify that assumption.</p>
<p><br/> <img src="https://www.sthda.com/english/sthda/RDoc/images/multiple-variances-test.png" alt="Compare Multiple Sample Variances in R" /> <br/></p>
<div id="statistical-tests-for-comparing-variances" class="section level1">
<h1>Statistical tests for comparing variances</h1>
<p>There are many solutions to test for the equality (<strong>homogeneity</strong>) of variance across groups, including:</p>
<ul>
<li><p><a href="https://www.sthda.com/english/english/wiki/f-test-compare-two-variances-in-r"><strong>F-test</strong></a>: Compare the variances of two samples. The data must be normally distributed.</p></li>
<li><p><strong>Bartlett’s test</strong>: Compare the variances of k samples, where k can be more than two samples. The data must be normally distributed. The Levene test is an alternative to the Bartlett test that is less sensitive to departures from normality.</p></li>
<li><p><strong>Levene’s test</strong>: Compare the variances of k samples, where k can be more than two samples. It’s an alternative to the Bartlett’s test that is less sensitive to departures from normality.</p></li>
<li><p><strong>Fligner-Killeen test</strong>: a non-parametric test which is very robust against departures from normality.</p></li>
</ul>
<br/>
<div class="warning">
The <strong>F-test</strong> has been described in our previous article: <a href="https://www.sthda.com/english/english/wiki/f-test">F-test to compare equality of two variances</a>. In the present article, we’ll describe the tests for comparing more than two variances.
</div>
<p><br/></p>
</div>
<div id="statistical-hypotheses" class="section level1">
<h1>Statistical hypotheses</h1>
<p>For all these tests (<strong>Bartlett’s test</strong>, <strong>Levene’s test</strong> or <strong>Fligner-Killeen’s test</strong>),</p>
<ul>
<li>the null hypothesis is that all populations variances are equal;</li>
<li>the alternative hypothesis is that at least two of them differ.</li>
</ul>
</div>
<div id="import-and-check-your-data-into-r" class="section level1">
<h1>Import and check your data into R</h1>
<p>To import your data, use the following R code:</p>
<pre class="r"><code># If .txt tab file, use this
my_data <- read.delim(file.choose())

# Or, if .csv file, use this
my_data <- read.csv(file.choose())</code></pre>
<p>Here, we’ll use ToothGrowth and PlantGrowth data sets:</p>
<pre class="r"><code># Load the data
data(ToothGrowth)

data(PlantGrowth)</code></pre>
<p>To have an idea of what the data look like, we start by displaying a random sample of 10 rows using the function <strong>sample_n</strong>()[in <strong>dplyr</strong> package]. First, install dplyr package if you don’t have it: <strong>install.packages(“dplyr”)</strong>.</p>
<p>Show 10 random rows:</p>
<pre class="r"><code>set.seed(123)
# Show PlantGrowth
dplyr::sample_n(PlantGrowth, 10)</code></pre>
<pre><code>   weight group
24   5.50  trt2
12   4.17  trt1
25   5.37  trt2
26   5.29  trt2
2    5.58  ctrl
14   3.59  trt1
22   5.12  trt2
13   4.41  trt1
11   4.81  trt1
21   6.31  trt2</code></pre>
<pre class="r"><code># PlantGrowth data structure
str(PlantGrowth)</code></pre>
<pre><code>&amp;#39;data.frame&amp;#39;:   30 obs. of  2 variables:
 $ weight: num  4.17 5.58 5.18 6.11 4.5 4.61 5.17 4.53 5.33 5.14 ...
 $ group : Factor w/ 3 levels "ctrl","trt1",..: 1 1 1 1 1 1 1 1 1 1 ...</code></pre>
<pre class="r"><code># Show ToothGrowth
dplyr::sample_n(ToothGrowth, 10)</code></pre>
<pre><code>    len supp dose
28 21.5   VC  2.0
40  9.7   OJ  0.5
34  9.7   OJ  0.5
6  10.0   VC  0.5
51 25.5   OJ  2.0
14 17.3   VC  1.0
3   7.3   VC  0.5
18 14.5   VC  1.0
50 27.3   OJ  1.0
46 25.2   OJ  1.0</code></pre>
<pre class="r"><code># ToothGrowth data structure
str(ToothGrowth)</code></pre>
<pre><code>&amp;#39;data.frame&amp;#39;:   60 obs. of  3 variables:
 $ len : num  4.2 11.5 7.3 5.8 6.4 10 11.2 11.2 5.2 7 ...
 $ supp: Factor w/ 2 levels "OJ","VC": 2 2 2 2 2 2 2 2 2 2 ...
 $ dose: num  0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 ...</code></pre>
<p><span class="warning">Note that, R considers the column “dose” [in ToothGrowth data set] as a numeric vector. We want to convert it as a grouping variable (factor).</span></p>
<pre class="r"><code>ToothGrowth$dose <- as.factor(ToothGrowth$dose)</code></pre>
<p><span class="question">We want to test the equality of variances between groups.</span></p>
</div>
<div id="compute-bartletts-test-in-r" class="section level1">
<h1>Compute Bartlett’s test in R</h1>
<br/>

<div class="block">
<strong>Bartlett’s test</strong> is used for testing homogeneity of variances in k samples, where k can be more than two. It’s adapted for normally distributed data. The <strong>Levene test</strong>, described in the next section, is a more robust alternative to the Bartlett test when the distributions of the data are non-normal.
</div>
<p><br/></p>
<p>The R function <strong>bartlett.test</strong>() can be used to compute Barlett’s test. The simplified format is as follow:</p>
<pre class="r"><code>bartlett.test(formula, data)</code></pre>
<ul>
<li><strong>formula</strong>: a formula of the form values ~ groups</li>
<li><strong>data</strong>: a matrix or data frame</li>
</ul>
<p>The function returns a list containing the following component:</p>
<br/>
<div class="block">
<ul>
<li><strong>statistic</strong>: Bartlett’s K-squared test statistic</li>
<li><strong>parameter</strong>: the degrees of freedom of the approximate chi-squared distribution of the test statistic.</li>
<li><strong>p.value</strong>: the p-value of the test</li>
</ul>
</div>
<p><br/></p>
<p>To perform the test, we’ll use the <em>PlantGrowth</em> data set, which contains the weight of plants obtained under 3 treatment groups.</p>
<ul>
<li><strong>Bartlett’s test with one independent variable</strong>:</li>
</ul>
<pre class="r"><code>res <- bartlett.test(weight ~ group, data = PlantGrowth)
res</code></pre>
<pre><code>
    Bartlett test of homogeneity of variances

data:  weight by group
Bartlett&amp;#39;s K-squared = 2.8786, df = 2, p-value = 0.2371</code></pre>
<p><span class="success">From the output, it can be seen that the p-value of 0.2370968 is not less than the significance level of 0.05. This means that there is no evidence to suggest that the variance in plant growth is statistically significantly different for the three treatment groups.</span></p>
<ul>
<li><strong>Bartlett’s test with multiple independent variables</strong>: the <strong>interaction</strong>() function must be used to collapse multiple factors into a single variable containing all combinations of the factors.</li>
</ul>
<pre class="r"><code>bartlett.test(len ~ interaction(supp,dose), data=ToothGrowth)</code></pre>
<pre><code>
    Bartlett test of homogeneity of variances

data:  len by interaction(supp, dose)
Bartlett&amp;#39;s K-squared = 6.9273, df = 5, p-value = 0.2261</code></pre>
</div>
<div id="compute-levenes-test-in-r" class="section level1">
<h1>Compute Levene’s test in R</h1>
<p><span class="success">As mentioned above, Levene’s test is an alternative to Bartlett’s test when the data is not normally distributed.</span></p>
<p>The function <strong>leveneTest</strong>() [in <strong>car</strong> package] can be used.</p>
<pre class="r"><code>library(car)
# Levene&amp;#39;s test with one independent variable
leveneTest(weight ~ group, data = PlantGrowth)</code></pre>
<pre><code>Levene&amp;#39;s Test for Homogeneity of Variance (center = median)
      Df F value Pr(>F)
group  2  1.1192 0.3412
      27               </code></pre>
<pre class="r"><code># Levene&amp;#39;s test with multiple independent variables
leveneTest(len ~ supp*dose, data = ToothGrowth)</code></pre>
<pre><code>Levene&amp;#39;s Test for Homogeneity of Variance (center = median)
      Df F value Pr(>F)
group  5  1.7086 0.1484
      54               </code></pre>
</div>
<div id="compute-fligner-killeen-test-in-r" class="section level1">
<h1>Compute Fligner-Killeen test in R</h1>
<p>The <strong>Fligner-Killeen test</strong> is one of the many tests for homogeneity of variances which is most robust against departures from normality.</p>
<p>The R function <strong>fligner.test</strong>() can be used to compute the test:</p>
<pre class="r"><code>fligner.test(weight ~ group, data = PlantGrowth)</code></pre>
<pre><code>
    Fligner-Killeen test of homogeneity of variances

data:  weight by group
Fligner-Killeen:med chi-squared = 2.3499, df = 2, p-value = 0.3088</code></pre>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning"> This analysis has been performed using <strong>R software</strong> (ver. 3.2.4). </span></p>
</div>

<script>jQuery(document).ready(function () {
    jQuery('#rdoc h1').addClass('wiki_paragraph1');
    jQuery('#rdoc h2').addClass('wiki_paragraph2');
    jQuery('#rdoc h3').addClass('wiki_paragraph3');
    jQuery('#rdoc h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->


<!-- END HTML -->]]></description>
			<pubDate>Thu, 06 Oct 2016 00:07:52 +0200</pubDate>
			
		</item>
		
	</channel>
</rss>
