richarddmorey / BayesFactor

BayesFactor R package for Bayesian data analysis with common statistical models.
https://richarddmorey.github.io/BayesFactor/
132 stars 49 forks source link

non-ASCII column names from random-effects only model's posteriors #149

Closed mattansb closed 3 years ago

mattansb commented 3 years ago

This causes issues on non-windows machines, but also makes it difficult to match posterior columns across models (both came up here: https://github.com/easystats/bayestestR/issues/345).

See example below:

library(BayesFactor)

# Setup data frame
df <- data.frame(
  id = factor(rep(1:48, each = 4)),
  b = factor(rep(c("b1","b2"), times = 96, each = 1)),
  y = rnorm(192,5,1) # Nonsensical for the current purposes
)

# Running Bayesian ANOVA

bf <- anovaBF(y ~ b + id,
              whichRandom = "id",
              data = df)   # disregard high numerical error, not recomputing here

out <- BayesFactor::posterior(1 / bf[1], iterations = 10)
colnames(as.data.frame(out))
#>  [1] "mu"   "id5"  "id6"  "id7"  "id8"  "id9"  "id:"  "id;"  "id<"  "id=" 
#> [11] "id5Ð" "id5Ô" "id5Ø" "id5Ü" "id5à" "id5ä" "id5è" "id5ì" "id5ð" "id5ô"
#> [21] "id6Ð" "id6Ô" "id6Ø" "id6Ü" "id6à" "id6ä" "id6è" "id6ì" "id6ð" "id6ô"
#> [31] "id7Ð" "id7Ô" "id7Ø" "id7Ü" "id7à" "id7ä" "id7è" "id7ì" "id7ð" "id7ô"
#> [41] "id8Ð" "id8Ô" "id8Ø" "id8Ü" "id8à" "id8ä" "id8è" "id8ì" "id8ð" "sig2"
#> [51] "g_id"

But random effect column-names are fine from other models:

out <- BayesFactor::posterior(bf[1], iterations = 10)
colnames(as.data.frame(out))
#>  [1] "mu"    "b-b1"  "b-b2"  "id-1"  "id-2"  "id-3"  "id-4"  "id-5"  "id-6" 
#> [10] "id-7"  "id-8"  "id-9"  "id-10" "id-11" "id-12" "id-13" "id-14" "id-15"
#> [19] "id-16" "id-17" "id-18" "id-19" "id-20" "id-21" "id-22" "id-23" "id-24"
#> [28] "id-25" "id-26" "id-27" "id-28" "id-29" "id-30" "id-31" "id-32" "id-33"
#> [37] "id-34" "id-35" "id-36" "id-37" "id-38" "id-39" "id-40" "id-41" "id-42"
#> [46] "id-43" "id-44" "id-45" "id-46" "id-47" "id-48" "sig2"  "g_b"   "g_id"

Created on 2020-10-15 by the reprex package (v0.3.0)

richarddmorey commented 3 years ago

I believe the code to add support for special characters was @jonathon-love's - looping him in here to see if he has any insight.

jonathon-love commented 3 years ago

hmm, let me take a look. as a general rule, any sort of unicode handling in R under windows is a mess.

jonathon-love commented 3 years ago

i'm not sure this is related to my mods ... but i can't quite figure out where this data frame is constructed. could you point me in the right direction rich?

with thanks

richarddmorey commented 3 years ago

i'm not sure this is related to my mods ... but i can't quite figure out where this data frame is constructed. could you point me in the right direction rich?

with thanks

Oh, I was just hoping you might see something obvious. I'll handle it for now and rope you back in if needed. I won't want to make a breaking change to JASP or jamovi, if this affects them.

richarddmorey commented 3 years ago

This was fixed by you before, @jonathon-love, and just hasn't made it to CRAN yet! I fixed the other issue mentioned in the link as well and will push this new version out soon.

IndrajeetPatil commented 3 years ago

@richarddmorey Do you have a timeline in mind as to when you will be pushing this fix to CRAN?

I am relying on the fixed version but can't push my package to CRAN unless BayesFactor's devel version is on CRAN.

I mean I can cheat my way to it by skipping a few tests that rely on this fix, but that will be Plan B.

richarddmorey commented 3 years ago

Unfortunately I'm deep in teaching right now. It is on the backburner and it could be some time in December. Sorry for the delay; I got a bunch of new teaching responsibilities this year.

IndrajeetPatil commented 3 years ago

Okay, no worries. For now, I will use the workaround I mentioned and will have another release once BayesFactor gets updated on CRAN.

mattansb commented 3 years ago

@richarddmorey Any plans for this update to hit CRAN any time soon?

IndrajeetPatil commented 2 years ago

Hi Richard, I was wondering the same thing as Mattan if an update will be heading to the CRAN soon.

Since over a year, we have been pretty much skipping the relevant tests and asking the users to update BayesFactor from GitHub, both of which are unfortunately not ideal. The bugs can get through in the former case, while beginners may just back off because they may not be comfortable in downloading a package from GitHub.

Thanks in advance for considering.

richarddmorey commented 2 years ago

I just pushed the new version to CRAN; assuming no issues, it should be up soon.

mattansb commented 2 years ago

Thanks @richarddmorey !