1 Loading Libraries

#install.packages("afex")
#install.packages("emmeans")
#install.packages("ggbeeswarm")
#install.packages("expss")

library(psych)    # for describe() and describeBy()
library(expss)    # for cross_cases()
library(car)      # for leveneTest()
library(afex)     # for ANOVA and afex_plot()
library(ggplot2)  # for visualizing results
library(emmeans)  # for posthoc tests

2 Importing Data

# For HW, import the project dataset you cleaned previously this will be the dataset you'll use throughout the rest of the semester

d <- read.csv(file="C:/Users/jd/OneDrive - Indiana University/M311/Research/Labs/Data/anova_labdata.csv", header=T)


# new code! this adds a column with a number for each row. It will make it easier if we need to drop outliers later
d$row <- 1:nrow(d)

Note: For your HW, you will choose to run EITHER a one-way ANOVA (a single IV with 3 or more levels) OR a two-way/factorial ANOVA (two IVs with 2 or 3 levels each). You will need to specify your hypothesis and customize your code based on the choice you make. We will run BOTH versions of the test in the lab for illustrative purposes.

3 One-Way ANOVA

3.1 State Your Hypothesis

We predict that there will be a significant difference in people’s level of companionship based on the type of pet they own (dog or cat) and their race (White or Black).

3.2 Check Your Variables

# you only need to check the variables you're using in the current analysis

str(d)
## 'data.frame':    1250 obs. of  7 variables:
##  $ X             : int  1 20 30 31 33 57 68 81 86 104 ...
##  $ pet           : chr  "dog" "cat" "dog" "dog" ...
##  $ race          : chr  "white" "white" "white" "white" ...
##  $ companionship : num  3.25 3.75 1 3.25 2 4 3.75 1.25 2.5 2.5 ...
##  $ pet_noise     : num  1.33 3.33 1 2.33 1.11 ...
##  $ life_happiness: num  2.3 1.6 3.9 1.7 3.9 1.8 1.3 3.5 2.6 3 ...
##  $ row           : int  1 2 3 4 5 6 7 8 9 10 ...
# make our categorical variables of interest "factors"
# because we'll use our newly created row ID variable for this analysis, so make sure it's coded as a factor, too.
d$race <- as.factor(d$race)
d$pet <- as.factor(d$pet)
d$row <- as.factor(d$row)


# check that our categorical variables of interest are now factors
str(d)
## 'data.frame':    1250 obs. of  7 variables:
##  $ X             : int  1 20 30 31 33 57 68 81 86 104 ...
##  $ pet           : Factor w/ 3 levels "cat","dog","rabbit": 2 1 2 2 2 2 1 1 2 2 ...
##  $ race          : Factor w/ 7 levels "asian","black",..: 7 7 7 7 7 7 7 7 7 2 ...
##  $ companionship : num  3.25 3.75 1 3.25 2 4 3.75 1.25 2.5 2.5 ...
##  $ pet_noise     : num  1.33 3.33 1 2.33 1.11 ...
##  $ life_happiness: num  2.3 1.6 3.9 1.7 3.9 1.8 1.3 3.5 2.6 3 ...
##  $ row           : Factor w/ 1250 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
# check our DV skew and kurtosis
describe(d$companionship)
##    vars    n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 1250 2.93 0.95      3    2.92 1.11   1   5     4 0.09    -0.74 0.03
# we'll use the describeBy() command to view our DV's skew and kurtosis across our IVs' levels
describeBy(d$companionship,
           group = list(d$race, d$pet))
## 
##  Descriptive statistics by group 
## : asian
## : cat
##    vars  n mean   sd median trimmed  mad  min  max range skew kurtosis   se
## X1    1 27 2.44 0.69   2.25    2.41 0.37 1.25 3.75   2.5 0.67     -0.5 0.13
## ------------------------------------------------------------ 
## : black
## : cat
##    vars n mean   sd median trimmed  mad min  max range skew kurtosis   se
## X1    1 2 1.62 0.88   1.62    1.62 0.93   1 2.25  1.25    0    -2.75 0.62
## ------------------------------------------------------------ 
## : mideast
## : cat
##    vars n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 2 1.75 1.06   1.75    1.75 1.11   1 2.5   1.5    0    -2.75 0.75
## ------------------------------------------------------------ 
## : multiracial
## : cat
##    vars n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 8 3.09 1.24   3.12    3.09 1.48 1.5   5   3.5 0.11    -1.65 0.44
## ------------------------------------------------------------ 
## : other
## : cat
##    vars n mean   sd median trimmed  mad min  max range skew kurtosis   se
## X1    1 3 2.83 1.23   2.25    2.83 0.37   2 4.25  2.25 0.37    -2.33 0.71
## ------------------------------------------------------------ 
## : prefer_not
## : cat
##    vars n mean   sd median trimmed  mad  min max range skew kurtosis   se
## X1    1 2 2.62 0.53   2.62    2.62 0.56 2.25   3  0.75    0    -2.75 0.37
## ------------------------------------------------------------ 
## : white
## : cat
##    vars   n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 153 2.62 0.89    2.5    2.58 0.74   1   5     4 0.43    -0.32 0.07
## ------------------------------------------------------------ 
## : asian
## : dog
##    vars   n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 110 3.08 0.94      3    3.08 0.74   1   5     4 0.01     -0.6 0.09
## ------------------------------------------------------------ 
## : black
## : dog
##    vars  n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 24  3.4 0.88   3.25    3.38 1.11   2   5     3 0.16    -1.36 0.18
## ------------------------------------------------------------ 
## : mideast
## : dog
##    vars n mean   sd median trimmed  mad  min max range skew kurtosis   se
## X1    1 9 3.19 0.92   2.75    3.19 0.74 2.25 4.5  2.25 0.24    -1.94 0.31
## ------------------------------------------------------------ 
## : multiracial
## : dog
##    vars  n mean   sd median trimmed  mad min  max range  skew kurtosis   se
## X1    1 54 3.19 0.98   3.25    3.22 1.11   1 4.75  3.75 -0.27    -0.88 0.13
## ------------------------------------------------------------ 
## : other
## : dog
##    vars n mean   sd median trimmed  mad  min max range skew kurtosis  se
## X1    1 8 3.28 0.56      3    3.28 0.19 2.75 4.5  1.75 1.15    -0.01 0.2
## ------------------------------------------------------------ 
## : prefer_not
## : dog
##    vars  n mean   sd median trimmed  mad  min max range  skew kurtosis   se
## X1    1 16 3.08 1.04   3.12    3.07 1.11 1.25   5  3.75 -0.04    -0.98 0.26
## ------------------------------------------------------------ 
## : white
## : dog
##    vars   n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 799 2.93 0.94      3    2.92 1.11   1   5     4 0.07    -0.75 0.03
## ------------------------------------------------------------ 
## : asian
## : rabbit
##    vars n mean   sd median trimmed  mad min max range skew kurtosis  se
## X1    1 2    4 0.71      4       4 0.74 3.5 4.5     1    0    -2.75 0.5
## ------------------------------------------------------------ 
## : black
## : rabbit
##   vars* n* mean* sd* median* trimmed* mad* min* max* range* skew* kurtosis* se*
## 1    NA NA    NA  NA      NA       NA   NA   NA   NA     NA    NA        NA  NA
## ------------------------------------------------------------ 
## : mideast
## : rabbit
##    vars n mean sd median trimmed mad min max range skew kurtosis se
## X1    1 1    4 NA      4       4   0   4   4     0   NA       NA NA
## ------------------------------------------------------------ 
## : multiracial
## : rabbit
##    vars n mean   sd median trimmed  mad  min  max range  skew kurtosis   se
## X1    1 3 2.58 1.26   2.75    2.58 1.48 1.25 3.75   2.5 -0.13    -2.33 0.73
## ------------------------------------------------------------ 
## : other
## : rabbit
##   vars* n* mean* sd* median* trimmed* mad* min* max* range* skew* kurtosis* se*
## 1    NA NA    NA  NA      NA       NA   NA   NA   NA     NA    NA        NA  NA
## ------------------------------------------------------------ 
## : prefer_not
## : rabbit
##   vars* n* mean* sd* median* trimmed* mad* min* max* range* skew* kurtosis* se*
## 1    NA NA    NA  NA      NA       NA   NA   NA   NA     NA    NA        NA  NA
## ------------------------------------------------------------ 
## : white
## : rabbit
##    vars  n mean   sd median trimmed  mad  min max range  skew kurtosis   se
## X1    1 27 3.81 0.59      4    3.82 0.74 2.75   5  2.25 -0.12    -0.88 0.11
# also use histograms to examine your continuous variable
hist(d$companionship)

