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

added simple model compare example #88

Closed

Conversation

kiante-fernandez
Copy link
Contributor

just added a working example of comparing models using ParetoSmooth.jl

Copy link
Contributor

github-actions bot commented Jul 8, 2024

Benchmark Results

master 9e14830... master/9e14830d706ed3...
logpdf/("SequentialSamplingModels.DDM", 10) 1.69 ± 0.18 μs 1.69 ± 0.17 μs 1
logpdf/("SequentialSamplingModels.DDM", 100) 17.2 ± 0.79 μs 17.2 ± 0.88 μs 0.997
logpdf/("SequentialSamplingModels.LBA", 10) 2.49 ± 0.19 μs 2.49 ± 0.2 μs 0.999
logpdf/("SequentialSamplingModels.LBA", 100) 23.9 ± 0.61 μs 23.9 ± 0.6 μs 1
logpdf/("SequentialSamplingModels.LNR", 10) 1.01 ± 0.17 μs 1.03 ± 0.17 μs 0.986
logpdf/("SequentialSamplingModels.LNR", 100) 8.63 ± 0.26 μs 8.65 ± 0.28 μs 0.998
logpdf/("SequentialSamplingModels.RDM", 10) 2.63 ± 0.25 μs 2.65 ± 0.23 μs 0.993
logpdf/("SequentialSamplingModels.RDM", 100) 25.1 ± 0.67 μs 25.2 ± 0.68 μs 0.996
logpdf/("SequentialSamplingModels.Wald", 10) 0.227 ± 0.17 μs 0.229 ± 0.17 μs 0.991
logpdf/("SequentialSamplingModels.Wald", 100) 2.02 ± 0.051 μs 2.03 ± 0.041 μs 0.996
logpdf/("SequentialSamplingModels.WaldMixture", 10) 1.11 ± 0.16 μs 1.12 ± 0.16 μs 0.999
logpdf/("SequentialSamplingModels.WaldMixture", 100) 10.9 ± 0.17 μs 10.9 ± 0.16 μs 1
rand/("SequentialSamplingModels.DDM", 10) 2.89 ± 0.36 μs 2.91 ± 0.33 μs 0.992
rand/("SequentialSamplingModels.DDM", 100) 27.7 ± 1.3 μs 27.7 ± 1.3 μs 0.999
rand/("SequentialSamplingModels.LBA", 10) 3.23 ± 1.3 μs 3.23 ± 1.3 μs 1
rand/("SequentialSamplingModels.LBA", 100) 16.9 ± 0.31 μs 16.8 ± 0.36 μs 1
rand/("SequentialSamplingModels.LCA", 10) 0.61 ± 0.23 ms 0.58 ± 0.2 ms 1.05
rand/("SequentialSamplingModels.LCA", 100) 6.69 ± 0.25 ms 6.44 ± 0.26 ms 1.04
rand/("SequentialSamplingModels.LNR", 10) 1.07 ± 0.17 μs 1.06 ± 0.17 μs 1
rand/("SequentialSamplingModels.LNR", 100) 7.42 ± 3.8 μs 7.54 ± 3.7 μs 0.985
rand/("SequentialSamplingModels.RDM", 10) 1.41 ± 0.33 μs 1.45 ± 0.33 μs 0.97
rand/("SequentialSamplingModels.RDM", 100) 10.9 ± 3.8 μs 10.9 ± 3.8 μs 0.993
rand/("SequentialSamplingModels.Wald", 10) 0.469 ± 0.16 μs 0.471 ± 0.17 μs 0.995
rand/("SequentialSamplingModels.Wald", 100) 2.88 ± 0.2 μs 2.89 ± 0.2 μs 0.997
rand/("SequentialSamplingModels.WaldMixture", 10) 1.22 ± 0.17 μs 1.22 ± 0.16 μs 0.998
rand/("SequentialSamplingModels.WaldMixture", 100) 11.8 ± 0.18 μs 11.8 ± 0.17 μs 0.999
simulate/SequentialSamplingModels.DDM 4 ± 2.2 μs 3.73 ± 1.4 μs 1.07
simulate/SequentialSamplingModels.LBA 3.71 ± 0.42 μs 3.75 ± 0.24 μs 0.989
simulate/SequentialSamplingModels.LCA 0.0837 ± 0.016 ms 0.079 ± 0.014 ms 1.06
simulate/SequentialSamplingModels.RDM 0.0751 ± 0.023 ms 0.0719 ± 0.023 ms 1.05
simulate/SequentialSamplingModels.Wald 9.28 ± 4.5 μs 9.1 ± 4.5 μs 1.02
simulate/SequentialSamplingModels.WaldMixture 4.03 ± 1.5 μs 4.01 ± 1.4 μs 1
simulate/mdft 0.185 ± 0.072 ms 0.183 ± 0.072 ms 1.01
time_to_load 1.53 ± 0.025 s 1.59 ± 0.046 s 0.963

