Rで何かをしたり、読書をするブログ

政府統計の総合窓口のデータや、OECDやUCIやのデータを使って、Rの練習をしています。ときどき、読書記録も載せています。

OECD Threatened species data analysis 3 - ANOVA(ANalysis Of VAriance) without lm() and anova()

 

www.crosshyou.info

 In this brlog, let's do ANOVA(Analysis of Variance).

We see average Value(percentage of threatened species) are different by SUBJECT.

f:id:cross_hyou:20210522080309p:plain

BIRD has the highest Value and PLANT has the lowest.
But this difference is statistically significant?

Let's check it in R. We can use lm() function.

f:id:cross_hyou:20210522081341p:plain

Use anova() to see the results.

f:id:cross_hyou:20210522081508p:plain

p-value is 0.0303, so it is significant at 5% significant level.

Now, let's do ANOVA without lm() and summary() function.

1. calculate overall average.

f:id:cross_hyou:20210522084257p:plain


f:id:cross_hyou:20210522082001p:plain

2. calculate average by SUBJECT

f:id:cross_hyou:20210522082511p:plain

3. calculate variance by SUBJECT

f:id:cross_hyou:20210522084257p:plain

We get 10990.3

f:id:cross_hyou:20210522084538p:plain

4. Calculate overall sum of squares

f:id:cross_hyou:20210522084758p:plain

5. Calculate SSE = SST - SSA

f:id:cross_hyou:20210522084936p:plain

We got 779.9

f:id:cross_hyou:20210522085042p:plain

6. calculate degree of freedom for SUBJECT

f:id:cross_hyou:20210522085328p:plain

We get 2.

f:id:cross_hyou:20210522085533p:plain

7. Calculatedegree of freedom for Residuals.

f:id:cross_hyou:20210522090108p:plain

We got 102

f:id:cross_hyou:20210522090222p:plain

Now, we got 2, 102, 779.9 and 10990.3.

8. we can calculate Mean Sq.

SUBJECT Mean Sq = 779.9 / 2 = 389.96

Residuals Mean Sq = 10990.3 / 102 = 107.75

f:id:cross_hyou:20210522090814p:plain

f:id:cross_hyou:20210522090903p:plain

 

9. Calculate F-value.

f:id:cross_hyou:20210522091115p:plain

We got 3.6192

f:id:cross_hyou:20210522091215p:plain

10. Calculate p-value

f:id:cross_hyou:20210522091709p:plain

Nice! Finally we got 0.0303!

f:id:cross_hyou:20210522091853p:plain

That's it.

Next blog is...

 

www.crosshyou.info

 



If you would like to see the first blog.
 

www.crosshyou.info