For this exercise, please try to reproduce the results from Experiment 2 of the associated paper (de la Fuente, Santiago, Roman, Dumitrache, & Casasanto, 2014). The PDF of the paper is included in the same folder as this Rmd file.

Methods summary:

Researchers tested the question of whether temporal focus differs between Moroccan and Spanish cultures, hypothesizing that Moroccans are more past-focused, whereas Spaniards are more future-focused. Two groups of participants (\(N = 40\) Moroccan and \(N=40\) Spanish) completed a temporal-focus questionnaire that contained questions about past-focused (“PAST”) and future-focused (“FUTURE”) topics. In response to each question, participants provided a rating on a 5-point Likert scale on which lower scores indicated less agreement and higher scores indicated greater agreement. The authors then performed a mixed-design ANOVA with agreement score as the dependent variable, group (Moroccan or Spanish, between-subjects) as the fixed-effects factor, and temporal focus (past or future, within-subjects) as the random effects factor. In addition, the authors performed unpaired two-sample t-tests to determine whether there was a significant difference between the two groups in agreement scores for PAST questions, and whether there was a significant difference in scores for FUTURE questions.


Target outcomes:

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

According to a mixed analysis of variance (ANOVA) with group (Spanish vs. Moroccan) as a between-subjects factor and temporal focus (past vs. future) as a within-subjectS factor, temporal focus differed significantly between Spaniards and Moroccans, as indicated by a significant interaction of temporal focus and group, F(1, 78) = 19.12, p = .001, ηp2 = .20 (Fig. 2). Moroccans showed greater agreement with past-focused statements than Spaniards did, t(78) = 4.04, p = .001, and Spaniards showed greater agreement with future-focused statements than Moroccans did, t(78) = −3.32, p = .001. (de la Fuente et al., 2014, p. 1685).


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

# #optional packages/functions:
# library(afex) # anova functions
# library(ez) # anova functions 2
# library(scales) # for plotting
# std.err <- function(x) sd(x)/sqrt(length(x)) # standard error

Step 2: Load data

# Just Experiment 2
data_path <- 'data/DeLaFuenteEtAl_2014_RawData.xls'
d <- read_excel(data_path, sheet=3)

Step 3: Tidy data

d <- d %>%
  rename(Agreement = `Agreement (0=complete disagreement; 5=complete agreement)`)

d <- d %>%
  mutate(group = recode(group,
                        "young Spaniard" = "Spaniards",
                        "Moroccan" = "Moroccans"))

Step 4: Run analysis

Pre-processing

d_avg <- d %>%
  group_by(participant, group, subscale) %>%
  summarise(mean_score = mean(Agreement, na.rm = TRUE)) %>%
  ungroup()
d_wide <- d_avg %>%
  pivot_wider(names_from = subscale, values_from = mean_score)

Descriptive statistics

Try to recreate Figure 2 (fig2.png, also included in the same folder as this Rmd file):

d_long <- d_wide %>%
  pivot_longer(cols = c(PAST, FUTURE),
               names_to = "subscale",
               values_to = "Agreement") %>%
  mutate(
    group = factor(group, levels = c("Spaniards", "Moroccans")),
    subscale = factor(subscale, levels = c("PAST", "FUTURE"))  
  )

summary_data <- d_long %>%
  group_by(group, subscale) %>%
  summarise(
    mean_Agreement = mean(Agreement, na.rm = TRUE),
    se_Agreement = sd(Agreement, na.rm = TRUE) / sqrt(n()),
    .groups = "drop"
  )

ggplot(summary_data, aes(x = group, y = mean_Agreement, fill = subscale)) +
  geom_bar(stat = "identity", position = position_dodge(width = 0.9), color = "black") + 
  geom_errorbar(aes(ymin = mean_Agreement - se_Agreement,
                    ymax = mean_Agreement + se_Agreement),
                position = position_dodge(width = 0.9), width = 0.25) +
  coord_cartesian(ylim = c(2, 4)) +
  labs(x = "Group", y = "Rating", fill = NULL) +
  scale_fill_manual(values = c("PAST" = "darkgray", "FUTURE" = "lightgray"),
                    labels = c("PAST" = "Past-Focused Statements", 
                               "FUTURE" = "Future-Focused Statements"),
                    guide = guide_legend(nrow = 1)) +
  theme_minimal() +
  theme(
    text = element_text(size = 12),
    legend.position = "top",
    legend.title = element_blank(),
    legend.text = element_text(size = 12),
    panel.grid = element_blank(),               
    axis.line = element_line(color = "black")   
  )

