Skip to content

Commit

Permalink
Update mixedlm.md
Browse files Browse the repository at this point in the history
Please, I have done the correction and also added the note as you specified. 

I will still need to exemplify that the three models can be combined in an operation, but that will be later.  I just want you to work on the aspect that is important to you and that I have already completed, then later I will do that.
 
Review the changes, and if you think I didn't still get some things right, always feel free to reach out. Thanks
  • Loading branch information
Good-Soma authored Jan 6, 2025
1 parent e329faf commit f371ea9
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions content/python/concepts/statsmodel/terms/mixedlm/mixedlm.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,50 @@ CatalogContent:
## Application of mixedlm model

- **Random Intercept Model**: Captures group-level variability in the intercept while keeping the slope fixed.
- Parameter:
- endog: A 1D array representing the dependent variable.
- exog: A 2D array of variable or covariate that determine the mean structure
- groups: A 1D array-like and a vector of label that indepence of data from different group.
- exog_re: (optional) A 2D array of covariates that define the covariance structure e.g random intercept covariance, if not provided, the default is a random intercept forneach group.
- use-sqrt: (optional), if true, optimization is performed using the lower triangle of the random effect covariance matrix. otherwisebl, it uses the lower triangle of the covariance matrix directly.
-
- **Random Slope Model**: Allows the slope to vary across groups to account for differences in trends.
- parameters:
- endog: A dependent variable represented as a 1D array.

exog: A 2D array of covariates or variables that determine the mean structure.

groups: A 1D array-like vector of labels ensuring that data from different groups remain independent.

re_formula: A string formula specifying the structure of the random effects.

use-sqrt: (Optional) If True, optimization is performed using the lower triangle of the square root of the random effects covariance matrix. Otherwise, it uses the lower triangle of the covariance matrix directly.

missing: (Optional) A string parameter specifying the method for handling missing data.
- **Variance Components Model**: Decomposes variance into different components to understand variability sources.
- parameters:
- endog: A dependent variable represented as a 1D array.

exog: A 2D array of covariates or variables that determine the mean structure.

groups: A 1D array-like vector of labels ensuring independence of data across groups.

vc_formula: A dictionary where keys represent the names of variance components, and the values are formulas specifying the structure of each variance component.

use-sqrt: (Optional) If True, optimization is performed using the lower triangle of the square root of the random effects covariance matrix. Otherwise, it uses the lower triangle of the covariance matrix directly.

missing: (Optional) A string parameter specifying the method for handling missing data.
Note: You can combine the:
random intercept model.
random slope model.
and covariance component model.
For a For a single operation, which also depends on type of data that is intended for measurement

## Syntax

```
import statsmodels.api as sm
import statsmodels.formula.api as smf
model = sm.MixedLM(endog, exog, groups, exog_re=None)
```
Expand All @@ -41,8 +78,9 @@ model = sm.MixedLM(endog, exog, groups, exog_re=None)
In this example, a mixed-effects model is fitted to NBA team performance data, with `'Minutes'` as a fixed effect and `'Team'` as a random effect to analyze points scored:

```
import pandas as pd
from statsmodels.formula.api import mixedlm
import statsmodels.api as sm
import statsmodels.formula.api as smf
# An example of the performance between two NBA teams' (team names: TeamG, TeamR)
data = pd.DataFrame({
Expand Down

0 comments on commit f371ea9

Please sign in to comment.