Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

alkaline-ml / statsmodels   python

Repository URL to install this package:

Version: 0.11.1 

/ genmod / tests / results / results_glm.py

"""
Results for test_glm.py.

Hard-coded from R or Stata.  Note that some of the remaining discrepancy vs.
Stata may be because Stata uses ML by default unless you specifically ask for
IRLS.
"""
import os

import numpy as np
import pandas as pd

from statsmodels.api import add_constant, categorical
from . import glm_test_resids

# Test Precisions
DECIMAL_4 = 4
DECIMAL_3 = 3
DECIMAL_2 = 2
DECIMAL_1 = 1
DECIMAL_0 = 0


class Longley(object):
    """
    Longley used for TestGlmGaussian

    Results are from Stata and R.
    """
    def __init__(self):

        self.resids = np.array([
            [267.34002976,  267.34002976,  267.34002976,
             267.34002976, 267.34002976],
            [-94.0139424,   -94.0139424,   -94.0139424,   -94.0139424,
             -94.0139424],
            [46.28716776,   46.28716776,   46.28716776,   46.28716776,
             46.28716776],
            [-410.11462193, -410.11462193, -410.11462193, -410.11462193,
             -410.11462193],
            [309.71459076,  309.71459076,  309.71459076,  309.71459076,
             309.71459076],
            [-249.31121533, -249.31121533, -249.31121533, -249.31121533,
             -249.31121533],
            [-164.0489564,  -164.0489564,  -164.0489564,  -164.0489564,
             -164.0489564],
            [-13.18035687,  -13.18035687,  -13.18035687,  -13.18035687,
             -13.18035687],
            [14.3047726,    14.3047726,    14.3047726,    14.3047726,
             14.3047726],
            [455.39409455,  455.39409455,  455.39409455,  455.39409455,
             455.39409455],
            [-17.26892711,  -17.26892711,  -17.26892711,  -17.26892711,
             -17.26892711],
            [-39.05504252,  -39.05504252,  -39.05504252,  -39.05504252,
             -39.05504252],
            [-155.5499736,  -155.5499736,  -155.5499736,  -155.5499736,
             -155.5499736],
            [-85.67130804,  -85.67130804,  -85.67130804,  -85.67130804,
             -85.67130804],
            [341.93151396,  341.93151396,  341.93151396,  341.93151396,
             341.93151396],
            [-206.75782519, -206.75782519, -206.75782519, -206.75782519,
             -206.75782519]])
        self.null_deviance = 185008826  # taken from R.
        self.params = np.array([
            1.50618723e+01,  -3.58191793e-02,
            -2.02022980e+00, -1.03322687e+00,  -5.11041057e-02,
            1.82915146e+03, -3.48225863e+06])
        self.bse = np.array([
            8.49149258e+01,   3.34910078e-02, 4.88399682e-01,
            2.14274163e-01,   2.26073200e-01,
            4.55478499e+02, 8.90420384e+05])
        self.aic_R = 235.23486961695903  # R adds 2 for dof to AIC
        self.aic_Stata = 14.57717943930524  # stata divides by nobs
        self.deviance = 836424.0555058046   # from R
        self.scale = 92936.006167311629
        self.llf = -109.61743480847952
        self.null_deviance = 185008826  # taken from R. Rpy bug

        self.bic_Stata = 836399.1760177979  # no bic in R?
        self.df_model = 6
        self.df_resid = 9

        # TODO: taken from Stata; not available in sm yet
        self.chi2 = 1981.711859508729

        # self.pearson_chi2 = 836424.1293162981   # from Stata (?)
        self.fittedvalues = np.array([
            60055.659970240202, 61216.013942398131,
            60124.71283224225, 61597.114621930756, 62911.285409240052,
            63888.31121532945, 65153.048956395127, 63774.180356866214,
            66004.695227399934, 67401.605905447621,
            68186.268927114084,  66552.055042522494,
            68810.549973595422, 69649.67130804155, 68989.068486039061,
            70757.757825193927])


class GaussianLog(object):
    """
    Uses generated data.  These results are from R and Stata.
    """
    def __init__(self):
        self.resids = np.array([
            [3.20800000e-04, 3.20800000e-04,
             8.72100000e-04, 3.20800000e-04,   3.20800000e-04],
            [8.12100000e-04,   8.12100000e-04,   2.16350000e-03,
             8.12100000e-04,   8.12100000e-04],
            [-2.94800000e-04,  -2.94800000e-04,  -7.69700000e-04,
             -2.94800000e-04,  -2.94800000e-04],
            [1.40190000e-03,   1.40190000e-03,   3.58560000e-03,
             1.40190000e-03,   1.40190000e-03],
            [-2.30910000e-03,  -2.30910000e-03,  -5.78490000e-03,
             -2.30910000e-03,  -2.30910000e-03],
            [1.10380000e-03,   1.10380000e-03,   2.70820000e-03,
             1.10380000e-03,   1.10380000e-03],
            [-5.14000000e-06,  -5.14000000e-06,  -1.23000000e-05,
             -5.14000000e-06,  -5.14000000e-06],
            [-1.65500000e-04,  -1.65500000e-04,  -3.89200000e-04,
             -1.65500000e-04,  -1.65500000e-04],
            [-7.55400000e-04,  -7.55400000e-04,  -1.73870000e-03,
             -7.55400000e-04,  -7.55400000e-04],
            [-1.39800000e-04,  -1.39800000e-04,  -3.14800000e-04,
             -1.39800000e-04,  -1.39800000e-04],
            [-7.17000000e-04,  -7.17000000e-04,  -1.58000000e-03,
             -7.17000000e-04,  -7.17000000e-04],
            [-1.12200000e-04,  -1.12200000e-04,  -2.41900000e-04,
             -1.12200000e-04,  -1.12200000e-04],
            [3.22100000e-04,   3.22100000e-04,   6.79000000e-04,
             3.22100000e-04,   3.22100000e-04],
            [-3.78000000e-05,  -3.78000000e-05,  -7.79000000e-05,
             -3.78000000e-05,  -3.78000000e-05],
            [5.54500000e-04,   5.54500000e-04,   1.11730000e-03,
             5.54500000e-04,   5.54500000e-04],
            [3.38400000e-04,   3.38400000e-04,   6.66300000e-04,
             3.38400000e-04,   3.38400000e-04],
            [9.72000000e-05,   9.72000000e-05,   1.87000000e-04,
             9.72000000e-05,   9.72000000e-05],
            [-7.92900000e-04,  -7.92900000e-04,  -1.49070000e-03,
             -7.92900000e-04,  -7.92900000e-04],
            [3.33000000e-04,   3.33000000e-04,   6.11500000e-04,
             3.33000000e-04,   3.33000000e-04],
            [-8.35300000e-04,  -8.35300000e-04,  -1.49790000e-03,
             -8.35300000e-04,  -8.35300000e-04],
            [-3.99700000e-04,  -3.99700000e-04,  -6.99800000e-04,
             -3.99700000e-04,  -3.99700000e-04],
            [1.41300000e-04,   1.41300000e-04,   2.41500000e-04,
             1.41300000e-04,   1.41300000e-04],
            [-8.50700000e-04,  -8.50700000e-04,  -1.41920000e-03,
             -8.50700000e-04,  -8.50700000e-04],
            [1.43000000e-06,   1.43000000e-06,   2.33000000e-06,
             1.43000000e-06,   1.43000000e-06],
            [-9.12000000e-05,  -9.12000000e-05,  -1.44900000e-04,
             -9.12000000e-05,  -9.12000000e-05],
            [6.75500000e-04,   6.75500000e-04,   1.04650000e-03,
             6.75500000e-04,   6.75500000e-04],
            [3.97900000e-04,   3.97900000e-04,   6.01100000e-04,
             3.97900000e-04,   3.97900000e-04],
            [1.07000000e-05,   1.07000000e-05,   1.57000000e-05,
             1.07000000e-05,   1.07000000e-05],
            [-8.15200000e-04,  -8.15200000e-04,  -1.17060000e-03,
             -8.15200000e-04,  -8.15200000e-04],
            [-8.46400000e-04,  -8.46400000e-04,  -1.18460000e-03,
             -8.46400000e-04,  -8.46400000e-04],
            [9.91200000e-04,   9.91200000e-04,   1.35180000e-03,
             9.91200000e-04,   9.91200000e-04],
            [-5.07400000e-04,  -5.07400000e-04,  -6.74200000e-04,
             -5.07400000e-04,  -5.07400000e-04],
            [1.08520000e-03,   1.08520000e-03,   1.40450000e-03,
             1.08520000e-03,   1.08520000e-03],
            [9.56100000e-04,   9.56100000e-04,   1.20500000e-03,
             9.56100000e-04,   9.56100000e-04],
            [1.87500000e-03,   1.87500000e-03,   2.30090000e-03,
             1.87500000e-03,   1.87500000e-03],
            [-1.93920000e-03,  -1.93920000e-03,  -2.31650000e-03,
             -1.93920000e-03,  -1.93920000e-03],
            [8.16000000e-04,   8.16000000e-04,   9.48700000e-04,
             8.16000000e-04,   8.16000000e-04],
            [1.01520000e-03,   1.01520000e-03,   1.14860000e-03,
             1.01520000e-03,   1.01520000e-03],
            [1.04150000e-03,   1.04150000e-03,   1.14640000e-03,
             1.04150000e-03,   1.04150000e-03],
            [-3.88200000e-04,  -3.88200000e-04,  -4.15600000e-04,
             -3.88200000e-04,  -3.88200000e-04],
            [9.95900000e-04,   9.95900000e-04,   1.03690000e-03,
             9.95900000e-04,   9.95900000e-04],
            [-6.82800000e-04,  -6.82800000e-04,  -6.91200000e-04,
             -6.82800000e-04,  -6.82800000e-04],
            [-8.11400000e-04,  -8.11400000e-04,  -7.98500000e-04,
             -8.11400000e-04,  -8.11400000e-04],
            [-1.79050000e-03,  -1.79050000e-03,  -1.71250000e-03,
             -1.79050000e-03,  -1.79050000e-03],
            [6.10000000e-04,   6.10000000e-04,   5.66900000e-04,
             6.10000000e-04,   6.10000000e-04],
            [2.52600000e-04,   2.52600000e-04,   2.28100000e-04,
             2.52600000e-04,   2.52600000e-04],
            [-8.62500000e-04,  -8.62500000e-04,  -7.56400000e-04,
             -8.62500000e-04,  -8.62500000e-04],
            [-3.47300000e-04,  -3.47300000e-04,  -2.95800000e-04,
             -3.47300000e-04,  -3.47300000e-04],
            [-7.79000000e-05,  -7.79000000e-05,  -6.44000000e-05,
             -7.79000000e-05,  -7.79000000e-05],
            [6.72000000e-04,   6.72000000e-04,   5.39400000e-04,
             6.72000000e-04,   6.72000000e-04],
            [-3.72100000e-04,  -3.72100000e-04,  -2.89900000e-04,
             -3.72100000e-04,  -3.72100000e-04],
            [-1.22900000e-04,  -1.22900000e-04,  -9.29000000e-05,
             -1.22900000e-04,  -1.22900000e-04],
            [-1.63470000e-03,  -1.63470000e-03,  -1.19900000e-03,
             -1.63470000e-03,  -1.63470000e-03],
            [2.64400000e-04,   2.64400000e-04,   1.88100000e-04,
             2.64400000e-04,   2.64400000e-04],
            [1.79230000e-03,   1.79230000e-03,   1.23650000e-03,
             1.79230000e-03,   1.79230000e-03],
            [-1.40500000e-04,  -1.40500000e-04,  -9.40000000e-05,
             -1.40500000e-04,  -1.40500000e-04],
            [-2.98500000e-04,  -2.98500000e-04,  -1.93600000e-04,
             -2.98500000e-04,  -2.98500000e-04],
            [-9.33100000e-04,  -9.33100000e-04,  -5.86400000e-04,
             -9.33100000e-04,  -9.33100000e-04],
            [9.11200000e-04,   9.11200000e-04,   5.54900000e-04,
             9.11200000e-04,   9.11200000e-04],
            [-1.31840000e-03,  -1.31840000e-03,  -7.77900000e-04,
             -1.31840000e-03,  -1.31840000e-03],
            [-1.30200000e-04,  -1.30200000e-04,  -7.44000000e-05,
             -1.30200000e-04,  -1.30200000e-04],
            [9.09300000e-04,   9.09300000e-04,   5.03200000e-04,
             9.09300000e-04,   9.09300000e-04],
            [-2.39500000e-04,  -2.39500000e-04,  -1.28300000e-04,
             -2.39500000e-04,  -2.39500000e-04],
            [7.15300000e-04,   7.15300000e-04,   3.71000000e-04,
             7.15300000e-04,   7.15300000e-04],
            [5.45000000e-05,   5.45000000e-05,   2.73000000e-05,
             5.45000000e-05,   5.45000000e-05],
            [2.85310000e-03,   2.85310000e-03,   1.38600000e-03,
             2.85310000e-03,   2.85310000e-03],
            [4.63400000e-04,   4.63400000e-04,   2.17800000e-04,
             4.63400000e-04,   4.63400000e-04],
            [2.80900000e-04,   2.80900000e-04,   1.27700000e-04,
             2.80900000e-04,   2.80900000e-04],
            [5.42000000e-05,   5.42000000e-05,   2.38000000e-05,
             5.42000000e-05,   5.42000000e-05],
            [-3.62300000e-04,  -3.62300000e-04,  -1.54000000e-04,
             -3.62300000e-04,  -3.62300000e-04],
            [-1.11900000e-03,  -1.11900000e-03,  -4.59800000e-04,
             -1.11900000e-03,  -1.11900000e-03],
            [1.28900000e-03,   1.28900000e-03,   5.11900000e-04,
             1.28900000e-03,   1.28900000e-03],
            [-1.40820000e-03,  -1.40820000e-03,  -5.40400000e-04,
             -1.40820000e-03,  -1.40820000e-03],
            [-1.69300000e-04,  -1.69300000e-04,  -6.28000000e-05,
             -1.69300000e-04,  -1.69300000e-04],
            [-1.03620000e-03,  -1.03620000e-03,  -3.71000000e-04,
             -1.03620000e-03,  -1.03620000e-03],
            [1.49150000e-03,   1.49150000e-03,   5.15800000e-04,
             1.49150000e-03,   1.49150000e-03],
            [-7.22000000e-05,  -7.22000000e-05,  -2.41000000e-05,
             -7.22000000e-05,  -7.22000000e-05],
            [5.49000000e-04,   5.49000000e-04,   1.76900000e-04,
             5.49000000e-04,   5.49000000e-04],
            [-2.12320000e-03,  -2.12320000e-03,  -6.60400000e-04,
             -2.12320000e-03,  -2.12320000e-03],
            [7.84000000e-06,   7.84000000e-06,   2.35000000e-06,
             7.84000000e-06,   7.84000000e-06],
            [1.15580000e-03,   1.15580000e-03,   3.34700000e-04,
             1.15580000e-03,   1.15580000e-03],
            [4.83400000e-04,   4.83400000e-04,   1.35000000e-04,
             4.83400000e-04,   4.83400000e-04],
            [-5.26100000e-04,  -5.26100000e-04,  -1.41700000e-04,
             -5.26100000e-04,  -5.26100000e-04],
            [-1.75100000e-04,  -1.75100000e-04,  -4.55000000e-05,
             -1.75100000e-04,  -1.75100000e-04],
            [-1.84600000e-03,  -1.84600000e-03,  -4.62100000e-04,
             -1.84600000e-03,  -1.84600000e-03],
            [2.07200000e-04,   2.07200000e-04,   5.00000000e-05,
             2.07200000e-04,   2.07200000e-04],
            [-8.54700000e-04,  -8.54700000e-04,  -1.98700000e-04,
             -8.54700000e-04,  -8.54700000e-04],
            [-9.20000000e-05,  -9.20000000e-05,  -2.06000000e-05,
             -9.20000000e-05,  -9.20000000e-05],
            [5.35700000e-04,   5.35700000e-04,   1.15600000e-04,
             5.35700000e-04,   5.35700000e-04],
            [-7.67300000e-04,  -7.67300000e-04,  -1.59400000e-04,
             -7.67300000e-04,  -7.67300000e-04],
            [-1.79710000e-03,  -1.79710000e-03,  -3.59500000e-04,
             -1.79710000e-03,  -1.79710000e-03],
            [1.10910000e-03,   1.10910000e-03,   2.13500000e-04,
             1.10910000e-03,   1.10910000e-03],
            [-5.53800000e-04,  -5.53800000e-04,  -1.02600000e-04,
             -5.53800000e-04,  -5.53800000e-04],
            [7.48000000e-04,   7.48000000e-04,   1.33400000e-04,
             7.48000000e-04,   7.48000000e-04],
            [4.23000000e-04,   4.23000000e-04,   7.26000000e-05,
             4.23000000e-04,   4.23000000e-04],
            [-3.16400000e-04,  -3.16400000e-04,  -5.22000000e-05,
             -3.16400000e-04,  -3.16400000e-04],
            [-6.63200000e-04,  -6.63200000e-04,  -1.05200000e-04,
             -6.63200000e-04,  -6.63200000e-04],
            [1.33540000e-03,   1.33540000e-03,   2.03700000e-04,
             1.33540000e-03,   1.33540000e-03],
            [-7.81200000e-04,  -7.81200000e-04,  -1.14600000e-04,
             -7.81200000e-04,  -7.81200000e-04],
            [1.67880000e-03,   1.67880000e-03,   2.36600000e-04,
             1.67880000e-03,   1.67880000e-03]])

        self.null_deviance = 56.691617808182208
        self.params = np.array([
            9.99964386e-01, -1.99896965e-02, -1.00027232e-04])
        self.bse = np.array([1.42119293e-04, 1.20276468e-05, 1.87347682e-07])
        self.aic_R = -1103.8187213072656  # adds 2 for dof for scale

        self.aic_Stata = -11.05818072104212  # divides by nobs for e(aic)
        self.deviance = 8.68876986288542e-05
        self.scale = 8.9574946938163984e-07  # from R but e(phi) in Stata
        self.llf = 555.9093606536328
        self.bic_Stata = -446.7014211525822
        self.df_model = 2
        self.df_resid = 97
        self.chi2 = 33207648.86501769   # from Stata not in sm
        self.fittedvalues = np.array([
            2.7181850213327747,  2.664122305869506,
            2.6106125414084405, 2.5576658143523567, 2.5052916730829535,
            2.4534991313100165, 2.4022966718815781, 2.3516922510411282,
            2.3016933031175575, 2.2523067456332542, 2.2035389848154616,
            2.1553959214958001, 2.107882957382607, 2.0610050016905817,
            2.0147664781120667, 1.969171332114154, 1.9242230385457144,
            1.8799246095383746, 1.8362786026854092, 1.7932871294825108,
            1.7509518640143886, 1.7092740518711942, 1.6682545192788105,
            1.6278936824271399, 1.5881915569806042, 1.5491477677552221,
            1.5107615585467538, 1.4730318020945796, 1.4359570101661721,
            1.3995353437472129, 1.3637646233226499, 1.3286423392342188,
            1.2941656621002184, 1.2603314532836074, 1.2271362753947765,
            1.1945764028156565, 1.162647832232141, 1.1313462931621328,
            1.1006672584668622, 1.0706059548334832, 1.0411573732173065,
            1.0123162792324054, 0.98407722347970683, 0.95643455180206194,
            0.92938241545618494, 0.90291478119174029, 0.87702544122826565,
            0.85170802312101246, 0.82695599950720078, 0.80276269772458597,
            0.77912130929465073, 0.75602489926313921, 0.73346641539106316,
            0.71143869718971686, 0.68993448479364294, 0.66894642766589496,
            0.64846709313034534, 0.62848897472617915, 0.60900450038011367,
            0.5900060403922629, 0.57148591523195513, 0.55343640314018494,
            0.5358497475357491, 0.51871816422248385, 0.50203384839536769,
            0.48578898144361343, 0.46997573754920047, 0.45458629007964013,
            0.4396128177740814, 0.42504751072218311, 0.41088257613548018,
            0.39711024391126759, 0.38372277198930843, 0.37071245150195081,
Loading ...