

{"id":4903,"date":"2017-12-06T05:07:52","date_gmt":"2017-12-05T23:37:52","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=4903"},"modified":"2021-08-25T17:26:18","modified_gmt":"2021-08-25T11:56:18","slug":"anova-in-r","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/anova-in-r\/","title":{"rendered":"ANOVA in R &#8211; A tutorial that will help you master its Ways of Implementation"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:2190,&quot;href&quot;:&quot;https:\\\/\\\/www.r-project.org\\\/foundation\\\/board.html&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20250918234711\\\/https:\\\/\\\/www.r-project.org\\\/foundation\\\/board.html&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-11 02:10:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-16 20:44:20&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-21 17:00:37&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-29 10:54:30&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-04 15:01:03&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-08 02:01:59&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-11 17:40:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-15 15:23:29&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-26 10:52:55&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-30 04:54:58&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-03 09:08:25&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-06 09:43:19&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-09 16:10:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-12 20:30:08&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-16 10:51:42&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-21 07:21:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-02 07:51:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-08 02:35:45&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-11 07:11:27&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-16 08:52:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-19 15:18:11&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-24 20:49:37&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-29 08:13:21&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-02 02:13:32&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-06 05:04:42&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-10 08:33:08&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-18 13:58:45&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-23 14:05:14&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-27 01:23:29&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-01 12:57:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-04 23:18:41&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-08 06:30:51&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-13 01:56:16&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-24 18:53:52&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-27 19:22:17&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-05-27 19:22:17&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p>In today&#8217;s era, more and more programmers are aspiring to become a Data Scientist. And, you must be aware that R programming is an essential ingredient for mastering Data Science. So, let&#8217;s jump to one of the most important topics of R; ANOVA model in R.<\/p>\n<p>In this tutorial, we will understand the complete model of ANOVA in R. Also, we will discuss the One-way and Two-way ANOVA in R along with its syntax. After this, learn about the ANOVA table and Classical ANOVA in R.<\/p>\n<p>Let&#8217;s start the tutorial.<\/p>\n<h3>What is ANOVA?<\/h3>\n<p><span style=\"font-weight: 400\">The ANOVA model which stands for <em><strong>Analysis of Variance<\/strong><\/em> is used to measure the statistical difference between the means. With the ANOVA model, we assess if the various groups share a common mean.\u00a0 As a result, we have found that it&#8217;s used for investigating data by comparing the means of subsets of data.<\/span><br \/>\n<b><\/b><\/p>\n<p><b>Anova.glm<\/b><\/p>\n<p>Generally, it&#8217;s an analysis of Deviance for Generalized Linear Model Fits.<\/p>\n<p><span style=\"font-weight: 400\">As a result, it&#8217;s needed to compute an analysis of deviance table for one or more generalized linear model fits.<\/span><br \/>\n<b><\/b><\/p>\n<p><em><strong>Learn everything about the <a href=\"https:\/\/data-flair.training\/blogs\/generalized-linear-models-in-r\/\">Generalized Linear Models in R<\/a><\/strong><\/em><\/p>\n<p><b>Keywords:<\/b><\/p>\n<p><span style=\"font-weight: 400\">models, regression<\/span><br \/>\n<b><\/b><\/p>\n<p><b>Usage:<\/b><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\"># S3 method for glm\r\nanova(object, \u2026, dispersion = NULL, test = NULL)<\/pre>\n<p><strong>Arguments:<\/strong><\/p>\n<p><strong>1. the object, \u2026<\/strong><\/p>\n<p>Basically, it&#8217;s the result of a call to glm or a list of objects for the &#8220;almost&#8221; method.<\/p>\n<p><strong>2. dispersion<\/strong><\/p>\n<p>Dispersion is defined as the parameter for the fitting family.<\/p>\n<p><strong>3. test<\/strong><\/p>\n<p>It&#8217;s a character string. As a result, it should match one of &#8220;Chisq&#8221;, &#8220;LRT&#8221;, &#8220;Rao&#8221;, &#8220;F&#8221; or &#8220;Cp&#8221;.<\/p>\n<h2>Implementing ANOVA in R<\/h2>\n<p>There are two ways of implementing ANOVA in R:<\/p>\n<ul>\n<li>One-way ANOVA<\/li>\n<li>Two-way ANOVA<\/li>\n<\/ul>\n<h3>One-way ANOVA in R<\/h3>\n<p><span style=\"font-weight: 400\">Let&#8217;s take an example of using insect sprays which is a type of data set. We are going to test 6 different insect sprays. As a result, we need to see if there was a difference in the number of insects found in the field after each spraying.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; attach(InsectSprays)\r\n&gt; data(InsectSprays)\r\n&gt; str(InsectSprays)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/One-way-ANOVA.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-60450\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/One-way-ANOVA.jpg\" alt=\"One-way ANOVA\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/One-way-ANOVA.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/One-way-ANOVA-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/One-way-ANOVA-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/One-way-ANOVA-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/One-way-ANOVA-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/One-way-ANOVA-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><em><strong>Do you know about <a href=\"https:\/\/data-flair.training\/blogs\/r-data-frame-introduction-operations\/\">Data Frame Operations in R<\/a><\/strong><\/em><\/p>\n<h4>1. Descriptive Statistics<\/h4>\n<ol>\n<li><span style=\"font-weight: 400\">With the help of descriptive statistics, we calculate the mean, variance and number of elements in each cell.<\/span><br \/>\n<b><\/b><\/li>\n<li><span style=\"font-weight: 400\">Visualise the data \u2013 boxplot; look at the distribution for outliers.<\/span><br \/>\n<b><\/b><\/li>\n<\/ol>\n<p><b>We will be using tapply() here<\/b><span style=\"font-weight: 400\">:<\/span><\/p>\n<p><span style=\"font-weight: 400\">tapply() function is a very useful shortcut in processing data. Also, we use it as a function. It should be applied to each subset of the response variable defined by each level of the factor.<\/span><\/p>\n<h4>2. Run 1-way ANOVA<\/h4>\n<p><strong>2.1 Oneway.test ( )<\/strong><\/p>\n<p>Use, for example<span style=\"font-weight: 400\">:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; oneway.test(count~spray)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Oneway.test_.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-60451\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Oneway.test_.jpg\" alt=\"Oneway.test\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Oneway.test_.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Oneway.test_-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Oneway.test_-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Oneway.test_-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Oneway.test_-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Oneway.test_-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400\">Default is equal variances not assumed that is Welch\u2019s correction applied and this explains why the denom df (which is k*{n-1}) is not a whole number in the output O.<\/span><\/p>\n<p>In order to alter this, we set the &#8220;var.equal =&#8221; option to TRUE.<\/p>\n<p><span style=\"font-weight: 400\">Oneway.test( ) corrects the non-homogeneity but doesn\u2019t give much information.<\/span><\/p>\n<p><strong>2.2 Run an ANOVA using aov( )<\/strong><\/p>\n<p><span style=\"font-weight: 400\"> We use the aov() function to store the output and use extraction functions to obtain what is required.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; #Author\u00a0DataFlair\r\n&gt; AOV_Output\u00a0&lt;-\u00a0aov(count\u00a0~\u00a0spray,\u00a0data=InsectSprays)\r\n&gt; summary(AOV_Output)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/aov-.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-60454\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/aov-.jpg\" alt=\"aov( ) - R Anova\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/aov-.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/aov--150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/aov--300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/aov--768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/aov--1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/aov--520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><em><strong>Have you checked &#8211; <a href=\"https:\/\/data-flair.training\/blogs\/survival-analysis-in-r\/\">Survival Analysis in R<\/a><\/strong><\/em><\/p>\n<h3>2. Two-way ANOVA in R<\/h3>\n<p><b>Two-way Analysis of Variance<\/b><\/p>\n<p><span style=\"font-weight: 400\">We use it to compare the means of populations which is classified in two different ways. Besides, we can use lm() to fit two-way ANOVA models in R.<\/span><br \/>\n<b><\/b><\/p>\n<p><b>For example<\/b><span style=\"font-weight: 400\">, <\/span><b>the command<\/b><span style=\"font-weight: 400\">:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; lm(Response ~ FactorA + FactorB)<\/pre>\n<p><span style=\"font-weight: 400\">fits a two- way ANOVA model without interactions. In contrast, the command:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; lm(Response ~ FactorA + FactorB + FactorA * FactorB )<\/pre>\n<p><span style=\"font-weight: 400\">includes an interaction term. Here, both FactorA and FactorB are categorical variables, while Response is quantitative.<\/span><\/p>\n<p><em><strong>Understand the complete <a href=\"https:\/\/data-flair.training\/blogs\/principal-components-and-factor-analysis-in-r\/\">concept of Factor Analysis in R<\/a><\/strong><\/em><\/p>\n<h3>Classical ANOVA in R<\/h3>\n<p><span style=\"font-weight: 400\">Generally, we start with a simple additive fixed effects model. In this model, we use the built-in function aov:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">aov(Y ~ A + B, data=d)<\/pre>\n<p><span style=\"font-weight: 400\">Now, to cross these factors or more for interacting with two variables, we use either of:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">aov(Y ~ A * B, data=d)\r\naov(Y ~ A + B + A:B, data=d)<\/pre>\n<p><span style=\"font-weight: 400\">So far so good. Furthermore, we make an assumption that B is nested within A:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">aov(Y ~ A\/B, data=d)\r\naov(Y ~ A + B %in% A, data=d)\r\naov(Y ~ A + A:B, data=d)<\/pre>\n<p>Therefore, in nesting, we add both &#8211; the main effect and the interaction.<\/p>\n<p><em><strong>You must definitely explore the <a href=\"https:\/\/data-flair.training\/blogs\/r-graphical-models-tutorial\/\">R Graphical Models tutorial<\/a><\/strong><\/em><\/p>\n<h4>Random Effects in Classical ANOVA<\/h4>\n<p><span style=\"font-weight: 400\">aov can also deal with random effects that provides everything which is being balanced. Assume A is alone random effect, e.g. a subject indicator.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">aov(Y ~ Error(A), data=d)<\/pre>\n<p><span style=\"font-weight: 400\">We make an assumption that A is random, B is fixed as well as nested within A.\u00a0<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">aov(Y ~ B + Error(A\/B), data=d)<\/pre>\n<p><span style=\"font-weight: 400\">or B and X are crossed (interacted) within levels of random A.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">aov(Y ~ (B*X) + Error(A\/(B*X)), data=d)<\/pre>\n<p><span style=\"font-weight: 400\">Or B and X within random A are categorized by (non-nested) G and H:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">aov(Y ~ (B*X*G*H) + Error(A\/(B*X)) + (G*H), data=d)<\/pre>\n<p><span style=\"font-weight: 400\">As a result, this Error business can become confusing and the balance requirements, a bit tiresome. Thus, for random effects models, it&#8217;s usually easier to move to lme4.<\/span><\/p>\n<p><em><strong>Must Learn &#8211; <a href=\"https:\/\/data-flair.training\/blogs\/generalized-linear-models-in-r\/\">Generalized Linear Models in R<\/a><\/strong><\/em><\/p>\n<h3>ANOVA Table in R<\/h3>\n<p>Let&#8217;s say, we have collected data, and our X values have been entered in <a href=\"https:\/\/www.r-project.org\/foundation\/board.html\">R<\/a> as an array called data.X and Y values as data.Y.<\/p>\n<p>Now, we will find the ANOVA values for the data. Then, follow the below steps:<\/p>\n<ul>\n<li>First, we will fit our data into a model. &gt; data.lm = lm(data.Y~data.X).<\/li>\n<li>Next, we will get R to produce an ANOVA table by typing : &gt; anova(data.lm).<\/li>\n<li>As a result, we will have an ANOVA table!<\/li>\n<\/ul>\n<p><strong>1. Fitted Values<\/strong><\/p>\n<p>Type:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; data.fit = fitted(data.lm)<\/pre>\n<p>to get the fitted values of the model.<\/p>\n<p>As a result, it gives us an array called &#8220;data.fit&#8221; that contains the fitted values of data.lm.<\/p>\n<p><strong>2. Residuals<\/strong><\/p>\n<p>We use this\u00a0to get the residuals of the model.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; data.res = resid(data.lm)<\/pre>\n<p>Now, as a result, we have an array of residuals.<\/p>\n<p><strong>3. Hypothesis Testing<\/strong><\/p>\n<ul>\n<li>In case if we have already found the ANOVA table for our data, then we are able to calculate our test statistic from the numbers given.<\/li>\n<li>If we want to find the F &#8211; quantile given by F(.95;3,24)<\/li>\n<\/ul>\n<p>Find this by typing:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; #Author DataFlair\r\n&gt; qf(.97,\u00a05,\u00a023)<\/pre>\n<ul>\n<li>If we want to find the t &#8211; quantile given by t(<span style=\"font-weight: 400\">0.975, 1.2, 20<\/span>)<\/li>\n<\/ul>\n<p>Type:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; qt(0.975,\u00a01.2,\u00a020)       #Calculating\u00a0the\u00a0t-quantile<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Hypothesis-Testing.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-60457\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Hypothesis-Testing.jpg\" alt=\"Hypothesis Testing - R ANOVA\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Hypothesis-Testing.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Hypothesis-Testing-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Hypothesis-Testing-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Hypothesis-Testing-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Hypothesis-Testing-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Hypothesis-Testing-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><em><strong>Don&#8217;t forget to check the <a href=\"https:\/\/data-flair.training\/blogs\/r-contengency-tables\/\">Creation of Contingency Tables in R<\/a><\/strong><\/em><\/p>\n<p><strong>4. P &#8211; values<\/strong><\/p>\n<p>In case if we want to get the p-value for the F &#8211; quantile of, say, 2.84, with degrees of freedom 3 and 24, we would type in<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; <span style=\"font-weight: 400\">pf(3.75, 2, 26) \u00a0\u00a0\u00a0\u00a0\u00a0#Calculating p-value for the f-quantile<\/span><\/pre>\n<p><strong>5. Normal Q-Q plot<\/strong><\/p>\n<p>Generally, we use &#8220;data.lm to get the normal probability for the standard residuals of our data.<\/p>\n<p>Although, we have already fit our data to a model, but now we will need the studentized residuals:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; data.stdres = rstandard(data.lm)<\/pre>\n<p>Also, type this to make the plot:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; qqnorm(data.stdres)<\/pre>\n<p>Then, to see the line, type:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; qqline(data.stdres)<\/pre>\n<h2>Summary<\/h2>\n<p>We have studied ANOVA in R with their different types and properties. It is very much useful in investigating data by comparing the means of subsets of the data. Still, if you have any confusion regarding ANOVA in R, ask in the comment section.<\/p>\n<p><em><strong>For now, you must have a look at <a href=\"https:\/\/data-flair.training\/blogs\/chi-square-test-in-r\/\">Chi-Square Test in R<\/a><\/strong><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In today&#8217;s era, more and more programmers are aspiring to become a Data Scientist. And, you must be aware that R programming is an essential ingredient for mastering Data Science. So, let&#8217;s jump to&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":60473,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[16712,20284,20288,20287,20285,20286],"class_list":["post-4903","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r","tag-anova-in-r","tag-implementing-anova-in-r","tag-r-anova-table","tag-r-classical-anova","tag-r-one-way-anova","tag-r-two-way-anova"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>ANOVA in R - A tutorial that will help you master its Ways of Implementation - DataFlair<\/title>\n<meta name=\"description\" content=\"Want to learn about the ANOVA in R? Get to know the core concept behind ANOVA, ways to implement ANOVA in R; One-way ANOVA, Two-way ANOVA, Classical &amp; ANOVA table.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/anova-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ANOVA in R - A tutorial that will help you master its Ways of Implementation - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Want to learn about the ANOVA in R? Get to know the core concept behind ANOVA, ways to implement ANOVA in R; One-way ANOVA, Two-way ANOVA, Classical &amp; ANOVA table.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/anova-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2017-12-05T23:37:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-25T11:56:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Anova-in-R.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"ANOVA in R - A tutorial that will help you master its Ways of Implementation - DataFlair","description":"Want to learn about the ANOVA in R? Get to know the core concept behind ANOVA, ways to implement ANOVA in R; One-way ANOVA, Two-way ANOVA, Classical & ANOVA table.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/anova-in-r\/","og_locale":"en_US","og_type":"article","og_title":"ANOVA in R - A tutorial that will help you master its Ways of Implementation - DataFlair","og_description":"Want to learn about the ANOVA in R? Get to know the core concept behind ANOVA, ways to implement ANOVA in R; One-way ANOVA, Two-way ANOVA, Classical & ANOVA table.","og_url":"https:\/\/data-flair.training\/blogs\/anova-in-r\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2017-12-05T23:37:52+00:00","article_modified_time":"2021-08-25T11:56:18+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Anova-in-R.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/anova-in-r\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/anova-in-r\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"ANOVA in R &#8211; A tutorial that will help you master its Ways of Implementation","datePublished":"2017-12-05T23:37:52+00:00","dateModified":"2021-08-25T11:56:18+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/anova-in-r\/"},"wordCount":1122,"commentCount":1,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/anova-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Anova-in-R.jpg","keywords":["ANOVA in R","Implementing ANOVA in R","R ANOVA Table","R Classical ANOVA","R One-way ANOVA","R Two-way ANOVA"],"articleSection":["R Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/anova-in-r\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/anova-in-r\/","url":"https:\/\/data-flair.training\/blogs\/anova-in-r\/","name":"ANOVA in R - A tutorial that will help you master its Ways of Implementation - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/anova-in-r\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/anova-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Anova-in-R.jpg","datePublished":"2017-12-05T23:37:52+00:00","dateModified":"2021-08-25T11:56:18+00:00","description":"Want to learn about the ANOVA in R? Get to know the core concept behind ANOVA, ways to implement ANOVA in R; One-way ANOVA, Two-way ANOVA, Classical & ANOVA table.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/anova-in-r\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/anova-in-r\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/anova-in-r\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Anova-in-R.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Anova-in-R.jpg","width":802,"height":420,"caption":"ANOVA in R topics"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/anova-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"R Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/r\/"},{"@type":"ListItem","position":3,"name":"ANOVA in R &#8211; A tutorial that will help you master its Ways of Implementation"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/4903","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=4903"}],"version-history":[{"count":10,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/4903\/revisions"}],"predecessor-version":[{"id":60506,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/4903\/revisions\/60506"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/60473"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=4903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=4903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=4903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}