easystats / modelbased

:chart_with_upwards_trend: Estimate effects, contrasts and means based on statistical models
https://easystats.github.io/modelbased/
GNU General Public License v3.0
234 stars 19 forks source link

Probabilistic location of points of change for Bayesian models #37

Open DominiqueMakowski opened 4 years ago

DominiqueMakowski commented 4 years ago

By locating the points of change (using find_inversions) on all the posterior draws of the link we could have a uni/multi-modal distribution of points of change.

DominiqueMakowski commented 3 years ago

Let me clarify what you said, past-Dom:

The describe_nonlinear() function breaks a nonlinear curve by locating points of direction change.

data <- modelbased::estimate_relation(lm(Sepal.Width ~ poly(Petal.Length, 3), data = iris))
modelbased::describe_nonlinear(data, x = "Petal.Length")
#> Start |  End | Length | Change | Slope |   R2
#> ---------------------------------------------
#> 1.00  | 3.62 |   0.36 |  -1.03 | -0.39 | 0.09
#> 3.62  | 6.90 |   0.54 |   0.51 |  0.16 | 0.09

Created on 2021-05-25 by the reprex package (v1.0.0)

However, in a Bayesian / bootsrapped context, we have many iterations of that "curve". So we could, in theory, get the location of a given inversion across all draws, and thus have a distribution of these locations. And conclude something like; "the relationship between x and y goes from negative to positive at around 0.33 (95% CI [0.21, 0.42])".

This comes with some critical issues:

I'm not sure it's an issue worth looking further into, especially since describe_nonlinear should not be used as an inferential procedure, but rather as a purely descriptive and exploratory insight into a pattern.

mattansb commented 3 years ago

Is the idea that this would work with smooths as well? If so, I suggest having a look here: https://gavinsimpson.github.io/gratia/reference/derivatives.html

Also, I think @lindeloev might know a thing or two about change points... (:

lindeloev commented 3 years ago

I think this is a pretty useful idea and something I could see myself using regularly! Random thoughts:

bwiernik commented 3 years ago

The mathematical term for this "point of inversion" is "inflection point". I would suggest using that language.

bwiernik commented 3 years ago

One important thing to bear in mind is that when summarizing multiple curves, the computation needs to be done on the curves (curvewise), not on points collapsing across curves (pointwise). See https://mjskay.github.io/ggdist/reference/curve_interval.html for discussion

lindeloev commented 3 years ago

Ah, sorry I understood it as the first derivative. "Inflection point" is good. My other thoughts are still relevant, I think.

Maybe it could be generalized so the user can choose which derivative to find maximum of:

f': Extrema f'': Inflection