PyProcessMacro 2.0.0__tar.gz → 2.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.
- {pyprocessmacro-2.0.0 → pyprocessmacro-2.1.0}/PKG-INFO +87 -4
- {pyprocessmacro-2.0.0 → pyprocessmacro-2.1.0}/PyProcessMacro.egg-info/PKG-INFO +87 -4
- {pyprocessmacro-2.0.0 → pyprocessmacro-2.1.0}/PyProcessMacro.egg-info/SOURCES.txt +4 -0
- {pyprocessmacro-2.0.0 → pyprocessmacro-2.1.0}/PyProcessMacro.egg-info/requires.txt +3 -0
- {pyprocessmacro-2.0.0 → pyprocessmacro-2.1.0}/README.md +84 -3
- {pyprocessmacro-2.0.0 → pyprocessmacro-2.1.0}/pyprocessmacro/__init__.py +1 -1
- pyprocessmacro-2.1.0/pyprocessmacro/bootstrap.py +242 -0
- pyprocessmacro-2.1.0/pyprocessmacro/effsize.py +77 -0
- {pyprocessmacro-2.0.0 → pyprocessmacro-2.1.0}/pyprocessmacro/models.py +131 -108
- {pyprocessmacro-2.0.0 → pyprocessmacro-2.1.0}/pyprocessmacro/process.py +119 -44
- pyprocessmacro-2.1.0/pyprocessmacro/serial.py +218 -0
- pyprocessmacro-2.1.0/pyprocessmacro/tidy.py +219 -0
- {pyprocessmacro-2.0.0 → pyprocessmacro-2.1.0}/pyprocessmacro/utils.py +3 -0
- {pyprocessmacro-2.0.0 → pyprocessmacro-2.1.0}/pyproject.toml +1 -0
- {pyprocessmacro-2.0.0 → pyprocessmacro-2.1.0}/LICENSE.txt +0 -0
- {pyprocessmacro-2.0.0 → pyprocessmacro-2.1.0}/MANIFEST.in +0 -0
- {pyprocessmacro-2.0.0 → pyprocessmacro-2.1.0}/PyProcessMacro.egg-info/dependency_links.txt +0 -0
- {pyprocessmacro-2.0.0 → pyprocessmacro-2.1.0}/PyProcessMacro.egg-info/top_level.txt +0 -0
- {pyprocessmacro-2.0.0 → pyprocessmacro-2.1.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyProcessMacro
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.1.0
|
|
4
4
|
Summary: A Python library for moderation, mediation and conditional process analysis. Based on Andrew F. Hayes' Process Macro.
|
|
5
5
|
Author-email: Quentin André <quentin.andre@insead.edu>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -27,6 +27,8 @@ Requires-Dist: pandas>=2.0
|
|
|
27
27
|
Requires-Dist: scipy>=1.10
|
|
28
28
|
Requires-Dist: matplotlib>=3.7
|
|
29
29
|
Requires-Dist: seaborn>=0.13
|
|
30
|
+
Provides-Extra: statsmodels
|
|
31
|
+
Requires-Dist: statsmodels>=0.14; extra == "statsmodels"
|
|
30
32
|
Provides-Extra: test
|
|
31
33
|
Requires-Dist: pytest>=8; extra == "test"
|
|
32
34
|
Requires-Dist: statsmodels>=0.14; extra == "test"
|
|
@@ -62,8 +64,9 @@ softwaress. PyProcessMacro is released under a MIT license.
|
|
|
62
64
|
# Features
|
|
63
65
|
|
|
64
66
|
In the current version, PyProcessMacro replicates the following features from the original Process Macro v2.16:
|
|
65
|
-
* All models (1 to 76)
|
|
66
|
-
|
|
67
|
+
* All models (1 to 76) are supported. Models 1 to 5 and 7 to 76 are tested for accuracy against the output of the
|
|
68
|
+
original Process macro (see `tests/test_models_accuracy.py`); Model 6 (serial mediation, added in 2.1) is tested
|
|
69
|
+
against statsmodels-based reference computations.
|
|
67
70
|
* Estimation of binary/continuous outcome variables. The binary outcomes are estimated in Logit using the
|
|
68
71
|
Newton-Raphson convergence algorithm, the continuous variables are estimated using OLS.
|
|
69
72
|
* All statistics reported by Process:
|
|
@@ -92,7 +95,6 @@ In the current version, the following features have not yet been ported to PyPro
|
|
|
92
95
|
* Support for categorical independent variables.
|
|
93
96
|
* Generation of individual fixed effects for repeated measures.
|
|
94
97
|
* R² improvement from moderators in moderation models (1, 2, 3).
|
|
95
|
-
* Estimation of serial mediation (Model 6)
|
|
96
98
|
* Some options (`normal`, `varorder`, ...). PyProcessMacro will issue a warning to tell you if an option you are
|
|
97
99
|
trying to use is not implemented.
|
|
98
100
|
|
|
@@ -233,6 +235,8 @@ As you can see, the syntax for PyProcessMacro is (almost) identical to that of P
|
|
|
233
235
|
|
|
234
236
|
Once the object is initialized, you can call its `summary()` method to display the estimation results
|
|
235
237
|
|
|
238
|
+
The standardized result tables (`tidy()`, `glance()`, `augment()`) are described in section 6.
|
|
239
|
+
|
|
236
240
|
You might have noticed that there is no argument `varlist` in PyProcessMacro. This is because the list of variables
|
|
237
241
|
is automatically inferred from the variable names given to x, y, m.
|
|
238
242
|
|
|
@@ -319,6 +323,37 @@ By default, the standard errors of the OLS outcome models use the standard (homo
|
|
|
319
323
|
p = Process(data=df, model=4, x="Effort", y="Success", m=["MediationSkills"], cov_type="HC3")
|
|
320
324
|
````
|
|
321
325
|
|
|
326
|
+
### G. Serial mediation (Model 6)
|
|
327
|
+
|
|
328
|
+
In Model 6 the mediators form a chain: each mediator depends on X and on the mediators before it, and Y depends
|
|
329
|
+
on X and on every mediator. Pass two to four mediators in causal order. PyProcessMacro reports the specific
|
|
330
|
+
indirect effect through every ordered subset of mediators (three paths for two mediators, seven for three,
|
|
331
|
+
fifteen for four), labelled by the path, plus the total and the pairwise contrasts when `total=True` and
|
|
332
|
+
`contrast=True`.
|
|
333
|
+
|
|
334
|
+
````python
|
|
335
|
+
p = Process(data=df, model=6, x="Effort", y="Success", m=["Attention", "MediationSkills"], total=True)
|
|
336
|
+
p.summary()
|
|
337
|
+
````
|
|
338
|
+
|
|
339
|
+
Model 6 has no moderators, so the spotlight, floodlight and plotting methods do not apply to it. Its estimates are
|
|
340
|
+
checked against products of statsmodels coefficients and against an independent resampler; no PROCESS output for
|
|
341
|
+
Model 6 is part of the test fixtures yet, so a comparison file generated with PROCESS 2.16 would be a welcome
|
|
342
|
+
contribution.
|
|
343
|
+
|
|
344
|
+
### H. Effect sizes for the indirect effect
|
|
345
|
+
|
|
346
|
+
With `effsize=True`, PyProcessMacro also reports the partially standardized indirect effect (the indirect effect
|
|
347
|
+
divided by the standard deviation of Y) and the completely standardized indirect effect (further multiplied by the
|
|
348
|
+
standard deviation of X), each with a bootstrap confidence interval computed by standardizing within every resample,
|
|
349
|
+
as PROCESS does. The option applies to unmoderated indirect paths with a continuous outcome, that is Models 4 and 6
|
|
350
|
+
with `logit=False`.
|
|
351
|
+
|
|
352
|
+
````python
|
|
353
|
+
p = Process(data=df, model=4, x="Effort", y="Success", m=["MediationSkills"], effsize=True)
|
|
354
|
+
p.indirect_model.effect_size_summary()
|
|
355
|
+
````
|
|
356
|
+
|
|
322
357
|
## 2. Accessing the estimation results
|
|
323
358
|
|
|
324
359
|
After the `Process` object is initialized, you are not limited to printing the summary. PyProcessMacro implements the
|
|
@@ -416,6 +451,28 @@ Note that the methods are called from the `indirect_model` object! If you call `
|
|
|
416
451
|
error.
|
|
417
452
|
|
|
418
453
|
|
|
454
|
+
### E. Diagnostics and custom tests with statsmodels
|
|
455
|
+
|
|
456
|
+
Each outcome model can be handed to [statsmodels](https://www.statsmodels.org), which refits the same design
|
|
457
|
+
matrix with the same covariance estimator and returns the statsmodels results object. From there you get
|
|
458
|
+
`summary()`, custom contrasts with `t_test()` and `wald_test()`, heteroskedasticity and influence diagnostics,
|
|
459
|
+
variance inflation factors, prediction intervals, and the table formatters that accept statsmodels results.
|
|
460
|
+
statsmodels is optional: install it with `pip install pyprocessmacro[statsmodels]`.
|
|
461
|
+
|
|
462
|
+
````python
|
|
463
|
+
p = Process(data=df, model=7, x="Effort", y="Success", w="Motivation", m=["MediationSkills"], suppr_init=True)
|
|
464
|
+
|
|
465
|
+
fit = p.outcome_models["Success"].to_statsmodels() # a statsmodels RegressionResults
|
|
466
|
+
print(fit.summary())
|
|
467
|
+
fit.t_test("Effort + MediationSkills = 0")
|
|
468
|
+
|
|
469
|
+
fits = p.to_statsmodels() # every outcome model, keyed by outcome name
|
|
470
|
+
````
|
|
471
|
+
|
|
472
|
+
For a different question, statsmodels also ships `statsmodels.stats.mediation.Mediation`, Imai-style causal
|
|
473
|
+
mediation with a sensitivity analysis; it estimates a different quantity and is a useful cross-check rather than
|
|
474
|
+
a replacement for the PROCESS approach.
|
|
475
|
+
|
|
419
476
|
## 3. Spotlight and Floodlight Analysis
|
|
420
477
|
|
|
421
478
|
### A. Compute direct/indirect effects for specific values (spotlight analysis)
|
|
@@ -646,6 +703,32 @@ g = p.plot_conditional_indirect_effects(med_name="MediationSkills", x="Motivatio
|
|
|
646
703
|
````
|
|
647
704
|

|
|
648
705
|
|
|
706
|
+
## 6. Standardized results: tidy(), glance() and augment()
|
|
707
|
+
|
|
708
|
+
Every table PyProcessMacro prints is also available in a standardized form, modelled on R's broom package:
|
|
709
|
+
|
|
710
|
+
* `tidy()` returns one long DataFrame with one row per estimate and fixed column names: `component`
|
|
711
|
+
(`outcome`, `direct`, `indirect`, `total`, `contrast`, or `index_mm`, `index_pmm`, `index_mmm`, `index_cmm`),
|
|
712
|
+
`outcome`, `term`, `moderator`, one column per moderator of the model holding the spotlight value the row is
|
|
713
|
+
evaluated at, then `estimate`, `std_error`, `statistic`, `p_value`, `conf_low`, `conf_high`, `method`,
|
|
714
|
+
`conf_level` and `n_boot`. Pass `component=` to keep one kind of row.
|
|
715
|
+
* `glance()` returns one row of fit statistics per outcome model, including the log-likelihood, AIC and BIC.
|
|
716
|
+
* `augment()` returns the analysis data with `.fitted_<outcome>` and `.resid_<outcome>` columns per outcome model.
|
|
717
|
+
|
|
718
|
+
````python
|
|
719
|
+
p = Process(data=df, model=7, x="Effort", y="Success", w="Motivation", m=["MediationSkills"], suppr_init=True)
|
|
720
|
+
|
|
721
|
+
estimates = p.tidy() # every estimate
|
|
722
|
+
indirect = p.tidy("indirect") # only the conditional indirect effects
|
|
723
|
+
fit = p.glance() # R², AIC, BIC, ... per outcome model
|
|
724
|
+
residuals = p.augment(outcome="Success") # fitted values and residuals of the outcome model
|
|
725
|
+
|
|
726
|
+
estimates.to_csv("process_model7.csv", index=False)
|
|
727
|
+
````
|
|
728
|
+
|
|
729
|
+
`summary()` returns the text it prints, so `report = p.summary()` keeps a copy, and a `Process` object displayed at
|
|
730
|
+
the end of a notebook cell shows its tables as HTML.
|
|
731
|
+
|
|
649
732
|
# 7. About
|
|
650
733
|
PyProcessMacro was developed by Quentin André during his PhD in Marketing at INSEAD Business School, France.
|
|
651
734
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyProcessMacro
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.1.0
|
|
4
4
|
Summary: A Python library for moderation, mediation and conditional process analysis. Based on Andrew F. Hayes' Process Macro.
|
|
5
5
|
Author-email: Quentin André <quentin.andre@insead.edu>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -27,6 +27,8 @@ Requires-Dist: pandas>=2.0
|
|
|
27
27
|
Requires-Dist: scipy>=1.10
|
|
28
28
|
Requires-Dist: matplotlib>=3.7
|
|
29
29
|
Requires-Dist: seaborn>=0.13
|
|
30
|
+
Provides-Extra: statsmodels
|
|
31
|
+
Requires-Dist: statsmodels>=0.14; extra == "statsmodels"
|
|
30
32
|
Provides-Extra: test
|
|
31
33
|
Requires-Dist: pytest>=8; extra == "test"
|
|
32
34
|
Requires-Dist: statsmodels>=0.14; extra == "test"
|
|
@@ -62,8 +64,9 @@ softwaress. PyProcessMacro is released under a MIT license.
|
|
|
62
64
|
# Features
|
|
63
65
|
|
|
64
66
|
In the current version, PyProcessMacro replicates the following features from the original Process Macro v2.16:
|
|
65
|
-
* All models (1 to 76)
|
|
66
|
-
|
|
67
|
+
* All models (1 to 76) are supported. Models 1 to 5 and 7 to 76 are tested for accuracy against the output of the
|
|
68
|
+
original Process macro (see `tests/test_models_accuracy.py`); Model 6 (serial mediation, added in 2.1) is tested
|
|
69
|
+
against statsmodels-based reference computations.
|
|
67
70
|
* Estimation of binary/continuous outcome variables. The binary outcomes are estimated in Logit using the
|
|
68
71
|
Newton-Raphson convergence algorithm, the continuous variables are estimated using OLS.
|
|
69
72
|
* All statistics reported by Process:
|
|
@@ -92,7 +95,6 @@ In the current version, the following features have not yet been ported to PyPro
|
|
|
92
95
|
* Support for categorical independent variables.
|
|
93
96
|
* Generation of individual fixed effects for repeated measures.
|
|
94
97
|
* R² improvement from moderators in moderation models (1, 2, 3).
|
|
95
|
-
* Estimation of serial mediation (Model 6)
|
|
96
98
|
* Some options (`normal`, `varorder`, ...). PyProcessMacro will issue a warning to tell you if an option you are
|
|
97
99
|
trying to use is not implemented.
|
|
98
100
|
|
|
@@ -233,6 +235,8 @@ As you can see, the syntax for PyProcessMacro is (almost) identical to that of P
|
|
|
233
235
|
|
|
234
236
|
Once the object is initialized, you can call its `summary()` method to display the estimation results
|
|
235
237
|
|
|
238
|
+
The standardized result tables (`tidy()`, `glance()`, `augment()`) are described in section 6.
|
|
239
|
+
|
|
236
240
|
You might have noticed that there is no argument `varlist` in PyProcessMacro. This is because the list of variables
|
|
237
241
|
is automatically inferred from the variable names given to x, y, m.
|
|
238
242
|
|
|
@@ -319,6 +323,37 @@ By default, the standard errors of the OLS outcome models use the standard (homo
|
|
|
319
323
|
p = Process(data=df, model=4, x="Effort", y="Success", m=["MediationSkills"], cov_type="HC3")
|
|
320
324
|
````
|
|
321
325
|
|
|
326
|
+
### G. Serial mediation (Model 6)
|
|
327
|
+
|
|
328
|
+
In Model 6 the mediators form a chain: each mediator depends on X and on the mediators before it, and Y depends
|
|
329
|
+
on X and on every mediator. Pass two to four mediators in causal order. PyProcessMacro reports the specific
|
|
330
|
+
indirect effect through every ordered subset of mediators (three paths for two mediators, seven for three,
|
|
331
|
+
fifteen for four), labelled by the path, plus the total and the pairwise contrasts when `total=True` and
|
|
332
|
+
`contrast=True`.
|
|
333
|
+
|
|
334
|
+
````python
|
|
335
|
+
p = Process(data=df, model=6, x="Effort", y="Success", m=["Attention", "MediationSkills"], total=True)
|
|
336
|
+
p.summary()
|
|
337
|
+
````
|
|
338
|
+
|
|
339
|
+
Model 6 has no moderators, so the spotlight, floodlight and plotting methods do not apply to it. Its estimates are
|
|
340
|
+
checked against products of statsmodels coefficients and against an independent resampler; no PROCESS output for
|
|
341
|
+
Model 6 is part of the test fixtures yet, so a comparison file generated with PROCESS 2.16 would be a welcome
|
|
342
|
+
contribution.
|
|
343
|
+
|
|
344
|
+
### H. Effect sizes for the indirect effect
|
|
345
|
+
|
|
346
|
+
With `effsize=True`, PyProcessMacro also reports the partially standardized indirect effect (the indirect effect
|
|
347
|
+
divided by the standard deviation of Y) and the completely standardized indirect effect (further multiplied by the
|
|
348
|
+
standard deviation of X), each with a bootstrap confidence interval computed by standardizing within every resample,
|
|
349
|
+
as PROCESS does. The option applies to unmoderated indirect paths with a continuous outcome, that is Models 4 and 6
|
|
350
|
+
with `logit=False`.
|
|
351
|
+
|
|
352
|
+
````python
|
|
353
|
+
p = Process(data=df, model=4, x="Effort", y="Success", m=["MediationSkills"], effsize=True)
|
|
354
|
+
p.indirect_model.effect_size_summary()
|
|
355
|
+
````
|
|
356
|
+
|
|
322
357
|
## 2. Accessing the estimation results
|
|
323
358
|
|
|
324
359
|
After the `Process` object is initialized, you are not limited to printing the summary. PyProcessMacro implements the
|
|
@@ -416,6 +451,28 @@ Note that the methods are called from the `indirect_model` object! If you call `
|
|
|
416
451
|
error.
|
|
417
452
|
|
|
418
453
|
|
|
454
|
+
### E. Diagnostics and custom tests with statsmodels
|
|
455
|
+
|
|
456
|
+
Each outcome model can be handed to [statsmodels](https://www.statsmodels.org), which refits the same design
|
|
457
|
+
matrix with the same covariance estimator and returns the statsmodels results object. From there you get
|
|
458
|
+
`summary()`, custom contrasts with `t_test()` and `wald_test()`, heteroskedasticity and influence diagnostics,
|
|
459
|
+
variance inflation factors, prediction intervals, and the table formatters that accept statsmodels results.
|
|
460
|
+
statsmodels is optional: install it with `pip install pyprocessmacro[statsmodels]`.
|
|
461
|
+
|
|
462
|
+
````python
|
|
463
|
+
p = Process(data=df, model=7, x="Effort", y="Success", w="Motivation", m=["MediationSkills"], suppr_init=True)
|
|
464
|
+
|
|
465
|
+
fit = p.outcome_models["Success"].to_statsmodels() # a statsmodels RegressionResults
|
|
466
|
+
print(fit.summary())
|
|
467
|
+
fit.t_test("Effort + MediationSkills = 0")
|
|
468
|
+
|
|
469
|
+
fits = p.to_statsmodels() # every outcome model, keyed by outcome name
|
|
470
|
+
````
|
|
471
|
+
|
|
472
|
+
For a different question, statsmodels also ships `statsmodels.stats.mediation.Mediation`, Imai-style causal
|
|
473
|
+
mediation with a sensitivity analysis; it estimates a different quantity and is a useful cross-check rather than
|
|
474
|
+
a replacement for the PROCESS approach.
|
|
475
|
+
|
|
419
476
|
## 3. Spotlight and Floodlight Analysis
|
|
420
477
|
|
|
421
478
|
### A. Compute direct/indirect effects for specific values (spotlight analysis)
|
|
@@ -646,6 +703,32 @@ g = p.plot_conditional_indirect_effects(med_name="MediationSkills", x="Motivatio
|
|
|
646
703
|
````
|
|
647
704
|

|
|
648
705
|
|
|
706
|
+
## 6. Standardized results: tidy(), glance() and augment()
|
|
707
|
+
|
|
708
|
+
Every table PyProcessMacro prints is also available in a standardized form, modelled on R's broom package:
|
|
709
|
+
|
|
710
|
+
* `tidy()` returns one long DataFrame with one row per estimate and fixed column names: `component`
|
|
711
|
+
(`outcome`, `direct`, `indirect`, `total`, `contrast`, or `index_mm`, `index_pmm`, `index_mmm`, `index_cmm`),
|
|
712
|
+
`outcome`, `term`, `moderator`, one column per moderator of the model holding the spotlight value the row is
|
|
713
|
+
evaluated at, then `estimate`, `std_error`, `statistic`, `p_value`, `conf_low`, `conf_high`, `method`,
|
|
714
|
+
`conf_level` and `n_boot`. Pass `component=` to keep one kind of row.
|
|
715
|
+
* `glance()` returns one row of fit statistics per outcome model, including the log-likelihood, AIC and BIC.
|
|
716
|
+
* `augment()` returns the analysis data with `.fitted_<outcome>` and `.resid_<outcome>` columns per outcome model.
|
|
717
|
+
|
|
718
|
+
````python
|
|
719
|
+
p = Process(data=df, model=7, x="Effort", y="Success", w="Motivation", m=["MediationSkills"], suppr_init=True)
|
|
720
|
+
|
|
721
|
+
estimates = p.tidy() # every estimate
|
|
722
|
+
indirect = p.tidy("indirect") # only the conditional indirect effects
|
|
723
|
+
fit = p.glance() # R², AIC, BIC, ... per outcome model
|
|
724
|
+
residuals = p.augment(outcome="Success") # fitted values and residuals of the outcome model
|
|
725
|
+
|
|
726
|
+
estimates.to_csv("process_model7.csv", index=False)
|
|
727
|
+
````
|
|
728
|
+
|
|
729
|
+
`summary()` returns the text it prints, so `report = p.summary()` keeps a copy, and a `Process` object displayed at
|
|
730
|
+
the end of a notebook cell shows its tables as HTML.
|
|
731
|
+
|
|
649
732
|
# 7. About
|
|
650
733
|
PyProcessMacro was developed by Quentin André during his PhD in Marketing at INSEAD Business School, France.
|
|
651
734
|
|
|
@@ -8,6 +8,10 @@ PyProcessMacro.egg-info/dependency_links.txt
|
|
|
8
8
|
PyProcessMacro.egg-info/requires.txt
|
|
9
9
|
PyProcessMacro.egg-info/top_level.txt
|
|
10
10
|
pyprocessmacro/__init__.py
|
|
11
|
+
pyprocessmacro/bootstrap.py
|
|
12
|
+
pyprocessmacro/effsize.py
|
|
11
13
|
pyprocessmacro/models.py
|
|
12
14
|
pyprocessmacro/process.py
|
|
15
|
+
pyprocessmacro/serial.py
|
|
16
|
+
pyprocessmacro/tidy.py
|
|
13
17
|
pyprocessmacro/utils.py
|
|
@@ -28,8 +28,9 @@ softwaress. PyProcessMacro is released under a MIT license.
|
|
|
28
28
|
# Features
|
|
29
29
|
|
|
30
30
|
In the current version, PyProcessMacro replicates the following features from the original Process Macro v2.16:
|
|
31
|
-
* All models (1 to 76)
|
|
32
|
-
|
|
31
|
+
* All models (1 to 76) are supported. Models 1 to 5 and 7 to 76 are tested for accuracy against the output of the
|
|
32
|
+
original Process macro (see `tests/test_models_accuracy.py`); Model 6 (serial mediation, added in 2.1) is tested
|
|
33
|
+
against statsmodels-based reference computations.
|
|
33
34
|
* Estimation of binary/continuous outcome variables. The binary outcomes are estimated in Logit using the
|
|
34
35
|
Newton-Raphson convergence algorithm, the continuous variables are estimated using OLS.
|
|
35
36
|
* All statistics reported by Process:
|
|
@@ -58,7 +59,6 @@ In the current version, the following features have not yet been ported to PyPro
|
|
|
58
59
|
* Support for categorical independent variables.
|
|
59
60
|
* Generation of individual fixed effects for repeated measures.
|
|
60
61
|
* R² improvement from moderators in moderation models (1, 2, 3).
|
|
61
|
-
* Estimation of serial mediation (Model 6)
|
|
62
62
|
* Some options (`normal`, `varorder`, ...). PyProcessMacro will issue a warning to tell you if an option you are
|
|
63
63
|
trying to use is not implemented.
|
|
64
64
|
|
|
@@ -199,6 +199,8 @@ As you can see, the syntax for PyProcessMacro is (almost) identical to that of P
|
|
|
199
199
|
|
|
200
200
|
Once the object is initialized, you can call its `summary()` method to display the estimation results
|
|
201
201
|
|
|
202
|
+
The standardized result tables (`tidy()`, `glance()`, `augment()`) are described in section 6.
|
|
203
|
+
|
|
202
204
|
You might have noticed that there is no argument `varlist` in PyProcessMacro. This is because the list of variables
|
|
203
205
|
is automatically inferred from the variable names given to x, y, m.
|
|
204
206
|
|
|
@@ -285,6 +287,37 @@ By default, the standard errors of the OLS outcome models use the standard (homo
|
|
|
285
287
|
p = Process(data=df, model=4, x="Effort", y="Success", m=["MediationSkills"], cov_type="HC3")
|
|
286
288
|
````
|
|
287
289
|
|
|
290
|
+
### G. Serial mediation (Model 6)
|
|
291
|
+
|
|
292
|
+
In Model 6 the mediators form a chain: each mediator depends on X and on the mediators before it, and Y depends
|
|
293
|
+
on X and on every mediator. Pass two to four mediators in causal order. PyProcessMacro reports the specific
|
|
294
|
+
indirect effect through every ordered subset of mediators (three paths for two mediators, seven for three,
|
|
295
|
+
fifteen for four), labelled by the path, plus the total and the pairwise contrasts when `total=True` and
|
|
296
|
+
`contrast=True`.
|
|
297
|
+
|
|
298
|
+
````python
|
|
299
|
+
p = Process(data=df, model=6, x="Effort", y="Success", m=["Attention", "MediationSkills"], total=True)
|
|
300
|
+
p.summary()
|
|
301
|
+
````
|
|
302
|
+
|
|
303
|
+
Model 6 has no moderators, so the spotlight, floodlight and plotting methods do not apply to it. Its estimates are
|
|
304
|
+
checked against products of statsmodels coefficients and against an independent resampler; no PROCESS output for
|
|
305
|
+
Model 6 is part of the test fixtures yet, so a comparison file generated with PROCESS 2.16 would be a welcome
|
|
306
|
+
contribution.
|
|
307
|
+
|
|
308
|
+
### H. Effect sizes for the indirect effect
|
|
309
|
+
|
|
310
|
+
With `effsize=True`, PyProcessMacro also reports the partially standardized indirect effect (the indirect effect
|
|
311
|
+
divided by the standard deviation of Y) and the completely standardized indirect effect (further multiplied by the
|
|
312
|
+
standard deviation of X), each with a bootstrap confidence interval computed by standardizing within every resample,
|
|
313
|
+
as PROCESS does. The option applies to unmoderated indirect paths with a continuous outcome, that is Models 4 and 6
|
|
314
|
+
with `logit=False`.
|
|
315
|
+
|
|
316
|
+
````python
|
|
317
|
+
p = Process(data=df, model=4, x="Effort", y="Success", m=["MediationSkills"], effsize=True)
|
|
318
|
+
p.indirect_model.effect_size_summary()
|
|
319
|
+
````
|
|
320
|
+
|
|
288
321
|
## 2. Accessing the estimation results
|
|
289
322
|
|
|
290
323
|
After the `Process` object is initialized, you are not limited to printing the summary. PyProcessMacro implements the
|
|
@@ -382,6 +415,28 @@ Note that the methods are called from the `indirect_model` object! If you call `
|
|
|
382
415
|
error.
|
|
383
416
|
|
|
384
417
|
|
|
418
|
+
### E. Diagnostics and custom tests with statsmodels
|
|
419
|
+
|
|
420
|
+
Each outcome model can be handed to [statsmodels](https://www.statsmodels.org), which refits the same design
|
|
421
|
+
matrix with the same covariance estimator and returns the statsmodels results object. From there you get
|
|
422
|
+
`summary()`, custom contrasts with `t_test()` and `wald_test()`, heteroskedasticity and influence diagnostics,
|
|
423
|
+
variance inflation factors, prediction intervals, and the table formatters that accept statsmodels results.
|
|
424
|
+
statsmodels is optional: install it with `pip install pyprocessmacro[statsmodels]`.
|
|
425
|
+
|
|
426
|
+
````python
|
|
427
|
+
p = Process(data=df, model=7, x="Effort", y="Success", w="Motivation", m=["MediationSkills"], suppr_init=True)
|
|
428
|
+
|
|
429
|
+
fit = p.outcome_models["Success"].to_statsmodels() # a statsmodels RegressionResults
|
|
430
|
+
print(fit.summary())
|
|
431
|
+
fit.t_test("Effort + MediationSkills = 0")
|
|
432
|
+
|
|
433
|
+
fits = p.to_statsmodels() # every outcome model, keyed by outcome name
|
|
434
|
+
````
|
|
435
|
+
|
|
436
|
+
For a different question, statsmodels also ships `statsmodels.stats.mediation.Mediation`, Imai-style causal
|
|
437
|
+
mediation with a sensitivity analysis; it estimates a different quantity and is a useful cross-check rather than
|
|
438
|
+
a replacement for the PROCESS approach.
|
|
439
|
+
|
|
385
440
|
## 3. Spotlight and Floodlight Analysis
|
|
386
441
|
|
|
387
442
|
### A. Compute direct/indirect effects for specific values (spotlight analysis)
|
|
@@ -612,6 +667,32 @@ g = p.plot_conditional_indirect_effects(med_name="MediationSkills", x="Motivatio
|
|
|
612
667
|
````
|
|
613
668
|

|
|
614
669
|
|
|
670
|
+
## 6. Standardized results: tidy(), glance() and augment()
|
|
671
|
+
|
|
672
|
+
Every table PyProcessMacro prints is also available in a standardized form, modelled on R's broom package:
|
|
673
|
+
|
|
674
|
+
* `tidy()` returns one long DataFrame with one row per estimate and fixed column names: `component`
|
|
675
|
+
(`outcome`, `direct`, `indirect`, `total`, `contrast`, or `index_mm`, `index_pmm`, `index_mmm`, `index_cmm`),
|
|
676
|
+
`outcome`, `term`, `moderator`, one column per moderator of the model holding the spotlight value the row is
|
|
677
|
+
evaluated at, then `estimate`, `std_error`, `statistic`, `p_value`, `conf_low`, `conf_high`, `method`,
|
|
678
|
+
`conf_level` and `n_boot`. Pass `component=` to keep one kind of row.
|
|
679
|
+
* `glance()` returns one row of fit statistics per outcome model, including the log-likelihood, AIC and BIC.
|
|
680
|
+
* `augment()` returns the analysis data with `.fitted_<outcome>` and `.resid_<outcome>` columns per outcome model.
|
|
681
|
+
|
|
682
|
+
````python
|
|
683
|
+
p = Process(data=df, model=7, x="Effort", y="Success", w="Motivation", m=["MediationSkills"], suppr_init=True)
|
|
684
|
+
|
|
685
|
+
estimates = p.tidy() # every estimate
|
|
686
|
+
indirect = p.tidy("indirect") # only the conditional indirect effects
|
|
687
|
+
fit = p.glance() # R², AIC, BIC, ... per outcome model
|
|
688
|
+
residuals = p.augment(outcome="Success") # fitted values and residuals of the outcome model
|
|
689
|
+
|
|
690
|
+
estimates.to_csv("process_model7.csv", index=False)
|
|
691
|
+
````
|
|
692
|
+
|
|
693
|
+
`summary()` returns the text it prints, so `report = p.summary()` keeps a copy, and a `Process` object displayed at
|
|
694
|
+
the end of a notebook cell shows its tables as HTML.
|
|
695
|
+
|
|
615
696
|
# 7. About
|
|
616
697
|
PyProcessMacro was developed by Quentin André during his PhD in Marketing at INSEAD Business School, France.
|
|
617
698
|
|