multi-sigma 1.0.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.
- multi_sigma-1.0.0/LICENSE +21 -0
- multi_sigma-1.0.0/PKG-INFO +106 -0
- multi_sigma-1.0.0/README.md +85 -0
- multi_sigma-1.0.0/multi_sigma.egg-info/PKG-INFO +106 -0
- multi_sigma-1.0.0/multi_sigma.egg-info/SOURCES.txt +9 -0
- multi_sigma-1.0.0/multi_sigma.egg-info/dependency_links.txt +1 -0
- multi_sigma-1.0.0/multi_sigma.egg-info/requires.txt +4 -0
- multi_sigma-1.0.0/multi_sigma.egg-info/top_level.txt +1 -0
- multi_sigma-1.0.0/multi_sigma.py +1005 -0
- multi_sigma-1.0.0/pyproject.toml +32 -0
- multi_sigma-1.0.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 aeabdou
|
|
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,106 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: multi-sigma
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Multi Sigma, multiple imputation for preserving subgroup variance
|
|
5
|
+
Author: Ahmed E. Abdou
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/aeabdou/multi-sigma
|
|
8
|
+
Keywords: multiple imputation,missing data,subgroup variance
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: numpy>=2.0
|
|
17
|
+
Requires-Dist: pandas>=2.0
|
|
18
|
+
Requires-Dist: scikit-learn>=1.3
|
|
19
|
+
Requires-Dist: tensorflow>=2.16
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# Multi Sigma
|
|
23
|
+
|
|
24
|
+
Multi Sigma is a multiple imputation method for continuous variables. It fills the missing values of a column several times, and gives each record imputed values whose spread follows the noise predicted for that record. This keeps the variance of the completed data close to the true variance, overall and within subgroups.
|
|
25
|
+
|
|
26
|
+
The method fits two neural networks on the records where the column is observed. The mean network predicts the value of the column. The sigma network predicts the size of the noise around that prediction. An imputed value is the predicted mean plus a residual drawn from the observed records and scaled by a weight that comes from the predicted noise of the record. With a lower bound, such as zero for income or consumption, no imputed value falls below the bound.
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
pip install multi-sigma
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
This also installs the libraries it needs. The function was tested with Python 3.13, NumPy 2.5, pandas 3.1, scikit-learn 1.9 and TensorFlow 2.21.
|
|
35
|
+
|
|
36
|
+
## Use
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from multi_sigma import multi_sigma
|
|
40
|
+
|
|
41
|
+
completed = multi_sigma(df, y="income")
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`completed` is a list of 20 completed data frames, one per imputation. Analyse each one and combine the results with Rubin's rules.
|
|
45
|
+
|
|
46
|
+
The data are passed the way they are passed to a model such as XGBoost, and `y` says what to impute.
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
multi_sigma(df, y="income") # one column of a data frame, by its name
|
|
50
|
+
multi_sigma(df, y=["income", "rent"]) # two or more columns, by a list of names
|
|
51
|
+
multi_sigma(df, y="all") # every continuous column that has missing values
|
|
52
|
+
multi_sigma(X, y) # X holds the predictors, y is the column to impute
|
|
53
|
+
multi_sigma(X, Y) # the same with two or more columns in Y
|
|
54
|
+
multi_sigma(arr, y=3) # one NumPy array with everything, the column at position 3
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`df`, `X`, `y` and `Y` can be pandas objects or NumPy arrays. With names, the predictors are every other column of the data frame, or the columns listed in `x`. With `X` and `y` passed separately, the predictors are the columns of `X`.
|
|
58
|
+
|
|
59
|
+
A column to impute must be continuous, which means here that it holds numbers and has more than 10 different values. Predictors must hold numbers, so a text column has to be turned into 0/1 columns first.
|
|
60
|
+
|
|
61
|
+
## The method
|
|
62
|
+
|
|
63
|
+
Three settings choose the method.
|
|
64
|
+
|
|
65
|
+
| Setting | Default | Meaning |
|
|
66
|
+
|---|---|---|
|
|
67
|
+
| `bounded` | `True` | The column has a lower bound and no imputed value falls below it. With `False` imputed values can be negative. |
|
|
68
|
+
| `lower_bound` | `0` | The lower bound when `bounded` is `True`. |
|
|
69
|
+
| `normalization` | `"self"` | `"self"` gives the self-normalized weights and `"observed"` the observed-normalized weights. |
|
|
70
|
+
|
|
71
|
+
The default is MS-SN, bounded Multi Sigma with self-normalized weights. `normalization="observed"` gives MS-ON. When several columns are imputed, `bounded` and `lower_bound` can be a dictionary with a value for each column.
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
multi_sigma(df, y=["income", "savings"], bounded={"savings": False})
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Other settings are `reps`, the number of imputations (20 by default), and `seed` and `draw_seed`, which make the results repeatable.
|
|
78
|
+
|
|
79
|
+
## Missing values in the predictors
|
|
80
|
+
|
|
81
|
+
A record is used whatever predictors it is missing. A missing predictor cell gets the average of that predictor. When a predictor is missing in at least 100 records of the training data, it also gets a 1/0 column that marks where it was missing, so the networks learn not to rely on it there. A predictor is dropped when it has too few observed values to learn from, when it is missing from every record to impute, or when it is missing in many records to impute but in few records of the training data. The function warns about every dropped predictor. The full rules are in the description at the top of `multi_sigma.py`.
|
|
82
|
+
|
|
83
|
+
## What comes back
|
|
84
|
+
|
|
85
|
+
A list with one item per imputation. With names, each item is the completed data frame or array. With `X` and `y` passed separately, each item is the completed `y`. Missing values of the predictors are not filled. `completed.info` holds, for every imputed column, the number of records imputed, their predicted means and what was done with predictors that have missing values.
|
|
86
|
+
|
|
87
|
+
## How to cite
|
|
88
|
+
|
|
89
|
+
If you use Multi Sigma, please cite the paper.
|
|
90
|
+
|
|
91
|
+
Abdou, A. E. (2026). Multi Sigma: Multiple Imputation for Preserving Subgroup Variance. Working paper.
|
|
92
|
+
|
|
93
|
+
```bibtex
|
|
94
|
+
@unpublished{abdou2026multisigma,
|
|
95
|
+
author = {Abdou, Ahmed E.},
|
|
96
|
+
title = {Multi Sigma: Multiple Imputation for Preserving Subgroup Variance},
|
|
97
|
+
note = {Working paper},
|
|
98
|
+
year = {2026}
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The **Cite this repository** button on the right of this page gives the same citation in other formats.
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
MIT License. See `LICENSE`.
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Multi Sigma
|
|
2
|
+
|
|
3
|
+
Multi Sigma is a multiple imputation method for continuous variables. It fills the missing values of a column several times, and gives each record imputed values whose spread follows the noise predicted for that record. This keeps the variance of the completed data close to the true variance, overall and within subgroups.
|
|
4
|
+
|
|
5
|
+
The method fits two neural networks on the records where the column is observed. The mean network predicts the value of the column. The sigma network predicts the size of the noise around that prediction. An imputed value is the predicted mean plus a residual drawn from the observed records and scaled by a weight that comes from the predicted noise of the record. With a lower bound, such as zero for income or consumption, no imputed value falls below the bound.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
pip install multi-sigma
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
This also installs the libraries it needs. The function was tested with Python 3.13, NumPy 2.5, pandas 3.1, scikit-learn 1.9 and TensorFlow 2.21.
|
|
14
|
+
|
|
15
|
+
## Use
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from multi_sigma import multi_sigma
|
|
19
|
+
|
|
20
|
+
completed = multi_sigma(df, y="income")
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`completed` is a list of 20 completed data frames, one per imputation. Analyse each one and combine the results with Rubin's rules.
|
|
24
|
+
|
|
25
|
+
The data are passed the way they are passed to a model such as XGBoost, and `y` says what to impute.
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
multi_sigma(df, y="income") # one column of a data frame, by its name
|
|
29
|
+
multi_sigma(df, y=["income", "rent"]) # two or more columns, by a list of names
|
|
30
|
+
multi_sigma(df, y="all") # every continuous column that has missing values
|
|
31
|
+
multi_sigma(X, y) # X holds the predictors, y is the column to impute
|
|
32
|
+
multi_sigma(X, Y) # the same with two or more columns in Y
|
|
33
|
+
multi_sigma(arr, y=3) # one NumPy array with everything, the column at position 3
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`df`, `X`, `y` and `Y` can be pandas objects or NumPy arrays. With names, the predictors are every other column of the data frame, or the columns listed in `x`. With `X` and `y` passed separately, the predictors are the columns of `X`.
|
|
37
|
+
|
|
38
|
+
A column to impute must be continuous, which means here that it holds numbers and has more than 10 different values. Predictors must hold numbers, so a text column has to be turned into 0/1 columns first.
|
|
39
|
+
|
|
40
|
+
## The method
|
|
41
|
+
|
|
42
|
+
Three settings choose the method.
|
|
43
|
+
|
|
44
|
+
| Setting | Default | Meaning |
|
|
45
|
+
|---|---|---|
|
|
46
|
+
| `bounded` | `True` | The column has a lower bound and no imputed value falls below it. With `False` imputed values can be negative. |
|
|
47
|
+
| `lower_bound` | `0` | The lower bound when `bounded` is `True`. |
|
|
48
|
+
| `normalization` | `"self"` | `"self"` gives the self-normalized weights and `"observed"` the observed-normalized weights. |
|
|
49
|
+
|
|
50
|
+
The default is MS-SN, bounded Multi Sigma with self-normalized weights. `normalization="observed"` gives MS-ON. When several columns are imputed, `bounded` and `lower_bound` can be a dictionary with a value for each column.
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
multi_sigma(df, y=["income", "savings"], bounded={"savings": False})
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Other settings are `reps`, the number of imputations (20 by default), and `seed` and `draw_seed`, which make the results repeatable.
|
|
57
|
+
|
|
58
|
+
## Missing values in the predictors
|
|
59
|
+
|
|
60
|
+
A record is used whatever predictors it is missing. A missing predictor cell gets the average of that predictor. When a predictor is missing in at least 100 records of the training data, it also gets a 1/0 column that marks where it was missing, so the networks learn not to rely on it there. A predictor is dropped when it has too few observed values to learn from, when it is missing from every record to impute, or when it is missing in many records to impute but in few records of the training data. The function warns about every dropped predictor. The full rules are in the description at the top of `multi_sigma.py`.
|
|
61
|
+
|
|
62
|
+
## What comes back
|
|
63
|
+
|
|
64
|
+
A list with one item per imputation. With names, each item is the completed data frame or array. With `X` and `y` passed separately, each item is the completed `y`. Missing values of the predictors are not filled. `completed.info` holds, for every imputed column, the number of records imputed, their predicted means and what was done with predictors that have missing values.
|
|
65
|
+
|
|
66
|
+
## How to cite
|
|
67
|
+
|
|
68
|
+
If you use Multi Sigma, please cite the paper.
|
|
69
|
+
|
|
70
|
+
Abdou, A. E. (2026). Multi Sigma: Multiple Imputation for Preserving Subgroup Variance. Working paper.
|
|
71
|
+
|
|
72
|
+
```bibtex
|
|
73
|
+
@unpublished{abdou2026multisigma,
|
|
74
|
+
author = {Abdou, Ahmed E.},
|
|
75
|
+
title = {Multi Sigma: Multiple Imputation for Preserving Subgroup Variance},
|
|
76
|
+
note = {Working paper},
|
|
77
|
+
year = {2026}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The **Cite this repository** button on the right of this page gives the same citation in other formats.
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
MIT License. See `LICENSE`.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: multi-sigma
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Multi Sigma, multiple imputation for preserving subgroup variance
|
|
5
|
+
Author: Ahmed E. Abdou
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/aeabdou/multi-sigma
|
|
8
|
+
Keywords: multiple imputation,missing data,subgroup variance
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: numpy>=2.0
|
|
17
|
+
Requires-Dist: pandas>=2.0
|
|
18
|
+
Requires-Dist: scikit-learn>=1.3
|
|
19
|
+
Requires-Dist: tensorflow>=2.16
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# Multi Sigma
|
|
23
|
+
|
|
24
|
+
Multi Sigma is a multiple imputation method for continuous variables. It fills the missing values of a column several times, and gives each record imputed values whose spread follows the noise predicted for that record. This keeps the variance of the completed data close to the true variance, overall and within subgroups.
|
|
25
|
+
|
|
26
|
+
The method fits two neural networks on the records where the column is observed. The mean network predicts the value of the column. The sigma network predicts the size of the noise around that prediction. An imputed value is the predicted mean plus a residual drawn from the observed records and scaled by a weight that comes from the predicted noise of the record. With a lower bound, such as zero for income or consumption, no imputed value falls below the bound.
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
pip install multi-sigma
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
This also installs the libraries it needs. The function was tested with Python 3.13, NumPy 2.5, pandas 3.1, scikit-learn 1.9 and TensorFlow 2.21.
|
|
35
|
+
|
|
36
|
+
## Use
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from multi_sigma import multi_sigma
|
|
40
|
+
|
|
41
|
+
completed = multi_sigma(df, y="income")
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`completed` is a list of 20 completed data frames, one per imputation. Analyse each one and combine the results with Rubin's rules.
|
|
45
|
+
|
|
46
|
+
The data are passed the way they are passed to a model such as XGBoost, and `y` says what to impute.
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
multi_sigma(df, y="income") # one column of a data frame, by its name
|
|
50
|
+
multi_sigma(df, y=["income", "rent"]) # two or more columns, by a list of names
|
|
51
|
+
multi_sigma(df, y="all") # every continuous column that has missing values
|
|
52
|
+
multi_sigma(X, y) # X holds the predictors, y is the column to impute
|
|
53
|
+
multi_sigma(X, Y) # the same with two or more columns in Y
|
|
54
|
+
multi_sigma(arr, y=3) # one NumPy array with everything, the column at position 3
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`df`, `X`, `y` and `Y` can be pandas objects or NumPy arrays. With names, the predictors are every other column of the data frame, or the columns listed in `x`. With `X` and `y` passed separately, the predictors are the columns of `X`.
|
|
58
|
+
|
|
59
|
+
A column to impute must be continuous, which means here that it holds numbers and has more than 10 different values. Predictors must hold numbers, so a text column has to be turned into 0/1 columns first.
|
|
60
|
+
|
|
61
|
+
## The method
|
|
62
|
+
|
|
63
|
+
Three settings choose the method.
|
|
64
|
+
|
|
65
|
+
| Setting | Default | Meaning |
|
|
66
|
+
|---|---|---|
|
|
67
|
+
| `bounded` | `True` | The column has a lower bound and no imputed value falls below it. With `False` imputed values can be negative. |
|
|
68
|
+
| `lower_bound` | `0` | The lower bound when `bounded` is `True`. |
|
|
69
|
+
| `normalization` | `"self"` | `"self"` gives the self-normalized weights and `"observed"` the observed-normalized weights. |
|
|
70
|
+
|
|
71
|
+
The default is MS-SN, bounded Multi Sigma with self-normalized weights. `normalization="observed"` gives MS-ON. When several columns are imputed, `bounded` and `lower_bound` can be a dictionary with a value for each column.
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
multi_sigma(df, y=["income", "savings"], bounded={"savings": False})
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Other settings are `reps`, the number of imputations (20 by default), and `seed` and `draw_seed`, which make the results repeatable.
|
|
78
|
+
|
|
79
|
+
## Missing values in the predictors
|
|
80
|
+
|
|
81
|
+
A record is used whatever predictors it is missing. A missing predictor cell gets the average of that predictor. When a predictor is missing in at least 100 records of the training data, it also gets a 1/0 column that marks where it was missing, so the networks learn not to rely on it there. A predictor is dropped when it has too few observed values to learn from, when it is missing from every record to impute, or when it is missing in many records to impute but in few records of the training data. The function warns about every dropped predictor. The full rules are in the description at the top of `multi_sigma.py`.
|
|
82
|
+
|
|
83
|
+
## What comes back
|
|
84
|
+
|
|
85
|
+
A list with one item per imputation. With names, each item is the completed data frame or array. With `X` and `y` passed separately, each item is the completed `y`. Missing values of the predictors are not filled. `completed.info` holds, for every imputed column, the number of records imputed, their predicted means and what was done with predictors that have missing values.
|
|
86
|
+
|
|
87
|
+
## How to cite
|
|
88
|
+
|
|
89
|
+
If you use Multi Sigma, please cite the paper.
|
|
90
|
+
|
|
91
|
+
Abdou, A. E. (2026). Multi Sigma: Multiple Imputation for Preserving Subgroup Variance. Working paper.
|
|
92
|
+
|
|
93
|
+
```bibtex
|
|
94
|
+
@unpublished{abdou2026multisigma,
|
|
95
|
+
author = {Abdou, Ahmed E.},
|
|
96
|
+
title = {Multi Sigma: Multiple Imputation for Preserving Subgroup Variance},
|
|
97
|
+
note = {Working paper},
|
|
98
|
+
year = {2026}
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The **Cite this repository** button on the right of this page gives the same citation in other formats.
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
MIT License. See `LICENSE`.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
multi_sigma
|