Winter 2025 ……………………………….. Score ____ / 20

Homework #7

Heidi Van Ness

___________________________________________

highlight and click “Run” the line below before knitting

install.packages(“rmarkdown”)

# set seed replace 12345678 with your student ID
seed = 78944924
set.seed(seed + 25)
# creates data table for homework
r<-c("A","A","A","A","A","A","B","B","B","B","B","B")
c<-c("M","M","M","F","F","F","M","M","M","F","F","F")
table<-data.frame(r,c)

table$X <-as.numeric(ifelse(table$r=="A" & table$c=="M",round(rnorm(2,mean=9,sd=3),0),
                 ifelse(table$r=="A" & table$c=="F",round(rnorm(2,mean=7,sd=3),0),
                        ifelse(table$r=="B" & table$c=="M",round(rnorm(2,mean=5,sd=3),0),
                               ifelse(table$r=="B" & table$c=="F", round(rnorm(2,mean=15,sd=3),0),"")))))
Row <- table$r

is.numeric(table$X)
## [1] TRUE
table
##    r c  X
## 1  A M  7
## 2  A M  9
## 3  A M  7
## 4  A F  4
## 5  A F  3
## 6  A F  4
## 7  B M  4
## 8  B M  6
## 9  B M  4
## 10 B F 15
## 11 B F 15
## 12 B F 15
# results for Two way ANOVA test
results <- aov(X ~ r*c, data = table)
summary(results)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## r            1  52.08   52.08   69.44 3.25e-05 ***
## c            1  30.08   30.08   40.11 0.000225 ***
## r:c          1 154.08  154.08  205.44 5.48e-07 ***
## Residuals    8   6.00    0.75                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# creates plot
interaction.plot(table$c, Row, table$X, main = "Two Way ANOVA", xlab = "Column", ylab = "X")