In: Math
*Please provide r studio file/code*
Question:
Test the equality of means of populations X,Y,Z using
ANOVA:
set.seed(88)
dta <- data.frame(v = c(2+2*rnorm(100),
3+3*rnorm(100),
4+4*rnorm(100)),
id = rep(c("x","y","z"),c(100,100,100)))
r code for Analysis of Variance
> set.seed(88)
> dta <- data.frame(v = c(2+2*rnorm(100),
+ 3+3*rnorm(100),
+ 4+4*rnorm(100)),
+ id = rep(c("x","y","z"),c(100,100,100)))
> head(dta)
v id
1 1.547489 x
2 3.293140 x
3 6.692117 x
4 -1.691237 x
5 2.919382 x
6 2.247562 x
> summary(dta)
v id
Min. :-5.3698 x:100
1st Qu.: 0.7782 y:100
Median : 2.9051 z:100
Mean : 3.0497
3rd Qu.: 4.9302
Max. :15.5232
> aov(dta$v~dta$id,data = dta )
Call:
aov(formula = dta$v ~ dta$id, data = dta)
Terms:
dta$id Residuals
Sum of Squares 195.3177 2675.4008
Deg. of Freedom 2 297
Residual standard error: 3.001347
Estimated effects may be unbalanced
> summary(aov(dta$v~dta$id,data = dta
))
Df Sum Sq Mean Sq F value Pr(>F)
dta$id 2 195.3 97.66 10.84 2.86e-05 ***
Residuals 297 2675.4 9.01
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
Analysis of variance
Null hypothesis:
There is no significant difference between given three groups (x,y,z)
Alternative Hypothesis:
There is at least one group which is significantly different from other two.
T test statistic
F value is 10.84
p value :
2.85e-05
Decision:
P value is less thna level of significance (i.e 2.85e-05<0.05 ), Hence we reject the null hypothesis
Conclusion:
Since we reject the null hypothesis, and conclude that there is at least one group which is significantly different from other two groups.