stat_power 0.1.0.alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +36 -0
- data/LICENSE +21 -0
- data/README.md +153 -0
- data/RELEASING.md +105 -0
- data/ROADMAP.md +99 -0
- data/docs/mathematical_conventions.md +88 -0
- data/docs/pwr_parity.md +62 -0
- data/lib/stat_power/correlation.rb +247 -0
- data/lib/stat_power/distributions/f_distribution.rb +141 -0
- data/lib/stat_power/distributions/noncentral_f.rb +217 -0
- data/lib/stat_power/distributions/noncentral_t.rb +103 -0
- data/lib/stat_power/distributions/normal.rb +130 -0
- data/lib/stat_power/distributions/student_t.rb +124 -0
- data/lib/stat_power/effect_size/conventional.rb +38 -0
- data/lib/stat_power/effect_size/proportion.rb +36 -0
- data/lib/stat_power/errors.rb +12 -0
- data/lib/stat_power/integration/adaptive_simpson.rb +133 -0
- data/lib/stat_power/normal_mean.rb +206 -0
- data/lib/stat_power/power_result.rb +20 -0
- data/lib/stat_power/proportion.rb +460 -0
- data/lib/stat_power/result.rb +6 -0
- data/lib/stat_power/solvers/bisection.rb +121 -0
- data/lib/stat_power/special_functions/beta.rb +100 -0
- data/lib/stat_power/t_test.rb +349 -0
- data/lib/stat_power/t_test_unequal.rb +247 -0
- data/lib/stat_power/unequal_power_result.rb +42 -0
- data/lib/stat_power/version.rb +5 -0
- data/lib/stat_power.rb +25 -0
- data/sig/stat_power.rbs +264 -0
- metadata +76 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 66d3d0229cc19ab03fc96007a171298ae29f1f6964d62d51d945799fa3a7a465
|
|
4
|
+
data.tar.gz: 1567693499022a1831ebaf0c216819458e9ddfd6389843d7581cd2c4d9534c65
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 17de540e8e06c53b81e1295c0e9176a09cbf1f25458900524d7e318a627da780bc82becc0d9963cbc9ac4ce3d334ecff2686630993d87149792e01f65afccd40
|
|
7
|
+
data.tar.gz: 278d9c38fbcf57c6d7bf522ab8126da06e1720f79b8393198620bc33049bc68123e6297f743e90b98fca31822173f8e65ae4f74e87866101921f21d453a79334
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## Unreleased
|
|
6
|
+
|
|
7
|
+
## 0.1.0.alpha.1 - 2026-09-19
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Initial gem structure
|
|
12
|
+
- RSpec, RuboCop, and Steep configuration
|
|
13
|
+
- CI across supported Ruby versions
|
|
14
|
+
- Project roadmap
|
|
15
|
+
- Mathematical conventions
|
|
16
|
+
- Standard normal PDF, CDF, survival function, and quantile utilities
|
|
17
|
+
- Deterministic bracketed bisection root solver
|
|
18
|
+
- Numerical domain and convergence error types
|
|
19
|
+
- CRAN `pwr` compatibility and validation strategy
|
|
20
|
+
- Normal-mean power analysis compatible with `pwr.norm.test`
|
|
21
|
+
- Conventional Cohen effect-size lookup
|
|
22
|
+
- Continuous and integer-required sample-size reporting
|
|
23
|
+
- Cohen's h effect-size calculation for proportions
|
|
24
|
+
- One-sample proportion power analysis compatible with `pwr.p.test`
|
|
25
|
+
- Equal-size two-sample proportion power analysis compatible with `pwr.2p.test`
|
|
26
|
+
- Unequal-size two-sample proportion power analysis compatible with `pwr.2p2n.test`
|
|
27
|
+
- Dedicated result object for unequal two-group designs
|
|
28
|
+
- Regularized incomplete beta special function
|
|
29
|
+
- Adaptive Simpson quadrature
|
|
30
|
+
- Central Student t PDF, CDF, survival, and quantile utilities
|
|
31
|
+
- Noncentral Student t CDF and survival utilities
|
|
32
|
+
- One-sample, paired, and equal-size two-sample t-test power analysis compatible with `pwr.t.test`
|
|
33
|
+
- Unequal-size two-sample t-test power analysis compatible with `pwr.t2n.test`
|
|
34
|
+
- Pearson correlation power analysis compatible with `pwr.r.test`
|
|
35
|
+
- Central F PDF, CDF, survival, and quantile utilities
|
|
36
|
+
- Noncentral F CDF and survival utilities
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Diogo Ribeiro
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# stat_power
|
|
2
|
+
|
|
3
|
+
Native Ruby statistical power analysis and sample-size determination.
|
|
4
|
+
|
|
5
|
+
> **Alpha release:** `stat_power` is under active development. The public API
|
|
6
|
+
> may change before the first stable release. Pin an exact version in production
|
|
7
|
+
> or research environments where reproducibility matters.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
The current release is a prerelease:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
gem install stat_power --prerelease
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
or pin the exact alpha:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
gem install stat_power -v 0.1.0.alpha.1
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
With Bundler:
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
gem "stat_power", "0.1.0.alpha.1"
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Status
|
|
30
|
+
|
|
31
|
+
The first compatibility target is the established CRAN `pwr` package. The
|
|
32
|
+
implementation is native Ruby and is validated against published formulas and
|
|
33
|
+
reference numerical results rather than being a line-by-line source port.
|
|
34
|
+
|
|
35
|
+
Implemented compatibility currently includes:
|
|
36
|
+
|
|
37
|
+
- `pwr.norm.test`
|
|
38
|
+
- `pwr.p.test`
|
|
39
|
+
- `pwr.2p.test`
|
|
40
|
+
- `pwr.2p2n.test`
|
|
41
|
+
- `pwr.t.test`
|
|
42
|
+
- `pwr.t2n.test`
|
|
43
|
+
- `pwr.r.test`
|
|
44
|
+
|
|
45
|
+
The library also contains the numerical distribution machinery required for
|
|
46
|
+
further power methods, including central/noncentral t and F distributions.
|
|
47
|
+
|
|
48
|
+
See [docs/pwr_parity.md](docs/pwr_parity.md) for the full compatibility matrix.
|
|
49
|
+
|
|
50
|
+
## Example
|
|
51
|
+
|
|
52
|
+
```ruby
|
|
53
|
+
require "stat_power"
|
|
54
|
+
|
|
55
|
+
result = StatPower::TTest.two_sample(
|
|
56
|
+
effect_size: 0.5,
|
|
57
|
+
alpha: 0.05,
|
|
58
|
+
power: 0.8
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
result.sample_size
|
|
62
|
+
# continuous observations required per group
|
|
63
|
+
|
|
64
|
+
result.required_sample_size
|
|
65
|
+
# smallest whole-number sample size per group
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Power-analysis methods follow a common convention: one principal parameter is
|
|
69
|
+
omitted and solved from the remaining values.
|
|
70
|
+
|
|
71
|
+
For example, achieved power:
|
|
72
|
+
|
|
73
|
+
```ruby
|
|
74
|
+
result = StatPower::Correlation.solve(
|
|
75
|
+
correlation: 0.3,
|
|
76
|
+
sample_size: 50,
|
|
77
|
+
alpha: 0.05
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
result.power
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Goals
|
|
84
|
+
|
|
85
|
+
- parity with the statistical families provided by CRAN `pwr`
|
|
86
|
+
- idiomatic Ruby APIs
|
|
87
|
+
- sample-size determination and achieved-power calculations
|
|
88
|
+
- inverse power problems
|
|
89
|
+
- effect-size utilities
|
|
90
|
+
- explicit assumptions and numerical tolerances
|
|
91
|
+
- independently reproducible numerical validation
|
|
92
|
+
- later extensions beyond `pwr`
|
|
93
|
+
|
|
94
|
+
## Alpha stability policy
|
|
95
|
+
|
|
96
|
+
During the `0.1.0.alpha.*` series:
|
|
97
|
+
|
|
98
|
+
- numerical correctness and validation take priority over API stability
|
|
99
|
+
- method and result names may change when inconsistencies are found
|
|
100
|
+
- every implemented statistical family should include independent reference tests
|
|
101
|
+
- new CRAN `pwr` parity targets may be added between alpha releases
|
|
102
|
+
|
|
103
|
+
The transition to beta will indicate that the public API is approaching a
|
|
104
|
+
freeze candidate.
|
|
105
|
+
|
|
106
|
+
## Development
|
|
107
|
+
|
|
108
|
+
Install dependencies:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
bundle install
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Run the test suite:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
bundle exec rspec
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Run lint and signature validation:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
bundle exec rubocop
|
|
124
|
+
bundle exec rbs validate
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Validate that the library loads:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
ruby -Ilib -e 'require "stat_power"'
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Build the gem locally:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
gem build stat_power.gemspec
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Mathematical conventions
|
|
140
|
+
|
|
141
|
+
See [docs/mathematical_conventions.md](docs/mathematical_conventions.md).
|
|
142
|
+
|
|
143
|
+
## Roadmap
|
|
144
|
+
|
|
145
|
+
See [ROADMAP.md](ROADMAP.md).
|
|
146
|
+
|
|
147
|
+
## Releasing
|
|
148
|
+
|
|
149
|
+
See [RELEASING.md](RELEASING.md).
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
MIT.
|
data/RELEASING.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Releasing stat_power
|
|
2
|
+
|
|
3
|
+
This project uses prerelease versions until the public API is ready to stabilize.
|
|
4
|
+
|
|
5
|
+
## One-time RubyGems trusted publisher setup
|
|
6
|
+
|
|
7
|
+
RubyGems Trusted Publishing allows GitHub Actions to publish without storing a
|
|
8
|
+
long-lived RubyGems API key.
|
|
9
|
+
|
|
10
|
+
For the first release of `stat_power`, create a **pending trusted publisher**
|
|
11
|
+
from the RubyGems.org account that should own the gem, using:
|
|
12
|
+
|
|
13
|
+
- Gem name: `stat_power`
|
|
14
|
+
- Repository owner: `DiogoRibeiro7`
|
|
15
|
+
- Repository name: `stat_power`
|
|
16
|
+
- Workflow filename: `release.yml`
|
|
17
|
+
- Environment: `release`
|
|
18
|
+
|
|
19
|
+
The workflow is stored at `.github/workflows/release.yml`.
|
|
20
|
+
|
|
21
|
+
After the first successful publication, the pending publisher becomes the
|
|
22
|
+
trusted publisher for the gem.
|
|
23
|
+
|
|
24
|
+
## Alpha release checklist
|
|
25
|
+
|
|
26
|
+
1. Ensure all CI jobs are green on `main`.
|
|
27
|
+
2. Confirm `lib/stat_power/version.rb` contains the intended version.
|
|
28
|
+
3. Update `CHANGELOG.md` with the release date.
|
|
29
|
+
4. Build the gem locally:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
gem build stat_power.gemspec
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
5. Inspect the built package:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
gem specification stat_power-*.gem name version files --yaml
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
6. Install the built gem into a clean location:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
GEM_HOME="$(mktemp -d)" gem install stat_power-*.gem --no-document
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
7. Run a smoke test against the installed package:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
ruby -e 'require "stat_power"; p StatPower::VERSION'
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
8. Confirm the RubyGems pending/trusted publisher is configured for
|
|
54
|
+
`.github/workflows/release.yml` and the `release` environment.
|
|
55
|
+
|
|
56
|
+
9. Create and push the release tag. The tag must match the version exactly:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
git checkout main
|
|
60
|
+
git pull --ff-only
|
|
61
|
+
git tag v0.1.0.alpha.1
|
|
62
|
+
git push origin v0.1.0.alpha.1
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Pushing the tag triggers the release workflow. It validates that:
|
|
66
|
+
|
|
67
|
+
- the tag matches `StatPower::VERSION`
|
|
68
|
+
- the tagged commit is contained in `main`
|
|
69
|
+
- the test suite passes
|
|
70
|
+
- RuboCop passes
|
|
71
|
+
- RBS signatures validate
|
|
72
|
+
- the gem builds successfully
|
|
73
|
+
|
|
74
|
+
The workflow then publishes to RubyGems using OIDC Trusted Publishing and
|
|
75
|
+
creates a GitHub Release. Prerelease versions are marked as prereleases on
|
|
76
|
+
GitHub automatically.
|
|
77
|
+
|
|
78
|
+
## After publishing
|
|
79
|
+
|
|
80
|
+
Verify the public installation path:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
gem install stat_power --prerelease
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Then confirm:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
ruby -e 'require "stat_power"; puts StatPower::VERSION'
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The expected output for the first alpha is:
|
|
93
|
+
|
|
94
|
+
```text
|
|
95
|
+
0.1.0.alpha.1
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Failed releases
|
|
99
|
+
|
|
100
|
+
If the workflow fails before the RubyGems publishing step, fix the problem and
|
|
101
|
+
move the release tag only if the version has not been published.
|
|
102
|
+
|
|
103
|
+
Once a version exists on RubyGems.org, do not overwrite or reuse that version.
|
|
104
|
+
Increment the prerelease version, for example from `0.1.0.alpha.1` to
|
|
105
|
+
`0.1.0.alpha.2`, and create a new tag.
|
data/ROADMAP.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Roadmap
|
|
2
|
+
|
|
3
|
+
## 0.1.x — CRAN pwr parity and numerical foundations
|
|
4
|
+
|
|
5
|
+
### Foundations
|
|
6
|
+
|
|
7
|
+
- [x] Core result and error types
|
|
8
|
+
- [x] Standard normal distribution utilities
|
|
9
|
+
- [x] Root-finding infrastructure
|
|
10
|
+
- [x] Conventional Cohen effect-size lookup
|
|
11
|
+
- [x] Normal mean power analysis equivalent to `pwr.norm.test`
|
|
12
|
+
- [x] Student t distribution utilities
|
|
13
|
+
- [x] Noncentral t distribution utilities
|
|
14
|
+
- [ ] Chi-square and noncentral chi-square utilities
|
|
15
|
+
- [x] F and noncentral F utilities
|
|
16
|
+
|
|
17
|
+
### pwr compatibility
|
|
18
|
+
|
|
19
|
+
- [x] `pwr.norm.test`
|
|
20
|
+
- [x] `pwr.p.test`
|
|
21
|
+
- [x] `pwr.2p.test`
|
|
22
|
+
- [x] `pwr.2p2n.test`
|
|
23
|
+
- [x] `pwr.t.test`
|
|
24
|
+
- [x] `pwr.t2n.test`
|
|
25
|
+
- [ ] `pwr.anova.test`
|
|
26
|
+
- [x] `pwr.r.test`
|
|
27
|
+
- [ ] `pwr.chisq.test`
|
|
28
|
+
- [ ] `pwr.f2.test`
|
|
29
|
+
- [x] `ES.h`
|
|
30
|
+
- [ ] `ES.w1`
|
|
31
|
+
- [ ] `ES.w2`
|
|
32
|
+
- [ ] power-curve data equivalent to `plot.power.htest`
|
|
33
|
+
|
|
34
|
+
Each migrated family must support the inverse problems exposed by the reference
|
|
35
|
+
method and include numerical parity tests.
|
|
36
|
+
|
|
37
|
+
## 0.2.x — Validation and usability
|
|
38
|
+
|
|
39
|
+
- Automated parity fixtures generated from R `pwr`
|
|
40
|
+
- Published Cohen examples
|
|
41
|
+
- Cross-validation against statsmodels where applicable
|
|
42
|
+
- Documented numerical tolerance policy
|
|
43
|
+
- Stable result objects
|
|
44
|
+
- User-facing method documentation
|
|
45
|
+
- Benchmarks
|
|
46
|
+
|
|
47
|
+
## 0.3.x — Beyond pwr: regression and richer designs
|
|
48
|
+
|
|
49
|
+
- Additional regression power models
|
|
50
|
+
- Partial and semi-partial correlation
|
|
51
|
+
- Unequal allocation helpers
|
|
52
|
+
- Attrition and dropout adjustments
|
|
53
|
+
|
|
54
|
+
## 0.4.x — Equivalence and non-inferiority
|
|
55
|
+
|
|
56
|
+
- TOST
|
|
57
|
+
- One-sided non-inferiority tests
|
|
58
|
+
- Equivalence for means and proportions
|
|
59
|
+
|
|
60
|
+
## 0.5.x — Repeated and clustered designs
|
|
61
|
+
|
|
62
|
+
- Repeated-measures designs
|
|
63
|
+
- Mixed designs
|
|
64
|
+
- Cluster-randomised trials
|
|
65
|
+
- Design effects
|
|
66
|
+
- Intra-cluster correlation
|
|
67
|
+
- Unequal cluster sizes
|
|
68
|
+
|
|
69
|
+
## 0.6.x — Precision-based design
|
|
70
|
+
|
|
71
|
+
- Confidence-interval width targets
|
|
72
|
+
- Mean, proportion, and difference precision
|
|
73
|
+
|
|
74
|
+
## 0.7.x — Simulation-based power
|
|
75
|
+
|
|
76
|
+
- User-defined simulation models
|
|
77
|
+
- Monte Carlo uncertainty estimates
|
|
78
|
+
- Reproducible random seeds
|
|
79
|
+
- Parallel execution interface
|
|
80
|
+
|
|
81
|
+
## 0.8.x — pwrss-inspired extensions
|
|
82
|
+
|
|
83
|
+
- Broader sample-size methods
|
|
84
|
+
- Minimum detectable effects
|
|
85
|
+
- Additional test families selected from mature reference implementations
|
|
86
|
+
|
|
87
|
+
## 0.9.x — API hardening
|
|
88
|
+
|
|
89
|
+
- Complete validation matrix
|
|
90
|
+
- Performance review
|
|
91
|
+
- Documentation audit
|
|
92
|
+
- API stability review
|
|
93
|
+
|
|
94
|
+
## 1.0.0
|
|
95
|
+
|
|
96
|
+
- Stable public API
|
|
97
|
+
- Complete user and mathematical documentation
|
|
98
|
+
- Reproducible validation suite
|
|
99
|
+
- RubyGems release
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Mathematical conventions
|
|
2
|
+
|
|
3
|
+
This document defines the conventions that all implementations in `stat_power` must follow.
|
|
4
|
+
|
|
5
|
+
## Probability and significance
|
|
6
|
+
|
|
7
|
+
The significance level is denoted by \(\alpha\), with \(0 < \alpha < 1\).
|
|
8
|
+
|
|
9
|
+
Statistical power is
|
|
10
|
+
|
|
11
|
+
\[
|
|
12
|
+
1 - \beta,
|
|
13
|
+
\]
|
|
14
|
+
|
|
15
|
+
where \(\beta\) is the Type II error probability.
|
|
16
|
+
|
|
17
|
+
Unless a method explicitly states otherwise, two-sided tests split \(\alpha\) equally across both tails.
|
|
18
|
+
|
|
19
|
+
## Sample size
|
|
20
|
+
|
|
21
|
+
For compatibility and numerical validation, solvers retain the continuous
|
|
22
|
+
sample-size solution produced by the underlying power equation.
|
|
23
|
+
|
|
24
|
+
A result may additionally expose the smallest design-valid integer sample size
|
|
25
|
+
not below that solution. This distinction is explicit: continuous values are
|
|
26
|
+
useful for parity checks and mathematical work, while integer values are useful
|
|
27
|
+
for study design.
|
|
28
|
+
|
|
29
|
+
For two-group designs, total sample size and per-group sample size must be
|
|
30
|
+
distinguished explicitly in the public API and documentation.
|
|
31
|
+
|
|
32
|
+
## Effect sizes
|
|
33
|
+
|
|
34
|
+
Standardised effect sizes follow conventional definitions:
|
|
35
|
+
|
|
36
|
+
- Cohen's \(d\) for standardised mean differences
|
|
37
|
+
- Cohen's \(h\) for differences between proportions on the arcsine scale
|
|
38
|
+
- Cohen's \(f\) for ANOVA
|
|
39
|
+
- Cohen's \(f^2\) for regression
|
|
40
|
+
- Cohen's \(w\) for chi-square tests
|
|
41
|
+
|
|
42
|
+
Conversions must document their assumptions and must not silently assume interchangeable effect-size definitions.
|
|
43
|
+
|
|
44
|
+
## Tail conventions
|
|
45
|
+
|
|
46
|
+
Alternatives use explicit names:
|
|
47
|
+
|
|
48
|
+
- `two_sided`
|
|
49
|
+
- `greater`
|
|
50
|
+
- `less`
|
|
51
|
+
|
|
52
|
+
Compatibility layers may accept reference-package spellings such as
|
|
53
|
+
`"two.sided"`, but results are normalised to the Ruby convention.
|
|
54
|
+
|
|
55
|
+
## Numerical solving
|
|
56
|
+
|
|
57
|
+
Inverse power problems are solved numerically only when a closed-form expression is unavailable or undesirable.
|
|
58
|
+
|
|
59
|
+
Root-finding routines must:
|
|
60
|
+
|
|
61
|
+
1. define a mathematically valid search interval,
|
|
62
|
+
2. verify that the requested solution is identifiable,
|
|
63
|
+
3. fail clearly when the target cannot be bracketed,
|
|
64
|
+
4. expose deterministic tolerances,
|
|
65
|
+
5. be covered by reference-value tests.
|
|
66
|
+
|
|
67
|
+
## Precision and tolerances
|
|
68
|
+
|
|
69
|
+
Reference comparisons must distinguish between:
|
|
70
|
+
|
|
71
|
+
- exact algebraic identities,
|
|
72
|
+
- floating-point agreement,
|
|
73
|
+
- agreement with external software that uses different numerical algorithms.
|
|
74
|
+
|
|
75
|
+
Tolerance values belong in tests or numerical configuration, not as undocumented magic constants.
|
|
76
|
+
|
|
77
|
+
## Validation
|
|
78
|
+
|
|
79
|
+
Every implemented test family must include at least one independently reproducible validation source, preferably two.
|
|
80
|
+
|
|
81
|
+
CRAN `pwr` is the initial compatibility target. Its documented statistical
|
|
82
|
+
models and numerical results are reference points, but `stat_power` uses an
|
|
83
|
+
independent native Ruby implementation.
|
|
84
|
+
|
|
85
|
+
Suitable additional references include peer-reviewed formulas, established
|
|
86
|
+
statistical textbooks, Python implementations, and published G*Power examples.
|
|
87
|
+
|
|
88
|
+
Agreement with another software package is evidence of consistency, not a substitute for verifying the underlying mathematics.
|
data/docs/pwr_parity.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# CRAN pwr parity
|
|
2
|
+
|
|
3
|
+
`stat_power` uses CRAN `pwr` as its first compatibility and validation target.
|
|
4
|
+
|
|
5
|
+
The implementation is native Ruby. The project does not translate or copy the
|
|
6
|
+
GPL-licensed R source line by line. Public statistical definitions, documented
|
|
7
|
+
behaviour, published formulas, and numerical outputs are used as independent
|
|
8
|
+
reference points.
|
|
9
|
+
|
|
10
|
+
## Compatibility target
|
|
11
|
+
|
|
12
|
+
| CRAN pwr function | stat_power target | Status |
|
|
13
|
+
| --- | --- | --- |
|
|
14
|
+
| `pwr.norm.test` | `StatPower::NormalMean.solve` | Implemented |
|
|
15
|
+
| `cohen.ES` | `StatPower::EffectSize::Conventional.resolve` | Implemented for conventional values |
|
|
16
|
+
| `pwr.p.test` | `StatPower::Proportion.one_sample` | Implemented |
|
|
17
|
+
| `pwr.2p.test` | `StatPower::Proportion.two_sample` | Implemented |
|
|
18
|
+
| `pwr.2p2n.test` | `StatPower::Proportion.two_sample_unequal` | Implemented |
|
|
19
|
+
| `pwr.t.test` | `StatPower::TTest.one_sample`, `.paired`, `.two_sample` | Implemented |
|
|
20
|
+
| `pwr.t2n.test` | `StatPower::TTest.two_sample_unequal` | Implemented |
|
|
21
|
+
| `pwr.anova.test` | balanced one-way ANOVA power | Planned |
|
|
22
|
+
| `pwr.r.test` | `StatPower::Correlation.solve` | Implemented |
|
|
23
|
+
| `pwr.chisq.test` | chi-square power | Planned |
|
|
24
|
+
| `pwr.f2.test` | general linear-model power | Planned |
|
|
25
|
+
| `ES.h` | `StatPower::EffectSize::Proportion.cohen_h` | Implemented |
|
|
26
|
+
| `ES.w1` | Cohen w for goodness of fit | Planned |
|
|
27
|
+
| `ES.w2` | Cohen w for contingency tables | Planned |
|
|
28
|
+
| `plot.power.htest` | power-curve data generation | Planned |
|
|
29
|
+
|
|
30
|
+
## Solver convention
|
|
31
|
+
|
|
32
|
+
As in `pwr`, a power-analysis family solves one omitted quantity from the
|
|
33
|
+
remaining quantities. Ruby uses explicit keyword arguments and `nil` for the
|
|
34
|
+
unknown parameter.
|
|
35
|
+
|
|
36
|
+
For example:
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
StatPower::NormalMean.solve(
|
|
40
|
+
effect_size: 0.5,
|
|
41
|
+
alpha: 0.05,
|
|
42
|
+
power: 0.8
|
|
43
|
+
)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
returns the continuous sample-size solution. Call
|
|
47
|
+
`required_sample_size` on the result to obtain the smallest integer not below
|
|
48
|
+
that solution.
|
|
49
|
+
|
|
50
|
+
## Validation policy
|
|
51
|
+
|
|
52
|
+
Each migrated family should include:
|
|
53
|
+
|
|
54
|
+
1. formula-level tests where a closed form or independently derived expression
|
|
55
|
+
is available,
|
|
56
|
+
2. numerical reference tests against CRAN `pwr`,
|
|
57
|
+
3. edge and invalid-domain tests,
|
|
58
|
+
4. inverse-problem tests for every parameter the family can solve.
|
|
59
|
+
|
|
60
|
+
Parity means agreement in the statistical model and numerical result within a
|
|
61
|
+
documented tolerance. Ruby naming and object design remain idiomatic rather
|
|
62
|
+
than cloning R syntax.
|