##Part 1: Analysis

##################### construct data frame
strangers_wide = data.frame(person1 = c(25, 40, 38, 66, 60, 76, 65, 70, 
    65), person2 = c(48, 45, 42, 75, 55, 70, 60, 65, 55), condition = c(rep("competitive", 
    3), rep("cooperative", 3), rep("independent", 3)), stringsAsFactors = F)
##################### 

############## coding scheme use helmert contrast coding scheme where inde = 2/3 if
############## independent, -1/3 else ...where comp.coop = 0 if independent, 1/2 if
############## competitive and -1/2 if cooperative

strangers_wide$inde = 2/3 * (strangers_wide$condition == "independent") - 
    1/3 * (strangers_wide$condition != "independent")
strangers_wide$comp.coop = 0 * (strangers_wide$condition == "independent") + 
    1/2 * (strangers_wide$condition == "competitive") - 1/2 * (strangers_wide$condition == 
    "cooperative")
############## 

################################### calculate w0 and ave for each pair
strangers_wide$w0 = (strangers_wide$person1 + strangers_wide$person2)/sqrt(2)
strangers_wide$ave = (strangers_wide$person1 + strangers_wide$person2)/2
################################### 
library(kableExtra)
## Warning: package 'kableExtra' was built under R version 3.6.3
socialModel = lm(strangers_wide$w0 ~ strangers_wide$inde + strangers_wide$comp.coop)
mcSummary(socialModel)
## Loading required package: car
## Warning: package 'car' was built under R version 3.6.3
## Loading required package: carData
## Warning: package 'carData' was built under R version 3.6.3
## lm(formula = strangers_wide$w0 ~ strangers_wide$inde + strangers_wide$comp.coop)
## 
## Omnibus ANOVA
##                  SS df       MS EtaSq     F     p
## Model      2641.333  2 1320.667 0.877 21.32 0.002
## Error       371.667  6   61.944                  
## Corr Total 3013.000  8  376.625                  
## 
##  RMSE AdjEtaSq
##  7.87    0.836
## 
## Coefficients
##                              Est StErr      t    SSR(3) EtaSq tol  CI_2.5
## (Intercept)               80.139 2.623 30.547 57800.000 0.994  NA  73.719
## strangers_wide$inde       14.142 5.565  2.541   400.000 0.518   1   0.524
## strangers_wide$comp.coop -38.655 6.426 -6.015  2241.333 0.858   1 -54.380
##                          CI_97.5     p
## (Intercept)               86.558 0.000
## strangers_wide$inde       27.760 0.044
## strangers_wide$comp.coop -22.931 0.001
strangers_wide$within.residuals = (strangers_wide$person1 - strangers_wide$ave)^2 + 
    (strangers_wide$person2 - strangers_wide$ave)^2
sum(strangers_wide$within.residuals)  #SS within
## [1] 431
MSE.within = sum(strangers_wide$within.residuals)/9  #MSE within
MSE.between = 1320.667

# compute means
cooperativeAve = (sum(strangers_wide$person1[strangers_wide$condition == 
    "cooperative"]) + sum(strangers_wide$person1[strangers_wide$condition == 
    "cooperative"]))/6  #67.333

compAve = (sum(strangers_wide$person1[strangers_wide$condition == "competitive"]) + 
    sum(strangers_wide$person1[strangers_wide$condition == "competitive"]))/6  #34.333

################################################### pull results from output to construct source table
mySource = data.frame(source = c("Between (omnibus)", "inde", "comp.coop", 
    "Error", "Total - Betwen", "Within - pair", "Total - overall"), SS = c(2641.333, 
    400, 2241.333, 371.667, 3013, 431, 3444), df = c(2, 1, 1, 6, 8, 9, 
    17), MS = c(1320.667, 400, 2241.333, 371.667, "-", 47.889, "-"), F = c(21.32, 
    6.456, 36.18, "-", "-", "-", "-"), PRE = c(0.877, 0.518, 0.858, "-", 
    "-", "-", "-"), p = c(0.002, 0.044, 0.001, "-", "-", "-", "-"))

knitr::kable(mySource, digits = 3, align = "lcccc") %>% kable_styling("striped")
source SS df MS F PRE p
Between (omnibus) 2641.333 2 1320.667 21.32 0.877 0.002
inde 400.000 1 400 6.456 0.518 0.044
comp.coop 2241.333 1 2241.333 36.18 0.858 0.001
Error 371.667 6 371.667
Total - Betwen 3013.000 8
Within - pair 431.000 9 47.889
Total - overall 3444.000 17
ICC = (MSE.between - MSE.within)/(MSE.between + MSE.within)  #ICC = .930

##Part 2: Summary

To examine whether scores of stranger closeness depended on setting (that is, the independent, competitive and cooperation conditions), a nested, repeated-measures ANOVA was conducted. In this model, condition type considered between partner pairs significantly predicted averages of partner closeness (F = 21.32, PRE = .877, p = .002). Additionally, there was a significant effect of cooperative/competitive condition (F = 36.180, PRE = .858, p = .001) with higher averages in the cooperative condition (M = 67.333) than in the competitive condition (M = 34.333)

Within pair error (MSE - within = 47.889) was minimal compared to that between groups (MSE - between = 1320.667), resulting in a substantially positive ICC of .930. As such, this ICC indicates that scores tended to be much more similar within groups than between. Therefore, if dependence within partner pairs were not accounted for, the F* values for each predictor would have been substantially inflated. Put another way, since the scores within groups exhibited substantial non-independence, their associated errors in the augmented model containing the two condition predictors would have been related (e.g.ย both errors very small) and therefore not representative of the true model error. In such cases when model error is deflated, the F statistic of the corresponding model is inflated.