Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ordinal regression docs #719

Merged
merged 13 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bambi/priors/scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def scale_threshold(self):
threshold = self.model.components["threshold"]
if isinstance(threshold, ConstantComponent) and threshold.prior.auto_scale:
response_level_n = len(np.unique(self.response_component.response_term.data))
mu = np.round(np.linspace(-2, 2, num=response_level_n - 1), 2)
mu = np.zeros(response_level_n - 1)
Copy link
Collaborator Author

@GStechschulte GStechschulte Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If sequential models assume that for every response level there is a latent continuous variable $Z_k$, then wouldn't we need each response level? Thus, mu should be mu = response_level_n and not response_level_n - 1?

Copy link
Collaborator

@tomicapretto tomicapretto Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh, I think you're right!

I'm thinking why the current approach is working and not failing. Is it because it's not considering the probability of Y being larger than the largest observed category? I think it would make sense for the years example, but I'm not sure if it would make sense for cases where there is a pre-specified set of categories.

I wrote that as I was looking at this visualization from the ordinal tutorial by Bürkner and Vuorre:

image

and I wonder: Do we always have a Pr(Y > K)? (as in the Y > 3 in the figure)

@GStechschulte if you make that modification and run the example, does it work?

Copy link
Collaborator Author

@GStechschulte GStechschulte Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remove the -1, I get ValueError: Incompatible Elemwise input shapes [(35,), (36,)].

This makes sense as I stated in the docs because the sequential model is a product of probabilities, i.e., the probability that $Y$ is equal to category $k$ is equal to the probability that it did not fall in one of the former categories $1: k-1$ multiplied by the probability that the sequential process stopped at $k$.

In the case of the attrition dataset, there are 36 response categories. Because of the statement above, this makes sense why the probability of category 36 is 1. There is no category after 36, so once you multiply all of the previous probabilities with the current category, you get 1. Thus, you don't need a parameter (threshold) for it.

threshold.prior = Prior("Normal", mu=mu, sigma=1)

def scale(self):
Expand Down
Loading
Loading