Poisson regression analysis is also one of nonlinear regression analysis. The distribution function can be estimated by the maximum likelihood estimation method assuming a Poisson distribution. This analysis method is basically an approach that can be used for those that have "count data" as the dependent variable. Also, the dependent variable must be an integer greater than or equal to 0. The following are typical examples of Poisson regression analysis that can be used. ex) Number of traffic accidents, number of visitors, number of children ... Please note that using it just because the distribution looks like a Poisson distribution will result in an incorrect analysis.
The distribution function of a typical Poisson distribution is as follows. $ \frac{\lambda^s exp(-\lambda)}{s!}$
In Poisson regression analysis, we put the following model.
Next, find $ P (y_i | X_i) $.
Next, find the likelihood function. $L(\beta)=\Pi P(y_i|X_i) $ The maximum likelihood estimate of this cannot be calculated by hand, so let the optimization function calculate it.
Calculating the marginal effect of $ E [y_i | X_i] = exp (X \ beta) $
import statsmodels.api as sm
import pandas as pd
#read data
data=pd.read_csv("___.csv")
target=data.loc[:,"name"]
explain=data.loc[:,["names"]]
#it is necessary to add constant variable
explain=sm.add_constant(explain)
model=sm.Poisson(target, explain)
result=model.fit()
#you can get beta but not Partial effect
print(result.summary())
#you can get Partial Effect!!
print(result.get_margeff(at="overall").summary())
#if you change [at="overall"], the way of calculation can be change
Recommended Posts