rstatspython 0.1.0__tar.gz
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.
- rstatspython-0.1.0/.gitignore +11 -0
- rstatspython-0.1.0/LICENSE +21 -0
- rstatspython-0.1.0/PKG-INFO +177 -0
- rstatspython-0.1.0/README.md +144 -0
- rstatspython-0.1.0/docs/Rstats-quickstart.pptx +0 -0
- rstatspython-0.1.0/docs/anova.md +123 -0
- rstatspython-0.1.0/docs/api.md +129 -0
- rstatspython-0.1.0/docs/publishing.md +68 -0
- rstatspython-0.1.0/docs/statistics.md +76 -0
- rstatspython-0.1.0/docs/validation.md +64 -0
- rstatspython-0.1.0/examples/anova-report.html +240 -0
- rstatspython-0.1.0/examples/longitudinal.csv +91 -0
- rstatspython-0.1.0/examples/quickstart.ipynb +241 -0
- rstatspython-0.1.0/examples/regression-report.html +187 -0
- rstatspython-0.1.0/examples/students.csv +151 -0
- rstatspython-0.1.0/pyproject.toml +44 -0
- rstatspython-0.1.0/src/rstats/__init__.py +11 -0
- rstatspython-0.1.0/src/rstats/_data.py +164 -0
- rstatspython-0.1.0/src/rstats/_posthoc.py +278 -0
- rstatspython-0.1.0/src/rstats/anova.py +422 -0
- rstatspython-0.1.0/src/rstats/categorical.py +180 -0
- rstatspython-0.1.0/src/rstats/descriptive.py +100 -0
- rstatspython-0.1.0/src/rstats/regression.py +302 -0
- rstatspython-0.1.0/src/rstats/result.py +68 -0
- rstatspython-0.1.0/src/rstats/visualization.py +180 -0
- rstatspython-0.1.0/tests/conftest.py +29 -0
- rstatspython-0.1.0/tests/reference/R-extended-session.txt +2 -0
- rstatspython-0.1.0/tests/reference/R-session.txt +23 -0
- rstatspython-0.1.0/tests/reference/README.md +39 -0
- rstatspython-0.1.0/tests/reference/ancova.csv +4 -0
- rstatspython-0.1.0/tests/reference/ancova_posthoc_BH.csv +4 -0
- rstatspython-0.1.0/tests/reference/ancova_posthoc_BY.csv +4 -0
- rstatspython-0.1.0/tests/reference/ancova_posthoc_bonferroni.csv +4 -0
- rstatspython-0.1.0/tests/reference/ancova_posthoc_holm.csv +4 -0
- rstatspython-0.1.0/tests/reference/chisq.csv +2 -0
- rstatspython-0.1.0/tests/reference/dunnett.csv +3 -0
- rstatspython-0.1.0/tests/reference/extended.R +37 -0
- rstatspython-0.1.0/tests/reference/factorial.csv +52 -0
- rstatspython-0.1.0/tests/reference/games_howell.csv +4 -0
- rstatspython-0.1.0/tests/reference/generate.R +119 -0
- rstatspython-0.1.0/tests/reference/gg_epsilon.csv +6 -0
- rstatspython-0.1.0/tests/reference/gof.csv +2 -0
- rstatspython-0.1.0/tests/reference/lm_multiple_coefficients.csv +5 -0
- rstatspython-0.1.0/tests/reference/lm_multiple_model.csv +2 -0
- rstatspython-0.1.0/tests/reference/lm_simple_coefficients.csv +3 -0
- rstatspython-0.1.0/tests/reference/lm_simple_model.csv +2 -0
- rstatspython-0.1.0/tests/reference/logistic_coefficients.csv +5 -0
- rstatspython-0.1.0/tests/reference/logistic_model.csv +2 -0
- rstatspython-0.1.0/tests/reference/mixed.csv +4 -0
- rstatspython-0.1.0/tests/reference/oneway.csv +3 -0
- rstatspython-0.1.0/tests/reference/repeated_one.csv +2 -0
- rstatspython-0.1.0/tests/reference/repeated_two.csv +121 -0
- rstatspython-0.1.0/tests/reference/repeated_two.csv.expected +4 -0
- rstatspython-0.1.0/tests/reference/scheffe.csv +4 -0
- rstatspython-0.1.0/tests/reference/tukey.csv +4 -0
- rstatspython-0.1.0/tests/reference/type1.csv +5 -0
- rstatspython-0.1.0/tests/reference/type2.csv +4 -0
- rstatspython-0.1.0/tests/reference/type3.csv +5 -0
- rstatspython-0.1.0/tests/reference/welch.csv +2 -0
- rstatspython-0.1.0/tests/test_behavior.py +245 -0
- rstatspython-0.1.0/tests/test_r_reference.py +223 -0
- rstatspython-0.1.0/tests/test_visualization.py +53 -0
- rstatspython-0.1.0/tools/build_teaching.py +214 -0
- rstatspython-0.1.0/tools/check_deck.py +33 -0
- rstatspython-0.1.0/tools/execute_notebook.py +59 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rstats contributors
|
|
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.
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: rstatspython
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Familiar commands. Complete statistical reports.
|
|
5
|
+
Project-URL: Repository, https://github.com/drdanrb/Rstats
|
|
6
|
+
Author: Rstats contributors
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Education
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
14
|
+
Requires-Python: >=3.12
|
|
15
|
+
Requires-Dist: matplotlib>=3.9
|
|
16
|
+
Requires-Dist: numpy>=2.0
|
|
17
|
+
Requires-Dist: pandas<4,>=2.2
|
|
18
|
+
Requires-Dist: patsy>=1.0
|
|
19
|
+
Requires-Dist: pingouin<0.8,>=0.6
|
|
20
|
+
Requires-Dist: scipy>=1.16
|
|
21
|
+
Requires-Dist: seaborn>=0.13.2
|
|
22
|
+
Requires-Dist: statsmodels<0.16,>=0.14.4
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
25
|
+
Requires-Dist: ipykernel>=6; extra == 'dev'
|
|
26
|
+
Requires-Dist: nbclient>=0.10; extra == 'dev'
|
|
27
|
+
Requires-Dist: nbformat>=5.10; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
29
|
+
Requires-Dist: python-pptx>=1; extra == 'dev'
|
|
30
|
+
Requires-Dist: ruff>=0.11; extra == 'dev'
|
|
31
|
+
Requires-Dist: twine>=6; extra == 'dev'
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# Rstats
|
|
35
|
+
|
|
36
|
+
**Familiar commands. Complete statistical reports.**
|
|
37
|
+
|
|
38
|
+
[Open the teaching notebook in Google Colab](https://colab.research.google.com/github/drdanrb/Rstats/blob/main/examples/quickstart.ipynb)
|
|
39
|
+
|
|
40
|
+
Rstats gives Python students and academics a short path from a pandas dataframe
|
|
41
|
+
to detailed, reusable statistical results. One analysis call includes the
|
|
42
|
+
tables, uncertainty, coding, sample accounting, and diagnostic notes that would
|
|
43
|
+
otherwise require several separate calls. Plot independently with `vis()`.
|
|
44
|
+
|
|
45
|
+
## Install
|
|
46
|
+
|
|
47
|
+
Python 3.12+; see CI for tested versions. This is an early research/teaching
|
|
48
|
+
release, not a package published on PyPI. **Do not install the unrelated
|
|
49
|
+
`rstats` PyPI package.** Install directly from GitHub:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
python -m pip install git+https://github.com/drdanrb/Rstats.git
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Or from the root of the supplied source checkout:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
python -m pip install -e ".[dev]"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The distribution is named `rstatspython`; the import is `rstats`. No R runtime
|
|
62
|
+
is required to use the library. In Colab, prefix the installation command with
|
|
63
|
+
`%pip` instead of `python -m pip`, or open the teaching notebook above and choose
|
|
64
|
+
**Runtime → Run all**. The notebook installs Rstats if necessary and downloads
|
|
65
|
+
the synthetic example data automatically; no file uploads are needed.
|
|
66
|
+
|
|
67
|
+
PyPI publishing is prepared but awaits the owner's one-time Trusted Publisher
|
|
68
|
+
setup. After the first successful publication, students will be able to use
|
|
69
|
+
`pip install rstatspython` (or `%pip install rstatspython` in Colab).
|
|
70
|
+
Until then, use the working GitHub installation above. See the
|
|
71
|
+
[publishing instructions](docs/publishing.md).
|
|
72
|
+
|
|
73
|
+
## One-line analyses
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
import pandas as pd
|
|
77
|
+
import rstats as rs
|
|
78
|
+
|
|
79
|
+
df = pd.read_csv("https://raw.githubusercontent.com/drdanrb/Rstats/main/examples/students.csv")
|
|
80
|
+
|
|
81
|
+
rs.descriptives(data=df, columns=["score", "study_hours"], by="group")
|
|
82
|
+
rs.table("group ~ passed", data=df, percent="row")
|
|
83
|
+
rs.chisq("group ~ passed", data=df)
|
|
84
|
+
rs.aov("score ~ group", data=df, posthocifsig=True)
|
|
85
|
+
rs.aov("score ~ group", data=df, covariates=["study_hours"])
|
|
86
|
+
rs.lm("score ~ study_hours + group", data=df)
|
|
87
|
+
rs.logmodel("passed ~ study_hours + group", data=df)
|
|
88
|
+
rs.vis("score ~ group", data=df, type="box")
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
In a notebook, leave a result as the cell's last expression to display its full
|
|
92
|
+
report. In a script use `print(result)` or `result.show()`.
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
result = rs.lm("score ~ study_hours + group", data=df)
|
|
96
|
+
result.tables["coefficients"].to_csv("coefficients.csv")
|
|
97
|
+
result.model.predict(df) # underlying statsmodels model
|
|
98
|
+
result.show()
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Small rules that keep things intuitive
|
|
102
|
+
|
|
103
|
+
- Formulas are strings: `"outcome ~ predictor + another"`.
|
|
104
|
+
- `+` adds terms; `*` includes main effects and interactions; `:` adds an
|
|
105
|
+
interaction alone. Backticks quote column names with spaces.
|
|
106
|
+
- In **ANOVA**, predictors are groups even if coded 1, 2, 3. Put continuous
|
|
107
|
+
adjustments in `covariates=["age"]`.
|
|
108
|
+
- In **regression**, numbers are continuous and text/category columns are
|
|
109
|
+
categorical. Use `categorical=["group"]` for numeric-coded categories.
|
|
110
|
+
- Set a regression reference with `reference={"group": "control"}`. Otherwise
|
|
111
|
+
the first declared pandas category, or sorted observed level, is the reference.
|
|
112
|
+
- `logmodel` models numeric outcome 1 by default. For text outcomes use
|
|
113
|
+
`event="passed"`; the report states exactly which event is modeled.
|
|
114
|
+
- `posthocifsig=True` means **Tukey**, not automatic method selection.
|
|
115
|
+
Use `posthocifsig="games-howell"` after Welch or `"holm"` for factorial,
|
|
116
|
+
covariate-adjusted, or repeated/mixed comparisons. Incompatible requests explain
|
|
117
|
+
the problem rather than silently changing the method.
|
|
118
|
+
|
|
119
|
+
## ANOVA without guessing
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
rs.aov("score ~ group * teaching", data=df, type=3, posthocifsig="holm")
|
|
123
|
+
rs.aov("score ~ group", data=df, method="welch", posthocifsig="games-howell")
|
|
124
|
+
rs.aov("score ~ time * group", data=long_df,
|
|
125
|
+
subject="student_id", within="time", posthocifsig="holm")
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Study design, sums-of-squares **type**, and variance **method** are different
|
|
129
|
+
choices. Ordinary ANOVA defaults to Type II; Type I is sequential and Type III
|
|
130
|
+
uses sum contrasts. Repeated/mixed designs use effect-specific tests and report
|
|
131
|
+
Greenhouse–Geisser inference where applicable. They do not get an invented
|
|
132
|
+
overall model F. See the [ANOVA and post hoc guide](docs/anova.md).
|
|
133
|
+
|
|
134
|
+
## Independent plotting
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
rs.vis("score ~ study_hours", data=df) # numeric/numeric → scatter
|
|
138
|
+
rs.vis("score ~ group", data=df) # numeric/category → box
|
|
139
|
+
rs.vis("score", data=df) # numeric → histogram
|
|
140
|
+
rs.vis("group", data=df) # category → counts
|
|
141
|
+
rs.vis("score ~ group", data=df, type="violin", palette="colorblind")
|
|
142
|
+
rs.vis("passed ~ group", data=df, type="proportion", normalize="row")
|
|
143
|
+
rs.vis("score ~ time", data=long_df, type="line", estimator="mean")
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Each plot returns a Matplotlib Axes: `ax.figure.savefig("figure.png")`.
|
|
147
|
+
No global Seaborn theme is changed. Plot data are complete cases for the plotted
|
|
148
|
+
variables; analytic sample counts remain in statistical reports.
|
|
149
|
+
|
|
150
|
+
## Documentation and teaching
|
|
151
|
+
|
|
152
|
+
- [API reference](docs/api.md)
|
|
153
|
+
- [ANOVA types, assumptions, and comparison methods](docs/anova.md)
|
|
154
|
+
- [Statistical conventions and limitations](docs/statistics.md)
|
|
155
|
+
- [Five-slide PowerPoint](docs/Rstats-quickstart.pptx)
|
|
156
|
+
- [Teaching notebook](examples/quickstart.ipynb)
|
|
157
|
+
- [Example ANOVA report](examples/anova-report.html) and [regression report](examples/regression-report.html)
|
|
158
|
+
- [Validation and R reference fixtures](tests/reference/README.md)
|
|
159
|
+
|
|
160
|
+
The included datasets are deterministic synthetic teaching data, not research
|
|
161
|
+
evidence. Tests are two-sided unless a method states otherwise. Missingness,
|
|
162
|
+
study design, independence, model assumptions, and causal interpretation remain
|
|
163
|
+
the analyst's responsibility; reports surface relevant details and never switch
|
|
164
|
+
methods based on assumption tests.
|
|
165
|
+
|
|
166
|
+
## Development
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
python -m pytest
|
|
170
|
+
python -m ruff check src tests tools
|
|
171
|
+
python -m build
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Python-version CI installs and tests on 3.12–3.15; platform/Colab smoke checks are
|
|
175
|
+
tracked separately. Do not infer passing environments from a workflow definition
|
|
176
|
+
alone. MANOVA/MANCOVA, arbitrary random effects, repeated-measures ANCOVA,
|
|
177
|
+
multinomial/ordinal logistic models, and SEM are outside this release.
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# Rstats
|
|
2
|
+
|
|
3
|
+
**Familiar commands. Complete statistical reports.**
|
|
4
|
+
|
|
5
|
+
[Open the teaching notebook in Google Colab](https://colab.research.google.com/github/drdanrb/Rstats/blob/main/examples/quickstart.ipynb)
|
|
6
|
+
|
|
7
|
+
Rstats gives Python students and academics a short path from a pandas dataframe
|
|
8
|
+
to detailed, reusable statistical results. One analysis call includes the
|
|
9
|
+
tables, uncertainty, coding, sample accounting, and diagnostic notes that would
|
|
10
|
+
otherwise require several separate calls. Plot independently with `vis()`.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
Python 3.12+; see CI for tested versions. This is an early research/teaching
|
|
15
|
+
release, not a package published on PyPI. **Do not install the unrelated
|
|
16
|
+
`rstats` PyPI package.** Install directly from GitHub:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
python -m pip install git+https://github.com/drdanrb/Rstats.git
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or from the root of the supplied source checkout:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
python -m pip install -e ".[dev]"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The distribution is named `rstatspython`; the import is `rstats`. No R runtime
|
|
29
|
+
is required to use the library. In Colab, prefix the installation command with
|
|
30
|
+
`%pip` instead of `python -m pip`, or open the teaching notebook above and choose
|
|
31
|
+
**Runtime → Run all**. The notebook installs Rstats if necessary and downloads
|
|
32
|
+
the synthetic example data automatically; no file uploads are needed.
|
|
33
|
+
|
|
34
|
+
PyPI publishing is prepared but awaits the owner's one-time Trusted Publisher
|
|
35
|
+
setup. After the first successful publication, students will be able to use
|
|
36
|
+
`pip install rstatspython` (or `%pip install rstatspython` in Colab).
|
|
37
|
+
Until then, use the working GitHub installation above. See the
|
|
38
|
+
[publishing instructions](docs/publishing.md).
|
|
39
|
+
|
|
40
|
+
## One-line analyses
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
import pandas as pd
|
|
44
|
+
import rstats as rs
|
|
45
|
+
|
|
46
|
+
df = pd.read_csv("https://raw.githubusercontent.com/drdanrb/Rstats/main/examples/students.csv")
|
|
47
|
+
|
|
48
|
+
rs.descriptives(data=df, columns=["score", "study_hours"], by="group")
|
|
49
|
+
rs.table("group ~ passed", data=df, percent="row")
|
|
50
|
+
rs.chisq("group ~ passed", data=df)
|
|
51
|
+
rs.aov("score ~ group", data=df, posthocifsig=True)
|
|
52
|
+
rs.aov("score ~ group", data=df, covariates=["study_hours"])
|
|
53
|
+
rs.lm("score ~ study_hours + group", data=df)
|
|
54
|
+
rs.logmodel("passed ~ study_hours + group", data=df)
|
|
55
|
+
rs.vis("score ~ group", data=df, type="box")
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
In a notebook, leave a result as the cell's last expression to display its full
|
|
59
|
+
report. In a script use `print(result)` or `result.show()`.
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
result = rs.lm("score ~ study_hours + group", data=df)
|
|
63
|
+
result.tables["coefficients"].to_csv("coefficients.csv")
|
|
64
|
+
result.model.predict(df) # underlying statsmodels model
|
|
65
|
+
result.show()
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Small rules that keep things intuitive
|
|
69
|
+
|
|
70
|
+
- Formulas are strings: `"outcome ~ predictor + another"`.
|
|
71
|
+
- `+` adds terms; `*` includes main effects and interactions; `:` adds an
|
|
72
|
+
interaction alone. Backticks quote column names with spaces.
|
|
73
|
+
- In **ANOVA**, predictors are groups even if coded 1, 2, 3. Put continuous
|
|
74
|
+
adjustments in `covariates=["age"]`.
|
|
75
|
+
- In **regression**, numbers are continuous and text/category columns are
|
|
76
|
+
categorical. Use `categorical=["group"]` for numeric-coded categories.
|
|
77
|
+
- Set a regression reference with `reference={"group": "control"}`. Otherwise
|
|
78
|
+
the first declared pandas category, or sorted observed level, is the reference.
|
|
79
|
+
- `logmodel` models numeric outcome 1 by default. For text outcomes use
|
|
80
|
+
`event="passed"`; the report states exactly which event is modeled.
|
|
81
|
+
- `posthocifsig=True` means **Tukey**, not automatic method selection.
|
|
82
|
+
Use `posthocifsig="games-howell"` after Welch or `"holm"` for factorial,
|
|
83
|
+
covariate-adjusted, or repeated/mixed comparisons. Incompatible requests explain
|
|
84
|
+
the problem rather than silently changing the method.
|
|
85
|
+
|
|
86
|
+
## ANOVA without guessing
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
rs.aov("score ~ group * teaching", data=df, type=3, posthocifsig="holm")
|
|
90
|
+
rs.aov("score ~ group", data=df, method="welch", posthocifsig="games-howell")
|
|
91
|
+
rs.aov("score ~ time * group", data=long_df,
|
|
92
|
+
subject="student_id", within="time", posthocifsig="holm")
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Study design, sums-of-squares **type**, and variance **method** are different
|
|
96
|
+
choices. Ordinary ANOVA defaults to Type II; Type I is sequential and Type III
|
|
97
|
+
uses sum contrasts. Repeated/mixed designs use effect-specific tests and report
|
|
98
|
+
Greenhouse–Geisser inference where applicable. They do not get an invented
|
|
99
|
+
overall model F. See the [ANOVA and post hoc guide](docs/anova.md).
|
|
100
|
+
|
|
101
|
+
## Independent plotting
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
rs.vis("score ~ study_hours", data=df) # numeric/numeric → scatter
|
|
105
|
+
rs.vis("score ~ group", data=df) # numeric/category → box
|
|
106
|
+
rs.vis("score", data=df) # numeric → histogram
|
|
107
|
+
rs.vis("group", data=df) # category → counts
|
|
108
|
+
rs.vis("score ~ group", data=df, type="violin", palette="colorblind")
|
|
109
|
+
rs.vis("passed ~ group", data=df, type="proportion", normalize="row")
|
|
110
|
+
rs.vis("score ~ time", data=long_df, type="line", estimator="mean")
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Each plot returns a Matplotlib Axes: `ax.figure.savefig("figure.png")`.
|
|
114
|
+
No global Seaborn theme is changed. Plot data are complete cases for the plotted
|
|
115
|
+
variables; analytic sample counts remain in statistical reports.
|
|
116
|
+
|
|
117
|
+
## Documentation and teaching
|
|
118
|
+
|
|
119
|
+
- [API reference](docs/api.md)
|
|
120
|
+
- [ANOVA types, assumptions, and comparison methods](docs/anova.md)
|
|
121
|
+
- [Statistical conventions and limitations](docs/statistics.md)
|
|
122
|
+
- [Five-slide PowerPoint](docs/Rstats-quickstart.pptx)
|
|
123
|
+
- [Teaching notebook](examples/quickstart.ipynb)
|
|
124
|
+
- [Example ANOVA report](examples/anova-report.html) and [regression report](examples/regression-report.html)
|
|
125
|
+
- [Validation and R reference fixtures](tests/reference/README.md)
|
|
126
|
+
|
|
127
|
+
The included datasets are deterministic synthetic teaching data, not research
|
|
128
|
+
evidence. Tests are two-sided unless a method states otherwise. Missingness,
|
|
129
|
+
study design, independence, model assumptions, and causal interpretation remain
|
|
130
|
+
the analyst's responsibility; reports surface relevant details and never switch
|
|
131
|
+
methods based on assumption tests.
|
|
132
|
+
|
|
133
|
+
## Development
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
python -m pytest
|
|
137
|
+
python -m ruff check src tests tools
|
|
138
|
+
python -m build
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Python-version CI installs and tests on 3.12–3.15; platform/Colab smoke checks are
|
|
142
|
+
tracked separately. Do not infer passing environments from a workflow definition
|
|
143
|
+
alone. MANOVA/MANCOVA, arbitrary random effects, repeated-measures ANCOVA,
|
|
144
|
+
multinomial/ordinal logistic models, and SEM are outside this release.
|
|
Binary file
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# ANOVA designs, types, and post hoc comparisons
|
|
2
|
+
|
|
3
|
+
## Choose the study design first
|
|
4
|
+
|
|
5
|
+
| Design | One-line call |
|
|
6
|
+
| --- | --- |
|
|
7
|
+
| Independent one-way | `rs.aov("score ~ group", data=df)` |
|
|
8
|
+
| Factorial | `rs.aov("score ~ group * method", data=df)` |
|
|
9
|
+
| ANCOVA | `rs.aov("score ~ group", data=df, covariates=["age"])` |
|
|
10
|
+
| Unequal-variance one-way | `rs.aov("score ~ group", data=df, method="welch")` |
|
|
11
|
+
| Repeated | `rs.aov("score ~ time", data=df, subject="id", within="time")` |
|
|
12
|
+
| Two within factors | `rs.aov("score ~ time * task", data=df, subject="id", within=["time", "task"])` |
|
|
13
|
+
| Mixed | `rs.aov("score ~ time * group", data=df, subject="id", within="time")` |
|
|
14
|
+
|
|
15
|
+
Predictors in ANOVA are grouping variables. Numeric group codes do not need
|
|
16
|
+
`C()`/`factor()`. Continuous covariates belong in `covariates=`, not among the
|
|
17
|
+
formula's groups. ANCOVA here assumes common covariate slopes; covariate-by-group
|
|
18
|
+
interactions and repeated-measures ANCOVA are not supported.
|
|
19
|
+
|
|
20
|
+
Repeated data must have one row per subject-condition combination. Within-factor
|
|
21
|
+
cells must form the complete Cartesian product. Incomplete subjects are excluded
|
|
22
|
+
and counted, including implicitly absent rows. Replicate cells must be
|
|
23
|
+
deliberately aggregated by the analyst first. A between factor must remain
|
|
24
|
+
constant within each subject. Arbitrary random effects and nested designs are
|
|
25
|
+
not covered by these commands.
|
|
26
|
+
|
|
27
|
+
## Sums of squares are a different choice
|
|
28
|
+
|
|
29
|
+
| `type` | Meaning | When to consider it |
|
|
30
|
+
| --- | --- | --- |
|
|
31
|
+
| `1` | Sequential: each term adjusts for preceding terms | Prespecified hierarchical questions; order matters |
|
|
32
|
+
| `2` (ordinary default) | Each main effect adjusts for other terms except interactions containing it | Additive models; interpret main effects carefully if interactions exist |
|
|
33
|
+
| `3` | Each term adjusts for all other model terms | Explicit full-model hypotheses, including interactions; uses sum contrasts |
|
|
34
|
+
|
|
35
|
+
There is no universally correct sums-of-squares type. In balanced additive
|
|
36
|
+
designs they often agree; in unbalanced designs they answer different questions.
|
|
37
|
+
Type II here intentionally differs from R `anova(lm(...))`'s sequential default.
|
|
38
|
+
Use `type=1` when matching that output. Python's formula engine may reorder main
|
|
39
|
+
effects ahead of interactions; inspect the returned table to verify the tested
|
|
40
|
+
sequence. Type III uses sum contrasts so hypotheses do not accidentally become
|
|
41
|
+
reference-cell tests. Empty-cell/rank-deficient designs are rejected.
|
|
42
|
+
|
|
43
|
+
Do not supply `type=` to Welch or repeated/mixed ANOVA. Welch uses a different
|
|
44
|
+
variance/df calculation. Repeated/mixed designs use effect-specific error strata.
|
|
45
|
+
The mixed backend uses Type II conventions when between-subject group sizes
|
|
46
|
+
differ, which can differ from Type III defaults in other software.
|
|
47
|
+
|
|
48
|
+
Ordinary models include overall F, p, and R². The omnibus and effect-specific
|
|
49
|
+
tables are separate. Repeated/mixed designs do not have a single artificial
|
|
50
|
+
overall F. Corrected df and p values accompany the uncorrected values;
|
|
51
|
+
Greenhouse–Geisser is primary where available unless `correction="none"`.
|
|
52
|
+
|
|
53
|
+
## Request comparisons explicitly
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
rs.aov("score ~ group", data=df, posthocifsig=True) # Tukey
|
|
57
|
+
rs.aov("score ~ group", data=df, method="welch", posthocifsig="games-howell")
|
|
58
|
+
rs.aov("score ~ group", data=df, posthocifsig="dunnett", control="control")
|
|
59
|
+
rs.aov("score ~ group", data=df, covariates=["age"], posthocifsig="holm")
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`False` is the default. `True` means Tukey, not an automatically selected method.
|
|
63
|
+
A named procedure runs only when its corresponding omnibus effect has primary
|
|
64
|
+
`p < alpha`. This gate is a convenience, not an additional global multiplicity
|
|
65
|
+
guarantee. Invalid method/design requests raise an error even if the omnibus
|
|
66
|
+
test would not have been significant.
|
|
67
|
+
|
|
68
|
+
| Method | Purpose / error control | Supported context |
|
|
69
|
+
| --- | --- | --- |
|
|
70
|
+
| `tukey` | All pairwise comparisons; familywise; Tukey–Kramer for unequal n | One independent factor, common variance, no covariates |
|
|
71
|
+
| `games-howell` | All pairwise comparisons with unequal variances and approximate df | One independent factor; the supported follow-up to Welch |
|
|
72
|
+
| `dunnett` | Each treatment against explicit `control=`; familywise | One independent factor, common variance, no covariates |
|
|
73
|
+
| `scheffe` | Conservative familywise coverage over arbitrary contrasts; reports pairwise contrasts | One independent factor, common variance, no covariates |
|
|
74
|
+
| `holm` | Step-down Bonferroni; familywise under arbitrary dependence | Ordinary model-adjusted or subject-aware comparisons |
|
|
75
|
+
| `bonferroni` | Single-step conservative familywise adjustment | Same |
|
|
76
|
+
| `sidak` | Single-step familywise adjustment under independence/suitable dependence | Same; correlated contrasts require care |
|
|
77
|
+
| `holm-sidak` | Step-down Šidák adjustment | Same dependence caveat |
|
|
78
|
+
| `fdr-bh` | Exploratory Benjamini–Hochberg false discovery rate | Independent/appropriate positively dependent comparison families |
|
|
79
|
+
| `fdr-by` | Exploratory Benjamini–Yekutieli false discovery rate | Arbitrary dependence; typically more conservative |
|
|
80
|
+
|
|
81
|
+
Holm/Bonferroni/Šidák/FDR are **adjustments**, not standalone tests. Reports
|
|
82
|
+
identify both the underlying test and adjustment. Welch currently permits only
|
|
83
|
+
Games–Howell as an automatic post hoc follow-up.
|
|
84
|
+
|
|
85
|
+
### Which comparisons are generated?
|
|
86
|
+
|
|
87
|
+
- A significant main effect generates all its marginal pairwise comparisons.
|
|
88
|
+
- A significant interaction generates simple-effect comparisons for each factor,
|
|
89
|
+
conditioning on every level combination of the other interacting factors.
|
|
90
|
+
- Each triggering effect is a separate adjustment family. For an interaction,
|
|
91
|
+
**all** generated simple effects belong to that family, not separate small
|
|
92
|
+
families per slice. Distinct omnibus effects are not jointly adjusted.
|
|
93
|
+
- OLS comparisons use fitted marginal-mean contrasts, equal weighting across
|
|
94
|
+
other factor levels, covariates at analyzed-sample means, and model covariance
|
|
95
|
+
and residual df. This can differ from raw means in unbalanced/adjusted models.
|
|
96
|
+
- Repeated/mixed follow-ups first average over remaining repeated factors within
|
|
97
|
+
each subject. Within-subject contrasts use paired t tests; between-subject
|
|
98
|
+
contrasts use Welch t tests on subject means. These are labeled explicitly
|
|
99
|
+
rather than presented as identical to the ANOVA's pooled-error contrasts.
|
|
100
|
+
|
|
101
|
+
`estimate` is group A minus group B. Specialized procedures return simultaneous
|
|
102
|
+
intervals. General adjusted t comparisons return **pointwise** CIs alongside
|
|
103
|
+
adjusted p values; the CI and adjusted significance decision need not agree.
|
|
104
|
+
No significance p value is attached to a raw group mean itself.
|
|
105
|
+
|
|
106
|
+
### Assumptions and boundaries
|
|
107
|
+
|
|
108
|
+
Independence is a study-design assumption. Ordinary ANOVA assumes appropriate
|
|
109
|
+
residual behavior and common variance; ANCOVA additionally requires a justified
|
|
110
|
+
linear adjustment and common slopes. Welch addresses variance heterogeneity,
|
|
111
|
+
not dependence or arbitrary distributional problems. Repeated inference depends
|
|
112
|
+
on its covariance assumptions; GG correction does not repair all violations.
|
|
113
|
+
Small samples, selection, missingness, and outliers require scientific judgment.
|
|
114
|
+
|
|
115
|
+
Read the group descriptives, diagnostics, effect sizes, and intervals alongside
|
|
116
|
+
p values. Diagnostics never silently switch the requested method.
|
|
117
|
+
|
|
118
|
+
Engine references: [statsmodels ANOVA](https://www.statsmodels.org/stable/generated/statsmodels.stats.anova.anova_lm.html),
|
|
119
|
+
[Pingouin repeated ANOVA](https://pingouin-stats.org/generated/pingouin.rm_anova.html),
|
|
120
|
+
[Pingouin mixed ANOVA](https://pingouin-stats.org/generated/pingouin.mixed_anova.html),
|
|
121
|
+
[SciPy Tukey/Games–Howell](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.tukey_hsd.html),
|
|
122
|
+
[SciPy Dunnett](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.dunnett.html),
|
|
123
|
+
[statsmodels adjustments](https://www.statsmodels.org/stable/generated/statsmodels.stats.multitest.multipletests.html).
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# API reference
|
|
2
|
+
|
|
3
|
+
All inference is two-sided where applicable. `alpha=.05` determines confidence
|
|
4
|
+
levels, significance labels, and post hoc gates. All analysis functions return
|
|
5
|
+
`AnalysisResult`; they do not generate figures.
|
|
6
|
+
|
|
7
|
+
## Shared conventions
|
|
8
|
+
|
|
9
|
+
- `data=` must be a pandas dataframe with unique column names.
|
|
10
|
+
- Formula: a quoted `"outcome ~ predictors"`. Supports `+`, `*`, `:`, parentheses,
|
|
11
|
+
and `0`/`-1` intercept removal for `lm` only. A single outcome is required.
|
|
12
|
+
- Backticks quote names with spaces: ``"`exam score` ~ group"``.
|
|
13
|
+
- `missing="drop"` explicitly reports deletion; `missing="raise"` rejects it.
|
|
14
|
+
Infinite analysis values are rejected.
|
|
15
|
+
- Formulas are a restricted column/operator language; arbitrary Python/R
|
|
16
|
+
expressions, transformations, and function evaluation are not supported.
|
|
17
|
+
Prepare transformed columns with pandas first.
|
|
18
|
+
- `result.tables` contains full-precision pandas dataframes. `result.metadata`
|
|
19
|
+
records choices, `result.diagnostics` contains notes, and `result.model`
|
|
20
|
+
exposes an underlying fitted statsmodels result when one exists.
|
|
21
|
+
- `result.show()` displays the report; `print(result)` prints a text version.
|
|
22
|
+
Notebook cells display a rich HTML report automatically.
|
|
23
|
+
|
|
24
|
+
## `descriptives(*, data, columns=None, by=None, alpha=.05)`
|
|
25
|
+
|
|
26
|
+
`columns` defaults to all nongrouping columns. `by` takes a name or list of names.
|
|
27
|
+
Available values are used independently per column; missing grouping values
|
|
28
|
+
form their own group. Numeric output includes valid/missing n, mean, median,
|
|
29
|
+
modes, sample SD/variance, min/max/range, Q1/Q3/IQR, unscaled MAD, bias-corrected
|
|
30
|
+
skewness/excess kurtosis, and t-based mean CIs. Categorical output contains
|
|
31
|
+
counts, valid percentages, and missing n. Undefined quantities remain missing.
|
|
32
|
+
|
|
33
|
+
## `table(formula, *, data, percent="valid", missing="drop")`
|
|
34
|
+
|
|
35
|
+
`"group"` produces a one-way table; `"group ~ passed"` produces a two-way
|
|
36
|
+
table with the left side as rows and right side as columns.
|
|
37
|
+
`percent="valid"`/`"total"` uses the valid grand total; `"row"` and `"column"`
|
|
38
|
+
use their respective two-way totals. Counts, percentages, and variable-specific
|
|
39
|
+
missingness are separate reusable tables.
|
|
40
|
+
|
|
41
|
+
## `chisq(formula, *, data=None, expected=None, method="pearson", correction=False, missing="drop")`
|
|
42
|
+
|
|
43
|
+
Use a two-way formula for independence. Pearson reports χ², df, p, uncorrected
|
|
44
|
+
Cramér's V, expected counts, and Pearson residuals. Set `correction=True` for
|
|
45
|
+
Yates correction on a 2×2 table; the association effect size remains uncorrected.
|
|
46
|
+
`method="fisher"` requests a two-sided 2×2 Fisher exact test with sample odds
|
|
47
|
+
ratio. Fisher does not use a continuity correction.
|
|
48
|
+
|
|
49
|
+
For goodness of fit, pass counts directly and fixed expected probabilities:
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
rs.chisq([20, 30, 50], expected=[.25, .25, .5])
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Omitted probabilities default to equal proportions. Counts must be nonnegative
|
|
56
|
+
integers; probabilities must be positive and sum to one. Reports Cohen's w.
|
|
57
|
+
|
|
58
|
+
## `aov(formula, *, data, covariates=None, type=None, method="standard", subject=None, within=None, posthocifsig=False, control=None, alpha=.05, correction="gg", missing="drop")`
|
|
59
|
+
|
|
60
|
+
Formula predictors are categorical, including numeric-coded groups. `covariates`
|
|
61
|
+
adds continuous additive adjustments; those variables must not also appear as
|
|
62
|
+
grouping predictors. `type=None` selects Type II for ordinary OLS designs.
|
|
63
|
+
Use integers 1, 2, or 3 explicitly for supported sums-of-squares types.
|
|
64
|
+
`method="welch"` is for one independent group factor without covariates.
|
|
65
|
+
|
|
66
|
+
Repeated/mixed designs require `subject` and `within` together, long-format
|
|
67
|
+
data, and a full factorial formula. `within` takes one name or a two-name list.
|
|
68
|
+
There may be one between factor only when there is exactly one within factor.
|
|
69
|
+
Do not supply `type` or `covariates` for these designs.
|
|
70
|
+
|
|
71
|
+
`correction="gg"` makes Greenhouse–Geisser inference primary where available;
|
|
72
|
+
`"none"` makes uncorrected inference primary. Both results are retained. For
|
|
73
|
+
ordinary/Welch designs this argument has no effect.
|
|
74
|
+
|
|
75
|
+
See [ANOVA and post hoc methods](anova.md) for compatibility and interpretation.
|
|
76
|
+
|
|
77
|
+
## `lm(formula, *, data, categorical=None, reference=None, alpha=.05, missing="drop")`
|
|
78
|
+
|
|
79
|
+
Ordinary least squares for continuous outcomes. Text/category predictors are
|
|
80
|
+
categorical automatically; `categorical=["group"]` marks numeric-coded groups.
|
|
81
|
+
`factor(group)` in the formula is an alternative. Use
|
|
82
|
+
`reference={"group": "control"}` to choose a baseline.
|
|
83
|
+
|
|
84
|
+
By default, the first observed level in declared pandas category order, or the
|
|
85
|
+
first sorted observed value, is the reference. Unused categories are removed.
|
|
86
|
+
Reports overall F, df, p, R²/adjusted R², residual SD, coefficient estimates,
|
|
87
|
+
SEs, t tests, confidence intervals, numeric descriptives, and diagnostic tests.
|
|
88
|
+
For models without an intercept, statsmodels reports uncentered R²; interpret
|
|
89
|
+
it separately from the usual centered R². No overall F exists for intercept-only
|
|
90
|
+
models; it is missing rather than a significance claim.
|
|
91
|
+
|
|
92
|
+
## `logmodel(formula, *, data, categorical=None, reference=None, event=None, alpha=.05, missing="drop")`
|
|
93
|
+
|
|
94
|
+
Binary logistic regression. Category/reference handling matches `lm`. Numeric
|
|
95
|
+
0/1 outcomes model 1; otherwise specify the event explicitly. Exactly two
|
|
96
|
+
observed outcomes and an intercept are required.
|
|
97
|
+
|
|
98
|
+
Reports the overall likelihood-ratio χ² against the intercept-only model,
|
|
99
|
+
McFadden pseudo-R², AIC, outcome counts, coefficients, z tests, odds ratios and
|
|
100
|
+
Wald CIs. Nonconvergence, detected separation, invalid covariance, and redundant
|
|
101
|
+
predictors raise explanatory errors. Large finite coefficients/SEs produce a
|
|
102
|
+
quasi-separation note, not a claim that every separation case can be detected.
|
|
103
|
+
|
|
104
|
+
## `vis(formula, *, data, type=None, categorical=None, hue=None, palette=None, colors="default", xlabel=None, ylabel=None, title=None, estimator=None, normalize=None, units=None, ax=None, **kwargs)`
|
|
105
|
+
|
|
106
|
+
Standalone plotting; returns Matplotlib Axes. No statistical model is fit by
|
|
107
|
+
this command. Complete cases are used for the plotted columns.
|
|
108
|
+
|
|
109
|
+
| Type | Input / additional requirement |
|
|
110
|
+
| --- | --- |
|
|
111
|
+
| `scatter` | `"numeric_y ~ numeric_x"` |
|
|
112
|
+
| `box`, `violin` | Numeric and grouping variable; explicit type treats numeric-coded groups as categories |
|
|
113
|
+
| `hist`, `density` | One numeric column name |
|
|
114
|
+
| `count` | One column, or two-way formula with outcome as hue |
|
|
115
|
+
| `proportion` | Two-way formula and `normalize="row"`, `"column"`, or `"total"`; row means within RHS group |
|
|
116
|
+
| `heatmap` | Two-way contingency counts |
|
|
117
|
+
| `line` | `estimator="mean"`/`"median"`, or `units="student_id"` for individual profiles |
|
|
118
|
+
|
|
119
|
+
Automatic defaults: numeric/numeric → scatter; numeric/categorical → box;
|
|
120
|
+
categorical/categorical → contingency heatmap; one numeric → histogram;
|
|
121
|
+
one categorical → count. Use `categorical=` to override numeric-coded groups.
|
|
122
|
+
|
|
123
|
+
`colors="default"` uses a colorblind-friendly palette. A Seaborn palette can be
|
|
124
|
+
specified with `palette=` or `colors=`. For continuous hue use a suitable
|
|
125
|
+
sequential palette explicitly. `**kwargs` passes plot-specific Seaborn options,
|
|
126
|
+
such as `bins=20`, `alpha=.6`, or `errorbar=None`. Heatmaps use `cmap=`.
|
|
127
|
+
Seaborn aggregate line intervals use its own bootstrap defaults; they are not
|
|
128
|
+
ANOVA-adjusted or repeated-measures contrast intervals. Set `seed=` for
|
|
129
|
+
reproducible bootstrap plots.
|