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

bayestestR broken after revising pd(). #619

Closed
strengejacke opened this issue Jul 31, 2023 · 13 comments
Closed

bayestestR broken after revising pd(). #619

strengejacke opened this issue Jul 31, 2023 · 13 comments
Labels
Bug 🐛 Something isn't working High priority 🏃 This issue should be addressed soon

Comments

@strengejacke
Copy link
Member

strengejacke commented Jul 31, 2023

This PR wasn't ready, and breaks parts of the code, e.g.

library(bayestestR)
x <- distribution_normal(4000)

describe_posterior(
  x,
  centrality = "all",
  dispersion = TRUE,
  test = "all",
  ci = 0.89,
  verbose = FALSE
)
#> Error in fix.by(by.y, y): 'by' must specify a uniquely valid column

Created on 2023-07-31 with reprex v2.0.2

Because those functions expect numerics instead of data frames for pd(), I guess.

Originally posted by @strengejacke in #618 (comment)

@strengejacke strengejacke added Bug 🐛 Something isn't working High priority 🏃 This issue should be addressed soon labels Jul 31, 2023
@DominiqueMakowski
Copy link
Member

@mattansb would adding as.numeric() be sufficient here?

@mattansb
Copy link
Member

mattansb commented Aug 1, 2023

I have no idea how describe posterior does all the merging. I think pd and p-map already have a as.numeric method.

@DominiqueMakowski
Copy link
Member

I'm on it but it's a weird error

@DominiqueMakowski
Copy link
Member

describe_posterior(x, test = "p_map")
Error in fix.by(by.y, y) : 'by' must specify a uniquely valid column
7.
stop(ngettext(sum(bad), "'by' must specify a uniquely valid column",
"'by' must specify uniquely valid columns"), domain = NA)
6.
fix.by(by.y, y)
5.
merge.data.frame(out, test_pmap, by = merge_by, all = TRUE)
4.
merge(out, test_pmap, by = merge_by, all = TRUE) at describe_posterior.R#474
3.
.describe_posterior(posteriors, centrality = centrality, dispersion = dispersion,
ci = ci, ci_method = ci_method, test = test, rope_range = rope_range,
rope_ci = rope_ci, keep_iterations = keep_iterations, bf_prior = bf_prior,
BF = BF, ...) at describe_posterior.R#540
2.
describe_posterior.double(x, verbose = FALSE, test = "p_map") at describe_posterior.R#109
1.
describe_posterior(x, verbose = FALSE, test = "p_map")

it also fails with other tests 🤔 🤔

@DominiqueMakowski
Copy link
Member

DominiqueMakowski commented Aug 1, 2023

image

It happens here, we're trying to merge these dfs by the cols but there is no Parameter columns... is it that last PR that removed it??

(disregard the print())

@strengejacke
Copy link
Member Author

This code is no longer run, because p_map() now always returns a data frame:

if (!is.data.frame(test_pmap)) {
test_pmap <- data.frame(
Parameter = "Posterior",
p_map = test_pmap,
stringsAsFactors = FALSE
)
}

Since the structure of the returned data frame for numeric input in p_map() differs from those in models, it now fails.

@DominiqueMakowski
Copy link
Member

Do you think we should re-add a Parameter argument to the output of p_dir and p_map or fix it at the merging level?

I should have checked the tests more thoroughly 🤕 (and not listen to Mattan's mellow voice softly whispering merge it in my ear)

@strengejacke
Copy link
Member Author

I think the easiest thing would be that the numeric method returns an additional column named Posterior, like what we do in describe_posterior(), i.e. something like

   data.frame( 
     Parameter = "Posterior", 
     p_map = pmap, 
     stringsAsFactors = FALSE 
   ) 

@mattansb
Copy link
Member

mattansb commented Aug 2, 2023

Okay, I can fix that.

mattansb added a commit that referenced this issue Aug 2, 2023
@mattansb
Copy link
Member

mattansb commented Aug 2, 2023

Okay, I've changed the .numeric() method for p_map(), p_direction(), map_estimate() and p_significance(), and describe_posterior() now works:

describe_posterior(x)
#> Warning: Could not estimate a good default ROPE range. Using 'c(-0.1, 0.1)'.Summary of Posterior Distribution
#> 
#> Parameter | Median |        95% CI |     pd |          ROPE | % in ROPE
#> -----------------------------------------------------------------------
#> Posterior |   1.04 | [-0.91, 2.92] | 86.00% | [-0.10, 0.10] |     5.89%

However, this did change the printing method -

Before:

library(bayestestR)

x <- rnorm(1000, 1)
pd(x)
#> Probability of Direction: 86.00%

After:

pd(x)
#> Probability of Direction
#> 
#> Parameter |     pd
#> ------------------
#> Posterior | 86.00%

I don't know if you want to preserve the previous behavior or not...

@strengejacke
Copy link
Member Author

I'd say the print is OK.

@DominiqueMakowski
Copy link
Member

That's okay

@strengejacke
Copy link
Member Author

Can this be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 Something isn't working High priority 🏃 This issue should be addressed soon
Projects
None yet
Development

No branches or pull requests

4 participants