3.3 Check Your Assumptions

3.3.1 ANOVA Assumptions

  • DV should be normally distributed across levels of the IV (we checked previously using “describeBy” function)
  • All levels of the IVs should have an equal number of cases and there should be no empty cells. Cells with low numbers decrease the power of the test (which increases chance of Type II error)
  • Homogeneity of variance should be confirmed (using Levene’s Test)
  • Outliers should be identified and removed – we will actually remove them this time!
  • If you have confirmed everything above, the sampling distribution should be normal.

3.3.2 Check levels of IVs

table(d$race)
## 
##       asian       black     mideast multiracial       other  prefer_not 
##         139          26          12          65          11          18 
##       white 
##         979
table(d$pet)
## 
##    cat    dog rabbit 
##    197   1020     33
# REMEMBER your test's level of POWER is determined by your SMALLEST subsample

3.3.3 Check for outliers using Cook’s distance and Residuals VS Leverage plot

3.3.3.1 Run a Regression to get both outlier plots

# use this commented out section below ONLY IF if you need to remove outliers
# to drop a single outlier, use this code:
# d <- subset(d, row_id!=c(1108))  # NOTE: Participant 1108 is not truly problamtic in the Lab, but we are going to removed them for demonstration.

# to drop multiple outliers, use this code:
# d <- subset(d, row_id!=c(1108) & row_id!=c(602))


# use the lm() command to run the regression
# formula is y~x, where y is our DV, x is our IV

d <- subset(d, row != 1108)
reg_model <- lm(companionship ~ pet, data = d)

3.3.3.2 Check for outliers

# Cook's distance
plot(reg_model, which = 4)

# Residuals VS Leverage
plot(reg_model, which = 5)

# IF you find outliers, go back up to line 114 or 117 and remove it/them, then re-run the reg_model code

3.3.4 Check homogeneity of variance

# use the leveneTest() command from the car package to test homogeneity of variance
# uses the 'formula' setup: formula is y~x, where y is our DV and x is our IV 
leveneTest(companionship ~ pet, data = d)
## Levene's Test for Homogeneity of Variance (center = median)
##         Df F value   Pr(>F)   
## group    2  6.1478 0.002204 **
##       1246                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

3.3.5 Issues with My Data

Our cell sizes are unequal between the three pet type group levels. A small sample size for the rabbit group limits our statistical power and increases our Type II error rate.

Levene’s test was significant for our three-level pet type variable with the One-Way ANOVA (p = .002). We are aware of this violation and are proceeding with the analysis for the purpose of this class.

We identified and removed one observation for the One-Way ANOVA as part of the lab demonstration.

[UPDATE this section in your HW.]

3.4 Run a One-Way ANOVA

aov_model <- aov_ez(data = d,
                    id = "row",
                    between = c("pet"),
                    dv = "companionship",
                    anova_table = list(es = "pes"))
## Contrasts set to contr.sum for the following variables: pet

3.5 View One-Way Output

nice(aov_model)
## Anova Table (Type 3 tests)
## 
## Response: companionship
##   Effect      df  MSE         F  pes p.value
## 1    pet 2, 1246 0.87 27.54 *** .042   <.001
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1

