I am trying to fit a linear mixed effects model to test whether participants performing a reaction times test become faster as the test progresses. I am using mixedlm() from statsmodels.formula.api. I want to fit a model in which time is the fixed effect (identified by the 'block' variable, which corresponds to the test block presentation order, ranging 0-5). As random effects I want to have random intercepts and random slopes for each participant (identified by the 'test_session_id' variable).'duration' contains the reaction times to each individual stimulus.
Here is my code below.
import statsmodels.formula.api as smf
smf.mixedlm("duration ~ block + (block | test_session_id)", data = sdmt_df_lme, groups=sdmt_df_lme['test_session_id'])
What I don't understand is what should be put into the 'formula' parameter and what should go into the 're_formula' parameter. The documentation is pretty vague, or maybe I don't have a sufficient understanding of the underlying statistics.
Specifically, when I leave 're_formula' blank, I get the following output:
Model: MixedLM Dependent Variable: duration
No. Observations: 3348 Method: REML
No. Groups: 62 Scale: 0.0603
Min. group size: 54 Log-Likelihood: -192.8144
Max. group size: 54 Converged: Yes
Mean group size: 54.0
Coef. Std.Err. z P>|z| [0.025 0.975]
Intercept 8.159 0.245 33.266 0.000 7.679 8.640
block -0.016 0.002 -6.609 0.000 -0.021 -0.012
block | test_session_id -0.000 0.000 -1.524 0.128 -0.000 0.000
Group Var 0.061 0.047
If instead I specify re_formula = '~ block + (block | test_session_id)', I get the following:
/usr/local/lib/python3.10/dist-packages/statsmodels/regression/mixed_linear_model.py:2238: ConvergenceWarning: The MLE may be on the boundary of the parameter space.
warnings.warn(msg, ConvergenceWarning)
/usr/local/lib/python3.10/dist-packages/statsmodels/regression/mixed_linear_model.py:2262: ConvergenceWarning: The Hessian matrix at the estimated parameter values is not positive definite.
warnings.warn(msg, ConvergenceWarning)
Model: MixedLM Dependent Variable: duration
No. Observations: 3348 Method: REML
No. Groups: 62 Scale: 0.0589
Min. group size: 54 Log-Likelihood: -227.0540
Max. group size: 54 Converged: Yes
Mean group size: 54.0
Coef. Std.Err. z P>|z| [0.025 0.975]
Intercept 8.149 0.880 9.265 0.000 6.425 9.873
block -0.016 0.003 -5.576 0.000 -0.022 -0.011
block | test_session_id -0.000 0.000 -0.403 0.687 -0.000 0.000
Group Var 0.002
Group x block Cov 0.000 0.159
block Var 0.000 0.000
Group x block | test_session_id Cov -0.000
block x block | test_session_id Cov 0.000 0.000
block | test_session_id Var 0.000
Any advice is greatly appreciated. Thanks