For this exercise, please try to reproduce the results from Study 1 of the associated paper (Maglio & Polman, 2014). The PDF of the paper is included in the same folder as this Rmd file.

Methods summary:

Researchers recruited 202 volunteers at a subway station in Toronto, Ontario, Canada. Half of the sample was traveling East, while the other half was traveling West. In a 2 (orientation: toward, away from) X 4 (station: Spadina, St. George, Bloor-Yonge, Sherbourne) design, each participant was randomly asked to estimate how far one of the four stations felt to them (1= very close, 7= very far). Authors conducted a 2 X 4 ANOVA on distance estimates, and then tested differences in distance estimates between East and West-bound groups for each individual station.


Target outcomes:

Below is the specific result you will attempt to reproduce (quoted directly from the results section of Study 1):

We carried out a 2 (orientation: toward, away from) × 4 (station: Spadina, St. George, Bloor-Yonge, Sherbourne) analysis of variance (ANOVA) on closeness ratings, which revealed no main effect of orientation, F < 1, and a main effect of station, F(3, 194) = 24.10, p < .001, ηp 2 = .27. This main effect was qualified by the predicted interaction between orientation and station, F(3, 194) = 16.28, p < .001, ηp2 = .20. We decomposed this interaction by the subjective-distance ratings between participants traveling east and west for each of the four subway stations. Westbound participants rated the stations to the west of Bay Street as closer than did eastbound participants; this effect was obtained for both the station one stop to the west (St. George, p < .001, ηp2 = .28) and the station two stops to the west (Spadina, p = .001, ηp2 = .20). The opposite pattern held true for stations to the east of Bay Street. Eastbound participants rated the stations to the east of Bay Street as closer than did westbound participants; this effect was obtained for both the station one stop to the east (Bloor-Yonge, p = .053, ηp2 = .08) and the station two stops to the east (Sherbourne, p < .001, ηp2 = .24). Figure 1 summarizes these results.


Step 1: Load packages

library(tidyverse) # for data munging
library(knitr) # for kable table formating
library(haven) # import and export 'SPSS', 'Stata' and 'SAS' Files
library(readxl) # import excel files
library(lsr)
library(ggthemes)

Step 2: Load data

# Just Study 1
d <- read_excel("data/S1_Subway.xlsx")

Step 3: Tidy data

The data are already tidy as provided by the authors.

Step 4: Run analysis

Pre-processing

You will notice that R doesn’t recognize some of these variables as factors. So let’s just factorize our variables before we proceed with the analyses.

d = d %>%
  mutate(
    DIRECTION = as.factor(DIRECTION),
    STN_NUMBER = as.factor(STN_NUMBER),
    STN_NAME = factor(STN_NAME, levels = c("SPAD", "STG", "B-Y", "SHER"))
  )

Inferential statistics

We carried out a 2 (orientation: toward, away from) × 4 (station: Spadina, St. George, Bloor-Yonge, Sherbourne) analysis of variance (ANOVA) on closeness ratings, which revealed no main effect of orientation, F < 1, and a main effect of station, F(3, 194) = 24.10, p < .001, ηp 2 = .27. This main effect was qualified by the predicted interaction between orientation and station, F(3, 194) = 16.28, p < .001, ηp2 = .20.

Note from teaching team: ηp2 = “partial eta squared”

First, check the number of observations for each condition

d %>%
  group_by(STN_NAME, DIRECTION) %>%
  summarize(
    num_obs = n(),
    .groups = "keep"
  ) %>%
  ungroup()
## # A tibble: 8 × 3
##   STN_NAME DIRECTION num_obs
##   <fct>    <fct>       <int>
## 1 SPAD     EAST           26
## 2 SPAD     WEST           25
## 3 STG      EAST           26
## 4 STG      WEST           25
## 5 B-Y      EAST           23
## 6 B-Y      WEST           26
## 7 SHER     EAST           26
## 8 SHER     WEST           25

Looks pretty even to me!

Now run the model

When I see “analysis of variance” in the paper, my first thought is to use the aov function in R. This is a wrapper function that fits a linear model to the data.

Note on statistics: the goal of this assignment is for you to get used to reproducing analyses. It is not intended to teach you about the subtleties of statistics; that will be covered in PSYC201B. We are happy to chat about these details in office hours, but do not worry if you do not understand them right now!

Now fill in the aov command with the proper variables (e.g. replace “VAR1” with the first variable of interest. This is a two-way ANOVA that tests for a main effect of direction (east vs west), a main effect of station, and an interaction between direction and station. The interaction term is denoted by the * below. For more information, do a little Googling about two-way ANOVAs.

mod <- aov(data = d,
           formula = DISTANCE ~ DIRECTION + STN_NAME + DIRECTION * STN_NAME)
anova(mod)
## Analysis of Variance Table
## 
## Response: DISTANCE
##                     Df  Sum Sq Mean Sq F value    Pr(>F)    
## DIRECTION            1   0.713  0.7129  0.6644     0.416    
## STN_NAME             3  75.158 25.0525 23.3492 6.011e-13 ***
## DIRECTION:STN_NAME   3  52.413 17.4710 16.2832 1.765e-09 ***
## Residuals          194 208.152  1.0729                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Check your results against the instructional team

Note: the values in the parentheses denote the degrees of freedom for the F-test. * Main effect of direction: F(1, 194) = 0.664 * Main effect of station: F(3, 194) = 23.35 * Interaction between direction and station: F(3,194) = 16.28

Note from instructors: We’re unclear as to why the F-values are slightly different from those in the paper. But students in previous versions of this class came to the same answer.

Effect size

Get the partial eta-squared (under the eta.sq.part column). Do your results match the original paper? Hint: they should!

etaSquared(mod)
##                         eta.sq eta.sq.part
## DIRECTION          0.001195964 0.001929304
## STN_NAME           0.223393543 0.265284110
## DIRECTION:STN_NAME 0.155789423 0.201151614

Station-specific analyses

We decomposed this interaction by the subjective-distance ratings between participants traveling east and west for each of the four subway stations. Westbound participants rated the stations to the west of Bay Street as closer than did eastbound participants; this effect was obtained for both the station one stop to the west (St. George, p < .001, ηp2 = .28) and the station two stops to the west (Spadina, p = .001, ηp2 = .20). The opposite pattern held true for stations to the east of Bay Street. Eastbound participants rated the stations to the east of Bay Street as closer than did westbound participants; this effect was obtained for both the station one stop to the east (Bloor-Yonge, p = .053, ηp2 = .08) and the station two stops to the east (Sherbourne, p < .001, ηp2 = .24). Figure 1 summarizes these results.

St. George

# STEP 1: filter the data to get only St. George estimates
st.george = d %>%
  filter(STN_NAME =="STG")

# STEP 2: was the estimated distance to St. George greater for eastbound or westbound travellers?
# no stats needed, just get the mean estimated distance between east and west directions
# Hint: you'll want group_by() and summarize()
st.george %>% 
  group_by(DIRECTION)%>%
  summarize(mean_distance=mean(DISTANCE,na.rm = TRUE))
## # A tibble: 2 × 2
##   DIRECTION mean_distance
##   <fct>             <dbl>
## 1 EAST               2.77
## 2 WEST               1.64
# STEP 3: Now run an aov on St. George data with distance as the response variable and direction as the explanatory variable
st.george.aov = aov(data = st.george, formula = DISTANCE ~ DIRECTION)
summary(st.george.aov)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## DIRECTION    1  16.25  16.252   18.79 7.23e-05 ***
## Residuals   49  42.38   0.865                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# STEP 4: Find the eta squared
etaSquared(st.george.aov)
##              eta.sq eta.sq.part
## DIRECTION 0.2772092   0.2772092

Spadina

## do the same for Spadina
spadina <- d %>%
  filter(STN_NAME == "SPAD")

spadina %>%
  group_by(DIRECTION) %>%
  summarize(mean_distance = mean(DISTANCE, na.rm = TRUE))
## # A tibble: 2 × 2
##   DIRECTION mean_distance
##   <fct>             <dbl>
## 1 EAST               3.65
## 2 WEST               2.64
spadina_aov <- aov(data = spadina, formula = DISTANCE ~ DIRECTION)
summary(spadina_aov)
##             Df Sum Sq Mean Sq F value  Pr(>F)   
## DIRECTION    1  13.10  13.100   11.97 0.00113 **
## Residuals   49  53.64   1.095                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#ETA Squared 
etaSquared(spadina_aov)
##              eta.sq eta.sq.part
## DIRECTION 0.1962763   0.1962763

Bloor-Yonge

## do the same for Bloor-Yonge
bloor_yonge <- d %>%
  filter(STN_NAME == "B-Y")
#mean distance
bloor_yonge %>%
  group_by(DIRECTION) %>%
  summarize(mean_distance = mean(DISTANCE, na.rm = TRUE))
## # A tibble: 2 × 2
##   DIRECTION mean_distance
##   <fct>             <dbl>
## 1 EAST               1.61
## 2 WEST               2.19
#ANOVA 
bloor_yonge_aov <- aov(data = bloor_yonge, formula = DISTANCE ~ DIRECTION)
summary(bloor_yonge_aov)
##             Df Sum Sq Mean Sq F value Pr(>F)  
## DIRECTION    1   4.16   4.157   3.945 0.0528 .
## Residuals   47  49.52   1.054                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#eta squared 
etaSquared(bloor_yonge_aov)
##              eta.sq eta.sq.part
## DIRECTION 0.0774451   0.0774451

Sherbourne

## do the same for Sherbourne

Step 5: Reflection

Were you able to reproduce the results you attempted to reproduce? If not, what part(s) were you unable to reproduce?

Yes, we successfully reproduced the results.

How difficult was it to reproduce your results?

It was not too difficult.

What aspects made it difficult? What aspects made it easy?

Just the rounding of the numbers I had to double check

Bonus: Reproduce Fig 1

# Load necessary libraries
library(dplyr)
library(ggplot2)

# Step 1: Calculate mean subjective distance and standard error for each station and direction
data_summary <- d %>%
  group_by(STN_NAME, DIRECTION) %>%
  summarize(
    mean_distance = mean(DISTANCE, na.rm = TRUE),
    SE = sd(DISTANCE, na.rm = TRUE) / sqrt(n())
  )

# Step 2: Plot the data
ggplot(data_summary, aes(x = STN_NAME, y = mean_distance, group = DIRECTION, color = DIRECTION)) +
  geom_line(aes(linetype = DIRECTION), size = 1) +
  geom_point(size = 3) +
  geom_errorbar(aes(ymin = mean_distance - SE, ymax = mean_distance + SE), width = 0.2) +
  scale_y_continuous(limits = c(0, 5)) +
  labs(x = NULL, y = "Subjective Distance") +
  theme_minimal() +
  theme(
    axis.title.y = element_text(size = 14),
    axis.text.x = element_text(size = 12, angle = 45, hjust = 1),
    legend.position = "top",
    legend.title = element_blank()
  ) +
  scale_color_manual(values = c("black", "gray")) +
  scale_linetype_manual(values = c("solid", "dashed")) +
  annotate("text", x = 1.5, y = -0.5, label = "West of Bay", hjust = 0.5, vjust = 1, fontface = "bold", color = "black") +
  annotate("text", x = 3.5, y = -0.5, label = "East of Bay", hjust = 0.5, vjust = 1, fontface = "bold", color = "black")