Inferential statistics

According to a mixed analysis of variance (ANOVA) with group (Spanish vs. Moroccan) as a between-subjects factor and temporal focus (past vs. future) as a within-subjects factor, temporal focus differed significantly between Spaniards and Moroccans, as indicated by a significant interaction of temporal focus and group, F(1, 78) = 19.12, p = .001, ηp2 = .20 (Fig. 2).

#install.packages("ez")
library("ez")

d_long_fixed <- d_long %>%
  mutate(participant_unique = paste0("P", participant, "_", group))

d_long_complete <- d_long_fixed %>%
  filter(!is.na(Agreement)) %>%  
  group_by(participant_unique) %>%
  filter(n() == 2) %>%  
  ungroup() %>%
  mutate(
    participant_unique = as.factor(participant_unique),
    group = as.factor(group),
    subscale = as.factor(subscale)
  )
missing_check <- d_long_complete %>%
  group_by(participant_unique, group) %>%
  summarise(
    n_obs = n(),
    has_past = sum(subscale == "PAST"),
    has_future = sum(subscale == "FUTURE"),
    .groups = "drop"
  )

#print(missing_check)

complete_participants <- missing_check %>%
  filter(n_obs == 2, has_past == 1, has_future == 1) %>%
  pull(participant_unique)

d_long_complete <- d_long_complete %>%
  filter(participant_unique %in% complete_participants)

#table(d_long_complete$participant_unique, d_long_complete$subscale)

# Now run the ANOVA
anova_result <- ezANOVA(
    data = d_long_complete,
    dv = .(Agreement),
    wid = .(participant_unique),
    within = .(subscale),
    between = .(group),
    detailed = TRUE,
    type = 3
)

print(anova_result)
## $ANOVA
##           Effect DFn DFd          SSn      SSd           F            p p<.05
## 1    (Intercept)   1  76 1543.4554821 15.24977 7692.090448 3.991708e-78     *
## 2          group   1  76    0.4398308 15.24977    2.191977 1.428650e-01      
## 3       subscale   1  76    3.9662047 37.77666    7.979308 6.040164e-03     *
## 4 group:subscale   1  76    9.1188907 37.77666   18.345608 5.327735e-05     *
##           ges
## 1 0.966785451
## 2 0.008226326
## 3 0.069591536
## 4 0.146734962

Moroccans showed greater agreement with past-focused statements than Spaniards did, t(78) = 4.04, p = .001,

# reproduce the above results here
past_data <- d_long_complete %>%
  filter(subscale == "PAST")

t_test_result <- t.test(Agreement ~ group, data = past_data)

print(t_test_result)
## 
##  Welch Two Sample t-test
## 
## data:  Agreement by group
## t = -3.8562, df = 74.91, p-value = 0.0002416
## alternative hypothesis: true difference in means between group Spaniards and group Moroccans is not equal to 0
## 95 percent confidence interval:
##  -0.8944060 -0.2850812
## sample estimates:
## mean in group Spaniards mean in group Moroccans 
##                2.691142                3.280886

and Spaniards showed greater agreement with future-focused statements than Moroccans did, t(78) = −3.32, p = .001.(de la Fuente et al., 2014, p. 1685)

# reproduce the above results here
future_data <- d_long_complete %>%
  filter(subscale == "FUTURE")

t_test_result <- t.test(Agreement ~ group, data = future_data)

print(t_test_result)
## 
##  Welch Two Sample t-test
## 
## data:  Agreement by group
## t = 3.3898, df = 69.358, p-value = 0.001157
## alternative hypothesis: true difference in means between group Spaniards and group Moroccans is not equal to 0
## 95 percent confidence interval:
##  0.1552941 0.5994067
## sample estimates:
## mean in group Spaniards mean in group Moroccans 
##                3.493590                3.116239

Step 5: Reflection

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

I got the same result but a different statistic, so I wasn’t able to fully reproduce it. Some values were missing from the original dataset. Specifically, participant number 25 did not have the PAST subscale completed, which resulted in a smaller dataset for the analysis.

How difficult was it to reproduce your results?

It was more difficult than in the previous paper because some values were missing.

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

The names were straightforward, which made it easy. It was difficult to figure out why I had fewer degrees of freedom.