utils.stats.fit_all_lm
utils.stats.fit_all_lm(basic, xlist, data, remove_na=True)
Fit a linear regression model for all possible combinations of independent variables.
Parameters
| basic |
str |
The basic model formula. |
required |
| xlist |
list |
A list of independent variables. |
required |
| data |
pandas.DataFrame |
The data frame containing the variables. |
required |
| remove_na |
bool |
Whether to remove missing values from the data frame. |
True |
Returns
| dict |
dict |
A dictionary containing the estimated coefficients, confidence intervals, p-values, AIC values, sample size, and the basic model formula. |
Examples
>>> from spotpython.utils.stats import fit_all_lm
>>> import pandas as pd
>>> data = pd.DataFrame({
>>> 'y': [1, 2, 3],
>>> 'x1': [4, 5, 6],
>>> 'x2': [7, 8, 9]
>>> })
>>> fit_all_lm("y ~ x1", ["x2"], data)
{'estimate': variables estimate conf_low conf_high p aic n
0 basic 1.000000 1.000000 1.000000 0.0 0.000000 3
1 x2 1.000000 1.000000 1.000000 0.0 0.000000 3}