ANOVA Effect Size [partial eta-squared] cutoffs from Cohen (1988): * η^2 < 0.01 indicates a trivial effect * η^2 >= 0.01 indicates a small effect * η^2 >= 0.06 indicates a medium effect * η^2 >= 0.14 indicates a large effect

3.6 Visualize One-Way Results

afex_plot(aov_model, x = "pet")

3.7 Run One-Way Posthoc Tests

Remember: We ONLY run posthoc IF the ANOVA test is SIGNIFICANT! E.g., only run the posthoc tests on pet type if there is a main effect for pet type

emmeans(aov_model, specs = "pet")
##  pet    emmean     SE   df lower.CL upper.CL
##  cat      2.60 0.0663 1246     2.47     2.73
##  dog      2.97 0.0291 1246     2.92     3.03
##  rabbit   3.79 0.1640 1246     3.47     4.11
## 
## Confidence level used: 0.95
pairs(emmeans(aov_model, specs = "pet"),
      adjust = "tukey")
##  contrast     estimate     SE   df t.ratio p.value
##  cat - dog      -0.379 0.0724 1246  -5.237 <0.0001
##  cat - rabbit   -1.194 0.1770 1246  -6.734 <0.0001
##  dog - rabbit   -0.815 0.1670 1246  -4.879 <0.0001
## 
## P value adjustment: tukey method for comparing a family of 3 estimates

3.8 Write Up One-Way ANOVA Results

To test our hypothesis that there will be a significant difference in people’s level of companionship based on the type of pet they own (dog, cat, or rabbit), we used a one-way ANOVA. Our data was unbalanced, with many more people who own a dog (n = 1020) than a cat (n = 197) or a rabbit (n = 32). This significantly decreases the power of our test and increases the chances of a Type II error. We also identified and removed one outlier following visual analysis of Cook’s distance and Residuals vs Leverage plots. A significant Levene’s test (p = .002) also indicates that our data violated the assumption of homogeneity of variance. This suggests that there is an increased chance of error. We continued with our analysis for the purpose of this class.

We found a significant effect of pet type on companionship, F(2, 1246) = 27.54, p < .001, ηp² = .042 (small effect, Cohen, 1988). Posthoc tests using Tukey adjustment revealed that participants who own a dog (M = 2.97, SE = 0.03) reported significantly more companionship than those who own a cat (M = 2.60, SE = 0.07), but significantly less companionship than those who own a rabbit (M = 3.79, SE = 0.16). All three comparisons were significant (p < .001). Participants who own a rabbit reported the highest amount of companionship overall (see Figure 1 for a comparison).

4 Two-Way ANOVA

4.1 State Your Hypothesis

We predict that there will be a significant difference in people’s level of companionship based on the type of pet they own (dog or cat) and participants’ race (White or Black). We also predict that there will be an interaction between pet type and participant race.

4.2 Check Your Variables

# you only need to check the variables you're using in the current analysis

str(d)
## 'data.frame':    1249 obs. of  7 variables:
##  $ X             : int  1 20 30 31 33 57 68 81 86 104 ...
##  $ pet           : Factor w/ 3 levels "cat","dog","rabbit": 2 1 2 2 2 2 1 1 2 2 ...
##  $ race          : Factor w/ 7 levels "asian","black",..: 7 7 7 7 7 7 7 7 7 2 ...
##  $ companionship : num  3.25 3.75 1 3.25 2 4 3.75 1.25 2.5 2.5 ...
##  $ pet_noise     : num  1.33 3.33 1 2.33 1.11 ...
##  $ life_happiness: num  2.3 1.6 3.9 1.7 3.9 1.8 1.3 3.5 2.6 3 ...
##  $ row           : Factor w/ 1250 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
# make our categorical variables of interest "factors"
# because we'll use our newly created row ID variable for this analysis, so make sure it's coded as a factor, too.

# d$row_id <- as.factor(d$row_id) # commented out since already did this step in the One-Way, above
# d$pet <- as.factor(d$pet) # IV1 # commented out since already did this step in the One-Way, above
d$race <- as.factor(d$race) # IV2


