import numpy as np
import statsmodels.api as sm
from scipy import stats
This data is based on the example in Gill and describes the proportion of voters who voted Yes to grant the Scottish Parliament taxation powers. The data are divided into 32 council districts. This example's explanatory variables include the amount of council tax collected in pounds sterling as of April 1997 per two adults before adjustments, the female percentage of total claims for unemployment benefits as of January, 1998, the standardized mortality rate (UK is 100), the percentage of labor force participation, regional GDP, the percentage of children aged 5 to 15, and an interaction term between female unemployment and the council tax. The original source files and variable information are included in /scotland/src/
data2 = sm.datasets.scotland.load()
data2.exog = sm.add_constant(data2.exog, prepend=False)
print(data2.exog[:5,:])
print(data2.endog[:5])
[[ 7.12000000e+02 2.10000000e+01 1.05000000e+02 8.24000000e+01 1.35660000e+04 1.23000000e+01 1.49520000e+04 1.00000000e+00] [ 6.43000000e+02 2.65000000e+01 9.70000000e+01 8.02000000e+01 1.35660000e+04 1.53000000e+01 1.70395000e+04 1.00000000e+00] [ 6.79000000e+02 2.83000000e+01 1.13000000e+02 8.63000000e+01 9.61100000e+03 1.39000000e+01 1.92157000e+04 1.00000000e+00] [ 8.01000000e+02 2.71000000e+01 1.09000000e+02 8.04000000e+01 9.48300000e+03 1.36000000e+01 2.17071000e+04 1.00000000e+00] [ 7.53000000e+02 2.20000000e+01 1.15000000e+02 6.47000000e+01 9.26500000e+03 1.46000000e+01 1.65660000e+04 1.00000000e+00]] [ 60.3 52.3 53.4 57. 68.7]
glm_gamma = sm.GLM(data2.endog, data2.exog, family=sm.families.Gamma())
glm_results = glm_gamma.fit()
print(glm_results.summary())
Generalized Linear Model Regression Results ============================================================================== Dep. Variable: y No. Observations: 32 Model: GLM Df Residuals: 24 Model Family: Gamma Df Model: 7 Link Function: inverse_power Scale: 0.00358428317349 Method: IRLS Log-Likelihood: -83.017 Date: Fri, 16 May 2014 Deviance: 0.087389 Time: 21:28:31 Pearson chi2: 0.0860 No. Iterations: 5 ============================================================================== coef std err t P>|t| [95.0% Conf. Int.] ------------------------------------------------------------------------------ x1 4.962e-05 1.62e-05 3.060 0.002 1.78e-05 8.14e-05 x2 0.0020 0.001 3.824 0.000 0.001 0.003 x3 -7.181e-05 2.71e-05 -2.648 0.008 -0.000 -1.87e-05 x4 0.0001 4.06e-05 2.757 0.006 3.23e-05 0.000 x5 -1.468e-07 1.24e-07 -1.187 0.235 -3.89e-07 9.56e-08 x6 -0.0005 0.000 -2.159 0.031 -0.001 -4.78e-05 x7 -2.427e-06 7.46e-07 -3.253 0.001 -3.89e-06 -9.65e-07 const -0.0178 0.011 -1.548 0.122 -0.040 0.005 ==============================================================================