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)

colnames(d)
## [1] "group"                                                    
## [2] "participant"                                              
## [3] "subscale"                                                 
## [4] "item"                                                     
## [5] "Agreement (0=complete disagreement; 5=complete agreement)"

Step 3: Tidy data

# Load the necessary packages
library(tidyverse)
library(haven)
library(afex)

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

# Rename the columns for clarity
colnames(d) <- c("group", "participant", "subscale", "item", "agreement")

# Check the structure of the data
str(d)
## tibble [1,680 × 5] (S3: tbl_df/tbl/data.frame)
##  $ group      : chr [1:1680] "Moroccan" "Moroccan" "Moroccan" "Moroccan" ...
##  $ participant: num [1:1680] 1 1 1 1 1 1 1 1 1 1 ...
##  $ subscale   : chr [1:1680] "PAST" "PAST" "PAST" "PAST" ...
##  $ item       : chr [1:1680] "1. Para mí son muy importantes las tradiciones y las antiguas costumbres" "2. Los jóvenes deben conservar las tradiciones" "3. Creo que las personas eran más felices hace unas décadas que en la actualidad" "4. La juventud de hoy en día necesita mantener los valores de sus padres y sus abuelos" ...
##  $ agreement  : num [1:1680] 4 4 5 2 4 3 4 2 2 3 ...

Step 4: Run analysis

Pre-processing

# Filter the data for Experiment 2 and relevant subscales
experiment_2_data <- d %>%
  filter(subscale %in% c("PAST", "FUTURE"))

# Compute the mean agreement scores for each group and subscale
mean_scores <- experiment_2_data %>%
  group_by(group, subscale) %>%
  summarize(mean_agreement = mean(agreement))

# Check the structure of the mean_scores data frame
str(mean_scores)
## gropd_df [4 × 3] (S3: grouped_df/tbl_df/tbl/data.frame)
##  $ group         : chr [1:4] "Moroccan" "Moroccan" "young Spaniard" "young Spaniard"
##  $ subscale      : chr [1:4] "FUTURE" "PAST" "FUTURE" "PAST"
##  $ mean_agreement: num [1:4] 3.12 3.29 3.49 2.67
##  - attr(*, "groups")= tibble [2 × 2] (S3: tbl_df/tbl/data.frame)
##   ..$ group: chr [1:2] "Moroccan" "young Spaniard"
##   ..$ .rows: list<int> [1:2] 
##   .. ..$ : int [1:2] 1 2
##   .. ..$ : int [1:2] 3 4
##   .. ..@ ptype: int(0) 
##   ..- attr(*, ".drop")= logi TRUE

Descriptive statistics

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

# Load the necessary packages
library(ggplot2)
library(dplyr)

# Create the plot
plot <- ggplot(mean_scores, aes(x = group, y = mean_agreement, fill = subscale)) +
  geom_bar(stat = "identity", position = "dodge", width = 0.7) +
  labs(title = "Results of Experiment 2",
       x = "Group",
       y = "Rating (2 to 4)") +
  scale_y_continuous(limits = c(2, 4), breaks = seq(2, 4, 0.5)) +  # Set y-axis limits and breaks
  theme_minimal() +
  scale_fill_manual(values = c("PAST" = "blue", "FUTURE" = "red")) +  # Fill colors for past and future
  geom_errorbar(aes(ymin = mean_agreement - std.err(mean_agreement),
                    ymax = mean_agreement + std.err(mean_agreement)),
                position = position_dodge(width = 0.7),
                width = 0.2) +
  geom_text(aes(label = round(mean_agreement, 2)),
            position = position_dodge(width = 0.7),
            vjust = -0.5) +
  theme(legend.title = element_blank())

# Display the plot
print(plot)

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).

# Load the necessary packages for ANOVA
library(afex)

# Run a mixed-design ANOVA
# Bmixed_anova <- aov_car(agreement ~ group * subscale + Error(participant / subscale), data = experiment_2_data)

# Print the ANOVA summary
# summary(mixed_anova)

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 5: Reflection

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

I was able to output the figure, but getting the figure right took longer than expected, so couldn’t get to the inferential stats within 3 hours.

How difficult was it to reproduce your results?

Somewhat difficult.

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

Getting the figure right with R took longer than expected.