# problem calculating the intercept manually in a linear mixed effect model

When I run a linear mixed effect model on this dataset, the intercept coefficient does not equal the mean of the marks where the other variables are 0.

data.head()
studid    IsTerm3    DaysTutoredInClass    Mark
--  --------  ---------  --------------------  ------
1   2219970          0                     3      62
2   2219939          0                     0      86
6   2219913          0                     0      87
9   2217602          0                     0      94
23   2217594          0                     0      51

import statsmodels.api as sm
import statsmodels.formula.api as smf
model = sm.MixedLM.from_formula("Mark ~ IsTerm3*DaysTutoredInClass",data,groups=data["studid"])
modelresult = model.fit()
print(modelresult.summary())

Mixed Linear Model Regression Results
=======================================================================
Model:                  MixedLM      Dependent Variable:      Mark
No. Observations:       122          Method:                  REML
No. Groups:             61           Scale:                   120.5626
Min. group size:        2            Likelihood:              -505.5485
Max. group size:        2            Converged:               Yes
Mean group size:        2.0
-----------------------------------------------------------------------
Coef.  Std.Err.   z    P>|z|  [0.025 0.975]
-----------------------------------------------------------------------
Intercept                   65.829    2.536 25.960 0.000  60.859 70.799
IsTerm3                     -6.955    2.187 -3.180 0.001 -11.242 -2.668
DaysTutoredInClass          -0.317    0.381 -0.831 0.406  -1.065  0.430
IsTerm3:DaysTutoredInClass   0.392    0.329  1.192 0.233  -0.253  1.037
Group Var                  203.596    6.257
=======================================================================


I was unable to reproduce the intercept coefficient with the following:

data[(data.IsTerm3 == 0)&(data.DaysTutoredInClass == 0)]['Mark'].mean()
66.53846153846153


I'm not sure what I'm doing wrong. Thanks for the help.

• There is nothing wrong here. You need to understand the interpretation of models that include an interaction term. Notice that 66.538 - 0.392 - 0.317 = 65.829 Oct 26 '19 at 12:32
• Hmm, I thought the intercept was the value of the dependent variable when all independent variables are 0. In 66.538 - 0.392 - 0.317 = 65.829 why do you exclude IsTerm3? Oct 26 '19 at 12:58