Introduction

My research interests lie broadly in culture, emotion, and well-being, topics that may not appear to be directly related to this study at first glance. However, the complex interplay between age, donation behaviour, and various relational factors (i.e., kinship, social distance) described in the original paper intuitively appears to me to be shaped by culture. Culture moulds how we understand age, our attitudes towards donation, and – perhaps most importantly here – how we relate to our families and close others (vs our non-relatives and strangers). When I looked over the original paper, I was interested to see that the sample was composed of “community-dwelling Chinese adults” apparently living in Hong Kong and immediately wondered if possible cultural differences between the sample used in original study and the sample used in the first replication attempt may have been implicated in the failure to replicate. Indeed, the authors of the original paper suggest the possibility of culture influencing their results, writing that “future studies should test whether this age difference in kin-selection in prosocial behaviors varies across cultures”. If possible within the constraints of this project, I would be interested in potentially controlling for cultural background in my replication attempt, but I am very interested in this project in any case.

To conduct this experiment, I will need to collect data from a sample of older and younger adults. I will need to create a survey containing the following demographic items: gender, age, core social network size (i.e., estimated number of important relatives/friends), level of education, and household income. Older participants will also be asked to complete the Alzheimer’s Disease Assessment Scale-Cognitive Subscale (ADAS-Cog) as a measure of cognitive function. All participants will be asked to complete a hypothetical donation task in they will be asked how much money or time they would donate to a number of targets who systematically vary in their closeness to and kinship with the participant. The study will use a mixed design in which age (older vs younger) is a between-subjects variable and donation form (money vs time), kinship with the target (relative vs non-relative), and social distance with the target (targets ranked 1st, 2nd, 5th, 10th, 20th, 50th, and 100th in a list of 100 people ranked in descending order of closeness) are within-subjects variables.

Analysis will involve first fitting a hyperbolic discount function to group data and testing for goodness of fit, then fitting a hyperbolic discount function to individual data to find each participant’s discount rate (k) and area under curve (AUC) values. k and AUC values will then be log-transformed. Correlations between demographic variables and transformed k and AUC values will be investigated, and finally I will run a mixed 2 (age) × 2 (donation form) × 2 (kinship) repeated measures ANOVA on transformed k and AUC values.

A key challenge will be recruitment of a sample of older adults. The older adult sample in the original study were 60-84 years old and it may be difficult to recruit people in this age bracket through Prolific. It may be worthwhile considering a) not including the older adult sample, b) the benefits and pitfalls of recruiting a slightly younger older adult sample, c) whether it might be possible to include age as a continuous rather than categorical variable and changing the analysis strategy accordingly, or d) including age as a control variable rather than as an independent variable of primary interest. A personal challenge will be learning how to fit a function to data; this is something I’ve never done before but a skill I’m looking forward to developing.

Github Repository

Original Paper

Link to Qualtrics survey

Summary of prior replication attempt

The prior replication attempt was conducted by Yochai Shavit in 2017 and was unable to replicate Gong et al.’s (2019) main findings. However, Shavit’s replication attempt departed from the original study on a number of dimensions. Firstly, the original sample consisted of 89 younger (age range: 18-44, mean: 30.1) and 66 older adults (age range: 60-84, mean: 69.4) from Hong Kong. In the replication attempt, based on a power analysis indicating that data from 45 younger and 45 older adults would be sufficient to detect a main effect of age with 80% power in a one-tailed t-test, 43 younger (age range: 19-35, mean: 28.2) and 47 older (age range: 57-74, mean: 62.7) adults living in the United States were recruited. The samples thus differed in three key ways: the sample in the replication study was smaller, the participants in the replication study were younger, and the samples represented two very different cultures. Of these, Shavit suggests - and I concur - that the factor likely to be most implicated in the failure to replicate is culture, given there are different norms surrounding donation and attitudes towards relatives in Hong Kong and the United States. Additional differences in implementation and analysis were as follows:

  1. The original study was conducted in person in a lab, whereas the replication study was conducted online. Given the study’s variables essentially consist exclusively of a survey, this seems unlikely to have caused any issues.

  2. Participants in the original study were asked to imagine they had 100,000 Hong Kong dollars (HKD), whereas participants in the replication study were asked to imagine they had 100,000 US dollars (USD) to fit the context in which the data was collected. 100,000 HKD is approximately equivalent to 13,000 USD. Shavit consulted the first author of the original study about how to reconcile this discrepancy and was told to instruct participants to imagine having 100,000 USD rather than an amount equivalent to 100,000 HKD. Because this study focuses on how much participants are relatively willing to donate to others as a function of how close they are and whether they are related to them, rather than the absolute amount they are willing to donate, I feel there should be minimal issues with this approach.

  3. In the original study, older participants’ cognitive function was assessed using the cognitive subscale of the Alzheimers’ Disease Assessment Scale (ADAS-Cog) to ensure the results would not be confounded with cognitive function. Because this is not a computer-based test, it was not used in the replication study. This seems unlikely to have been an issue because, in the original study, cognitive function and willingness to donate were not significantly correlated.

  4. Because the replication study was conducted online, Shavit included a simple attention check and excluded participants who failed it.

  5. The authors of the original study fit the hyperbolic discount function to the data using Matlab, but Shavit did this using the “optim” function from the ‘stats’ package in R. Shavit was able to obtain similar results to the original authors when testing this procedure a priori using simulated data, suggesting that differences in the results were not an artefact of different software being used for analysis.

  6. The authors of the original study did not report how they dealt with missing data. In the replication study, Shavit excluded participants with missing AUC values from analysis.

  7. In the original study, the younger adult group was comprised of participants aged between 18 and 44. Shavit elected to collect data from participants aged between 18 and 35. Additionally, the youngest participant/s in the older adult group in the original study was/were 60, but the youngest participant/s in the older adult group in the replication study was/were 57 because of constraints with regard to participant screening on Mechanical Turk.

  8. The authors of the original study did not report using any post-hoc correction when conducting t-tests. In the replication study, Shavit reported the results of t-tests both with and without Bonferroni correction.

