0% found this document useful (0 votes)
48 views6 pages

ANOVA Analysis and Assumptions

1) The document performs an ANOVA analysis to test for differences in marks between three sections. It checks the assumptions of normality and homogeneity of variances. 2) The ANOVA results show there are significant differences in marks between the sections. Post-hoc Tukey's HSD tests indicate differences between sections 1 and 3, and sections 2 and 3. 3) A second dataset is analyzed including a location factor, and the assumptions of normality and homogeneity hold for this analysis as well. The ANOVA table is shown for the model with location as a factor.

Uploaded by

kvs ramana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views6 pages

ANOVA Analysis and Assumptions

1) The document performs an ANOVA analysis to test for differences in marks between three sections. It checks the assumptions of normality and homogeneity of variances. 2) The ANOVA results show there are significant differences in marks between the sections. Post-hoc Tukey's HSD tests indicate differences between sections 1 and 3, and sections 2 and 3. 3) A second dataset is analyzed including a location factor, and the assumptions of normality and homogeneity hold for this analysis as well. The ANOVA table is shown for the model with location as a factor.

Uploaded by

kvs ramana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

R Console Page 1

> #Anova
> #Assumptions:
> #1.Normality
> #2.homogeneity
> #3.independece of observations
> dt<-read.csv("anova1.csv")
> dt
marks sec
1 18 1
2 19 1
3 20 1
4 17 1
5 18 1
6 15 2
7 16 2
8 17 2
9 19 2
10 18 2
11 5 3
12 4 3
13 6 3
14 7 3
15 3 3
> str(dt)
'data.frame': 15 obs. of 2 variables:
$ marks: int 18 19 20 17 18 15 16 17 19 18 ...
$ sec : int 1 1 1 1 1 2 2 2 2 2 ...
> attach(dt)
The following object is masked _by_ .GlobalEnv:

marks

> section<-as.factor(sec)
> section
[1] 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3
Levels: 1 2 3
> library(rstatix)

Attaching package: ‘rstatix’


R Console Page 2

The following object is masked from ‘package:stats’:

filter

Warning message:
package ‘rstatix’ was built under R version 4.1.3
> install.packages('rstatix')
Warning: package ‘rstatix’ is in use and will not be
installed
> dt %>% group_by(sec) %>% shapiro_test(marks)
# A tibble: 3 x 4
sec variable statistic p
<int> <chr> <dbl> <dbl>
1 1 marks 0.961 0.814
2 2 marks 0.987 0.967
3 3 marks 0.987 0.967
>
> #2.for homoginity
> bartlett.test(marks~as.factor(sec),data=dt)

Bartlett test of homogeneity of variances

data: marks by as.factor(sec)


Bartlett's K-squared = 0.47112, df = 2, p-value = 0.
7901

> #using anova


> res<-aov(marks~sec,data=dt)
> res
Call:
aov(formula = marks ~ sec, data = dt)

Terms:
sec Residuals
Sum of Squares 448.9000 118.8333
Deg. of Freedom 1 13

Residual standard error: 3.023413


R Console Page 3

Estimated effects may be unbalanced


> summary(res)
Df Sum Sq Mean Sq F value Pr(>F)
sec 1 448.9 448.9 49.11 9.23e-06 ***
Residuals 13 118.8 9.1
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’
0.1 ‘ ’ 1
> res<-aov(marks~as,factor(sec),data=dt)
Error in model.frame.default(formula = marks ~ as, d
ata = dt, drop.unused.levels = TRUE) :
invalid type (closure) for variable 'as'
In addition: Warning message:
In if (projections) qr <- lmcall$qr <- TRUE :
the condition has length > 1 and only the first el
ement will be used
> res<-aov(marks~as.factor(sec),data=dt)
> summary(res)
Df Sum Sq Mean Sq F value Pr(>F)

as.factor(sec) 2 542.5 271.3 129.2 7.65e-09 **


*
Residuals 12 25.2 2.1

---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’
0.1 ‘ ’ 1
>
> #NH: Avg(s1)=Avg(s2)=Avg(s3) there is no significe
nt diff in sections
> #AH: Avg(s1)#Avg(s2)=Avg(s3) there is atleast one
significent diff in sections
> #AH: Avg(s1)=Avg(s2)#Avg(s3) there is atleast one
significent diff in sections
> #AH: Avg(s1)#Avg(s2)#Avg(s3) there is atleast one
significent diff in sections
> # {any e power(stars) thing leads to reaject null
hypo}
>
R Console Page 4

> #post-hoc tests when equal variances assumed is do


ne
> #post-hoc tests when equal variances assumed is no
t done
> #post-hoc tests when equal variances assumed is do
ne
> #Scheffe,Tuskey....
> #post-hoc can only be done when homiginity is sati
sfied
> TuskeyHSD(res)
Error in TuskeyHSD(res) : could not find function "T
uskeyHSD"
> TukeyHSD(res)
Tukey multiple comparisons of means
95% family-wise confidence level

Fit: aov(formula = marks ~ as.factor(sec), data = dt


)

$`as.factor(sec)`
diff lwr upr p adj
2-1 -1.4 -3.845137 1.045137 0.3132778
3-1 -13.4 -15.845137 -10.954863 0.0000000
3-2 -12.0 -14.445137 -9.554863 0.0000001

> aggregate(marks,by=list(sec),FUN=mean)
Error in aggregate.data.frame(as.data.frame(x), ...)
:
arguments must have same length
> with(dt,aggregate(marks,by=list(sec),FUN=mean))
Group.1 x
1 1 18.4
2 2 17.0
3 3 5.0
> dt1<-read.csv("anova1loc.csv")
> dt1
marks sec loc
1 18 1 1
2 19 1 2
R Console Page 5

3 20 1 3
4 17 1 4
5 18 1 5
6 15 2 1
7 16 2 2
8 17 2 3
9 19 2 4
10 18 2 5
11 5 3 1
12 4 3 2
13 6 3 3
14 7 3 4
15 3 3 5
> bartlett.test(marks~as.factor(loc),data=dt)
Error in is.factor(x) : object 'loc' not found
> res1<-aov(marks~as.factor(loc),data=dt)
Error in is.factor(x) : object 'loc' not found
> bartlett.test(marks~as.factor(loc),data=dt1)

Bartlett test of homogeneity of variances

data: marks by as.factor(loc)


Bartlett's K-squared = 0.18911, df = 4, p-value = 0.
9958

> res1<-aov(marks~as.factor(loc),data=dt1)
> res1
Call:
aov(formula = marks ~ as.factor(loc), data = dt1)

Terms:
as.factor(loc) Residuals
Sum of Squares 7.7333 560.0000
Deg. of Freedom 4 10

Residual standard error: 7.483315


Estimated effects may be unbalanced
> save.image("C:\\Users\\kvs Ramana\\Documents\\R pr
ogram\\anova")
R Console Page 6

> res1<-aov(marks~as.factor(loc),data=dt1)

You might also like