Benchmark Plots

A plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR.
Go to "Actions"->"Benchmark a pull request"->[the most recent run]->"Artifacts" (at the bottom).

@DominiqueMakowski
Copy link
Contributor

Kind of irrelevant to that PR, but just thought I'd mention that we recently implemented an automated reporting for loo comparisons in R:

library(brms)
library(report)

m1 <- brms::brm(mpg ~ qsec, data = mtcars, refresh=0)
m2 <- brms::brm(mpg ~ qsec + drat, data = mtcars, refresh=0)
m3 <- brms::brm(mpg ~ qsec + drat + wt, data = mtcars, refresh=0)


x <- brms::loo_compare(
  brms::add_criterion(m1, "loo"),
  brms::add_criterion(m2, "loo"),
  brms::add_criterion(m3, "loo"),
  model_names = c("m1", "m2", "m3")
)

report(x)
#> The difference in predictive accuracy, as indexed by Expected Log Predictive
#> Density (ELPD-LOO), suggests that 'm3' is the best model (ELPD = -79.19),
#> followed by 'm2' (diff-ELPD = -13.30 +- 4.42, p = 0.003) and 'm1' (diff-ELPD =
#> -23.01 +- 4.43, p < .001)
report(x, include_IC = FALSE)
#> The difference in predictive accuracy, as indexed by Expected Log Predictive
#> Density (ELPD-LOO), suggests that 'm3' is the best model (ELPD = -79.19),
#> followed by 'm2' (diff-ELPD = -13.30 +- 4.42, p = 0.003) and 'm1' (diff-ELPD =
#> -23.01 +- 4.43, p < .001)
report(x, include_ENP = TRUE)
#> The difference in predictive accuracy, as indexed by Expected Log Predictive
#> Density (ELPD-LOO), suggests that 'm3' is the best model (LOOIC = 158.39, ENP =
#> 5.14), followed by 'm2' (diff-ELPD = -13.30 +- 4.42, p = 0.003, LOOIC = 184.98,
#> ENP = 3.97) and 'm1' (diff-ELPD = -23.01 +- 4.43, p < .001, LOOIC = 204.42, ENP
#> = 2.52)

Created on 2024-07-08 with reprex v2.0.2

The interesting thing we add is a p-value, based on the z-approximation of ELPD diff and ELPD diff SE (but I'm not sure the SE is returned by PSILOO for Julia).

@kiante-fernandez
Copy link
Contributor Author

Oh, that is quite neat! Thanks for sharing. I believe that they are. Also do you have any papers/preprint on adding that p-value?
As an aside, I would love to see a simple package that spits out model comparison metrics, sort of like performance.

@DominiqueMakowski
Copy link
Contributor

No paper but see the details section (https://easystats.github.io/report/reference/report.compare.loo.html#details) basically it comes from a Stan thread where Vehtari was showing how the ELPD diff is normally distributed, and how the ELPD SE can be used to get a standardized z-ELPD-diff. Once you have a z-like value, getting the p-value becomes trivial

I would love to see a simple package that spits out model comparison metric

And I dream of seeing a whole easystats.jl :p one day maybe

@itsdfish
Copy link
Owner

itsdfish commented Jul 8, 2024

@kiante-fernandez, aweome! This looks like it will be a useful addition to the documentation. Thanks for the PR. I will review by the end of the week.

@DominiqueMakowski, that looks very useful. I could see a use for something similar in Julia, perhaps Report.jl, which would work as a general inferface across the statistical packages.

@itsdfish
Copy link
Owner

@kiante-fernandez, thanks for the PR.

Please make sure to run the documentation locally. There were several errors (despite the tests showing the docs were built correctly). One was that Paretosmooth was not added to the Project.toml in the docs folder. There were a few other minor errors. I also removed the for loop in the turing model to make the example simpler. For some reason, my changes did not merge into this PR. So I will add those through a seperate PR.

@itsdfish itsdfish closed this Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants