You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DiscreteMargins.summary_frame() fails with *** ValueError: all the input arrays must have same number of dimensions #3309
summary_frame() of a MNLogit estimate is failing for me, because the dimensions of self.conf_int(alpha) are twice the size of everything else in the following list of arrays:
@cpbl Thanks for reporting, I never looked at this, we have some problems because the params in MNLogit are 2 dimensional, while most of the generic structure is designed for 1-dimensional params.
They look just like what I wanted them to show! so probably good. I haven't compared the s.e.'s to another package/software.
Yes, is the way to fix this just to test self.margeff.ndim, and behave differently in the two cases?
The problem is that I'm not sure we have access here to the different categorical values of the MNLogit, which ought really to be in the DataFrame (?)
margeff and margeff_se are unit tested, against Stata 11 AFAICS
so this is most likely in conf_int which doesn't have unit tests in the main CheckMNLogitBaseZero.
I don't know if there are generic tests for it.
Or maybe it's just a missing reshape in summary.
I just saw your comment appear.
I don't know yet where the special code for MNLogit 2d handling is in the margin code.
I will try to dig in with the Ames example from the unit tests, since know I don't know the shape of any of these extra results for MNLogit. The unit tests use ravel by column stacking, e.g. self.pvalues = np.reshape(pvalues, (6,-1), order='F')
looks like the problems with the 3-d conf_int are confined to the summaries summary() gives me only a single column for the confint which looks like the lower bound
summary_frame might also have an index error
summary is looping over the multivariate endog, but summary_frame does not have the extra loop.
Is there supposed to be a hierarchical/multi index for the dataFrame with (endog_name, exog_name)?
Then, we could just ravel/reshape the numbers for the table and create the double index.
>>> table = np.column_stack([i.ravel("F") for i in [self.margeff, self.margeff_se, self.tvalues,
self.pvalues, self.conf_int(alpha)[:, 0, :], self.conf_int(alpha)[:, 1, :]]])
>>> table.shape
(35, 6)
this creates a numpy array for the dataframe with the params table columns, and rows are stacked equation by equation, like in the printed summary table
Hi @josef-pkt .
I don't know how standardised these things are, so I'm posing this suggestion here rather than as a new issue, but might it not likely be a more useful format to have the "endog" column be named after the variable itself, instead of having it repeated in every row? I my example below, the column would be SWL and the entries 0,1,2,...
I for one will always want to back out such a format.
IMO, your suggestion would look nicer in this case. I thought about it but I don't have a strong enough preference to make up my mind for changes. summary() uses the same helper function for the endog level names, from which I took this. (Similarly, patsy created variable names for categorical levels are a bit verbose for nice printing, but they are descriptive for coding.)
I thought about using the endog name itself as index column title, but since it's currently also in the index level names, I thought I stay "generic". And, I thought that it should be easy for users to change the index title on the dataframe, but I didn't try.
(We will have to review and add things like this for other multivariate endog cases, which might have different endog names instead of levels of one endog as in MNLogit.)
@cpbl you could open a new issue. I think we could add at least some options for naming conventions to the summary_frame methods.
In general, we will need to add also automatic name creation for multivariate endog, when we need the raveled params and associated statistics. (But I haven't started to look at the status of that yet.)
Activity
josef-pkt commentedon Dec 9, 2016
@cpbl Thanks for reporting, I never looked at this, we have some problems because the params in MNLogit are 2 dimensional, while most of the generic structure is designed for 1-dimensional params.
Do margeff and margeff_se itself look ok?
cpbl commentedon Dec 9, 2016
They look just like what I wanted them to show! so probably good. I haven't compared the s.e.'s to another package/software.
Yes, is the way to fix this just to test self.margeff.ndim, and behave differently in the two cases?
The problem is that I'm not sure we have access here to the different categorical values of the MNLogit, which ought really to be in the DataFrame (?)
josef-pkt commentedon Dec 9, 2016
margeff and margeff_se are unit tested, against Stata 11 AFAICS
so this is most likely in conf_int which doesn't have unit tests in the main CheckMNLogitBaseZero.
I don't know if there are generic tests for it.
Or maybe it's just a missing reshape in summary.
I just saw your comment appear.
I don't know yet where the special code for MNLogit 2d handling is in the margin code.
I will try to dig in with the Ames example from the unit tests, since know I don't know the shape of any of these extra results for MNLogit. The unit tests use ravel by column stacking, e.g.
self.pvalues = np.reshape(pvalues, (6,-1), order='F')josef-pkt commentedon Dec 9, 2016
looks like the problems with the 3-d conf_int are confined to the summaries
summary()gives me only a single column for the confint which looks like the lower boundsummary_frame might also have an index error
summary is looping over the multivariate endog, but summary_frame does not have the extra loop.
Is there supposed to be a hierarchical/multi index for the dataFrame with (endog_name, exog_name)?
Then, we could just ravel/reshape the numbers for the table and create the double index.
josef-pkt commentedon Dec 9, 2016
one down:
summary is a refactoring victim when we split the columns of the conf_int.
margin header has one column less
cpbl commentedon Dec 9, 2016
I have something like this to generate the DataFrame in DiscreteMargins.summary_frame()
josef-pkt commentedon Dec 9, 2016
this creates a numpy array for the dataframe with the params table columns, and rows are stacked equation by equation, like in the printed summary table
@cpbl
Does stacking with multi-index look fine to you?
I'm not really a pandas expert. This is what I'm experimenting with right now
compared to plain summary
josef-pkt commentedon Dec 9, 2016
messages just crossed.
I had the column_stacking like you have before, but I think the unraveled row stacking might be more useful.
cpbl commentedon Dec 9, 2016
@josef-pkt Great!
I should have just had dinner while waiting for the expert to do it properly!
Thanks for offering pandas output in these things.
josef-pkt commentedon Dec 9, 2016
using the multiindex, as far as I can figure it out
BUG: MNLogit margins fix summary and summary_frame, closes statsmodel…
BUG: MNLogit margins fix summary and summary_frame, closes statsmodel…
BUG: MNLogit margins fix summary and summary_frame, closes statsmodel…
cpbl commentedon Dec 10, 2016
Hi @josef-pkt .
I don't know how standardised these things are, so I'm posing this suggestion here rather than as a new issue, but might it not likely be a more useful format to have the "endog" column be named after the variable itself, instead of having it repeated in every row? I my example below, the column would be
SWLand the entries 0,1,2,...I for one will always want to back out such a format.
josef-pkt commentedon Dec 10, 2016
I didn't look at the index names for the endog levels itself, those are created by a helper function
https://github.com/statsmodels/statsmodels/pull/3311/files#diff-478f341af1e21db20f0a65d99614ed6aR473
IMO, your suggestion would look nicer in this case. I thought about it but I don't have a strong enough preference to make up my mind for changes.
summary()uses the same helper function for the endog level names, from which I took this. (Similarly, patsy created variable names for categorical levels are a bit verbose for nice printing, but they are descriptive for coding.)I thought about using the endog name itself as index column title, but since it's currently also in the index level names, I thought I stay "generic". And, I thought that it should be easy for users to change the index title on the dataframe, but I didn't try.
(We will have to review and add things like this for other multivariate endog cases, which might have different endog names instead of levels of one endog as in MNLogit.)
josef-pkt commentedon Dec 10, 2016
@cpbl you could open a new issue. I think we could add at least some options for naming conventions to the
summary_framemethods.In general, we will need to add also automatic name creation for multivariate endog, when we need the
raveledparamsand associated statistics. (But I haven't started to look at the status of that yet.)add basic distributed_estimation notebook
BUG: MNLogit margins fix summary and summary_frame, closes statsmodel…