Methods

Power Analysis

Original effect size, power analysis for samples to achieve 80%, 90%, 95% power to detect that effect size. Considerations of feasibility for selecting planned sample size.

How much power does your planned sample have for original effect? For an attenuated effect that is half the size of the original?

(If power analysis is not possible or precise, discuss more fully how you determined a sample size that would be sufficient for rescue.)

Planned Sample

Planned sample size will be based on power analysis. I will collect data from both a younger sample (aged between 18 and 44, following the original study) and an older sample (aged above 60, following the original study). The author of the replication study suggested that cultural differences may have driven the failure to replicate. I will not be able to collect data specifically from Hong Kong Chinese participants as in the original study due to a dearth of Hong Kong residents actively using Prolific, but one option may be to recruit participants who identify as Asian and/or list a Chinese language (e.g., Mandarin, Cantonese) as their first language to try to sample people with more similar cultural backgrounds to the participants in the original study than those who participated in the first replication attempt.

Materials

Participants will be asked to list their gender, age, level of education, and household income. As a measure of core social network size, participants will be asked to estimate the number of important friends and family they have in their lives.

Participants will then be asked to complete hypothetical donation tasks for both relatives and non-relatives. The initial instruction will be as follows: “The following task asks you to imagine that you have a list of 100 relatives (non-relatives) arranged in descending order of their closeness with you. The person at position #1 is your closest relative (non-relative), while the person at position #100 is a relative (non-relative) you may know but are not close at all. You do not have to actually create the list – just imagine that you have done so. Next you will be asked to answer questions regarding these relatives (non-relatives) at a given position.”

Participants will then be asked 14 questions regarding how much money and time they would be willing to donate to the relatives and non-relatives at each of the following positions on those lists: 1st, 2nd, 5th, 10th, 20th, 50th, and 100th. The questions will read as follows: “Imagine that the relative (non-relative) at position N on your list is now hospitalized. He/she needs to be accompanied and taken care of in the hospital, as well as a large amount of money to pay for the medical expense. If you now own 100 thousand of US dollars and 100 days of vacation, how much money would you donate to him/her, and how many days would you spend taking care of him/her?”

The only difference between the materials described here and those used in the original study is that participants will be asked to imagine they have 100,000 US dollars rather than 10,000 HK dollars, following the instructions given to the author of the first replication attempt from the first author of the original study.

Procedure

Participants will be asked to complete a Qualtrics survey containing the measures described above in the order they appear above.

Controls

Following the first replication attempt, I will include a simple attention check. After participants are asked how much time and money they would be willing to donate to a relative at position 20 on their list, they will also be asked the following question: “In the last question, your answers referred to the participant in position:” with 3, 7, 12, 16, 20, 28, and 42 as answer choices. Participants who do not answer ‘20’ will be excluded from analysis.

Analysis Plan

Firstly, identifiable information will be removed from the data set. Next, I will follow the analysis plan outlined in the original study:

To analyze the donation data, we first modeled the group donation data. For each age × donation form × kinship cell, a hyperbolic discount function (i.e., Equation 1) was fit to the group median values (Jones & Rachlin, 2006; Rachlin & Jones, 2007, 2008) over the seven social distances (N = 1, 2, 5, 10, 20, 50, and 100): \[v=V/(1+kN)\] where V is the undiscounted reward value, v is the reward value that a person would like to forgo for the benefit for someone at a social distance N, and k is a constant indexing degree of social discounting (i.e., discount rate) across social distances. Following the convention of the literature, group median values instead of mean values were used because such data were usually not normally distributed (e.g., Jones & Rachlin, 2006).

The fitting process was conducted by curve fit toolbox of Matlab (version 2015a), where R-square and root-mean-square error (RMSE) were used to assess the goodness of fit. Such a modeling technique has been widely used in the literature on temporal (e.g., Frederick, Loewenstein, & O’Donoghue, 2002) and social discounting (e.g., Jones & Rachlin, 2006). The technique enables us to sketch individuals’ donation willingness across various social distances with simple parameters like discount rate (k) and area under curve (AUC) (e.g., Jones & Rachlin, 2006; Margittai et al., 2015). Discount rate (k) reflects a donor’s social-distance dependent selectivity as to donation willingness—a larger k value indicates a higher level of selectivity, that is, the donor treats socially close and distant recipients more differently. AUC could be used to index the donor’s overall generosity to people independent of social distance, with a larger value indicating a higher level of generosity (Margittai et al., 2015; Strombach et al., 2014).

Once the appropriateness of the hyperbolic discount function was confirmed for group data, we then conducted the same fitting process to individual data to get the discount rate (k) and the AUC for each participant under different conditions. Again following the convention of the literature, individual data that did not fit the hyperbolic discount function were excluded from further analyses (Vuchinich & Simpson, 1998). The individuals’ k and AUC values were then normalized by a natural logarithm transformation (e.g., Margittai et al., 2015), and transformed values that exceeded ±3 SDs were treated as outliers.

