You ran a study that crosses two two-level factors — gender fully crossed with sector — and the question that motivated the design is not either main effect but whether they interact: does the effect of gender on job satisfaction differ by sector, or equivalently does the effect of sector differ by gender? That is the classic 2x2 factorial interaction, the difference in cell differences.

As an MCPower formula this is job_satisfaction ~ gender * sector, where * expands to gender + sector + gender:sector. Both gender and sector are two-level factors; the test of interest is the interaction term gender:sector.

Variations

  • Search for the N you need instead of scoring one design: swap find_power(sample_size=200, …) for find_sample_size(target_test="gender:sector", from_size=100, to_size=600, by=25). A 2x2 interaction needs markedly more N than either main effect, so set the upper bound generously.
  • Test the main effects too by setting target_test="gender" (or target_test="all" for every term plus the omnibus), if you also care about the average effects, not only the interaction.
  • Stronger or weaker moderation: move gender:sector across the factor benchmarks — 0.20 (subtle), 0.50 (medium), 0.80 (the two groups respond very differently) — to see how fast power for the interaction collapses as the effect shrinks.
  • A wider design: give one factor three or more levels with set_variable_type("sector=(factor,3)") — the interaction then spans several contrasts and demands still more N.
  • Same design, other fields:
    • Clinical: pain_score ~ treatment * site — does treatment effectiveness differ across clinical sites?
    • Ecology: abundance ~ habitat * nitrogen — does the nitrogen effect on species abundance differ between habitat types?

Not this setup?

If you'd rather have…

Copy-paste setup

from mcpower import MCPower

# 2x2 factorial: does the effect of `gender` depend on `sector`? '*' expands
# gender * sector to gender + sector + gender:sector, so the interaction
# (the difference in cell differences) is fitted explicitly.
model = MCPower("job_satisfaction = gender * sector")

# Both predictors are two-level factors: gender and sector.
model.set_variable_type("gender=binary, sector=binary")

# Effect sizes on the factor benchmark scale (0.20 / 0.50 / 0.80):
#   gender=0.50         -> medium main effect of gender.
#   sector=0.50         -> medium main effect of sector.
#   gender:sector=0.50  -> medium interaction (the moderation effect).
model.set_effects("gender=0.50, sector=0.50, gender:sector=0.50")

model.set_seed(2137)

# Power for the interaction (the 2x2 cell-difference test) at N=200.
model.find_power(sample_size=200, target_test="gender:sector")
suppressMessages(library(mcpower))

# 2x2 factorial: does the effect of `gender` depend on `sector`? '*' expands
# gender * sector to gender + sector + gender:sector, so the interaction
# (the difference in cell differences) is fitted explicitly.
model <- MCPower$new("job_satisfaction ~ gender * sector")

# Both predictors are two-level factors: gender and sector.
model$set_variable_type("gender=binary, sector=binary")

# Effect sizes on the factor benchmark scale (0.20 / 0.50 / 0.80):
#   gender=0.50          -> medium main effect of gender.
#   sector=0.50          -> medium main effect of sector.
#   gender:sector=0.50   -> medium interaction (the moderation effect).
model$set_effects("gender=0.50, sector=0.50, gender:sector=0.50")

model$set_seed(2137)

# Power for the interaction (the 2x2 cell-difference test) at N=200.
invisible(model$find_power(sample_size = 200, target_test = "gender:sector"))