## Concept of ANOVA- One way, Two way, N way & Post Hoc Using "R"

**What is ANOVA ?🧐**

- ANOVA is Analysis of Variance, it is collection of statistical models that is used to analyse the difference among various means.
- ANOVA can determine whether the mean of three or more groups are different. ANOVA uses F- Test to do this.
- It allows comparison of different sample at different point of types.
- ANOVA uses the F-test to determine whether the variability between group means is larger than the variability of the observations within the groups. If that ratio is sufficiently large, you can conclude that not all the means are equal(taken from blog.minitab.com).
- The result obtained from Multiple T-Test & ANOVA will be similar but in T-Test there are chances of Type -1 error so we prefer ANOVA over T-Test.
- Type-1 error compounds with each T-Test (.95×.95×.95 = .857)

**Perquisites for ANOVA Analysis.🌱**

- T-Test can be used to test difference between two mean, when there are more than two mean it is possible to compare each mean with each other using multiple T-Test, but there are several complications while doing this, so we deploy ANOVA for multiple means
- For ANOVA Analysis we use F-Test which is an extension to T-test & Z-test.
- F- Test is named after Sir Ronald Fisher. F test is used to test the overall significance for a regression model and to compare the fits of different models, also to test the equality of mean
- F-Statistic is the ratio of two variance.

**What types of research problem is solved by Anova. Examples 👨🔬**

- A group of fever patients taking three way of cure: Ayurvedic medicine, Allopathic & Homeopathic to find which cure is better than others.
- Four types of teaching methodologies and to find which one is better
- Athletes from different academy compete in a race. To see which academy is better

**Types of ANOVA 🤷♀️**

- One Way ANOVA- It has just one independent variable, For example- Intelligence is dependent on independent variable "class performance". These independent variable can have certain levels i.e. splits

- Two Way ANOVA - It has two independent variables For example- Intelligence is dependent on independent variable "class performance" and "Age of student". These two independent variable can have certain levels i.e. splits. A two way ANOVA allows the researcher to simultaneously test for the effect of two independent variable on the dependent variable.
- N Way ANOVA- In this type there are more than two independent variable For example, Intelligence is dependent upon independent variables like food, sleep, exercise, water intake , meditation, yoga. These independent variable can have certain levels i.e. splits

**Anova equations and mathematical explanation 💹**

__An example showing ANOVA Result__

F(2,12) = 4.12, p=.04 this 2,12 is the degree of freedom for variance between the group and variance within the group, for F = 4.12 and we have statistically significant p =.04 and thus reject null hypothesis (that mean of different groups are same).

F(b,w)

b is the degree of freedom for variance between the group

w is the degree of freedom for variance within the group

where

b= number of groups-1

w=total no. of observations - no. of groups

**Anova Analysis in R 🔧**

- To calculate ANOVA in R it's quite simple you can watch the video below and practice in R

- One of a lucid and classy example as how to calculate ANOVA in R is given in the link below. http://www.gardenersown.co.uk/Education/Lectures/R/anova.htm
- There are two new syntax that are used here

- To find ANOVA for single independent variable in R we use code as below

>result<- aov(values~ind,data = stacked)

>summary(result)

- To find ANOVA for multiple independent variable in R we use code as below

OR

>aov(formula=dep~indep1+indep2+indep3+indep1:indep2:indep3,data=datasets) # after independent variable are placed in + they are taken with colon ":" it tells the aov(ANOVA) of the interaction of independent variables

**ANOVA & its relation to other further statistics (Post- Hoc Test)(TukeyHSD)**

- After we came to know that the p<.05 and the mean of groups are different then we perform Post Hoc Test to find where the difference lies.
- ANOVA tell us that group mean were significantly different. But it doesn't tell us which mean are exactly different.
- So, if ANOVA shows significant result then it is followed by Post-Hoc
- The test compares all possible pairs of means.
- To evaluate Post-Hoc we use the simplest command as below
- >TukeyHSD(aov2) # here aov2 is the ANOVA analysis that we have evaluated