Next, the transformed individual k and AUC values were correlated with demographic variables to preliminarily check the influences of demographic variables on donation willingness. To examine the moderating roles of donation form and kinship in the relation between age and donation willingness, the transformed individual AUC values and k values were submitted respectively to a 2 (age: younger and older) × 2 (donation form: money and time) × 2 (kinship: relatives and nonrelatives) mixed design, repeated measures ANOVA (and post hoc tests), with and without controlling for demographic variables.

I will depart from the above analysis plan only in that I will use R rather than Matlab to conduct curve fitting and analyse data. Additionally, as in the first replication attempt, I will report the results of t-tests both with and without applying Bonferroni correction.

The key analysis of interest is the mixed design, repeated measures ANOVA of transformed AUC values controlling for demographic variables.

Differences from Original Study and 1st replication

  1. Data will be collected on Prolific rather than in person (as in the original study) or on Mechanical Turk (as in the first replication attempt). This is unlikely to make a difference to the results because this is a survey study.

  2. The original study’s participants were Hong Kong Chinese adults living in Hong Kong, whereas the first replication attempt sampled residents of the United States of any ethnicity. Rather than recruiting participants who live in a specific country, I will recruit participants who identify as Asian and/or list a Chinese language (e.g., Mandarin, Cantonese) as their first language to attempt to sample people with a relatively similar cultural background to the original study’s participants. If cultural differences were indeed implicated in the failure to replicate, this strategy may increase the chances of replicating the original study’s findings.

Methods Addendum (Post Data Collection)

You can comment this section out prior to final report with data collection.

Actual Sample

Sample size, demographics, data exclusions based on rules spelled out in analysis plan

Differences from pre-data collection methods plan

Any differences from what was described as the original plan, or “none”.

Results

Data preparation

Load relevant libraries

library(knitr)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
library(car)
## Loading required package: carData
## 
## Attaching package: 'car'
## 
## The following object is masked from 'package:dplyr':
## 
##     recode
## 
## The following object is masked from 'package:purrr':
## 
##     some
library(ez)
library(broom)
library(pander)
library(kableExtra)
## 
## Attaching package: 'kableExtra'
## 
## The following object is masked from 'package:dplyr':
## 
##     group_rows
library(lme4)
## Loading required package: Matrix
## 
## Attaching package: 'Matrix'
## 
## The following objects are masked from 'package:tidyr':
## 
##     expand, pack, unpack
library(lmerTest)
## 
## Attaching package: 'lmerTest'
## 
## The following object is masked from 'package:lme4':
## 
##     lmer
## 
## The following object is masked from 'package:stats':
## 
##     step
library(effsize)
library(RColorBrewer)

Write function to compute hyperbolic function

discount <- function (V, k, N) {
  nu <- V / (1 + k * N)
  
  return(nu)
}

Write function to compute RMSE

data_vs_discount <- function(V, k, N, amount) {
  nu <- discount(V, k, N)
  
  RMSE <- sqrt(mean((amount - nu)^2))
  
  return(RMSE)
}

Import data

df = read.csv("psych251_pilot_data.csv", header=T)
df <- tail(df, -2)

Remove identifying information and extraneous variables

df = select(df, -1:-17)

Add subject IDs

df$id <- 1:5 

Remove participants who failed attention check

df = filter(df, attention_check==5)

Group participants based on age (create an ‘age group’ column where participants are listed as either ‘younger’ or ‘older’)

df <- df%>%
  mutate(age_group = dplyr::case_when(age <= 35 ~ "younger", age > 60 ~ "older"),
         age_group = factor(age_group, level = c("younger", "older"))
  )

summary(df$age_group)
## younger   older 
##       2       1

Converting critical variables to numeric

df[,c(1:38)]=as.numeric(unlist(df[,c(1:38)]))

Making data set longer

og_lng=df%>%
  gather(condition, amount, c(matches("_money"),matches("_time"))
         )%>%
  separate(condition, c("kin", "soc_dist", "donation"), "_")%>%
  spread(kin, amount)%>%
  gather(kinship, amount,
         rel, nonrel)

For each age × donation form × kinship cell, fit hyperbolic discount function (i.e., Equation 1) to group median values over seven social distances (N = 1, 2, 5, 10, 20, 50, and 100)

#create df with monetary amounts divided by 1000 for plotting and analyses (to have the same units for time and money donations)
df_og2=df%>%mutate(rel_1_money=rel_1_money/1000, 
                      rel_2_money=rel_2_money/1000, 
                      rel_5_money=rel_5_money/1000, 
                      rel_10_money=rel_10_money/1000, 
                      rel_20_money=rel_20_money/1000, 
                      rel_50_money=rel_50_money/1000, 
                      rel_100_money=rel_100_money/1000, 
                      nonrel_1_money=nonrel_1_money/1000, 
                      nonrel_2_money=nonrel_2_money/1000, 
                      nonrel_5_money=nonrel_5_money/1000, 
                      nonrel_10_money=nonrel_10_money/1000, 
                      nonrel_20_money=nonrel_20_money/1000, 
                      nonrel_50_money=nonrel_50_money/1000, 
                      nonrel_100_money=nonrel_100_money/1000)

#long-form this dataframe
og_lng2=df_og2%>%
  gather(condition, amount, c(matches("_money"),matches("_time"))
         )%>%
  separate(condition, c("kin", "soc_dist", "donation"), "_")%>%
  spread(kin, amount)%>%
  gather(kinship, amount,
         rel,nonrel)

