rajatsen91
rajatsen91

Reputation: 222

GLM gamma regression in Python statsmodels

Consider the GLM gamma function fitting in Python package statsmodel.

Here is the code:

import numpy
import statsmodels.api as sm

model = sm.GLM(ytrain, xtrain, family=sm.families.Gamma(link = sm.genmod.families.links.identity)).fit()

print model.summary()

This gives me the summary of the fitted model parameters, obtained by a gamma regression. What I am interested in, is the exact pdf $P(y | X)$ from the above model. What I can gather so far is the model.params*x gives the mean of the gamma as a function of the training data. How to infer the shape of the pdf from the summary ?

Upvotes: 5

Views: 7035

Answers (1)

Josef
Josef

Reputation: 22897

GLM has a get_distribution method that returns a scipy.stats distribution instance with the transformed parameterization. The distribution instance will have all the available methods like pdf, cdf and rvs.

http://www.statsmodels.org/devel/generated/statsmodels.genmod.generalized_linear_model.GLM.get_distribution.html

This is currently used only internally for some limited cases.

Note, the identity link does not guarantee that the mean is positive for all sets of explanatory variables.

Upvotes: 5

Related Questions