Native Ruby statistical power analysis and sample-size determination.
Alpha release:
stat_poweris under active development. The public API may change before the first stable release. Pin an exact version in production or research environments where reproducibility matters.
The current release is a prerelease:
gem install stat_power --prereleaseor pin the exact alpha:
gem install stat_power -v 0.1.0.alpha.3With Bundler:
gem "stat_power", "0.1.0.alpha.3"The first compatibility target is the established CRAN pwr package. The
implementation is native Ruby and is validated against published formulas and
reference numerical results rather than being a line-by-line source port.
Implemented compatibility currently includes:
pwr.norm.testpwr.p.testpwr.2p.testpwr.2p2n.testpwr.t.testpwr.t2n.testpwr.r.testpwr.anova.testpwr.f2.testpwr.chisq.testES.hES.w1ES.w2- power-curve data generation equivalent in purpose to
plot.power.htest
The library also contains the numerical distribution machinery required by these methods, including central/noncentral t, F, and chi-square distributions.
See docs/pwr_parity.md for the full compatibility matrix.
require "stat_power"
result = StatPower::TTest.two_sample(
effect_size: 0.5,
alpha: 0.05,
power: 0.8
)
result.sample_size
# continuous observations required per group
result.required_sample_size
# smallest whole-number sample size per groupPower-analysis methods follow a common convention: one principal parameter is omitted and solved from the remaining values.
For example, achieved power:
result = StatPower::Correlation.solve(
correlation: 0.3,
sample_size: 50,
alpha: 0.05
)
result.power- parity with the statistical families provided by CRAN
pwr - idiomatic Ruby APIs
- sample-size determination and achieved-power calculations
- inverse power problems
- effect-size utilities
- explicit assumptions and numerical tolerances
- independently reproducible numerical validation
- later extensions beyond
pwr
During the 0.1.0.alpha.* series:
- numerical correctness and validation take priority over API stability
- method and result names may change when inconsistencies are found
- every implemented statistical family should include independent reference tests
- new CRAN
pwrparity targets may be added between alpha releases
The transition to beta will indicate that the public API is approaching a freeze candidate.
Set up the checkout:
bin/setupOpen a console with the library loaded:
bin/consoleRun everything CI runs:
bundle exec rake verifyThat is the same as running each check individually:
bundle exec rspec # specs
bundle exec rubocop # lint
bundle exec rbs validate # signature syntax
bundle exec steep check # lib/ type checked against sig/Measure test coverage. Instrumentation roughly doubles the runtime, so it is opt-in; CI enforces a minimum in a dedicated job.
COVERAGE=1 bundle exec rspec
open coverage/index.htmlBuild the gem locally:
gem build stat_power.gemspecContributions are welcome. Because this is a numerical library, the bar is reproducibility: every statistical result must be justified by a published formula or an independently generated reference value.
See CONTRIBUTING.md for the workflow, the shape a new power-analysis family is expected to take, and how to supply reference values.
Participation is governed by the Code of Conduct.
If stat_power disagrees with pwr, R, G*Power or a textbook, that is the
highest-priority class of bug here. Open an issue using the Numerical
discrepancy template.
See SECURITY.md for supported versions and how to report a vulnerability privately. A numerically incorrect result is a bug, not a vulnerability; report those as ordinary issues.
See docs/mathematical_conventions.md.
For numerical reference fixtures and tolerance rules, see docs/validation.md.
See ROADMAP.md.
See RELEASING.md.
MIT.