Note. Boxplots display the interquartile range (IQR, center box), and the whiskers extend 1.5*IQR from the lower and upper hinge. The white point indicates the mean and the white center line indicates the median.


Data Import

load("data/wrangled.RData")

Extract Effects for Simulation

Prepare Data

# TBD

ML Regression

Run multilevel regression to extract the effect sizes and covariance matrices

# run regresion 
lmer_quality_contemporary <-
  lmer(
    quality_overall_1 ~ 
      keymotive_fulfillemt_1_cwc + (1 + keymotive_fulfillemt_1_cwc | PID),
    data = dtWorkerSupp$workerOutWithinBetween
  )
lmer_attitude_contemporary <-
  lmer(
    thermometerDutch_1 ~ 
      keymotive_fulfillemt_1_cwc + (1 + keymotive_fulfillemt_1_cwc | PID),
    data = dtWorkerSupp$workerOutWithinBetween
  )
lmer_attitude_need_quality_contemporary <-
  lmer(
    thermometerDutch_1 ~
      keymotive_fulfillemt_1_cwc + quality_overall_1_cwc + (1 + keymotive_fulfillemt_1_cwc + quality_overall_1_cwc | PID),
    data = dtWorkerSupp$workerOutWithinBetween
  )

For the main analyses we have four fixed effects of interest. (1) The effect of need fulfillment on interaction quality: b = 0.433, (2) the effect of need fulfillment on outgroup attitudes: b = 0.175, (3) the effect of need fulfillment on outgroup attitudes while controlling for interaction quality: b = 0.037, as well as (4) the effect of interaction quality on outgroup attitudes while controlling for need fulfillment: b = 0.226.

Power Simulation Parameters

nsim <- 1000
progress <- FALSE
n_ppt <- 250
n_measure <- 180 # 3 months with 2 measurements per day

# extrapolate data:
sim_n_quality <- extend(lmer_quality_contemporary, along="PID", n = n_ppt)
sim_n_attitude <- extend(lmer_attitude_contemporary, along="PID", n = n_ppt)
sim_n_attitude_full <- extend(lmer_attitude_need_quality_contemporary, along="PID", n = n_ppt)

# extrapolate data:
sim_t_quality <- extend(lmer_quality_contemporary, within="PID", n = n_measure)
sim_t_attitude <- extend(lmer_attitude_contemporary, within="PID", n = n_measure)
sim_t_attitude_full <- extend(lmer_attitude_need_quality_contemporary, within="PID", n = n_measure)

Power Simulation Participant Numbers

Simulate different participant numbers for all fixed effects.

Power of Quality ~ NeedFulfill for different numbers of participants

# Run and plot simulations
pc_n_quality_need = powerCurve(
  fit = sim_n_quality,
  test = simr::fixed("keymotive_fulfillemt_1_cwc", "t"),
  along = "PID",
  progress = progress,
  breaks = seq(1, 12, 1),
  nsim = nsim
)
plot(pc_n_quality_need) +
  title("Quality given Need Fulfillment [participant numbers]")

## integer(0)

Power of Attitude ~ NeedFulfill for different numbers of participants

# Run and plot simulations
pc_n_attitude_need = powerCurve(
  fit = sim_n_attitude,
  test = simr::fixed("keymotive_fulfillemt_1_cwc", "t"),
  along = "PID",
  progress = progress,
  breaks = seq(1, 45, 1),
  nsim = nsim
)
plot(pc_n_attitude_need) +
  title("Attitudes given Need Fulfillment [participant numbers]")

## integer(0)

Power of Attitude ~ NeedFulfill + Quality for different numbers of participants

we expect this to be super small. Keep in mind that the b = 0.037. So even with a large number of participants, we would not expect these effects to be meaningful.

# Run and plot simulations
pc_n_attitude_need = powerCurve(
  fit = sim_n_attitude_full,
  test = simr::fixed("keymotive_fulfillemt_1_cwc", "t"),
  along = "PID",
  progress = progress,
  breaks = seq(10, 250, 10),
  nsim = nsim
)
plot(pc_n_attitude_need) +
  title("Attitudes given Need Fulfillment (controling for Quality) [participant numbers]")

## integer(0)

Power of Attitude ~ Quality given NeedFulfill for different numbers of participants

# Run and plot simulations
pc_n_attitude_full_quality = powerCurve(
  fit = sim_t_attitude_full,
  test = simr::fixed("quality_overall_1_cwc", "t"),
  along = "PID",
  progress = progress,
  breaks = seq(1, 25, 1),
  nsim = nsim
)
plot(pc_n_attitude_full_quality) +
  title("Attitudes given Quality (controlling for Need Fulfillment) [participant numbers]")

