Question: Convert the following RStudio code into Jupyter-Python code: Two-way Factorial Analysis of Variance > factorial View(factorial) > factorial growth diet coat 1 6.6 A light

Convert the following RStudio code into Jupyter-Python code:

Two-way Factorial Analysis of Variance

> factorial <- read.delim("/Course Downloadable Data Exercises-20190120/TRB/data/factorial.txt")

> View(factorial)

> factorial

growth diet coat

1 6.6 A light

2 7.2 A light

3 6.9 B light

4 8.3 B light

5 7.9 C light

6 9.2 C light

7 8.3 A dark

8 8.7 A dark

9 8.1 B dark

10 8.5 B dark

11 9.1 C dark

12 9.0 C dark

> attach(factorial)

> model<-aov(growth~diet*coat)

> summary(model)

Df Sum Sq Mean Sq F value Pr(>F)

diet 2 2.6600 1.3300 3.677 0.0907 .

coat 1 2.6133 2.6133 7.226 0.0361 *

diet:coat 2 0.6867 0.3433 0.949 0.4383

Residuals 6 2.1700 0.3617

---

Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1

> tapply(growth,list(coat,diet),sum)

A B C

dark 17.0 16.6 18.1

light 13.8 15.2 17.1

> SSAB<-sum(as.vector(tapply(growth,list(coat,diet),sum))^2)/2

> CF<-sum(growth)^2/length(growth)

> SSAB-CF-2.66-2.61333

[1] 0.68667

> model2<-update(model , ~ . - diet:coat)

> anova(model,model2)

Analysis of Variance Table

Model 1: growth ~ diet * coat

Model 2: growth ~ diet + coat

Res.Df RSS Df Sum of Sq F Pr(>F)

1 6 2.1700

2 8 2.8567 -2 -0.68667 0.9493 0.4383

> summary(model2)

Df Sum Sq Mean Sq F value Pr(>F)

diet 2 2.660 1.3300 3.725 0.0719 .

coat 1 2.613 2.6133 7.319 0.0269 *

Residuals 8 2.857 0.3571

---

Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1

> model3<-update(model2, ~. -diet)

> anova(model2,model3)

Analysis of Variance Table

Model 1: growth ~ diet + coat

Model 2: growth ~ coat

Res.Df RSS Df Sum of Sq F Pr(>F)

1 8 2.8567

2 10 5.5167 -2 -2.66 3.7246 0.0719 .

---

Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1

> summary(model3)

Df Sum Sq Mean Sq F value Pr(>F)

coat 1 2.613 2.6133 4.737 0.0546 .

Residuals 10 5.517 0.5517

---

Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1

> tapply(growth,diet,mean)

A B C

7.70 7.95 8.80

> diet2<-factor(1+(diet=="C"))

> diet2

[1] 1 1 1 1 2 2 1 1 1 1 2 2

Levels: 1 2

> model4<-update(model3, ~. +diet2)

> anova(model3,model4)

Analysis of Variance Table

Model 1: growth ~ coat

Model 2: growth ~ coat + diet2

Res.Df RSS Df Sum of Sq F Pr(>F)

1 10 5.5167

2 9 2.9817 1 2.535 7.6518 0.02189 *

---

Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1

> model5<-update(model4, ~. +diet2:coat)

> anova(model4,model5)

Analysis of Variance Table

Model 1: growth ~ coat + diet2

Model 2: growth ~ coat + diet2 + coat:diet2

Res.Df RSS Df Sum of Sq F Pr(>F)

1 9 2.9817

2 8 2.7000 1 0.28167 0.8346 0.3877

> summary(model4)

Df Sum Sq Mean Sq F value Pr(>F)

coat 1 2.613 2.6133 7.888 0.0204 *

diet2 1 2.535 2.5350 7.652 0.0219 *

Residuals 9 2.982 0.3313

---

Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!