def glm(data, xseq, **params):
"""
Fit GLM
"""
X = sm.add_constant(data['x'])
Xseq = sm.add_constant(xseq)
results = sm.GLM(data['y'], X).fit(**params['method_args'])
data = pd.DataFrame({'x': xseq})
data['y'] = results.predict(Xseq)
if params['se']:
# TODO: Depends on statsmodel > 0.7
# https://github.com/statsmodels/statsmodels/pull/2151
# https://github.com/statsmodels/statsmodels/pull/3406
# Remove the try/except when a compatible version is released
try:
prediction = results.get_prediction(Xseq)
ci = prediction.conf_int(1 - params['level'])
data['ymin'] = ci[:, 0]
data['ymax'] = ci[:, 1]
except (AttributeError, TypeError):
warnings.warn(
"Cannot compute confidence intervals."
"Install latest/development version of statmodels.")
return data
评论列表
文章目录