Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
poisson regression
I am working with poisson regression with pandas
and I have a question about this specific command
with y,x being respectively the dependent, independent variables.

the following code takes two columns from an excel file and works properly

import pandas as pd
from statsmodels.formula.api import poisson
from statsmodels.formula.api import negativebinomial

data = pd.read_csv(r'file.csv')
varcomp = 'y ~ x'
model_1 = poisson(varcomp, data).fit()
print( model_1.summary())

but now I want x and y to be two rows instead of columns, but I am a bit lost
and don't know how to proceed.

I have tried to convert those two columns into lists, since I will be able to do the same with rows,
but once I implement them into the
command, I get an error.
Thank you in advance.


model_1 = poisson('y_list ~ x_list', data).fit()
print( model_1.summary())
File "C:\Users\lib\site-packages\patsy\", line 312, in dmatrices raise PatsyError("model is missing required outcome variables") patsy.PatsyError: model is missing required outcome variables
Did you try transposing the dataframe?
tdata = data.transpose()
I was certainly not aware of that option, and thanks for letting me know.
However, if possible, I would like to stick to lists, since it gives me
more freedom to do what I need to do,
for instance in some cases, I have to sum the numbers from different cells
before starting to work with them, and I am not sure how else to do it.
Any ideas?

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020