For this exercise, please try to reproduce the results from Study 1 of the associated paper (Joel, Teper, & MacDonald, 2014). The PDF of the paper is included in the same folder as this Rmd file.
In study 1, 150 introductory psychology students were randomly assigned to a “real” or a “hypothetical” condition. In the real condition, participants believed that they would have a real opportuniy to connect with potential romantic partners. In the hypothetical condition, participants simply imagined that they are on a date. All participants were required to select their favorite profile and answer whether they were willing to exchange contact information.
Below is the specific result you will attempt to reproduce (quoted directly from the results section of Study 1):
We next tested our primary hypothesis that participants would be more reluctant to reject the unattractive date when they believed the situation to be real rather than hypothetical. Only 10 of the 61 participants in the hypothetical condition chose to exchange contact information with the unattractive potential date (16%). In contrast, 26 of the 71 participants in the real condition chose to exchange contact information (37%). A chi-square test of independence indicated that participants were significantly less likely to reject the unattractive potential date in the real condition compared with the hypothetical condition, X^2(1, N = 132) = 6.77, p = .009.
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:
# library(broom)
# library(labelled)# converts SPSS's labelled to R's factor
# Just Study 1
d <- read_sav('data/Empathy Gap Study 1 data.sav')
# want frame in long format with:
# cols: participant ID, condition {real, hypothetical}, exchangeinfo {yes, no}
dtidy <- d |> select("ID", "condition", "exchangeinfo")
# since between-subj conditions... and only one trial... this is already in long format!
Only 10 of the 61 participants in the hypothetical condition chose to exchange contact information with the unattractive potential date (16%). In contrast, 26 of the 71 participants in the real condition chose to exchange contact information (37%).
# reproduce the above results here
dtidy |>
# replace "2" (did not exchange info) with "0" so that mean gives us proportion people said yes!
mutate(exchangeinfo = replace(exchangeinfo, exchangeinfo == 2, 0)) |>
group_by(condition) |>
summarize(mean = mean(exchangeinfo))
## # A tibble: 2 × 2
## condition mean
## <dbl+lbl> <dbl>
## 1 0 [hypothetical] 0.164
## 2 1 [real] 0.366
A chi-square test of independence indicated that participants were significantly less likely to reject the unattractive potential date in the real condition compared with the hypothetical condition, X^2(1, N = 132) = 6.77, p = .009.
Hint: if you are using the function chisq.test(), make sure to set the continuity correction to false (“correct = FALSE”) since sample size is greater than 20.
# chi-squared test of independence assesses the association between two categorical variables.
# reproduce the above results here
dtidy_replaced <- dtidy |>
# replace "2" (did not exchange info) with "0" so that mean gives us proportion people said yes!
mutate(exchangeinfo = replace(exchangeinfo, exchangeinfo == 2, 0))
#real_exchanged <- dtidy_replaced |>
# filter(dtidy_replaced$condition == 1) |>
# pull(exchangeinfo)
#hypo_exchanged <- dtidy_replaced |>
# filter(dtidy_replaced$condition == 0) |>
# pull(exchangeinfo)
dtidy_replaced |>
select(exchangeinfo, condition) |>
table() |>
chisq.test(correct=FALSE)
##
## Pearson's Chi-squared test
##
## data: table(select(dtidy_replaced, exchangeinfo, condition))
## X-squared = 6.7674, df = 1, p-value = 0.009284
Were you able to reproduce the results you attempted to reproduce? If not, what part(s) were you unable to reproduce?
Yes
How difficult was it to reproduce your results?
kinda difficult (looked like, if I knew R, this would take all of 15 min; but, since I don’t really know R, it took about 2 hours total)
What aspects made it difficult? What aspects made it easy?
Knowing how to do most of the things I needed in Python+pandas, but having no idea really how to do the simple things (select only some columns, filter rows based on logical condition over values, etc.) in R / tidyverse. Also, I didn’t really understand the difference btwn a chi-squared test for independence vs. goodness of fit.