<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/one-way-analysis-of-variance-exercises/"></div></div><div><a data-url="https://www.r-bloggers.com/one-way-analysis-of-variance-exercises/" data-counturl="https://www.r-bloggers.com/one-way-analysis-of-variance-exercises/" data-count="horizontal" data-text="One Way Analysis of Variance Exercises" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://r-exercises.com/2016/09/30/one-way-analysis-of-variance-exercises/"> R-exercises</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a target="_blank" href="http://r-exercises.com/wp-content/uploads/2016/09/normaldistribution.jpg?x61433"><img sizes="(max-width: 300px) 100vw, 300px" alt="normaldistribution" class="wp-image-2100" src="https://i2.wp.com/r-exercises.com/wp-content/uploads/2016/09/normaldistribution-300x188.jpg?resize=300%2C188" data-recalc-dims="1"></a>When we are interested in finding if there is a statistical difference in the mean of two groups we use the t test. When we have more than two groups we cannot use the t test, instead we have to use analysis of variance (ANOVA). In one way ANOVA we have one continuous dependent variable and one independent grouping variable or factor. When we have two groups the t test and one way ANOVA are equivalent.</p>
<p>For our one way ANOVA results to be valid there are several assumptions that need to be satisfied. These assumptions are listed below.</p>
<ol>
<li>The dependent variable is required to be continuous</li>
<li>The independent variable is required to be categorical with or more categories.</li>
<li>The dependent and independent variables have values for each row of data.</li>
<li>Observations in each group are independent.</li>
<li>The dependent variable is approximately normally distributed in each group.</li>
<li>There is approximate equality of variance in all the groups.</li>
<li>We should not have any outliers</li>
</ol>
<p>When our data shows non-normality, unequal variance or presence of outliers you can transform your data or use a non-parametric test like Kruskal-Wallis. It is good to note Kruskal-Wallis does not require normality of data but still requires equal variance in your groups.</p>
<p>For this exercise we will use data on patients having stomach, colon, ovary, brochus, or breast cancer. The objective of the study was to identify if the number of days a patient survived was influenced by the organ affected. Our dependent variable is Survival measured in days. Our independent variable is Organ. The data is available here <a target="_blank" href="http://lib.stat.cmu.edu/DASL/Datafiles/CancerSurvival.html">http://lib.stat.cmu.edu/DASL/Datafiles/CancerSurvival.html</a> and a <a target="_blank" href="http://r-exercises.com/wp-content/uploads/2016/10/cancer-survival.csv">cancer-survival</a> file has been uploaded</p>
<p>Solutions to these exercises can be found <a target="_blank" href="http://r-exercises.com/?p=2084&preview=true">here</a></p>
<p>Exercise 1</p>
<p>Load the data into R</p>
<p>Exercise 2</p>
<p>Create summary statistics for each organ</p>
<p>Exercise 3</p>
<p>Check if we have any outliers using boxplot</p>
<p>Exercise 4</p>
<p>Check for normality using Shapiro.wilk test</p>
<p> </p>
<p>Exercise 5</p>
<p>Check for equality of variance</p>
<p>Exercise 6</p>
<p>Transform your data and check for normality and equality of variance.</p>
<p>Exercise 7</p>
<p>Run one way ANOVA test</p>
<p>Exercise 8</p>
<p>Perform a Tukey HSD post hoc test</p>
<p>Exercise 9</p>
<p>Interpret results</p>
<p>Exercise 10</p>
<p>Use a Kruskal-Wallis test</p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/one-way-analysis-of-variance-exercises/"></div></div><div><a data-url="https://www.r-bloggers.com/one-way-analysis-of-variance-exercises/" data-counturl="https://www.r-bloggers.com/one-way-analysis-of-variance-exercises/" data-count="vertical" data-text="One Way Analysis of Variance Exercises" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://r-exercises.com/2016/09/30/one-way-analysis-of-variance-exercises/"> R-exercises</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/JLB1W_kO86c"></a></div>