#set variable soc_dist to be numeric in both dataframes
#original df
og_lng$soc_dist=as.character(og_lng$soc_dist)
og_lng$soc_dist=as.numeric(og_lng$soc_dist)
is.numeric(og_lng$soc_dist)
## [1] TRUE
#df for plotting and analysis
og_lng2$soc_dist=as.character(og_lng2$soc_dist)
og_lng2$soc_dist=as.numeric(og_lng2$soc_dist)
is.numeric(og_lng2$soc_dist)
## [1] TRUE
#create table with original median values
med_table=og_lng%>%group_by(age_group,kinship,donation,soc_dist)%>%summarise(med_amnt=median(amount))
## `summarise()` has grouped output by 'age_group', 'kinship', 'donation'. You can
## override using the `.groups` argument.
#create table of median values with the transformed monetary amounts
med_table2=og_lng2%>%group_by(age_group,kinship,donation,soc_dist)%>%summarise(med_amnt=median(amount))
## `summarise()` has grouped output by 'age_group', 'kinship', 'donation'. You can
## override using the `.groups` argument.
  1. Check goodness of fit using R-square and RMSE
#define dataset
d=med_table2

#create empty vectors to store values
age_group=vector(mode="character",length=0); donation=vector(mode="character",length=0); kinship=vector(mode="character",length=0); V_values=vector(mode="numeric",length=0); k_values=vector(mode="numeric",length=0); RMSE=vector(mode="numeric",length=0); R_sq=vector(mode="numeric",length=0)

#run for each age group, extract values for donation * kinship conditions

for(i in unique(d$age_group)){
  
  d_money_rel=d%>%filter(age_group==i, donation=="money", kinship=="rel") #-> create temp df to get values from
  age_group=c(age_group,i) #-> store the appropriate age group
  donation=c(donation, "money") #-> store the appropriate donation
  kinship=c(kinship, "rel") #-> store the appropriate kinship
  optim_discount_wrapper <- function(x) { #-> define discount wrapper to get V, k, and RMSE values for this                                                      condition
  return(data_vs_discount(V = x[1], k = x[2],  
                          N = d_money_rel$soc_dist, 
                          amount = d_money_rel$med_amnt))
}

  opt1=optim(c(100, 0.2), optim_discount_wrapper, method = "L-BFGS-B", lower=c(0,0), upper=c(300,100)) #-> run discount_wrapper
  V_values=c(V_values,opt1$par[1]) #-> store resulting V_value
  k_values=c(k_values, opt1$par[2]) #-> store resulting k_value
  RMSE=c(RMSE, opt1$value) #-> store resulting RMSE value
  d_money_rel$pred=discount(V = opt1$par[1], k = opt1$par[2],N = d_money_rel$soc_dist) #-> store predictions in temp                                                                                          dataset
  cor1=cor.test(d_money_rel$med_amnt, d_money_rel$pred) #-> run cor.test to get correlation of predictions and data
  R_sq=c(R_sq, (cor1$estimate)^2) #-> square the estimate (pearson's R) to get R^2.
  
  
  d_money_nonrel=d%>%filter(age_group==i, donation=="money", kinship=="nonrel") #-> do all of this for the next donation                                                                               * Kinship condition
  age_group=c(age_group,i)
  donation=c(donation, "money")
  kinship=c(kinship, "nonrel")
  optim_discount_wrapper <- function(x) {
  return(data_vs_discount(V = x[1], k = x[2],  
                          N = d_money_nonrel$soc_dist, 
                          amount = d_money_nonrel$med_amnt))
}

  opt2=optim(c(100, 0.2), optim_discount_wrapper, method = "L-BFGS-B", lower=c(0,0), upper=c(300,100))
  V_values=c(V_values,opt2$par[1])
  k_values=c(k_values, opt2$par[2])
  RMSE=c(RMSE, opt2$value)
  d_money_nonrel$pred=discount(V = opt2$par[1], k = opt2$par[2],N = d_money_nonrel$soc_dist)
  cor2=cor.test(d_money_nonrel$med_amnt, d_money_nonrel$pred)
  R_sq=c(R_sq, (cor2$estimate)^2)


  d_time_rel=d%>%filter(age_group==i, donation=="time", kinship=="rel")
  age_group=c(age_group,i)
  donation=c(donation, "time")
  kinship=c(kinship, "rel")
  optim_discount_wrapper <- function(x) {
  return(data_vs_discount(V = x[1], k = x[2],  
                          N = d_time_rel$soc_dist, 
                          amount = d_time_rel$med_amnt))
}

  opt3=optim(c(100, 0.2), optim_discount_wrapper, method = "L-BFGS-B", lower=c(0,0), upper=c(300,100))
  V_values=c(V_values,opt3$par[1])
  k_values=c(k_values, opt3$par[2])
  RMSE=c(RMSE, opt3$value)
  d_time_rel$pred=discount(V = opt3$par[1], k = opt3$par[2],N = d_time_rel$soc_dist)
  cor3=cor.test(d_time_rel$med_amnt, d_time_rel$pred)
  R_sq=c(R_sq, (cor3$estimate)^2)

  
  d_time_nonrel=d%>%filter(age_group==i, donation=="time", kinship=="nonrel")
  age_group=c(age_group,i)
  donation=c(donation, "time")
  kinship=c(kinship, "nonrel")
  optim_discount_wrapper <- function(x) {
  return(data_vs_discount(V = x[1], k = x[2],  
                          N = d_time_nonrel$soc_dist, 
                          amount = d_time_nonrel$med_amnt))
}

  opt4=optim(c(100, 0.2), optim_discount_wrapper, method = "L-BFGS-B", lower=c(0,0), upper=c(300,100))
  V_values=c(V_values,opt4$par[1])
  k_values=c(k_values, opt4$par[2])
  RMSE=c(RMSE, opt4$value)
  d_time_nonrel$pred=discount(V = opt4$par[1], k = opt4$par[2],N = d_time_nonrel$soc_dist)
  cor4=cor.test(d_time_nonrel$med_amnt, d_time_nonrel$pred)
  R_sq=c(R_sq, (cor4$estimate)^2)

}