## integer(0)

Power Simulation Measurement Numbers

Simulate different number of within person measurements.

Power of Quality ~ NeedFulfill for different numbers of measurements

# Run and plot simulations
pc_t_quality_need = powerCurve(
  fit = sim_t_quality,
  test = simr::fixed("keymotive_fulfillemt_1_cwc", "t"),
  within = "PID",
  progress = progress,
  breaks = seq(1, 20, 1),
  nsim = nsim
)
plot(pc_t_quality_need) +
  title("Quality given Need Fulfillment [measurement numbers]")

## integer(0)

Power of Attitude ~ NeedFulfill for different numbers of measurements

# Run and plot simulations
pc_t_attitude_need = powerCurve(
  fit = sim_t_attitude,
  test = simr::fixed("keymotive_fulfillemt_1_cwc", "t"),
  within = "PID",
  progress = progress,
  breaks = seq(1, 25, 1),
  nsim = nsim
)
plot(pc_t_attitude_need) +
  title("Attitudes given Need Fulfillment [measurement numbers]")

## integer(0)

Power of Attitude ~ NeedFulfill given Quality for different numbers of measurements

we expect this to be super small. Keep in mind that the b = 0.037. So even with a large number of measurements, we would not expect these effects to be meaningful.

# Run and plot simulations
pc_t_attitude_full_need = powerCurve(
  fit = sim_t_attitude_full,
  test = simr::fixed("keymotive_fulfillemt_1_cwc", "t"),
  within = "PID",
  progress = progress,
  breaks = seq(10, 180, 10),
  nsim = nsim
)
plot(pc_t_attitude_full_need) +
  title("Attitudes given Need Fulfillment (controlling for Quality) [measurement numbers]")

## integer(0)

Power of Attitude ~ Quality given NeedFulfill for different numbers of measurements

# Run and plot simulations
pc_t_attitude_full_quality = powerCurve(
  fit = sim_t_attitude_full,
  test = simr::fixed("quality_overall_1_cwc", "t"),
  within = "PID",
  progress = progress,
  breaks = seq(1, 15, 1),
  nsim = nsim
)
plot(pc_t_attitude_full_quality) +
  title("Attitudes given Quality (controlling for Need Fulfillment) [measurement numbers]")

## integer(0)

Export data and plots

# save simulations, because this takes for freakin' ever.      
save(list = ls(pattern = "plt."), 
     file = "data/S1_Workers/processed/PowerSimPlots.RData")

#load("PowerSimPlots.RData")

Software Information

The full session information with all relevant system information and all loaded and installed packages is available in the collapsible section below.

System Info
Table 1: R environment session info for reproducibility of results
Setting Value
version R version 4.3.0 (2023-04-21)
os macOS Ventura 13.3.1
system x86_64, darwin20
ui X11
language (EN)
collate en_US.UTF-8
ctype en_US.UTF-8
tz Europe/Amsterdam
date 2023-05-19
pandoc 3.1.1 @ /usr/local/bin/ (via rmarkdown)

