powersim_workshop_2026/02_ttest/exercises-ttest1.md

2.3 KiB
Raw Blame History

Exercise: Power simulation and power curves for t-test

Temporal value asymmetry

“participants … were asked to imagine that they had agreed to spend 5 hr entering data into a computer and to indicate how much money it would be fair for them to receive. Some participants imagined that they had completed the work 1 month previously, and others imagined that they would complete the work 1 month in the future . . . Participants believed that they should receive 101% more money for work they would do 1 month later (M = \$125.04) than for identical work that they had done 1 month previously (M = \$62.20), t(119) = 2.22, p = .03, $d = 0.41$” (Caruso, Gilbert, and Wilson 2008, 797)

Plan a direct replication

  1. What is a plausible standard deviation? Hint: d = (M1 M2)/SD
  2. What is an interesting minimal effect size (in $, Euro, or min)?
  3. Simulate responses for 120 participants in both the past and the future condition, assuming normal distributions with the same variance. Use the standard deviation and the minimal effect size from 1. and 2.
  4. Parameter recovery: Repeat the simulation from 3. 2000 times to re-estimate the parameters (\mu_1, \mu_2, \sigma) from the simulated responses. Visualize the recovered parameters in box plots.
    Hint: SE = 2/\sqrt{n} \cdot SD, where n is the total sample size.
t <- t.test(x, y, mu = 0, var.equal = TRUE)
c(t$estimate, sd.pool = sqrt(n) / 2 * t$stderr)
  1. Power simulation: Increase the total sample size to find out the n necessary for 80% power for the t-test.
  2. Power curves:
    • Write an R function that takes sample size n, minimal effect d, standard deviation sd, and number of replications nrep as arguments. It should return the simulated power.
    • Use this function to simulate the power for each combination of 4 different standard deviations and 4 sample sizes.
    • Visualize these power curves in a single plot.

References

Caruso, E. M., D. T. Gilbert, and T. D. Wilson. 2008. “A Wrinkle in Time: Asymmetric Valuation of Past and Future Events.” Psychological Science 19 (8): 796801. https://doi.org/10.1111/j.1467-9280.2008.02159.x.