In: Math
Problem 1.
(a) The columns of response and factors can be defined in R as follows, use these codes to solve the problem.
y<-c(2, 3, 10, 12, 8, 4, 11, 8)##response : scores
a<-c("Heart","Heart", "Soul", "Soul","Heart","Heart", "Soul", "Soul")##factor A
b<-c("D", "D", "D", "D", "R", "R", "R", "R")##factor B (group variable)
(b) Find the overall mean, row means, column means, each cell mean for the table given in problem 1.
R code:
y<-c(2, 3, 10, 12, 8, 4, 11, 8)##response : scores
a<-c("Heart","Heart", "Soul", "Soul","Heart","Heart", "Soul", "Soul")##factor A
b<-c("D", "D", "D", "D", "R", "R", "R", "R")##factor B (group
variable)
M=data.frame(cbind(y,a,b))
#overall mean
G=mean(y)
# Row means
Row1=mean(y[1:4])
Row2=mean(y[5:8])
#column means
Column1=mean(c(y[1:2],y[5:6]))
Column2=mean(c(y[3:4],y[7:8]))
#Cell means
Cell_11=mean(y[1:2])
Cell_12=mean(y[3:4])
Cell_21=mean(y[5:6])
Cell_22=mean(y[7:8])
G
Row1
Row2
Column1
Column2
Cell_11
Cell_12
Cell_21
Cell_22
Output:
G
[1] 7.25
> Row1
[1] 6.75
> Row2
[1] 7.75
> Column1
[1] 4.25
> Column2
[1] 10.25
> Cell_11
[1] 2.5
> Cell_12
[1] 11
> Cell_21
[1] 6
> Cell_22
[1] 9.5
Overall mean=7.25
Mean of Row 1 (Level "D" of factor B)= 6.75
Mean of Row 2 (Level "R" of factor B)= 7.75
Mean of Column1 (Level "Heart" of factor A)= 4.25
Mean of Column2 (Level "Soul" of factor A)= 10.25
Mean of Cell (D, Heart)=2.5
Mean of Cell (D, Soul)=11
Mean of Cell (R, Heart)=6
Mean of Cell (R, Soul)= 9.5