#Add all vectors to one dataset
med_smry=as.data.frame(cbind(`Age group`=age_group, Donation=donation, Kinship=kinship, V=V_values, k=k_values, `R sqr`=R_sq, RMSE), row.names = F)%>%mutate(V=as.character(V), k=as.character(k), `R sqr`=as.character(`R sqr`), RMSE=as.character(RMSE))%>%mutate(V=as.numeric(V), k=as.numeric(k), `R sqr`=as.numeric(`R sqr`), RMSE=as.numeric(RMSE))

kable(med_smry, digits = 2, align = "c", caption = "Estimated Parameters and Goodness-of-fit Indices of the Hyperbolic Functions, group median values")
Estimated Parameters and Goodness-of-fit Indices of the Hyperbolic Functions, group median values
Age group Donation Kinship V k R sqr RMSE
younger money rel 55.16 0.03 0.90 6.03
younger money nonrel 66.35 0.17 0.89 8.48
younger time rel 78.95 0.06 0.94 6.39
younger time nonrel 121.65 0.25 0.97 5.37
older money rel 84.67 0.53 0.91 7.42
older money nonrel 300.00 5.20 0.96 4.93
older time rel 165.03 0.51 0.95 10.66
older time nonrel 300.00 2.29 0.98 7.04
  1. Fit hyperbolic discount function to individual data and calculate k and AUC values for each participant in each condition
#Create the empty dataframe, in which each participant have 4 rows
df2=as.data.frame(cbind(
  id=rep(unique(og_lng2$id),4),
  age_group=c(),
  gender=c(),
  education=c(),
  income=c(),
  social_network_size=c(),
  ethnicity=c(),
  kinship=c(),
  donation=c(),
  k=c(),
  AUC=c()
))

#Fill in values for demographics (age, age group, gender, education, income, social_network_size)
for (i in unique(df2$id)){
  df_sub=filter(df_og2, id==i)
  df2[df2$id==i, 'age']=df_sub$age
  df2[df2$id==i, 'age_group']=df_sub$age_group
  df2[df2$id==i, 'gender']=df_sub$gender
  df2[df2$id==i, 'education']=df_sub$education
  df2[df2$id==i, 'income']=df_sub$income
  df2[df2$id==i, 'social_network_size']=df_sub$social_network_size
  df2[df2$id==i, 'ethnicity']=df_sub$ethnicity
}
df2=as.data.frame(cbind(
  id=rep(unique(og_lng2$id),4),
  age_group=c(),
  gender=c(),
  education=c(),
  income=c(),
  social_network_size=c(),
  ethnicity=c(),
  kinship=c(),
  donation=c(),
  k=c(),
  AUC=c()
))

#Fill in values for demographics
for (i in unique(df2$id)){
  df_sub=filter(df_og2, id==i)
  df2[df2$id==i, 'age']=df_sub$age
  df2[df2$id==i, 'age_group']=df_sub$age_group
  df2[df2$id==i, 'gender']=df_sub$gender
  df2[df2$id==i, 'education']=df_sub$education
  df2[df2$id==i, 'income']=df_sub$income
  df2[df2$id==i, 'social_network_size']=df_sub$social_network_size
  df2[df2$id==i, 'ethnicity']=df_sub$ethnicity
}
#for each individual, extract values for donation * kinship conditions

#set variable soc_dist in og_lng2 to be numeric
og_lng2$soc_dist=as.character(og_lng2$soc_dist)
og_lng2$soc_dist=as.numeric(og_lng2$soc_dist)
is.numeric(og_lng2$soc_dist)
## [1] TRUE
#Get length of number of participants (n) as value
n_p=length(unique(df2$id))

#Create 4 temporary df's to store values from each iteration
df2_mr=df2[1:n_p,] #-> for money_relative
df2_mnr=df2[(n_p+1):(n_p*2),] #->for money_nonrelative
df2_tr=df2[(2*n_p+1):(n_p*3),] #->for time_relative
df2_tnr=df2[(3*n_p+1):(n_p*4),] #->for time_nonrel


