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 logit regression: cutoff ordering during optimization #81

Closed
Rubaiyat-Alam opened this issue Jul 17, 2022 · 5 comments
Closed
Labels
bug Something isn't working

Comments

@Rubaiyat-Alam
Copy link

Rubaiyat-Alam commented Jul 17, 2022

Hello,

I'm running the ordinal response model in Econometrics.jl (which corresponds to Stata's ologit) and am experiencing an error. For certain specs, after I run the ologit, I get an error which says that log is being taken of a negative value. The same spec works fine on Stata. I coded up the ologit in Julia, and it looks like the ordering of the cutoff is not being maintained over the optimization process. I explain in detail below.

In ordinal logit we must have that cutoff 1 < cutoff 2 < cutoff 3 < .... and so on. This ordering must hold at all times during the optimization because Pr(d = j |X) = F(cutoff_j ... |X) - F(cutoff_j-1 .... |X), so if cutoff_{j - 1} > cutoff_{j}, then Pr(d = j |X) becomes negative. Since ologit estimation requires taking logs of probability, this could end up in taking log of a negative value, throwing an error.

What happens when I run ologit is that as the optimizer perturbs over differing values of the cutoff, it sometimes uses trial values where cutoff_{j - 1} > cutoff_j, which throws an error of logs being taken of a negative value.

My guess is that the optimization problem for ologit needs to include a constraint of the cutoffs following the right ordering, and that will be enough.

I'm not attaching a MWE that showcases the error - I run into this error for my research dataset and haven't constructed a fake dataset that recreates this. If the above isn't clear please let me know, I'll try to come up with a MWE. I can also post screenshots of the error (which basically says log of a negative value is being taken) if it helps.

And thanks for creating and updating the package in general! Let me know if more info is needed.

@Rubaiyat-Alam Rubaiyat-Alam added the bug Something isn't working label Jul 17, 2022
@Nosferican
Copy link
Owner

Hi @Rubaiyat-Alam, is this something you are experiencing with the package or in your implementation of ordinal logistic regression? The key to avoiding that issue is a nice optimization trick,

ζ[2:end - 1] .= cumsum(vcat(β[n + 1], exp.(β[n + 2:end])))

Basically, the parameter that the model optimizes is the log of the partial addition. In other words, when recovering the thresholds, you ensure that those are monotonically increasing since you are taking the cumulative addition of positive values ensured by taking the exponent of the parameter estimates.

Let me know if that helps in what you are asking.

@Rubaiyat-Alam
Copy link
Author

Hi,

Thanks for the reply. It's something I'm experiencing with the package, not my own implementation. I'm attaching an image showing the error. As you can see an error seems to be thrown with regards to Optim.

ologit

@Nosferican
Copy link
Owner

Could you share a sample dataset that triggers the error to help me debug this?

@Nosferican
Copy link
Owner

I might be have a bit of time to look into it in case you can share a MRE. Thanks!

@Nosferican
Copy link
Owner

Closing because of stale. Feel free to re-open if anything new on it.

@Nosferican Nosferican closed this as not planned Won't fix, can't repro, duplicate, stale Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants