You have one continuous outcome and two groups — control vs treatment — and you want to know whether their mean pain scores differ. This is the independent-samples t-test, written here as a regression on a single binary predictor: pain_score ~ treatment.

Variations

  • Smaller or larger gap. The effect is on the binary benchmark scale — swap treatment=0.50 (medium) for treatment=0.20 (small) or treatment=0.80 (large) to see how the expected separation moves power.
  • Unbalanced groups. If you expect a lopsided split rather than 50/50, set the treatment proportion when you declare the variable type (e.g. a 30/70 allocation) — unbalanced cells cost power for the same total N.
  • Solve for N instead. Replace find_power(sample_size=120, …) with find_sample_size(target_test="treatment", from_size=30, to_size=300, by=10) to get the minimum N that reaches 80% power.
  • Same design, other fields:
    • Ecology: abundance ~ habitat — does species abundance differ between two habitat types (disturbed vs undisturbed)?
    • Social science: wage ~ gender — does wage differ between two gender groups?

Not this setup?

If you'd rather have…

Copy-paste setup

from mcpower import MCPower

# Two-group mean comparison: does pain_score differ between the two treatment groups?
model = MCPower("pain_score = treatment")

# treatment is a binary two-level predictor (0 = control, 1 = treatment).
model.set_variable_type("treatment=binary")

# Expected effect on the binary benchmark scale: 0.50 = a medium group gap.
model.set_effects("treatment=0.50")

model.find_power(sample_size=120, target_test="treatment")
suppressMessages(library(mcpower))

# Two-group mean comparison: does pain_score differ between the two treatment groups?
model <- MCPower$new("pain_score ~ treatment")

# treatment is a binary two-level predictor (0 = control, 1 = treatment).
model$set_variable_type("treatment=binary")

# Expected effect on the binary benchmark scale: 0.50 = a medium group gap.
model$set_effects("treatment=0.50")

invisible(model$find_power(sample_size = 120, target_test = "treatment"))