What is model.cov_params() in statsmodels?

1.3k Views Asked by At

I am unable to understand what the [cov_params][1] from a fitted statsmodel represents. I thought it would be the covariance matrix of the data but that does not seem to be the case. It is not even scale*convariance_matrix_of_the_data

I have used the following code snippet to try to understand:

A random dataset preparation

import pandas as pd
import numpy as np
np.random.seed(42)
df = pd.DataFrame({'num1':np.random.randn(30,),
                   'num2':np.random.randn(30,),
                  'labels':np.random.choice([1,0],30)})


Computing covariance matrix on it:

df.drop('labels',axis=1).cov()
output:
        num1        num2
num1    0.810012    0.082823
num2    0.082823    0.866951

computing the cov_params() from the model:

  1. Fitting the model:
import statsmodels.api as sm
mod = sm.formula.glm(formula = "labels ~ num1+num2",\
              data = df,
             family = sm.families.Binomial()).fit()

scale is 1.0:

mod.scale
output
1.0

Getting cov_params:

mod.cov_params()
output:
            Intercept   num1        num2
Intercept   0.162491    0.006924    0.006894
num1        0.006924    0.234236    0.004327
num2        0.006894    0.004327    0.198648

As you can see the cov values between num1 and num2 are not the same in the two cav matrices. They are not even a scaled version of each other by mod.scale parameter as mod.scale is 1.0

Can you help me understand what is mod.cov_params() [1]: https://www.statsmodels.org/0.8.0/generated/statsmodels.genmod.generalized_linear_model.GLMResults.cov_params.html

0

There are 0 best solutions below