I am going through a stats workbook with python, there is a practice hands on question on which i am stuck. Its related to Poisson regression and here is the problem statement:-
Perform the following tasks:
- Load the R data set Insurance from MASS package and Capture the data as pandas data frame
- Build a Poisson regression model with a log of an independent variable, Holders and dependent variable Claims.
- Fit the model with data.
- Find the sum of residuals.
I am stuck with point 4 above. Can anyone help with this step?
Here is what i have done so far :-
import statsmodels.api as sm
import statsmodels.formula.api as smf
import numpy as np
df = sm.datasets.get_rdataset('Insurance', package='MASS', cache=False).data
poisson_model = smf.poisson('np.log(Holders) ~ -1 + Claims', df)
poisson_result = poisson_model.fit()
print(poisson_result.summary())
Now how to get sum of residuals?