# we're going to recode our race variable into two groups: poc and white
# in doing so, we are creating a new variable "poc" that has only 2 levels

table(d$race)
## 
##       asian       black     mideast multiracial       other  prefer_not 
##         139          26          12          64          11          18 
##       white 
##         979
d$poc <- NA_character_

d$poc[d$race == "black"] <- "poc"
d$poc[d$race == "white"] <- "white"

table(d$poc, useNA = "always")
## 
##   poc white  <NA> 
##    26   979   244
# make our new categorical variable into a "factor"
d$poc <- as.factor(d$poc)

# check that all our categorical variables of interest are now factors
str(d)
## 'data.frame':    1249 obs. of  8 variables:
##  $ X             : int  1 20 30 31 33 57 68 81 86 104 ...
##  $ pet           : Factor w/ 3 levels "cat","dog","rabbit": 2 1 2 2 2 2 1 1 2 2 ...
##  $ race          : Factor w/ 7 levels "asian","black",..: 7 7 7 7 7 7 7 7 7 2 ...
##  $ companionship : num  3.25 3.75 1 3.25 2 4 3.75 1.25 2.5 2.5 ...
##  $ pet_noise     : num  1.33 3.33 1 2.33 1.11 ...
##  $ life_happiness: num  2.3 1.6 3.9 1.7 3.9 1.8 1.3 3.5 2.6 3 ...
##  $ row           : Factor w/ 1250 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
##  $ poc           : Factor w/ 2 levels "poc","white": 2 2 2 2 2 2 2 2 2 1 ...
# Our small number of participants owning rabbits is going to hurt us for the Two-Way 
# We will create a new dataframe and call it "d_twoway" and remove the rabbit owning Ps.

d_twoway <- subset(d, pet != "rabbit" & !is.na(poc))
d_twoway$pet <- droplevels(d_twoway$pet)

# check our DV skew and kurtosis
describe(d_twoway$companionship)
##    vars   n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 978 2.89 0.94   2.75    2.87 1.11   1   5     4 0.13    -0.72 0.03
# we'll use the describeBy() command to view our DV's skew and kurtosis across our IVs' levels
describeBy(d_twoway$companionship,
           group = d_twoway$pet)
## 
##  Descriptive statistics by group 
## group: cat
##    vars   n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 155  2.6 0.89    2.5    2.57 0.74   1   5     4 0.42    -0.31 0.07
## ------------------------------------------------------------ 
## group: dog
##    vars   n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 823 2.94 0.94      3    2.93 1.11   1   5     4 0.07    -0.74 0.03
describeBy(d_twoway$companionship,
           group = d_twoway$poc)  
## 
##  Descriptive statistics by group 
## group: poc
##    vars  n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 26 3.26 0.99      3    3.27 1.11   1   5     4 -0.1    -0.82 0.19
## ------------------------------------------------------------ 
## group: white
##    vars   n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 952 2.88 0.94   2.75    2.86 1.11   1   5     4 0.13    -0.72 0.03
# also use histograms to examine your continuous variable
hist(d_twoway$companionship)

4.3 Check Your Assumptions

4.3.1 ANOVA Assumptions

  • DV should be normally distributed across levels of the IV (we checked previously using “describeBy” function)
  • All levels of the IVs should have an equal number of cases and there should be no empty cells. Cells with low numbers decrease the power of the test (which increases chance of Type II error)
  • Homogeneity of variance should be confirmed (using Levene’s Test)
  • Outliers should be identified and removed – we will actually remove them this time!
  • If you have confirmed everything above, the sampling distribution should be normal.

4.3.2 Check levels of IVs

xtabs(~ pet + poc, data = d_twoway)
##      poc
## pet   poc white
##   cat   2   153
##   dog  24   799
## If cross_cases() doesn't work for you, then use xtabs() instead. Fill in the code below and remove the "#" to run. Then hashtag out the cross_cases() line above.

# xtabs(~ V1 + V2, data=d_twoway)

# REMEMBER your test's level of POWER is determined by your SMALLEST subsample