#run discount wrapper for each subject in 2*2 conditions
for(i in unique(df2$id)){
  #money relative
  d_mon_rel=og_lng2%>%filter(id==i, donation=="money", kinship=="rel") #-> create temp df to get values from
  df2_mr[df2_mr$id==i, 'donation']="money" #-> store the appropriate donation
  df2_mr[df2_mr$id==i, 'kinship']="rel" #-> store the appropriate kinship
  
  optim_discount_wrapper <- function(x) { #-> define discount wrapper to get V, k, and RMSE values for this                                                      condition
  return(data_vs_discount(V = x[1], k = x[2],  
                          N = d_mon_rel$soc_dist, 
                          amount = d_mon_rel$amount))
}

  opt1=optim(c(100, 0.2), optim_discount_wrapper, method = "L-BFGS-B", lower=c(0,0), upper=c(300,100)) #-> run discount_wrapper
  df2_mr[df2_mr$id==i, 'k']=opt1$par[2] #-> store resulting k_value
  df2_mr[df2_mr$id==i, 'V']=opt1$par[1] #-> store resulting V_value

  # Get AUC value - using WolframAlpha, the integral of this discount function is:
# V/k*ln(abs(1+k*n))+c -> we don't really care about c for AUC.
  k=opt1$par[2]
  V=opt1$par[1]

  #Evaluate for upper bound
  up=V/k*log(abs(1+k*100))
  lower=V/k*log(abs(1+k*0))

  df2_mr[df2_mr$id==i,'AUC']=up-lower
  
#money nonrelative
  d_mon_nonrel=og_lng2%>%filter(id==i, donation=="money", kinship=="nonrel") 
  df2_mnr[df2_mnr$id==i, 'donation']="money" 
  df2_mnr[df2_mnr$id==i, 'kinship']="nonrel" 
  
  optim_discount_wrapper <- function(x) { 
  return(data_vs_discount(V = x[1], k = x[2],  
                          N = d_mon_nonrel$soc_dist, 
                          amount = d_mon_nonrel$amount))
}

  opt2=optim(c(100, 0.2), optim_discount_wrapper, method = "L-BFGS-B", lower=c(0,0), upper=c(300,100)) 
  df2_mnr[df2_mnr$id==i, 'k']=opt2$par[2] 
  df2_mnr[df2_mnr$id==i, 'V']=opt2$par[1]

  # Get AUC value 
  k=opt2$par[2]
  V=opt2$par[1]

  #Evaluate for upper bound
  up=V/k*log(abs(1+k*100))
  lower=V/k*log(abs(1+k*0))

  df2_mnr[df2_mnr$id==i,'AUC']=up-lower
  
#time relative
  d_time_rel=og_lng2%>%filter(id==i, donation=="time", kinship=="rel")
  df2_tr[df2_tr$id==i, 'donation']="time" 
  df2_tr[df2_tr$id==i, 'kinship']="rel" 
  
  optim_discount_wrapper <- function(x) { 
  return(data_vs_discount(V = x[1], k = x[2],  
                          N = d_time_rel$soc_dist, 
                          amount = d_time_rel$amount))
}

  opt3=optim(c(100, 0.2), optim_discount_wrapper, method = "L-BFGS-B", lower=c(0,0), upper=c(300,100)) 
  df2_tr[df2_tr$id==i, 'k']=opt3$par[2]
  df2_tr[df2_tr$id==i, 'V']=opt3$par[1]

  # Get AUC value 
  k=opt3$par[2]
  V=opt3$par[1]

  #Evaluate for upper bound
  up=V/k*log(abs(1+k*100))
  lower=V/k*log(abs(1+k*0))

  df2_tr[df2_tr$id==i,'AUC']=up-lower
  
#time nonrelative
  d_time_nonrel=og_lng2%>%filter(id==i, donation=="time", kinship=="nonrel")
  df2_tnr[df2_tnr$id==i, 'donation']="time" 
  df2_tnr[df2_tnr$id==i, 'kinship']="nonrel" 
  
  optim_discount_wrapper <- function(x) { 
  return(data_vs_discount(V = x[1], k = x[2],  
                          N = d_time_nonrel$soc_dist, 
                          amount = d_time_nonrel$amount))
}

  opt4=optim(c(100, 0.2), optim_discount_wrapper, method = "L-BFGS-B", lower=c(0,0), upper=c(300,100)) 
  df2_tnr[df2_tnr$id==i, 'k']=opt4$par[2]
  df2_tnr[df2_tnr$id==i, 'V']=opt4$par[1]

  # Get AUC value 
  k=opt4$par[2]
  V=opt4$par[1]

  #Evaluate for upper bound
  up=V/k*log(abs(1+k*100))
  lower=V/k*log(abs(1+k*0))

  df2_tnr[df2_tnr$id==i,'AUC']=up-lower
}

#Combine all into one dataframe (df2)
df2=full_join(df2_mr, df2_mnr)%>%full_join(df2_tr)%>%full_join(df2_tnr)
## Joining with `by = join_by(id, age, age_group, gender, education, income,
## social_network_size, ethnicity, donation, kinship, k, V, AUC)`
## Joining with `by = join_by(id, age, age_group, gender, education, income,
## social_network_size, ethnicity, donation, kinship, k, V, AUC)`
## Joining with `by = join_by(id, age, age_group, gender, education, income,
## social_network_size, ethnicity, donation, kinship, k, V, AUC)`
df2_plot_pred=df2
  1. Exclude participants whose data does not fit hyperbolic discount function
  2. Normalise individual k and AUC values via natural log transformation
  3. Exclude individuals with transformed values that exceed ±3 SDs
  4. Correlational analyses on demographic variables and transformed individual k/AUC values
#recode all NaN AUC values as missing data (NA)
for(i in 1:length(df2$id)){
  if(is.nan(df2$AUC[i])){df2$AUC[i]=NA}else{df2$AUC[i]=df2$AUC[i]}
}

#Negative or zero AUC or k values (indicating a problem with the fitting process)
df2$AUC=recode(df2$AUC, "lo:0.01=NA")
df2$k=recode(df2$k, "lo:0.01=NA")