Package Info
Table 2: Package info for reproducibility of results
Package Loaded version Date Source
binom 1.1-1.1 2022-05-02 CRAN (R 4.3.0)
bookdown 0.34 2023-05-09 CRAN (R 4.3.0)
brms 2.19.0 2023-03-14 CRAN (R 4.3.0)
car 3.1-2 2023-03-30 CRAN (R 4.3.0)
carData 3.0-5 2022-01-06 CRAN (R 4.3.0)
data.table 1.14.8 2023-02-17 CRAN (R 4.3.0)
devtools 2.4.5 2022-10-11 CRAN (R 4.3.0)
dplyr 1.1.2 2023-04-20 CRAN (R 4.3.0)
ggpattern 1.0.1 2022-11-09 CRAN (R 4.3.0)
ggplot2 3.4.2 2023-04-03 CRAN (R 4.3.0)
ggridges 0.5.4 2022-09-26 CRAN (R 4.3.0)
ggthemes 4.2.4 2021-01-20 CRAN (R 4.3.0)
gridExtra 2.3 2017-09-09 CRAN (R 4.3.0)
haven 2.5.2 2023-02-28 CRAN (R 4.3.0)
Hmisc 5.1-0 2023-05-08 CRAN (R 4.3.0)
iterators 1.0.14 2022-02-05 CRAN (R 4.3.0)
kableExtra 1.3.4 2021-02-20 CRAN (R 4.3.0)
knitr 1.42 2023-01-25 CRAN (R 4.3.0)
lme4 1.1-33 2023-04-25 CRAN (R 4.3.0)
lmerTest 3.1-3 2020-10-23 CRAN (R 4.3.0)
lubridate 1.9.2 2023-02-10 CRAN (R 4.3.0)
Matrix 1.5-4 2023-04-04 CRAN (R 4.3.0)
pander 0.6.5 2022-03-18 CRAN (R 4.3.0)
papaja 0.1.1 2022-07-05 CRAN (R 4.3.0)
pbkrtest 0.5.2 2023-01-19 CRAN (R 4.3.0)
plotly 4.10.1 2022-11-07 CRAN (R 4.3.0)
plotrix 3.8-2 2021-09-08 CRAN (R 4.3.0)
plyr 1.8.8 2022-11-11 CRAN (R 4.3.0)
psych 2.3.3 2023-03-18 CRAN (R 4.3.0)
purrr 1.0.1 2023-01-10 CRAN (R 4.3.0)
RColorBrewer 1.1-3 2022-04-03 CRAN (R 4.3.0)
Rcpp 1.0.10 2023-01-22 CRAN (R 4.3.0)
remedy 0.1.0 2018-12-03 CRAN (R 4.3.0)
reshape2 1.4.4 2020-04-09 CRAN (R 4.3.0)
RLRsim 3.1-8 2022-03-16 CRAN (R 4.3.0)
rmarkdown 2.21 2023-03-26 CRAN (R 4.3.0)
sessioninfo 1.2.2 2021-12-06 CRAN (R 4.3.0)
simr 1.0.7 2023-04-13 CRAN (R 4.3.0)
stringi 1.7.12 2023-01-11 CRAN (R 4.3.0)
stringr 1.5.0 2022-12-02 CRAN (R 4.3.0)
testthat 3.1.8 2023-05-04 CRAN (R 4.3.0)
tibble 3.2.1 2023-03-20 CRAN (R 4.3.0)
tinylabels 0.2.3 2022-02-06 CRAN (R 4.3.0)
usethis 2.1.6 2022-05-25 CRAN (R 4.3.0)

Full Session Info (including loaded but unattached packages — for troubleshooting only)

R version 4.3.0 (2023-04-21)

Platform: x86_64-apple-darwin20 (64-bit)

locale: en_US.UTF-8||en_US.UTF-8||en_US.UTF-8||C||en_US.UTF-8||en_US.UTF-8

attached base packages:

  • grid
  • stats
  • graphics
  • grDevices
  • datasets
  • utils
  • methods
  • base

other attached packages:

  • purrr(v.1.0.1)
  • lubridate(v.1.9.2)
  • reshape2(v.1.4.4)
  • stringi(v.1.7.12)
  • papaja(v.0.1.1)
  • tinylabels(v.0.2.3)
  • Hmisc(v.5.1-0)
  • devtools(v.2.4.5)
  • usethis(v.2.1.6)
  • tibble(v.3.2.1)
  • plotly(v.4.10.1)
  • haven(v.2.5.2)
  • stringr(v.1.5.0)
  • kableExtra(v.1.3.4)
  • dplyr(v.1.1.2)
  • plyr(v.1.8.8)
  • pander(v.0.6.5)
  • sessioninfo(v.1.2.2)
  • jtools(v.2.2.1)
  • lmerTest(v.3.1-3)
  • data.table(v.1.14.8)
  • simr(v.1.0.7)
  • testthat(v.3.1.8)
  • car(v.3.1-2)
  • carData(v.3.0-5)
  • RLRsim(v.3.1-8)
  • plotrix(v.3.8-2)
  • pbkrtest(v.0.5.2)
  • lme4(v.1.1-33)
  • Matrix(v.1.5-4)
  • iterators(v.1.0.14)
  • binom(v.1.1-1.1)
  • ggridges(v.0.5.4)
  • ggpattern(v.1.0.1)
  • gridExtra(v.2.3)
  • RColorBrewer(v.1.1-3)
  • ggthemes(v.4.2.4)
  • ggplot2(v.3.4.2)
  • psych(v.2.3.3)
  • brms(v.2.19.0)
  • Rcpp(v.1.0.10)
  • bookdown(v.0.34)
  • remedy(v.0.1.0)
  • knitr(v.1.42)
  • rmarkdown(v.2.21)

loaded via a namespace (and not attached):

  • shinythemes(v.1.2.0)
  • splines(v.4.3.0)
  • later(v.1.3.1)
  • datawizard(v.0.7.1)
  • rpart(v.4.1.19)
  • xts(v.0.13.1)
  • lifecycle(v.1.0.3)
  • rprojroot(v.2.0.3)
  • StanHeaders(v.2.21.0-7)
  • processx(v.3.8.1)
  • lattice(v.0.21-8)
  • MASS(v.7.3-58.4)
  • insight(v.0.19.1)
  • crosstalk(v.1.2.0)
  • backports(v.1.4.1)
  • magrittr(v.2.0.3)
  • sass(v.0.4.6)
  • remotes(v.2.4.2)
  • jquerylib(v.0.1.4)
  • yaml(v.2.3.7)
  • httpuv(v.1.6.11)
  • pkgbuild(v.1.4.0)
  • minqa(v.1.2.5)
  • pkgload(v.1.3.2)
  • abind(v.1.4-5)
  • rvest(v.1.0.3)
  • nnet(v.7.3-18)
  • tensorA(v.0.36.2)
  • inline(v.0.3.19)
  • bridgesampling(v.1.1-2)
  • svglite(v.2.1.1)
  • codetools(v.0.2-19)
  • DT(v.0.27)
  • xml2(v.1.3.4)
  • tidyselect(v.1.2.0)
  • bayesplot(v.1.10.0)
  • farver(v.2.1.1)
  • effectsize(v.0.8.3)
  • matrixStats(v.0.63.0)
  • stats4(v.4.3.0)
  • base64enc(v.0.1-3)
  • webshot(v.0.5.4)
  • jsonlite(v.1.8.4)
  • Formula(v.1.2-5)
  • ellipsis(v.0.3.2)
  • emmeans(v.1.8.6)
  • systemfonts(v.1.0.4)
  • tools(v.4.3.0)
  • glue(v.1.6.2)
  • mnormt(v.2.1.1)
  • xfun(v.0.39)
  • mgcv(v.1.8-42)
  • distributional(v.0.3.2)
  • loo(v.2.6.0)
  • withr(v.2.5.0)
  • numDeriv(v.2016.8-1.1)
  • fastmap(v.1.1.1)
  • boot(v.1.3-28.1)
  • fansi(v.1.0.4)
  • shinyjs(v.2.1.0)
  • callr(v.3.7.3)
  • digest(v.0.6.31)
  • timechange(v.0.2.0)
  • R6(v.2.5.1)
  • mime(v.0.12)
  • estimability(v.1.4.1)
  • colorspace(v.2.1-0)
  • gtools(v.3.9.4)
  • markdown(v.1.6)
  • threejs(v.0.3.3)
  • utf8(v.1.2.3)
  • tidyr(v.1.3.0)
  • generics(v.0.1.3)
  • renv(v.0.14.0)
  • prettyunits(v.1.1.1)
  • httr(v.1.4.6)
  • htmlwidgets(v.1.6.2)
  • parameters(v.0.21.0)
  • pkgconfig(v.2.0.3)
  • dygraphs(v.1.1.1.6)
  • gtable(v.0.3.3)
  • brio(v.1.1.3)
  • htmltools(v.0.5.5)
  • profvis(v.0.3.8)
  • scales(v.1.2.1)
  • posterior(v.1.4.1)
  • rstudioapi(v.0.14)
  • coda(v.0.19-4)
  • checkmate(v.2.2.0)
  • nlme(v.3.1-162)
  • nloptr(v.2.0.3)
  • cachem(v.1.0.8)
  • zoo(v.1.8-12)
  • parallel(v.4.3.0)
  • miniUI(v.0.1.1.1)
  • foreign(v.0.8-84)
  • pillar(v.1.9.0)
  • vctrs(v.0.6.2)
  • shinystan(v.2.6.0)
  • urlchecker(v.1.0.1)
  • promises(v.1.2.0.1)
  • cluster(v.2.1.4)
  • xtable(v.1.8-4)
  • htmlTable(v.2.4.1)
  • evaluate(v.0.21)
  • mvtnorm(v.1.1-3)
  • cli(v.3.6.1)
  • compiler(v.4.3.0)
  • rlang(v.1.1.1)
  • crayon(v.1.5.2)
  • rstantools(v.2.3.1)
  • rematch2(v.2.1.2)
  • ps(v.1.7.5)
  • forcats(v.1.0.0)
  • fs(v.1.6.2)
  • rstan(v.2.21.8)
  • viridisLite(v.0.4.2)
  • munsell(v.0.5.0)
  • lazyeval(v.0.2.2)
  • colourpicker(v.1.2.0)
  • bayestestR(v.0.13.1)
  • Brobdingnag(v.1.2-9)
  • hms(v.1.1.3)
  • shiny(v.1.7.4)
  • highr(v.0.10)
  • fontawesome(v.0.5.1)
  • memoise(v.2.0.1)
  • igraph(v.1.4.2)
  • broom(v.1.0.4)
  • RcppParallel(v.5.1.7)
  • bslib(v.0.4.2)