4.3.3 Check for outliers using Cook’s distance and Residuals VS Leverage plot

4.3.3.1 Run a Regression to get both outlier plots

# use this commented out section below ONLY IF if you need to remove outliers
# to drop a single outlier, use this code:
# d_twoway <- subset(d_twoway, row_id!=c(1108))

# to drop multiple outliers, use this code:
# d_twoway <- subset(d_twoway, row_id!=c(1108) & row_id!=c(602))


# use the lm() command to run the regression
# formula is y~x1*x2 + c, where y is our DV, x1 is our first IV, x2 is our second IV.

xtabs(~ pet + poc, data = d_twoway)
##      poc
## pet   poc white
##   cat   2   153
##   dog  24   799
reg_model2 <- lm(companionship ~ pet * poc,
                 data = d_twoway)

#### Check for Two-Way outliers
# Cook's distance
plot(reg_model2, which = 4)

# Residuals vs Leverage
plot(reg_model2, which = 5)

# IF you find outliers, go back up and remove it/them using the subset(), then re-run the reg_model code

4.3.4 Check homogeneity of variance

# use the leveneTest() command from the car package to test homogeneity of variance
# uses the 'formula' setup: formula is y~x1*x2, where y is our DV and x1 is our first IV and x2 is our second IV

leveneTest(companionship ~ pet * poc,
           data = d_twoway)
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   3  0.9611 0.4104
##       974

4.3.5 Issues with My Data

Our cell sizes are unequal between the pet type group levels. A small sample size for one of the cells of our combined variables (cat & poc, n = 2) limits our statistical power and increases our Type II error rate.

Levene’s test was not significant for the Two-Way ANOVA (p = .410), indicating there is no evidence of a violation of homogeneity of variance.

We did not identify any severe influential outliers for the Two-Way ANOVA.

[UPDATE this section in your HW.]

4.4 Run a Two-Way ANOVA

aov_model2 <- aov_ez(data = d_twoway,
                     id = "row",
                     between = c("pet", "poc"),
                     dv = "companionship",
                     anova_table = list(es = "pes"))
## Contrasts set to contr.sum for the following variables: pet, poc

4.5 View Two-Way Output

nice(aov_model2)
## Anova Table (Type 3 tests)
## 
## Response: companionship
##    Effect     df  MSE       F   pes p.value
## 1     pet 1, 974 0.87 9.03 **  .009    .003
## 2     poc 1, 974 0.87    0.57 <.001    .452
## 3 pet:poc 1, 974 0.87  4.46 *  .005    .035
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1

ANOVA Effect Size [partial eta-squared] cutoffs from Cohen (1988): * η^2 < 0.01 indicates a trivial effect * η^2 >= 0.01 indicates a small effect * η^2 >= 0.06 indicates a medium effect * η^2 >= 0.14 indicates a large effect

4.6 Visualize Results

afex_plot(aov_model2, x = "pet", trace = "poc")

afex_plot(aov_model2, x = "poc", trace = "pet")

# NOTE: for the Two-Way, you will need to decide which plot version makes the MOST SENSE based on your data / rationale when you make the nice Figure 2 at the end.

4.7 Run Two-Way Posthoc Tests

ONLY run posthoc IF the ANOVA test is SIGNIFICANT! E.g., only run the posthoc tests if there is a sig main effect or interaction.

# IV1 main effect: Pet type
emmeans(aov_model2, specs = "pet")
## NOTE: Results may be misleading due to involvement in interactions
##  pet emmean     SE  df lower.CL upper.CL
##  cat   2.12 0.3320 974     1.47     2.77
##  dog   3.16 0.0967 974     2.97     3.35
## 
## Results are averaged over the levels of: poc 
## Confidence level used: 0.95
pairs(emmeans(aov_model2, specs = "pet"),
      adjust = "tukey")
## NOTE: Results may be misleading due to involvement in interactions
##  contrast  estimate    SE  df t.ratio p.value
##  cat - dog    -1.04 0.346 974  -3.005  0.0027
## 
## Results are averaged over the levels of: poc
# IV2 main effect: Race
emmeans(aov_model2, specs = "poc")
## NOTE: Results may be misleading due to involvement in interactions
##  poc   emmean     SE  df lower.CL upper.CL
##  poc     2.51 0.3440 974     1.84     3.18
##  white   2.77 0.0412 974     2.69     2.85
## 
## Results are averaged over the levels of: pet 
## Confidence level used: 0.95
pairs(emmeans(aov_model2, specs = "poc"),
      adjust = "tukey")
## NOTE: Results may be misleading due to involvement in interactions
##  contrast    estimate    SE  df t.ratio p.value
##  poc - white    -0.26 0.346 974  -0.752  0.4523
## 
## Results are averaged over the levels of: pet
# IV1 and IV2 interaction effect
emmeans(aov_model2, specs = "pet", by = "poc")
## poc = poc:
##  pet emmean     SE  df lower.CL upper.CL
##  cat   1.62 0.6600 974    0.329     2.92
##  dog   3.40 0.1910 974    3.022     3.77
## 
## poc = white:
##  pet emmean     SE  df lower.CL upper.CL
##  cat   2.62 0.0755 974    2.468     2.76
##  dog   2.93 0.0330 974    2.860     2.99
## 
## Confidence level used: 0.95
pairs(emmeans(aov_model2, specs = "pet", by = "poc"),
      adjust = "tukey")
## poc = poc:
##  contrast  estimate     SE  df t.ratio p.value
##  cat - dog   -1.771 0.6870 974  -2.577  0.0101
## 
## poc = white:
##  contrast  estimate     SE  df t.ratio p.value
##  cat - dog   -0.309 0.0824 974  -3.753  0.0002
emmeans(aov_model2, specs = "poc", by = "pet")
## pet = cat:
##  poc   emmean     SE  df lower.CL upper.CL
##  poc     1.62 0.6600 974    0.329     2.92
##  white   2.62 0.0755 974    2.468     2.76
## 
## pet = dog:
##  poc   emmean     SE  df lower.CL upper.CL
##  poc     3.40 0.1910 974    3.022     3.77
##  white   2.93 0.0330 974    2.860     2.99
## 
## Confidence level used: 0.95
pairs(emmeans(aov_model2, specs = "poc", by = "pet"),
      adjust = "tukey")
## pet = cat:
##  contrast    estimate    SE  df t.ratio p.value
##  poc - white   -0.991 0.665 974  -1.491  0.1362
## 
## pet = dog:
##  contrast    estimate    SE  df t.ratio p.value
##  poc - white    0.471 0.193 974   2.433  0.0152

4.8 Write Up Two-Way ANOVA Results

To test our hypothesis that the type of pet someone owns and their race would affect companionship and interact significantly, we used a Two-Way ANOVA. Our data met most of the assumptions, although the groups were unbalanced, with 799 White participants who own dogs compared to only 2 Black participants who own cats.

As predicted, we found a significant main effect for pet type, F(1, 974) = 9.03, p = .003, ηp² = .009 (trivial effect; Cohen, 1988). Dog owners reported more companionship (M = 3.16, SE = 0.10) than cat owners (M = 2.12, SE = 0.33). Contrary to our expectations, we did not find a significant main effect for race (p = .452).

Lastly, we found support for an interaction between pet type and race (see Figure 2), F(1, 974) = 4.46, p = .035, ηp² = .005 (trivial effect). When comparing by race, Black participants who own dogs (M = 3.40, SE = 0.19) reported significantly more companionship than Black participants who own cats (M = 1.62, SE = 0.66; p = .010). Similarly, White dog owners (M = 2.93, SE = 0.03) reported more companionship than White cat owners (M = 2.62, SE = 0.08; p < .001). When comparing by pet ownership, Black dog owners reported significantly more companionship than White dog owners (p = .015), while Black and White cat owners did not differ significantly (p = .136).

References

Cohen J. (1988). Statistical Power Analysis for the Behavioral Sciences. New York, NY: Routledge Academic.