#check if AUC is normally distributed
AUc_hist=ggplot(data=df2, aes(x=AUC))+geom_histogram() #-> strong positive skew
logAUC_hist=ggplot(data = df2, aes(x=log(AUC)))+geom_histogram() #-> looks better

#check if k is normally distributed
k_hist=ggplot(data=df2, aes(x=k))+geom_histogram() #-> strong positive skew
log_k_hist=ggplot(data = df2, aes(x=log(k)))+geom_histogram() #-> looks better

#Since Gong et al., used log(AUC) and log(k) for their analysis, I shall do the same
df2$logAUC=log(df2$AUC)
df2$log_k=log(df2$k)

#compute +/- 3 S.D for logAUC and log_k values
logAUC_hi=mean(df2$logAUC, na.rm=T)+(3*sd(df2$logAUC, na.rm = T))
logAUC_lo=mean(df2$logAUC, na.rm=T)-(3*sd(df2$logAUC, na.rm = T))

log_k_hi=mean(df2$log_k, na.rm=T)+(3*sd(df2$logAUC, na.rm = T))
log_k_lo=mean(df2$log_k, na.rm=T)-(3*sd(df2$logAUC, na.rm = T))

#df2=df2%>%filter(k<=(mean(k)+3*sd(k)) & k>=(mean(k)-3*sd(k)) & AUC<=(mean(AUC)+3*sd(AUC))& AUC>=(mean(AUC)-3*sd(AUC))) #-> retain only observations that meet criteria

#recode all observations outside of the +/- 3 S.D range as missing values
df2$logAUC[df2$logAUC<logAUC_lo]=NA
df2$logAUC[df2$logAUC>logAUC_hi]=NA

df2$log_k[df2$log_k<log_k_lo]=NA
df2$log_k[df2$log_k>log_k_hi]=NA


#check that the minimal values are not lower than k and AUC "_low"'s, and maximal not higher than "_high"'s
min(df2$log_k, na.rm = T)<log_k_lo; max(df2$log_k,na.rm = T)>log_k_hi; min(df2$logAUC,na.rm = T)<logAUC_lo; max(df2$logAUC,na.rm = T)>logAUC_hi
## [1] FALSE
## [1] FALSE
## [1] FALSE
## [1] FALSE
#Change id to factor
is.numeric(df2$id) #-> true
## [1] TRUE
df2$id=as.character(df2$id); df2$id=as.factor(df2$id)
is.factor(df2$id)#-> true
## [1] TRUE
summary(df2$age_group); summary(df2$donation); summary(df2$kinship) 
## younger   older 
##       8       4
##    Length     Class      Mode 
##        12 character character
##    Length     Class      Mode 
##        12 character character
# check that predictors are factors and AUC is numeric
is.factor(df2$age_group); is.factor(df2$donation); is.factor(df2$kinship) #-> age_group yes, others no
## [1] TRUE
## [1] FALSE
## [1] FALSE
is.character(df2$donation)#-> true
## [1] TRUE
df2$donation=as.factor(df2$donation); is.factor(df2$donation)
## [1] TRUE
is.character(df2$kinship)#-> true
## [1] TRUE
df2$kinship=as.factor(df2$kinship); is.factor(df2$kinship)
## [1] TRUE
is.numeric(df2$logAUC)#-> True
## [1] TRUE
## Remove all observations of subjects with outliers

na_counts=df2%>%group_by(id)%>%summarise(naAUC_counts=sum(is.na(logAUC)),na_k_counts=sum(is.na(log_k)))%>%ungroup()

for (i in unique(df2$id)){
  temp=filter(na_counts, id==i)
  df2[df2$id==i, 'naAUC_counts']=temp$naAUC_counts
  df2[df2$id==i, 'na_k_counts']=temp$na_k_counts
}

df2_noNA_AUC=df2%>%filter(naAUC_counts==0)
df2_noNA_k=df2%>%filter(na_k_counts==0)

Confirmatory analysis

  1. 2 (age: younger vs older) × 2 (donation form: money vs time) × 2 (kinship: relatives vs non-relatives) mixed design, repeated measures ANOVA of transformed individual AUC values, with demographic variables as control + post-hoc tests if applicable
  2. 2 (age: younger vs older) × 2 (donation form: money vs time) × 2 (kinship: relatives vs non-relatives) mixed design, repeated measures ANOVA of transformed individual AUC values, without demographic variables as control + post-hoc tests if applicable
  3. 2 (age: younger vs older) × 2 (donation form: money vs time) × 2 (kinship: relatives vs non-relatives) mixed design, repeated measures ANOVA of transformed individual k values, with demographic variables as control + post-hoc tests if applicable
  4. 2 (age: younger vs older) × 2 (donation form: money vs time) × 2 (kinship: relatives vs non-relatives) mixed design, repeated measures ANOVA of transformed individual k values, without demographic variables as control + post-hoc tests if applicable
#AUC without covariates
anova_AUC1=ezANOVA(data = df2_noNA_AUC, wid=.(id), dv=na.omit(logAUC), within  = .(donation, kinship), between = .(age_group), type = 3, observed = .(age_group))
## Warning: Data is unbalanced (unequal N per group). Make sure you specified a
## well-considered value for the type argument to ezANOVA().
kable(anova_AUC1$ANOVA)
Effect DFn DFd F p p<.05 ges
2 age_group 1 1 0.0139420 0.9251768 0.0095837
3 donation 1 1 0.6048178 0.5791976 0.1113435
5 kinship 1 1 0.0245129 0.9011297 0.0009335
4 age_group:donation 1 1 0.1827065 0.7428457 0.0378495
6 age_group:kinship 1 1 0.2752470 0.6924078 0.0104922
7 donation:kinship 1 1 0.1553131 0.7610079 0.0012874
8 age_group:donation:kinship 1 1 0.1324978 0.7777596 0.0010997
#AUC with covariates
anova_AUC2=ezANOVA(data = df2_noNA_AUC, wid=.(id), dv=na.omit(logAUC), within  = .(donation, kinship), between = .(age_group), between_covariates = .(gender, social_network_size) ,type = 3, observed = .(age_group))
## Warning: Data is unbalanced (unequal N per group). Make sure you specified a
## well-considered value for the type argument to ezANOVA().
## Warning: Implementation of ANCOVA in this version of ez is experimental and not
## yet fully validated. Also, note that ANCOVA is intended purely as a tool to
## increase statistical power; ANCOVA can not eliminate confounds in the data.
## Specifically, covariates should: (1) be uncorrelated with other predictors and
## (2) should have effects on the DV that are independent of other predictors.
## Failure to meet these conditions may dramatically increase the rate of
## false-positives.
## Warning: Covariate"gender" is numeric and will therefore be fit to a linear
## effect.
## Warning: Covariate"social_network_size" is numeric and will therefore be fit to
## a linear effect.
kable(anova_AUC2$ANOVA)
Effect DFn DFd F p p<.05 ges
2 age_group 1 1 3.5490049 0.3106692 0.5398670
3 donation 1 1 0.6048178 0.5791976 0.1129715
5 kinship 1 1 0.0245129 0.9011297 0.0009489
4 age_group:donation 1 1 0.1827065 0.7428457 0.0384734
6 age_group:kinship 1 1 0.2752470 0.6924078 0.0106651
7 donation:kinship 1 1 0.1553131 0.7610079 0.0013086
8 age_group:donation:kinship 1 1 0.1324978 0.7777596 0.0011178
#k value without covariates
anova_k1=ezANOVA(data = df2_noNA_k, wid=.(id), dv=na.omit(log_k), within  = .(donation, kinship), between = .(age_group), type = 3, observed = .(age_group))
## Warning: Data is unbalanced (unequal N per group). Make sure you specified a
## well-considered value for the type argument to ezANOVA().
kable(anova_k1$ANOVA)
Effect DFn DFd F p p<.05 ges
2 age_group 1 1 0.0275096 0.8953628 0.0214806
3 donation 1 1 0.7334202 0.5491474 0.0407098
5 kinship 1 1 0.9306530 0.5114358 0.0465314
4 age_group:donation 1 1 0.2151666 0.7235031 0.0124501
6 age_group:kinship 1 1 0.6915613 0.5583670 0.0362646
7 donation:kinship 1 1 0.0091784 0.9391949 0.0002630
8 age_group:donation:kinship 1 1 0.3490176 0.6602931 0.0100028
#AUC with covariates
anova_k2=ezANOVA(data = df2_noNA_k, wid=.(id), dv=na.omit(log_k), within  = .(donation, kinship), between = .(age_group), between_covariates = .(gender, social_network_size) ,type = 3, observed = .(age_group))
## Warning: Data is unbalanced (unequal N per group). Make sure you specified a
## well-considered value for the type argument to ezANOVA().
## Warning: Implementation of ANCOVA in this version of ez is experimental and not
## yet fully validated. Also, note that ANCOVA is intended purely as a tool to
## increase statistical power; ANCOVA can not eliminate confounds in the data.
## Specifically, covariates should: (1) be uncorrelated with other predictors and
## (2) should have effects on the DV that are independent of other predictors.
## Failure to meet these conditions may dramatically increase the rate of
## false-positives.
## Warning: Covariate"gender" is numeric and will therefore be fit to a linear
## effect.
## Warning: Covariate"social_network_size" is numeric and will therefore be fit to
## a linear effect.
kable(anova_k2$ANOVA)
Effect DFn DFd F p p<.05 ges
2 age_group 1 1 22.8777267 0.1312087 0.7651173
3 donation 1 1 0.7334202 0.5491474 0.0414521
5 kinship 1 1 0.9306530 0.5114358 0.0473746
4 age_group:donation 1 1 0.2151666 0.7235031 0.0126869
6 age_group:kinship 1 1 0.6915613 0.5583670 0.0369544
7 donation:kinship 1 1 0.0091784 0.9391949 0.0002680
8 age_group:donation:kinship 1 1 0.3490176 0.6602931 0.0101931

Three-panel graph with original, 1st replication, and your replication is ideal here

Exploratory analyses

Any follow-up analyses desired (not required).

Discussion

Mini meta analysis

Combining across the original paper, 1st replication, and 2nd replication, what is the aggregate effect size?

Summary of Replication Attempt

Open the discussion section with a paragraph summarizing the primary result from the confirmatory analysis and the assessment of whether it replicated, partially replicated, or failed to replicate the original result.

Commentary

Add open-ended commentary (if any) reflecting (a) insights from follow-up exploratory analysis, (b) assessment of the meaning of the replication (or not) - e.g., for a failure to replicate, are the differences between original and present study ones that definitely, plausibly, or are unlikely to have been moderators of the result, and (c) discussion of any objections or challenges raised by the current and original authors about the replication attempt. None of these need to be long.