Does annual rainfall predict plant biomass once soil nitrogen is held constant? Two continuous predictors of a continuous outcome — the classic two-predictor multiple regression. As an MCPower formula this is plant_biomass ~ rainfall + soil_nitrogen, fit by ordinary least squares: rainfall is the predictor of interest, soil_nitrogen a second continuous variable whose own association you also want enough power to detect.

Variations

  • One predictor matters, the other is just a control. Keep target_test="rainfall" to power only the predictor of interest; soil_nitrogen then acts as an adjustment covariate you don't need to detect.
  • Different effect-size guesses. Continuous predictors run on the 0.10 / 0.25 / 0.40 small / medium / large scale — dial each predictor up or down to match your literature estimate.
  • Make a predictor categorical. Swap continuous soil_nitrogen for a binary group (set_variable_type("soil_nitrogen=binary")) and rescale its effect to the 0.20 / 0.50 / 0.80 binary benchmarks.
  • Solve for sample size instead of power. Replace find_power(...) with find_sample_size(target_test="rainfall, soil_nitrogen", from_size=50, to_size=400) to sweep a grid and report the smallest N that reaches 80% power.
  • Correlated predictors. If rainfall and soil_nitrogen are themselves related, add set_correlations("corr(rainfall, soil_nitrogen)=0.3") so the simulation reflects the collinearity you expect in real data.
  • Same design, other fields:
    • Clinical: cholesterol ~ dose + age — adjusted effect of dose on cholesterol holding age constant; same two-predictor additive OLS structure.
    • Social: wage ~ years_education + experience_years — adjusted wage return to education controlling for experience; same formula shape.

Not this setup?

If you'd rather have…

Copy-paste setup

from mcpower import MCPower

# Two continuous predictors of a continuous outcome (OLS).
# rainfall is the predictor of interest; soil_nitrogen is a second continuous covariate
# whose association we also want enough power to detect.
model = MCPower("plant_biomass = rainfall + soil_nitrogen")

# Standardised effect sizes (continuous benchmarks: 0.10 / 0.25 / 0.40).
#   rainfall=0.25 -> a medium association.
#   soil_nitrogen=0.10 -> a small association.
model.set_effects("rainfall=0.25, soil_nitrogen=0.10")

# Both predictors are continuous, so no set_variable_type() is needed.
# OLS defaults apply: 1600 simulations, alpha=0.05, seed=2137.
model.find_power(sample_size=200, target_test="rainfall, soil_nitrogen")
suppressMessages(library(mcpower))

# Two continuous predictors of a continuous outcome (OLS).
# rainfall is the predictor of interest; soil_nitrogen is a second continuous covariate
# whose association we also want enough power to detect.
model <- MCPower$new("plant_biomass ~ rainfall + soil_nitrogen")

# Standardised effect sizes (continuous benchmarks: 0.10 / 0.25 / 0.40).
#   rainfall=0.25 -> a medium association.
#   soil_nitrogen=0.10 -> a small association.
model$set_effects("rainfall=0.25, soil_nitrogen=0.10")

# Both predictors are continuous, so no set_variable_type() is needed.
# OLS defaults apply: 1600 simulations, alpha=0.05, seed=2137.
invisible(model$find_power(sample_size = 200, target_test = "rainfall, soil_nitrogen"))