简体   繁体   中英

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM