{"id":10870,"date":"2019-11-29T00:47:52","date_gmt":"2019-11-28T22:47:52","guid":{"rendered":"https:\/\/www.datanovia.com\/en\/?post_type=dt_courses&#038;p=10870"},"modified":"2020-01-13T22:33:28","modified_gmt":"2020-01-13T20:33:28","slug":"comparing-multiple-means-in-r","status":"publish","type":"dt_courses","link":"https:\/\/www.datanovia.com\/en\/courses\/comparing-multiple-means-in-r\/","title":{"rendered":"Comparing Multiple Means in R"},"content":{"rendered":"<div id=\"rdoc\">\n<h2>Course description<\/h2>\n<p>This course describes how to compare multiple means in R using the <strong>ANOVA<\/strong> (Analysis of Variance) method and variants, including:<\/p>\n<ul>\n<li><strong>ANOVA test<\/strong> for comparing independent measures.<\/li>\n<li><strong>Repeated-measures ANOVA<\/strong>, which is used for analyzing data where same subjects are measured more than once.<\/li>\n<li><strong>Mixed ANOVA<\/strong>, which is used to compare the means of groups cross-classified by at least two factors, where one factor is a \u201c<em>within-subjects<\/em>\u201d factor (repeated measures) and the other factor is a \u201c<em>between-subjects<\/em>\u201d factor.<\/li>\n<li><strong>ANCOVA<\/strong> (analyse of covariance), an extension of the one-way ANOVA that incorporate a covariate variable.<\/li>\n<li><strong>MANOVA<\/strong> (multivariate analysis of variance), an ANOVA with two or more continuous outcome variables.<\/li>\n<\/ul>\n<p>We also provide R code to check ANOVA assumptions and perform Post-Hoc analyses. Additionally, we\u2019ll present:<\/p>\n<ul>\n<li><strong>Kruskal-Wallis test<\/strong>, which is a non-parametric alternative to the one-way ANOVA test.<\/li>\n<li><strong>Friedman test<\/strong>, which is a non-parametric alternative to the one-way repeated measures ANOVA test.<\/li>\n<\/ul>\n<div class='dt-sc-hr-invisible-medium  '><\/div>\n<div class='dt-sc-ico-content type1'><div class='custom-icon' ><a href='https:\/\/www.datanovia.com\/en\/product\/practical-statistics-in-r-for-comparing-groups-numerical-variables\/' target='_blank'><span class='fa fa-book'><\/span><\/a><\/div><h4><a href='https:\/\/www.datanovia.com\/en\/product\/practical-statistics-in-r-for-comparing-groups-numerical-variables\/' target='_blank'> Related Book <\/a><\/h4>Practical Statistics in R II - Comparing Groups: Numerical Variables<\/div>\n<div class='dt-sc-hr-invisible-medium  '><\/div>\n<div id=\"r-functions-and-packages\" class=\"section level2\">\n<h2>R functions and packages<\/h2>\n<p>There are different functions\/packages in R for computing ANOVA. These include:<\/p>\n<ul>\n<li><code>aov()<\/code> [stats]: Computes type I sum of squares (SS). Should be only used when you have balanced designs (group sizes are equal).<\/li>\n<li><code>Anova()<\/code> [car]: Computes type-II and type-III sum of squares. Type-II will yield identical ANOVA results as type-I when the data are balanced. When data are unbalanced, type-III will emulate the approach taken by popular commercial statistics packages like SAS and SPSS, but this approach is not without criticism.<\/li>\n<li><code>ezANOVA()<\/code> [ez], <code>car_aov()<\/code> [afex] and <code>anova_test()<\/code> [rstatix]: Wrappers around the function <code>Anova()<\/code> [car] for facilitating the analysis of factorial experiments, including purely \u2018within-Ss\u2019 designs (repeated measures), purely \u2018between-Ss\u2019 designs, and mixed \u2018within-and-between-Ss\u2019 designs.<\/li>\n<\/ul>\n<p>The advantage of <code>anova_test()<\/code> [rstatix] is that it supports both model and formula as inputs. Variables can be also specified as character vector using the arguments <code>dv<\/code>, <code>wid<\/code>, <code>between<\/code>, <code>within<\/code>, <code>covariate<\/code>. Read more in the documentation by typing <code>?anova_test<\/code> in R console. It provides a simple and intuitive pipe-friendly framework, coherent with the <code>tidyverse<\/code> design philosophy. Additionally, it supports grouped data as returned by the function <code>dplyr::group_by()<\/code>. The results include ANOVA table, generalized effect size and some assumption checks.<\/p>\n<div class=\"success\">\n<p>In this guide, we\u2019ll use mainly the function <code>anova_test()<\/code>.<\/p>\n<\/div>\n<\/div>\n<div id=\"recommendations\" class=\"section level2\">\n<h2>Recommendations<\/h2>\n<ul>\n<li>The <strong>outcome<\/strong> variable, also known as dependent variable (dv), should be numeric<\/li>\n<li>The <strong>grouping variables<\/strong>, also known as predictors or independent variables, should be factors. If you want to compute ANCOVA models, you can also add numeric predictors.<\/li>\n<li><strong>Do not use the R base functions aov() and anova()<\/strong> to get ANOVA tables unless you know what you are doing. They compute the type-I sum of squares, which is not, for example, suitable for unbalanced designs. The results, obtained with the default options of theses functions, are different from those obtained with commercial stats softwares, including SPSS and SAS, and most other stats packages. These differences are important and will be confusing and give you misleading results unless you understand them.<\/li>\n<\/ul>\n<p>Follow the recommendations below:<\/p>\n<ul>\n<li>If you have a factorial design with <strong>independent measures<\/strong>, you can define your model using <code>lm()<\/code> and then use <code>rstatix::anova_test()<\/code> or <code>car::Anova()<\/code> to calculate F tests.<\/li>\n<li>If you have perfect <strong>balanced repeated measures design<\/strong> with no missing values, then use <code>rstatix::anova_test()<\/code>.<\/li>\n<li>If you have an <strong>unbalanced repeated measures design<\/strong>, or you repeated measures with missing data, use linear mixed models instead via the <code>lme4::lmer()<\/code>.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<p><!--end rdoc--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This course describes how to compare multiple means in R using the ANOVA (Analysis of Variance) method and variants, including: i) ANOVA test for comparing independent measures; 2) Repeated-measures ANOVA, which is used for analyzing data where same subjects are measured more than once; 3) Mixed ANOVA, which is used to compare the means of groups cross-classified by at least two factors, where one factor is a &#8220;within-subjects&#8221; factor (repeated measures) and the other factor is a &#8220;between-subjects&#8221; factor; 4) ANCOVA (analyse of covariance), an extension of the one-way ANOVA that incorporate a covariate variable; 5) MANOVA (multivariate analysis of variance), an ANOVA with two or more continuous outcome variables.<\/p>\n<p>We also provide R code to check ANOVA assumptions and perform Post-Hoc analyses. Additionally, we&#8217;ll present: 1) Kruskal-Wallis test, which is a non-parametric alternative to the one-way ANOVA test; 2) Friedman test, which is a non-parametric alternative to the one-way repeated measures ANOVA test.<\/p>\n","protected":false},"author":1,"featured_media":9110,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","class_list":["post-10870","dt_courses","type-dt_courses","status-publish","has-post-thumbnail","hentry","course_category-basic-statistics","course_category-biostatistics","course_category-comparing-means"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Comparing Multiple Means in R: The Ultimate Guide - Datanovia<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.datanovia.com\/en\/courses\/comparing-multiple-means-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Comparing Multiple Means in R: The Ultimate Guide - Datanovia\" \/>\n<meta property=\"og:description\" content=\"This course describes how to compare multiple means in R using the ANOVA (Analysis of Variance) method and variants, including: i) ANOVA test for comparing independent measures; 2) Repeated-measures ANOVA, which is used for analyzing data where same subjects are measured more than once; 3) Mixed ANOVA, which is used to compare the means of groups cross-classified by at least two factors, where one factor is a &quot;within-subjects&quot; factor (repeated measures) and the other factor is a &quot;between-subjects&quot; factor; 4) ANCOVA (analyse of covariance), an extension of the one-way ANOVA that incorporate a covariate variable; 5) MANOVA (multivariate analysis of variance), an ANOVA with two or more continuous outcome variables.   We also provide R code to check ANOVA assumptions and perform Post-Hoc analyses. Additionally, we&#039;ll present: 1) Kruskal-Wallis test, which is a non-parametric alternative to the one-way ANOVA test; 2) Friedman test, which is a non-parametric alternative to the one-way repeated measures ANOVA test.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.datanovia.com\/en\/courses\/comparing-multiple-means-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Datanovia\" \/>\n<meta property=\"article:modified_time\" content=\"2020-01-13T20:33:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2019\/05\/Sterne.royale.8.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"512\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.datanovia.com\/en\/courses\/comparing-multiple-means-in-r\/\",\"url\":\"https:\/\/www.datanovia.com\/en\/courses\/comparing-multiple-means-in-r\/\",\"name\":\"Comparing Multiple Means in R: The Ultimate Guide - Datanovia\",\"isPartOf\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/courses\/comparing-multiple-means-in-r\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/courses\/comparing-multiple-means-in-r\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2019\/05\/Sterne.royale.8.jpg\",\"datePublished\":\"2019-11-28T22:47:52+00:00\",\"dateModified\":\"2020-01-13T20:33:28+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/courses\/comparing-multiple-means-in-r\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.datanovia.com\/en\/courses\/comparing-multiple-means-in-r\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.datanovia.com\/en\/courses\/comparing-multiple-means-in-r\/#primaryimage\",\"url\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2019\/05\/Sterne.royale.8.jpg\",\"contentUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2019\/05\/Sterne.royale.8.jpg\",\"width\":1024,\"height\":512},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.datanovia.com\/en\/courses\/comparing-multiple-means-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.datanovia.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Courses\",\"item\":\"https:\/\/www.datanovia.com\/en\/courses\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Comparing Multiple Means in R\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#website\",\"url\":\"https:\/\/www.datanovia.com\/en\/\",\"name\":\"Datanovia\",\"description\":\"Data Mining and Statistics for Decision Support\",\"publisher\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.datanovia.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#organization\",\"name\":\"Datanovia\",\"url\":\"https:\/\/www.datanovia.com\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png\",\"contentUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png\",\"width\":98,\"height\":99,\"caption\":\"Datanovia\"},\"image\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Comparing Multiple Means in R: The Ultimate Guide - Datanovia","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:\/\/www.datanovia.com\/en\/courses\/comparing-multiple-means-in-r\/","og_locale":"en_US","og_type":"article","og_title":"Comparing Multiple Means in R: The Ultimate Guide - Datanovia","og_description":"This course describes how to compare multiple means in R using the ANOVA (Analysis of Variance) method and variants, including: i) ANOVA test for comparing independent measures; 2) Repeated-measures ANOVA, which is used for analyzing data where same subjects are measured more than once; 3) Mixed ANOVA, which is used to compare the means of groups cross-classified by at least two factors, where one factor is a \"within-subjects\" factor (repeated measures) and the other factor is a \"between-subjects\" factor; 4) ANCOVA (analyse of covariance), an extension of the one-way ANOVA that incorporate a covariate variable; 5) MANOVA (multivariate analysis of variance), an ANOVA with two or more continuous outcome variables.   We also provide R code to check ANOVA assumptions and perform Post-Hoc analyses. Additionally, we'll present: 1) Kruskal-Wallis test, which is a non-parametric alternative to the one-way ANOVA test; 2) Friedman test, which is a non-parametric alternative to the one-way repeated measures ANOVA test.","og_url":"https:\/\/www.datanovia.com\/en\/courses\/comparing-multiple-means-in-r\/","og_site_name":"Datanovia","article_modified_time":"2020-01-13T20:33:28+00:00","og_image":[{"width":1024,"height":512,"url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2019\/05\/Sterne.royale.8.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.datanovia.com\/en\/courses\/comparing-multiple-means-in-r\/","url":"https:\/\/www.datanovia.com\/en\/courses\/comparing-multiple-means-in-r\/","name":"Comparing Multiple Means in R: The Ultimate Guide - Datanovia","isPartOf":{"@id":"https:\/\/www.datanovia.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.datanovia.com\/en\/courses\/comparing-multiple-means-in-r\/#primaryimage"},"image":{"@id":"https:\/\/www.datanovia.com\/en\/courses\/comparing-multiple-means-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2019\/05\/Sterne.royale.8.jpg","datePublished":"2019-11-28T22:47:52+00:00","dateModified":"2020-01-13T20:33:28+00:00","breadcrumb":{"@id":"https:\/\/www.datanovia.com\/en\/courses\/comparing-multiple-means-in-r\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.datanovia.com\/en\/courses\/comparing-multiple-means-in-r\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.datanovia.com\/en\/courses\/comparing-multiple-means-in-r\/#primaryimage","url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2019\/05\/Sterne.royale.8.jpg","contentUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2019\/05\/Sterne.royale.8.jpg","width":1024,"height":512},{"@type":"BreadcrumbList","@id":"https:\/\/www.datanovia.com\/en\/courses\/comparing-multiple-means-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.datanovia.com\/en\/"},{"@type":"ListItem","position":2,"name":"Courses","item":"https:\/\/www.datanovia.com\/en\/courses\/"},{"@type":"ListItem","position":3,"name":"Comparing Multiple Means in R"}]},{"@type":"WebSite","@id":"https:\/\/www.datanovia.com\/en\/#website","url":"https:\/\/www.datanovia.com\/en\/","name":"Datanovia","description":"Data Mining and Statistics for Decision Support","publisher":{"@id":"https:\/\/www.datanovia.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.datanovia.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.datanovia.com\/en\/#organization","name":"Datanovia","url":"https:\/\/www.datanovia.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png","contentUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png","width":98,"height":99,"caption":"Datanovia"},"image":{"@id":"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/"}}]}},"multi-rating":{"mr_rating_results":[{"adjusted_star_result":0,"star_result":0,"total_max_option_value":5,"adjusted_score_result":0,"score_result":0,"percentage_result":0,"adjusted_percentage_result":0,"count":0,"post_id":10870}]},"_links":{"self":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/dt_courses\/10870","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/dt_courses"}],"about":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/types\/dt_courses"}],"author":[{"embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/comments?post=10870"}],"version-history":[{"count":1,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/dt_courses\/10870\/revisions"}],"predecessor-version":[{"id":11061,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/dt_courses\/10870\/revisions\/11061"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/media\/9110"}],"wp:attachment":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/media?parent=10870"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}