pymer4 0.9.0__py3-none-any.whl

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.
Files changed (77) hide show
  1. conda/meta.yaml +61 -0
  2. docs/_config.yml +51 -0
  3. docs/_toc.yml +41 -0
  4. docs/api/config.md +9 -0
  5. docs/api/expressions.ipynb +227 -0
  6. docs/api/io.md +9 -0
  7. docs/api/models/glm.md +98 -0
  8. docs/api/models/glmer.md +94 -0
  9. docs/api/models/index.md +30 -0
  10. docs/api/models/lm.md +75 -0
  11. docs/api/models/lmer.md +92 -0
  12. docs/api/rfuncs.md +9 -0
  13. docs/api/tidystats.md +133 -0
  14. docs/development/contributing.md +73 -0
  15. docs/development/design.md +122 -0
  16. docs/development/extending.ipynb +384 -0
  17. docs/index.md +45 -0
  18. docs/logo-bold.png +0 -0
  19. docs/logo.png +0 -0
  20. docs/pages/comingfromR.md +18 -0
  21. docs/pages/faqs.ipynb +701 -0
  22. docs/pages/installation.md +126 -0
  23. docs/pages/migrating.md +36 -0
  24. docs/pages/new.md +350 -0
  25. docs/pages/quickstart.ipynb +2349 -0
  26. docs/tutorials/01_lm.ipynb +1918 -0
  27. docs/tutorials/02_categorical.ipynb +2841 -0
  28. docs/tutorials/03_lmms.ipynb +1253 -0
  29. docs/tutorials/04_glmms.ipynb +1179 -0
  30. pymer4/__init__.py +5 -0
  31. pymer4/config.py +53 -0
  32. pymer4/expressions.py +77 -0
  33. pymer4/io.py +86 -0
  34. pymer4/models/__init__.py +64 -0
  35. pymer4/models/base.py +718 -0
  36. pymer4/models/glm.py +85 -0
  37. pymer4/models/glmer.py +89 -0
  38. pymer4/models/lm.py +122 -0
  39. pymer4/models/lmer.py +291 -0
  40. pymer4/resources/advertising.csv +201 -0
  41. pymer4/resources/chickweight.csv +579 -0
  42. pymer4/resources/credit.csv +401 -0
  43. pymer4/resources/gammas.csv +6001 -0
  44. pymer4/resources/mtcars.csv +33 -0
  45. pymer4/resources/penguins.csv +345 -0
  46. pymer4/resources/poker.csv +301 -0
  47. pymer4/resources/sample_data.csv +565 -0
  48. pymer4/resources/sleep.csv +181 -0
  49. pymer4/resources/titanic.csv +892 -0
  50. pymer4/resources/titanic_test.csv +419 -0
  51. pymer4/resources/titanic_train.csv +892 -0
  52. pymer4/rfuncs.py +47 -0
  53. pymer4/tests/conftest.py +42 -0
  54. pymer4/tests/test_funcs.py +185 -0
  55. pymer4/tests/test_glm.py +98 -0
  56. pymer4/tests/test_glmer.py +207 -0
  57. pymer4/tests/test_io.py +36 -0
  58. pymer4/tests/test_lm.py +538 -0
  59. pymer4/tests/test_lmer.py +309 -0
  60. pymer4/tidystats/__init__.py +28 -0
  61. pymer4/tidystats/base.py +17 -0
  62. pymer4/tidystats/bridge.py +355 -0
  63. pymer4/tidystats/broom.py +54 -0
  64. pymer4/tidystats/easystats.py +190 -0
  65. pymer4/tidystats/emmeans_lib.py +101 -0
  66. pymer4/tidystats/lmerTest.py +128 -0
  67. pymer4/tidystats/multimodel.py +173 -0
  68. pymer4/tidystats/plutils.py +158 -0
  69. pymer4/tidystats/stats.py +71 -0
  70. pymer4/tidystats/tables.py +618 -0
  71. pymer4/tidystats/tibble.py +17 -0
  72. pymer4/version.py +3 -0
  73. pymer4-0.9.0.dist-info/METADATA +71 -0
  74. pymer4-0.9.0.dist-info/RECORD +77 -0
  75. pymer4-0.9.0.dist-info/WHEEL +5 -0
  76. pymer4-0.9.0.dist-info/licenses/LICENSE.txt +21 -0
  77. pymer4-0.9.0.dist-info/top_level.txt +4 -0
conda/meta.yaml ADDED
@@ -0,0 +1,61 @@
1
+ # Get information from pyproject.toml file
2
+ {% set pyproject = load_file_data('../pyproject.toml', from_recipe_dir=True) %}
3
+ {% set project = pyproject.get('project', {}) %}
4
+ {% set min_python = project.get('requires-python') %}
5
+ {% set pip_deps = project.get('dependencies', []) %}
6
+ {% set conda_deps = pyproject.get('tool', {}).get('pixi', {}).get('dependencies', []) %}
7
+ {% set name = project.get('name')%}
8
+ {% set version_match = load_file_regex(
9
+ load_file="../pymer4/version.py",
10
+ from_recipe_dir=True,
11
+ regex_pattern='__version__ = "([0-9.]+)"') %}
12
+ {% set version = version_match[1] %}
13
+
14
+ package:
15
+ name: {{ name }}
16
+ version: {{ version }}
17
+
18
+ source:
19
+ git_url: ../
20
+ path: ../
21
+
22
+ build:
23
+ noarch: python
24
+ script: pip install . -vv --no-deps
25
+ string: {{ GIT_DESCRIBE_HASH }}
26
+
27
+ requirements:
28
+ host:
29
+ - python
30
+ - pip
31
+ - numpy >=1.20
32
+ - setuptools >=61.0.0
33
+ - setuptools-scm
34
+ - hatchling
35
+
36
+ # Load both Python and R requirements from pyproject.toml
37
+ run:
38
+ - python {{ min_python }}
39
+ {% for dep, ver in conda_deps.items() %}
40
+ - {{ dep }} {{ ver }}
41
+ {% endfor %}
42
+ {% for dep in pip_deps %}
43
+ - {{ dep.lower() }}
44
+ {% endfor %}
45
+
46
+ # Run basic import tests and full test suite after building
47
+ test:
48
+ imports:
49
+ - pymer4
50
+ commands:
51
+ - python -c "from pymer4 import test_install; test_install()"
52
+
53
+ about:
54
+ home: "https://eshinjolly.com/pymer4/"
55
+ license: MIT
56
+ license_family: MIT
57
+ summary: "pymer4: all the convenience of lme4 in python"
58
+
59
+ extra:
60
+ recipe-maintainers:
61
+ - ejolly
docs/_config.yml ADDED
@@ -0,0 +1,51 @@
1
+ # Learn more at https://jupyterbook.org/customize/config.html
2
+ title: Pymer4
3
+ author: Eshin Jolly
4
+ logo: 'logo-bold.png'
5
+
6
+ # See https://jupyterbook.org/content/execute.html
7
+ execute:
8
+ execute_notebooks: 'off'
9
+ exclude_patterns:
10
+ - '*bak.ipynb'
11
+
12
+
13
+ repository:
14
+ url: https://github.com/ejolly/pymer4
15
+ path_to_book: docs
16
+ branch: main
17
+
18
+ html:
19
+ home_page_in_navbar: false
20
+ use_edit_page_button: false
21
+ use_issues_button: true
22
+ use_multitoc_numbering: false
23
+ use_repository_button: true
24
+ announcement: "Version 0.9.0 includes a totally new API and new features that are not backwards compatible with previous versions! Check out the <a style='color: #87CEEB;' href='pages/migrating.html'>migration guide</a> for more information."
25
+ parse:
26
+ myst_enable_extensions:
27
+ - amsmath
28
+ - colon_fence
29
+ - dollarmath
30
+ - linkify
31
+ - substitution
32
+ - tasklist
33
+
34
+ sphinx:
35
+ extra_extensions:
36
+ - 'sphinx_design'
37
+ - 'sphinx.ext.autodoc'
38
+ - 'sphinx.ext.autosummary'
39
+ - 'sphinx.ext.napoleon'
40
+ - 'sphinx.ext.viewcode'
41
+ - 'sphinxcontrib.mermaid'
42
+
43
+ config:
44
+ add_function_parentheses: true
45
+ add_module_names: true
46
+ autosummary_generate: true
47
+ autosummary_generate_overwrite: true
48
+ viewcode_line_numbers: true
49
+ viewcode_follow_imported_members: true
50
+ templates_path: templates
51
+ suppress_warnings: ["etoc.toctree"]
docs/_toc.yml ADDED
@@ -0,0 +1,41 @@
1
+ format: jb-book
2
+ root: index
3
+ parts:
4
+ - caption: Pymer4
5
+ maxdepth: 1
6
+ chapters:
7
+ - file: pages/installation
8
+ - file: pages/quickstart.ipynb
9
+ - file: pages/new
10
+ - file: pages/migrating
11
+ - file: pages/faqs
12
+
13
+ - caption: Tutorials
14
+ maxdepth: 1
15
+ chapters:
16
+ - file: tutorials/01_lm.ipynb
17
+ - file: tutorials/02_categorical.ipynb
18
+ - file: tutorials/03_lmms.ipynb
19
+ - file: tutorials/04_glmms.ipynb
20
+
21
+ - caption: API Reference
22
+ maxdepth: 3
23
+ chapters:
24
+ - file: api/models/index.md
25
+ sections:
26
+ - file: api/models/lm.md
27
+ - file: api/models/glm.md
28
+ - file: api/models/lmer.md
29
+ - file: api/models/glmer.md
30
+ - file: api/tidystats.md
31
+ - file: api/config.md
32
+ - file: api/expressions.ipynb
33
+ - file: api/io.md
34
+ - file: api/rfuncs.ipynb
35
+
36
+ - caption: Developer Guide
37
+ maxdepth: 1
38
+ chapters:
39
+ - file: development/contributing.md
40
+ - file: development/extending.ipynb
41
+ - file: development/design.md
docs/api/config.md ADDED
@@ -0,0 +1,9 @@
1
+ # `pymer4.config`
2
+
3
+ Functions to check `pymer4`'s configuration and installation status
4
+
5
+ ```{eval-rst}
6
+ .. automodule:: pymer4.config
7
+ :members:
8
+ :member-order: alphabetical
9
+ ```
@@ -0,0 +1,227 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# `pymer4.expressions`\n",
8
+ "\n",
9
+ "Custom `polars` expressions useable inside of any polars context and compatible with other `polars` selectors.\n",
10
+ "\n",
11
+ "**Examples**"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "code",
16
+ "execution_count": 22,
17
+ "metadata": {
18
+ "tags": [
19
+ "remove-input"
20
+ ]
21
+ },
22
+ "outputs": [],
23
+ "source": [
24
+ "from pymer4 import load_dataset\n",
25
+ "import polars as pl\n",
26
+ "\n",
27
+ "mtcars = load_dataset('mtcars').select('mpg', 'disp', 'cyl')"
28
+ ]
29
+ },
30
+ {
31
+ "cell_type": "markdown",
32
+ "metadata": {},
33
+ "source": [
34
+ "Center `mpg` and zscore `disp` by passing in their names as you would to `pl.col()`"
35
+ ]
36
+ },
37
+ {
38
+ "cell_type": "code",
39
+ "execution_count": 23,
40
+ "metadata": {},
41
+ "outputs": [
42
+ {
43
+ "data": {
44
+ "text/html": [
45
+ "<div><style>\n",
46
+ ".dataframe > thead > tr,\n",
47
+ ".dataframe > tbody > tr {\n",
48
+ " text-align: right;\n",
49
+ " white-space: pre-wrap;\n",
50
+ "}\n",
51
+ "</style>\n",
52
+ "<small>shape: (5, 5)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>mpg</th><th>disp</th><th>cyl</th><th>mpg_centered</th><th>disp_zscore</th></tr><tr><td>f64</td><td>f64</td><td>i64</td><td>f64</td><td>f64</td></tr></thead><tbody><tr><td>21.0</td><td>160.0</td><td>6</td><td>0.909375</td><td>-0.57062</td></tr><tr><td>21.0</td><td>160.0</td><td>6</td><td>0.909375</td><td>-0.57062</td></tr><tr><td>22.8</td><td>108.0</td><td>4</td><td>2.709375</td><td>-0.990182</td></tr><tr><td>21.4</td><td>258.0</td><td>6</td><td>1.309375</td><td>0.220094</td></tr><tr><td>18.7</td><td>360.0</td><td>8</td><td>-1.390625</td><td>1.043081</td></tr></tbody></table></div>"
53
+ ],
54
+ "text/plain": [
55
+ "shape: (5, 5)\n",
56
+ "┌──────┬───────┬─────┬──────────────┬─────────────┐\n",
57
+ "│ mpg ┆ disp ┆ cyl ┆ mpg_centered ┆ disp_zscore │\n",
58
+ "│ --- ┆ --- ┆ --- ┆ --- ┆ --- │\n",
59
+ "│ f64 ┆ f64 ┆ i64 ┆ f64 ┆ f64 │\n",
60
+ "╞══════╪═══════╪═════╪══════════════╪═════════════╡\n",
61
+ "│ 21.0 ┆ 160.0 ┆ 6 ┆ 0.909375 ┆ -0.57062 │\n",
62
+ "│ 21.0 ┆ 160.0 ┆ 6 ┆ 0.909375 ┆ -0.57062 │\n",
63
+ "│ 22.8 ┆ 108.0 ┆ 4 ┆ 2.709375 ┆ -0.990182 │\n",
64
+ "│ 21.4 ┆ 258.0 ┆ 6 ┆ 1.309375 ┆ 0.220094 │\n",
65
+ "│ 18.7 ┆ 360.0 ┆ 8 ┆ -1.390625 ┆ 1.043081 │\n",
66
+ "└──────┴───────┴─────┴──────────────┴─────────────┘"
67
+ ]
68
+ },
69
+ "execution_count": 23,
70
+ "metadata": {},
71
+ "output_type": "execute_result"
72
+ }
73
+ ],
74
+ "source": [
75
+ "from pymer4.expressions import center, zscore, scale\n",
76
+ "\n",
77
+ "mtcars.with_columns(\n",
78
+ " center('mpg').alias('mpg_centered'), \n",
79
+ " zscore('disp').alias('disp_zscore')\n",
80
+ " ).head()"
81
+ ]
82
+ },
83
+ {
84
+ "cell_type": "markdown",
85
+ "metadata": {},
86
+ "source": [
87
+ "Normalize all columns by dividing by their standard deviations using a polars selector like `pl.all()`"
88
+ ]
89
+ },
90
+ {
91
+ "cell_type": "code",
92
+ "execution_count": 19,
93
+ "metadata": {},
94
+ "outputs": [
95
+ {
96
+ "data": {
97
+ "text/html": [
98
+ "<div><style>\n",
99
+ ".dataframe > thead > tr,\n",
100
+ ".dataframe > tbody > tr {\n",
101
+ " text-align: right;\n",
102
+ " white-space: pre-wrap;\n",
103
+ "}\n",
104
+ "</style>\n",
105
+ "<small>shape: (5, 6)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>mpg</th><th>disp</th><th>cyl</th><th>mpg_scaled</th><th>disp_scaled</th><th>cyl_scaled</th></tr><tr><td>f64</td><td>f64</td><td>i64</td><td>f64</td><td>f64</td><td>f64</td></tr></thead><tbody><tr><td>21.0</td><td>160.0</td><td>6</td><td>3.484351</td><td>1.290961</td><td>3.35961</td></tr><tr><td>21.0</td><td>160.0</td><td>6</td><td>3.484351</td><td>1.290961</td><td>3.35961</td></tr><tr><td>22.8</td><td>108.0</td><td>4</td><td>3.783009</td><td>0.871399</td><td>2.23974</td></tr><tr><td>21.4</td><td>258.0</td><td>6</td><td>3.550719</td><td>2.081674</td><td>3.35961</td></tr><tr><td>18.7</td><td>360.0</td><td>8</td><td>3.102731</td><td>2.904662</td><td>4.47948</td></tr></tbody></table></div>"
106
+ ],
107
+ "text/plain": [
108
+ "shape: (5, 6)\n",
109
+ "┌──────┬───────┬─────┬────────────┬─────────────┬────────────┐\n",
110
+ "│ mpg ┆ disp ┆ cyl ┆ mpg_scaled ┆ disp_scaled ┆ cyl_scaled │\n",
111
+ "│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │\n",
112
+ "│ f64 ┆ f64 ┆ i64 ┆ f64 ┆ f64 ┆ f64 │\n",
113
+ "╞══════╪═══════╪═════╪════════════╪═════════════╪════════════╡\n",
114
+ "│ 21.0 ┆ 160.0 ┆ 6 ┆ 3.484351 ┆ 1.290961 ┆ 3.35961 │\n",
115
+ "│ 21.0 ┆ 160.0 ┆ 6 ┆ 3.484351 ┆ 1.290961 ┆ 3.35961 │\n",
116
+ "│ 22.8 ┆ 108.0 ┆ 4 ┆ 3.783009 ┆ 0.871399 ┆ 2.23974 │\n",
117
+ "│ 21.4 ┆ 258.0 ┆ 6 ┆ 3.550719 ┆ 2.081674 ┆ 3.35961 │\n",
118
+ "│ 18.7 ┆ 360.0 ┆ 8 ┆ 3.102731 ┆ 2.904662 ┆ 4.47948 │\n",
119
+ "└──────┴───────┴─────┴────────────┴─────────────┴────────────┘"
120
+ ]
121
+ },
122
+ "execution_count": 19,
123
+ "metadata": {},
124
+ "output_type": "execute_result"
125
+ }
126
+ ],
127
+ "source": [
128
+ "mtcars.with_columns(\n",
129
+ " # Normalize all columns\n",
130
+ " scale(pl.all()).name.suffix('_scaled')\n",
131
+ " ).head()"
132
+ ]
133
+ },
134
+ {
135
+ "cell_type": "markdown",
136
+ "metadata": {},
137
+ "source": [
138
+ "Expression are extensible `.over('column_name')`expressions. \n",
139
+ "\n",
140
+ "For example, we can z-score `mpg` over all rows or by sub-groups of `cyl`"
141
+ ]
142
+ },
143
+ {
144
+ "cell_type": "code",
145
+ "execution_count": 21,
146
+ "metadata": {},
147
+ "outputs": [
148
+ {
149
+ "data": {
150
+ "text/html": [
151
+ "<div><style>\n",
152
+ ".dataframe > thead > tr,\n",
153
+ ".dataframe > tbody > tr {\n",
154
+ " text-align: right;\n",
155
+ " white-space: pre-wrap;\n",
156
+ "}\n",
157
+ "</style>\n",
158
+ "<small>shape: (5, 5)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>mpg</th><th>disp</th><th>cyl</th><th>mpg_zscore</th><th>mpg_zscore_by_cyl</th></tr><tr><td>f64</td><td>f64</td><td>i64</td><td>f64</td><td>f64</td></tr></thead><tbody><tr><td>21.0</td><td>160.0</td><td>6</td><td>0.150885</td><td>0.864867</td></tr><tr><td>21.0</td><td>160.0</td><td>6</td><td>0.150885</td><td>0.864867</td></tr><tr><td>22.8</td><td>108.0</td><td>4</td><td>0.449543</td><td>-0.856715</td></tr><tr><td>21.4</td><td>258.0</td><td>6</td><td>0.217253</td><td>1.140053</td></tr><tr><td>18.7</td><td>360.0</td><td>8</td><td>-0.230735</td><td>1.406224</td></tr></tbody></table></div>"
159
+ ],
160
+ "text/plain": [
161
+ "shape: (5, 5)\n",
162
+ "┌──────┬───────┬─────┬────────────┬───────────────────┐\n",
163
+ "│ mpg ┆ disp ┆ cyl ┆ mpg_zscore ┆ mpg_zscore_by_cyl │\n",
164
+ "│ --- ┆ --- ┆ --- ┆ --- ┆ --- │\n",
165
+ "│ f64 ┆ f64 ┆ i64 ┆ f64 ┆ f64 │\n",
166
+ "╞══════╪═══════╪═════╪════════════╪═══════════════════╡\n",
167
+ "│ 21.0 ┆ 160.0 ┆ 6 ┆ 0.150885 ┆ 0.864867 │\n",
168
+ "│ 21.0 ┆ 160.0 ┆ 6 ┆ 0.150885 ┆ 0.864867 │\n",
169
+ "│ 22.8 ┆ 108.0 ┆ 4 ┆ 0.449543 ┆ -0.856715 │\n",
170
+ "│ 21.4 ┆ 258.0 ┆ 6 ┆ 0.217253 ┆ 1.140053 │\n",
171
+ "│ 18.7 ┆ 360.0 ┆ 8 ┆ -0.230735 ┆ 1.406224 │\n",
172
+ "└──────┴───────┴─────┴────────────┴───────────────────┘"
173
+ ]
174
+ },
175
+ "execution_count": 21,
176
+ "metadata": {},
177
+ "output_type": "execute_result"
178
+ }
179
+ ],
180
+ "source": [
181
+ "mtcars.with_columns(\n",
182
+ " zscore('mpg').alias('mpg_zscore'),\n",
183
+ " zscore('mpg').over('cyl').alias('mpg_zscore_by_cyl')\n",
184
+ " ).head()\n"
185
+ ]
186
+ },
187
+ {
188
+ "cell_type": "markdown",
189
+ "metadata": {},
190
+ "source": [
191
+ "---"
192
+ ]
193
+ },
194
+ {
195
+ "cell_type": "markdown",
196
+ "metadata": {},
197
+ "source": [
198
+ "\n",
199
+ "```{eval-rst}\n",
200
+ ".. automodule:: pymer4.expressions\n",
201
+ " :members:\n",
202
+ " :member-order: alphabetical\n"
203
+ ]
204
+ }
205
+ ],
206
+ "metadata": {
207
+ "kernelspec": {
208
+ "display_name": "default",
209
+ "language": "python",
210
+ "name": "python3"
211
+ },
212
+ "language_info": {
213
+ "codemirror_mode": {
214
+ "name": "ipython",
215
+ "version": 3
216
+ },
217
+ "file_extension": ".py",
218
+ "mimetype": "text/x-python",
219
+ "name": "python",
220
+ "nbconvert_exporter": "python",
221
+ "pygments_lexer": "ipython3",
222
+ "version": "3.12.9"
223
+ }
224
+ },
225
+ "nbformat": 4,
226
+ "nbformat_minor": 2
227
+ }
docs/api/io.md ADDED
@@ -0,0 +1,9 @@
1
+ # `pymer4.io`
2
+
3
+ Functions to load and save models and datasets
4
+
5
+ ```{eval-rst}
6
+ .. automodule:: pymer4.io
7
+ :members:
8
+ :member-order: alphabetical
9
+ ```
docs/api/models/glm.md ADDED
@@ -0,0 +1,98 @@
1
+ # `pymer4.models.glm`
2
+
3
+ :::{admonition} Tutorial
4
+ :class: tip
5
+ Check out the [linear regression](../../tutorials/01_lm.ipynb) and [GLMs tutorial](../../tutorials/04_glmms.ipynb) for usage examples
6
+ :::
7
+
8
+ ## GLM
9
+
10
+ **G**eneralized **L**inear **M**odels fit using Maximum-Likelihood-Estimation (MLE)
11
+
12
+ GLMs are useful for estimating models with non-gaussian outcome variables. These include models like logistic regression for binary data and poisson regression for count data that are controlled using the `family` and `link` arguments when initializing a model along with a formula and data.
13
+
14
+ For some models like logistic regression, it can be helpful to use `.fit(exponentiate=True)` to transform estimates to the odds scale to aid interpretability. By default the `'fitted'` column in `model.data` and the output of `model.predict()` uses `type_predict = 'response'` so that model predictions are on the *response* scale, i.e. probabilities for logistic regression.
15
+
16
+ ```python
17
+ from pymer4 import load_dataset('titanic')
18
+ from pymer4.models import glm
19
+
20
+ titanic = load_dataset('titanic')
21
+
22
+ # Logistic regression with logit link
23
+ log_reg = glm('survived ~ fare', family='binomial', data=titanic)
24
+
25
+ # See parameter estimates on odds scale
26
+ log_reg.fit(exponentiate=True)
27
+
28
+ # Logistic regression with probit link
29
+ probit_reg = glm('survived ~ fare', family='binomial', link='probit', data=titanic)
30
+
31
+ # Now estimates on the link scale
32
+ # which is z-score of p(survived)
33
+ probit_reg.fit()
34
+
35
+ ```
36
+
37
+ ---
38
+
39
+ ```{eval-rst}
40
+ .. autoclass:: pymer4.models.glm.glm
41
+ :exclude-members: fit
42
+
43
+ ```
44
+
45
+ ## Estimation Methods
46
+
47
+ Estimation methods comprise the most common method you will work with on a routine basis for estimating model parameters, omnibus-tests, marginal estimations & comparisons, predictions, and simulations.
48
+
49
+ ```{eval-rst}
50
+ .. autofunction:: pymer4.models.glm.glm.fit
51
+ .. autofunction:: pymer4.models.base.model.anova
52
+ .. autofunction:: pymer4.models.base.model.emmeans
53
+ .. autofunction:: pymer4.models.base.model.empredict
54
+ .. autofunction:: pymer4.models.glm.glm.predict
55
+ .. autofunction:: pymer4.models.base.model.simulate
56
+ .. autofunction:: pymer4.models.base.model.vif
57
+
58
+ ```
59
+
60
+ ## Summary Methods
61
+
62
+ Summary methods return nicely formatted outputs of the `.result_*` attributes of a fitted model
63
+
64
+ ```{eval-rst}
65
+ .. autofunction:: pymer4.models.glm.glm.summary
66
+ .. autofunction:: pymer4.models.base.model.summary_anova
67
+
68
+ ```
69
+
70
+ ## Transformation & Factor Methods
71
+
72
+ These methods are essential for working *categorical predictors* (factors), customizing specific linear hypotheses, and transforming continous predictors (e.g. mean-centering).
73
+
74
+ ```{eval-rst}
75
+
76
+ .. autofunction:: pymer4.models.base.model.set_factors
77
+ .. autofunction:: pymer4.models.base.model.unset_factors
78
+ .. autofunction:: pymer4.models.base.model.show_factors
79
+ .. autofunction:: pymer4.models.base.model.set_contrasts
80
+ .. autofunction:: pymer4.models.base.model.show_contrasts
81
+ .. autofunction:: pymer4.models.base.model.set_transforms
82
+ .. autofunction:: pymer4.models.base.model.unset_transforms
83
+ .. autofunction:: pymer4.models.base.model.show_transforms
84
+
85
+ ```
86
+
87
+ ## Auxillary Methods
88
+
89
+ Helper methods for more advanced functionality and debugging
90
+
91
+ ```{eval-rst}
92
+
93
+ .. autofunction:: pymer4.models.base.model.to_sklearn
94
+ .. autofunction:: pymer4.models.base.model.report
95
+ .. autofunction:: pymer4.models.base.model.show_logs
96
+ .. autofunction:: pymer4.models.base.model.clear_logs
97
+
98
+ ```
@@ -0,0 +1,94 @@
1
+ # `pymer4.models.glmer`
2
+
3
+ :::{admonition} Tutorial
4
+ :class: tip
5
+ Check out the [LMMs ](../../tutorials/03_lmms.ipynb) and [GLMMs tutorial](../../tutorials/04_glmms.ipynb) for usage examples
6
+ :::
7
+
8
+ ## GLMMs
9
+
10
+ **G**eneralized **L**inear **M**odels **M**odels fit using Restricted-Maximum-Likelihood-Estimation (REML) or Maximum-Likelihood-Estimation (MLE)
11
+
12
+ GLMMs generalize LMMs like GLMs generalize LMs. They are well suited for non-independent data and non-gaussian outcome variables such as binary outcomes or counts. This includes models like mixed-effects logistic-regression and multi-level poisson models.
13
+
14
+ Like LMMs they are particularly useful in situations when observations are non-independent (e.g. repeated-measures designs, hierarchical data, panel-data, time-series, clustered data). To account for this GLMMs estimate additional *random-effects* estimates that reflect how a cluster of observations deviates from fixed effects estimates (e.g. random-intercepts and/or random-slopes)
15
+
16
+ For some models like mixed logistic-regression, it can be helpful to use `.fit(exponentiate=True)` to transform estimates to the odds scale to aid interpretability. By default the `'fitted'` column in `model.data` and the output of `model.predict()` uses `type_predict = 'response'` so that model predictions are on the *response* scale, i.e. probabilities for mixed logistic-regression.
17
+
18
+ ```python
19
+ from pymer4 import load_dataset('titanic')
20
+ from pymer4.models import glm
21
+
22
+ titanic = load_dataset('titanic')
23
+
24
+ # Logistic regression accounting repeated observations within pclass
25
+ # by estimating a random intercept per level of pclass
26
+ log_reg = glm('survived ~ fare + (1|plass)', family='binomial', data=titanic)
27
+ log_reg.set_factors('pclass')
28
+
29
+ # See parameter estimates on odds scale
30
+ log_reg.fit(exponentiate=True)
31
+ ```
32
+
33
+ ---
34
+
35
+ ```{eval-rst}
36
+ .. autoclass:: pymer4.models.glmer.glmer
37
+ :exclude-members: fit, summary
38
+
39
+ ```
40
+
41
+ ## Estimation Methods
42
+
43
+ Estimation methods comprise the most common method you will work with on a routine basis for estimating model parameters, omnibus-tests, marginal estimations & comparisons, predictions, and simulations.
44
+
45
+ ```{eval-rst}
46
+ .. autofunction:: pymer4.models.glmer.glmer.fit
47
+ .. autofunction:: pymer4.models.lmer.lmer.anova
48
+ .. autofunction:: pymer4.models.lmer.lmer.emmeans
49
+ .. autofunction:: pymer4.models.base.model.empredict
50
+ .. autofunction:: pymer4.models.glmer.glmer.predict
51
+ .. autofunction:: pymer4.models.lmer.lmer.simulate
52
+ .. autofunction:: pymer4.models.base.model.vif
53
+
54
+ ```
55
+
56
+ ## Summary Methods
57
+
58
+ Summary methods return nicely formatted outputs of the `.result_*` attributes of a fitted model
59
+
60
+ ```{eval-rst}
61
+ .. autofunction:: pymer4.models.glmer.glmer.summary
62
+ .. autofunction:: pymer4.models.base.model.summary_anova
63
+
64
+ ```
65
+
66
+ ## Transformation & Factor Methods
67
+
68
+ These methods are essential for working *categorical predictors* (factors), customizing specific linear hypotheses, and transforming continous predictors (e.g. mean-centering).
69
+
70
+ ```{eval-rst}
71
+
72
+ .. autofunction:: pymer4.models.base.model.set_factors
73
+ .. autofunction:: pymer4.models.base.model.unset_factors
74
+ .. autofunction:: pymer4.models.base.model.show_factors
75
+ .. autofunction:: pymer4.models.base.model.set_contrasts
76
+ .. autofunction:: pymer4.models.base.model.show_contrasts
77
+ .. autofunction:: pymer4.models.base.model.set_transforms
78
+ .. autofunction:: pymer4.models.base.model.unset_transforms
79
+ .. autofunction:: pymer4.models.base.model.show_transforms
80
+
81
+ ```
82
+
83
+ ## Auxillary Methods
84
+
85
+ Helper methods for more advanced functionality and debugging
86
+
87
+ ```{eval-rst}
88
+
89
+ .. autofunction:: pymer4.models.base.model.to_sklearn
90
+ .. autofunction:: pymer4.models.base.model.report
91
+ .. autofunction:: pymer4.models.base.model.show_logs
92
+ .. autofunction:: pymer4.models.base.model.clear_logs
93
+
94
+ ```
@@ -0,0 +1,30 @@
1
+ # `pymer4.models`
2
+
3
+ ## Overview
4
+
5
+ `pymer4` includes 4 types of models that share a consistent API and can be imported like this:
6
+
7
+ ```python
8
+ from pymer4.models import lm, glm, lmer, glmer
9
+ ```
10
+
11
+ Clicking the links below will take you to their respective API documentation pages.
12
+
13
+ | Model | Description |
14
+ |--------|-------------|
15
+ | [`lm()`](./lm.md) | linear regression fit via ordinary-least-squares (OLS) |
16
+ | [`glm()`](./glm.md) | generalized linear models (e.g logistic regression) fit via maximum-likelihood-estimate (MLE) |
17
+ | [`lmer()`](./lmer.md) | linear-mixed / multi-level models |
18
+ | [`glmer()`](./glmer.md) | geneneralized linear-mixed / multi-level models |
19
+
20
+
21
+ ## Comparing Models
22
+
23
+ Nested model comparison is available across all model types using the `compare()` function
24
+
25
+ ```{eval-rst}
26
+ .. autofunction:: pymer4.models.compare
27
+ ```
28
+
29
+ <!-- #TODO -->
30
+ <!-- Additional model comparison is possible via `scikit-learn` using `.to_sklearn()` -->