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

inconsistency between the prior scale information included in output dataframe #222

Closed
IndrajeetPatil opened this issue Sep 9, 2020 · 38 comments
Labels
3 investigators ❔❓ Need to look further into this issue Bug 🐛 Something isn't working Low priority 😴 This issue can be easily workaround or happens only in edge cases

Comments

@IndrajeetPatil
Copy link
Member

@mattansb Thinking of this further, another thing I notice is that Prior_Scale values are NA for anovaBF outputs.

Should we be including rscaleFixed and rscaleRandom argument values here?

library(BayesFactor)
#> Loading required package: coda
#> Loading required package: Matrix
#> ************
#> Welcome to BayesFactor 0.9.12-4.2. If you have questions, please contact Richard Morey (richarddmorey@gmail.com).
#> 
#> Type BFManual() to open the manual.
#> ************
library(parameters)

data(puzzles)

result = anovaBF(RT ~ shape*color + ID, data = puzzles, whichRandom = "ID",
                 whichModels = 'top', progress=FALSE)

as.data.frame(model_parameters(result))$Prior_Scale
#>  [1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
@mattansb

This comment has been minimized.

@IndrajeetPatil

This comment has been minimized.

@IndrajeetPatil

This comment has been minimized.

@mattansb
Copy link
Member

It's hard to match the different parameters to the rscale* values (I've had a little back and forth about this with Richard some time ago). That is why, currently, bayestestR::describe_prior() behaves like this:

describe_prior(result)
#>    Parameter Prior_Distribution Prior_Location Prior_Scale
#> 1      fixed             cauchy              0   0.5000000
#> 2     random             cauchy              0   1.0000000
#> 3 continuous             cauchy              0   0.3535534

(And does not return the dist/loc/scale on a parameter basis...)

It is unfortunate that the docs and internals from BayesFactor are somewhat opaque... 🤷‍♂️

I suggest opening this as a feature request on bayestestR - if it works there, it will work here as well.

@IndrajeetPatil IndrajeetPatil transferred this issue from easystats/parameters Sep 11, 2020
@IndrajeetPatil IndrajeetPatil changed the title inconsistency between the prior scale defaults across BF tests inconsistency between the prior scale information included in output dataframe Sep 11, 2020
@DominiqueMakowski
Copy link
Member

Doesn't describe_priors rely itself on insight::get_priors 😁

I'm not sure I understand what is the issue?

@IndrajeetPatil
Copy link
Member Author

The issue is that Prior_Scale column from model_parameters for anovaBF contains NAs, while it is not NA for the other BF tests.

For example, one-sample t-test

    library(BayesFactor)
    library(parameters)

    model <- ttestBF(x = rnorm(100, 1, 1))
    as.data.frame(model_parameters(model))
    #>    Parameter    Median    CI_low  CI_high pd ROPE_Percentage Prior_Distribution
    #> 1 Difference 0.8943024 0.7003134 1.105907  1               0             cauchy
    #>   Prior_Location Prior_Scale Effects   Component           BF
    #> 1              0   0.7071068   fixed conditional 7.536535e+15

@strengejacke

This comment has been minimized.

@strengejacke

This comment has been minimized.

@IndrajeetPatil
Copy link
Member Author

IndrajeetPatil commented Sep 12, 2020

Ah, thanks for the details. I guess then the issue is if the info about prior scale present in bayestestR::describe_posterior can also be included in parameters::model_parameters for anovaBF outputs.

@mattansb
Copy link
Member

mattansb commented Sep 12, 2020 via email

@DominiqueMakowski
Copy link
Member

If I understand, in order to fix it and to have prior information displayed alongside each parameter, we would in theory need to retrieve which parameters are "continuous" "fixed" and "random" and combine accordingly with the parameters table is that correct?

@strengejacke
Copy link
Member

Yes, that's how I understood this as well.

@DominiqueMakowski
Copy link
Member

I feel like it would make sense to retrieve this kind of info at insight's level no?

@IndrajeetPatil

This comment has been minimized.

@DominiqueMakowski

This comment has been minimized.

@IndrajeetPatil IndrajeetPatil transferred this issue from easystats/bayestestR Sep 15, 2020
@strengejacke
Copy link
Member

Now we need someone who knows whether a parameter is fixed, random or continuous.

@strengejacke strengejacke added 3 investigators ❔❓ Need to look further into this issue Bug 🐛 Something isn't working labels Sep 15, 2020
@mattansb
Copy link
Member

This won't work for the cases detailed in #223 ...

get_type <- function(trm) {
  if (grepl(":", trm, fixed = TRUE)) {
    trm <- unlist(strsplit(trm, ":", fixed = TRUE))
  }
  
  if (any(trm %in% dataTypes[["random"]])) {
    "random"
  } else if (any(trm %in% dataTypes[["continuous"]])) {
    "continuous"
  } else if (any(trm %in% dataTypes[["fixed"]])) {
    "fixed"
  } else {
    ""
  }
}


library(BayesFactor)
#> Loading required package: coda
#> Loading required package: Matrix
#> ************
#> Welcome to BayesFactor 0.9.12-4.2. If you have questions, please contact Richard Morey (richarddmorey@gmail.com).
#> 
#> Type BFManual() to open the manual.
#> ************

iris$ID <- factor(rep(1:30, each = 5))
res <- lmBF(Sepal.Length ~ Species * Sepal.Width + Petal.Width + ID + Sepal.Width:ID, data = iris,
            whichRandom = c("ID","Sepal.Width:ID"),
            progress = FALSE)
#> Warning in doNwaySampling(method, y, X, rscale, iterations, gMap, incCont, :
#> Some NAs were removed from sampling results: 10000 in total.

pars <- insight::get_parameters(res)

if (insight::model_info(res)$is_linear) {
  dataTypes <- res@numerator[[1]]@dataTypes
  dataTypes <- tapply(names(dataTypes), dataTypes, "[", simplify = FALSE)
  
  par_names_clean <- sub("\\-(.*)", "", colnames(pars))
  # par_names_clean <- par_names_clean[-(which(par_names_clean=="sig2"):length(par_names_clean))]
  
  par_types <- sapply(par_names_clean, get_type)
}



par_types <- setNames(names(par_types),par_types)

priors <- insight::get_priors(res)
idx <- sapply(names(par_types), function(x) {
  if (!any(i <- x==priors$Parameter)) return(NA)
  which(i)
})


priors <- priors[idx,]
priors$Parameter <- colnames(pars)

priors
#>                                         Parameter Distribution Location
#> NA                                             mu         <NA>       NA
#> 1                                  Species-setosa       cauchy        0
#> 1.1                            Species-versicolor       cauchy        0
#> 1.2                             Species-virginica       cauchy        0
#> 3                         Sepal.Width-Sepal.Width       cauchy        0
#> 3.1                       Petal.Width-Petal.Width       cauchy        0
#> 2                                            ID-1       cauchy        0
#> 2.1                                          ID-2       cauchy        0
#> 2.2                                          ID-3       cauchy        0
#> 2.3                                          ID-4       cauchy        0
#> 2.4                                          ID-5       cauchy        0
#> 2.5                                          ID-6       cauchy        0
#> 2.6                                          ID-7       cauchy        0
#> 2.7                                          ID-8       cauchy        0
#> 2.8                                          ID-9       cauchy        0
#> 2.9                                         ID-10       cauchy        0
#> 2.10                                        ID-11       cauchy        0
#> 2.11                                        ID-12       cauchy        0
#> 2.12                                        ID-13       cauchy        0
#> 2.13                                        ID-14       cauchy        0
#> 2.14                                        ID-15       cauchy        0
#> 2.15                                        ID-16       cauchy        0
#> 2.16                                        ID-17       cauchy        0
#> 2.17                                        ID-18       cauchy        0
#> 2.18                                        ID-19       cauchy        0
#> 2.19                                        ID-20       cauchy        0
#> 2.20                                        ID-21       cauchy        0
#> 2.21                                        ID-22       cauchy        0
#> 2.22                                        ID-23       cauchy        0
#> 2.23                                        ID-24       cauchy        0
#> 2.24                                        ID-25       cauchy        0
#> 2.25                                        ID-26       cauchy        0
#> 2.26                                        ID-27       cauchy        0
#> 2.27                                        ID-28       cauchy        0
#> 2.28                                        ID-29       cauchy        0
#> 2.29                                        ID-30       cauchy        0
#> 3.2      Species:Sepal.Width-setosa.&.Sepal.Width       cauchy        0
#> 3.3  Species:Sepal.Width-versicolor.&.Sepal.Width       cauchy        0
#> 3.4   Species:Sepal.Width-virginica.&.Sepal.Width       cauchy        0
#> 2.30                             Sepal.Width:ID-1       cauchy        0
#> 2.31                             Sepal.Width:ID-2       cauchy        0
#> 2.32                             Sepal.Width:ID-3       cauchy        0
#> 2.33                             Sepal.Width:ID-4       cauchy        0
#> 2.34                             Sepal.Width:ID-5       cauchy        0
#> 2.35                             Sepal.Width:ID-6       cauchy        0
#> 2.36                             Sepal.Width:ID-7       cauchy        0
#> 2.37                             Sepal.Width:ID-8       cauchy        0
#> 2.38                             Sepal.Width:ID-9       cauchy        0
#> 2.39                            Sepal.Width:ID-10       cauchy        0
#> 2.40                            Sepal.Width:ID-11       cauchy        0
#> 2.41                            Sepal.Width:ID-12       cauchy        0
#> 2.42                            Sepal.Width:ID-13       cauchy        0
#> 2.43                            Sepal.Width:ID-14       cauchy        0
#> 2.44                            Sepal.Width:ID-15       cauchy        0
#> 2.45                            Sepal.Width:ID-16       cauchy        0
#> 2.46                            Sepal.Width:ID-17       cauchy        0
#> 2.47                            Sepal.Width:ID-18       cauchy        0
#> 2.48                            Sepal.Width:ID-19       cauchy        0
#> 2.49                            Sepal.Width:ID-20       cauchy        0
#> 2.50                            Sepal.Width:ID-21       cauchy        0
#> 2.51                            Sepal.Width:ID-22       cauchy        0
#> 2.52                            Sepal.Width:ID-23       cauchy        0
#> 2.53                            Sepal.Width:ID-24       cauchy        0
#> 2.54                            Sepal.Width:ID-25       cauchy        0
#> 2.55                            Sepal.Width:ID-26       cauchy        0
#> 2.56                            Sepal.Width:ID-27       cauchy        0
#> 2.57                            Sepal.Width:ID-28       cauchy        0
#> 2.58                            Sepal.Width:ID-29       cauchy        0
#> 2.59                            Sepal.Width:ID-30       cauchy        0
#> NA.1                                         sig2         <NA>       NA
#> NA.2                                    g_Species         <NA>       NA
#> NA.3                                         g_ID         <NA>       NA
#> NA.4                                 g_continuous         <NA>       NA
#>          Scale
#> NA          NA
#> 1    0.5000000
#> 1.1  0.5000000
#> 1.2  0.5000000
#> 3    0.3535534
#> 3.1  0.3535534
#> 2    1.0000000
#> 2.1  1.0000000
#> 2.2  1.0000000
#> 2.3  1.0000000
#> 2.4  1.0000000
#> 2.5  1.0000000
#> 2.6  1.0000000
#> 2.7  1.0000000
#> 2.8  1.0000000
#> 2.9  1.0000000
#> 2.10 1.0000000
#> 2.11 1.0000000
#> 2.12 1.0000000
#> 2.13 1.0000000
#> 2.14 1.0000000
#> 2.15 1.0000000
#> 2.16 1.0000000
#> 2.17 1.0000000
#> 2.18 1.0000000
#> 2.19 1.0000000
#> 2.20 1.0000000
#> 2.21 1.0000000
#> 2.22 1.0000000
#> 2.23 1.0000000
#> 2.24 1.0000000
#> 2.25 1.0000000
#> 2.26 1.0000000
#> 2.27 1.0000000
#> 2.28 1.0000000
#> 2.29 1.0000000
#> 3.2  0.3535534
#> 3.3  0.3535534
#> 3.4  0.3535534
#> 2.30 1.0000000
#> 2.31 1.0000000
#> 2.32 1.0000000
#> 2.33 1.0000000
#> 2.34 1.0000000
#> 2.35 1.0000000
#> 2.36 1.0000000
#> 2.37 1.0000000
#> 2.38 1.0000000
#> 2.39 1.0000000
#> 2.40 1.0000000
#> 2.41 1.0000000
#> 2.42 1.0000000
#> 2.43 1.0000000
#> 2.44 1.0000000
#> 2.45 1.0000000
#> 2.46 1.0000000
#> 2.47 1.0000000
#> 2.48 1.0000000
#> 2.49 1.0000000
#> 2.50 1.0000000
#> 2.51 1.0000000
#> 2.52 1.0000000
#> 2.53 1.0000000
#> 2.54 1.0000000
#> 2.55 1.0000000
#> 2.56 1.0000000
#> 2.57 1.0000000
#> 2.58 1.0000000
#> 2.59 1.0000000
#> NA.1        NA
#> NA.2        NA
#> NA.3        NA
#> NA.4        NA

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

@strengejacke
Copy link
Member

We should first fix clean_parameters() for such models. This is usually the base for matching parameters:

library(insight)
library(BayesFactor)
#> Loading required package: coda
#> Loading required package: Matrix
#> ************
#> Welcome to BayesFactor 0.9.12-4.2. If you have questions, please contact Richard Morey (richarddmorey@gmail.com).
#> 
#> Type BFManual() to open the manual.
#> ************
iris$ID <- factor(rep(1:30, each = 5))
m1 <- lmBF(Sepal.Length ~ Species * Sepal.Width + Petal.Width + ID + Sepal.Width:ID, data = iris,
            rscaleCont = c(Sepal.Width = 0.123, Petal.Width = 0.321),
            whichRandom = c("ID","Sepal.Width:ID"))
#> Warning in rscale[rscaleTypes == "continuous"] <- rscaleCont: number of items to
#> replace is not a multiple of replacement length
#> Warning in doNwaySampling(method, y, X, rscale, iterations, gMap, incCont, :
#> Some NAs were removed from sampling results: 10000 in total.
clean_parameters(m1)
#> Warning in rscale[rscaleTypes == "continuous"] <- rscaleCont: number of items to
#> replace is not a multiple of replacement length
#>                                        Parameter Effects   Component
#> 1                                 Species-setosa   fixed conditional
#> 2                             Species-versicolor   fixed conditional
#> 3                              Species-virginica   fixed conditional
#> 4                                    Sepal.Width   fixed conditional
#> 5                                    Petal.Width   fixed conditional
#> 6                                           ID-1   fixed conditional
#> 7                                           ID-2   fixed conditional
#> 8                                           ID-3   fixed conditional
#> 9                                           ID-4   fixed conditional
#> 10                                          ID-5   fixed conditional
#> 11                                          ID-6   fixed conditional
#> 12                                          ID-7   fixed conditional
#> 13                                          ID-8   fixed conditional
#> 14                                          ID-9   fixed conditional
#> 15                                         ID-10   fixed conditional
#> 16                                         ID-11   fixed conditional
#> 17                                         ID-12   fixed conditional
#> 18                                         ID-13   fixed conditional
#> 19                                         ID-14   fixed conditional
#> 20                                         ID-15   fixed conditional
#> 21                                         ID-16   fixed conditional
#> 22                                         ID-17   fixed conditional
#> 23                                         ID-18   fixed conditional
#> 24                                         ID-19   fixed conditional
#> 25                                         ID-20   fixed conditional
#> 26                                         ID-21   fixed conditional
#> 27                                         ID-22   fixed conditional
#> 28                                         ID-23   fixed conditional
#> 29                                         ID-24   fixed conditional
#> 30                                         ID-25   fixed conditional
#> 31                                         ID-26   fixed conditional
#> 32                                         ID-27   fixed conditional
#> 33                                         ID-28   fixed conditional
#> 34                                         ID-29   fixed conditional
#> 35                                         ID-30   fixed conditional
#> 36      Species:Sepal.Width-setosa.&.Sepal.Width   fixed conditional
#> 37  Species:Sepal.Width-versicolor.&.Sepal.Width   fixed conditional
#> 38   Species:Sepal.Width-virginica.&.Sepal.Width   fixed conditional
#> 39                              Sepal.Width:ID-1   fixed conditional
#> 40                              Sepal.Width:ID-2   fixed conditional
#> 41                              Sepal.Width:ID-3   fixed conditional
#> 42                              Sepal.Width:ID-4   fixed conditional
#> 43                              Sepal.Width:ID-5   fixed conditional
#> 44                              Sepal.Width:ID-6   fixed conditional
#> 45                              Sepal.Width:ID-7   fixed conditional
#> 46                              Sepal.Width:ID-8   fixed conditional
#> 47                              Sepal.Width:ID-9   fixed conditional
#> 48                             Sepal.Width:ID-10   fixed conditional
#> 49                             Sepal.Width:ID-11   fixed conditional
#> 50                             Sepal.Width:ID-12   fixed conditional
#> 51                             Sepal.Width:ID-13   fixed conditional
#> 52                             Sepal.Width:ID-14   fixed conditional
#> 53                             Sepal.Width:ID-15   fixed conditional
#> 54                             Sepal.Width:ID-16   fixed conditional
#> 55                             Sepal.Width:ID-17   fixed conditional
#> 56                             Sepal.Width:ID-18   fixed conditional
#> 57                             Sepal.Width:ID-19   fixed conditional
#> 58                             Sepal.Width:ID-20   fixed conditional
#> 59                             Sepal.Width:ID-21   fixed conditional
#> 60                             Sepal.Width:ID-22   fixed conditional
#> 61                             Sepal.Width:ID-23   fixed conditional
#> 62                             Sepal.Width:ID-24   fixed conditional
#> 63                             Sepal.Width:ID-25   fixed conditional
#> 64                             Sepal.Width:ID-26   fixed conditional
#> 65                             Sepal.Width:ID-27   fixed conditional
#> 66                             Sepal.Width:ID-28   fixed conditional
#> 67                             Sepal.Width:ID-29   fixed conditional
#> 68                             Sepal.Width:ID-30   fixed conditional
#> 69                                          ID-1  random conditional
#> 70                                          ID-2  random conditional
#> 71                                          ID-3  random conditional
#> 72                                          ID-4  random conditional
#> 73                                          ID-5  random conditional
#> 74                                          ID-6  random conditional
#> 75                                          ID-7  random conditional
#> 76                                          ID-8  random conditional
#> 77                                          ID-9  random conditional
#> 78                                         ID-10  random conditional
#> 79                                         ID-11  random conditional
#> 80                                         ID-12  random conditional
#> 81                                         ID-13  random conditional
#> 82                                         ID-14  random conditional
#> 83                                         ID-15  random conditional
#> 84                                         ID-16  random conditional
#> 85                                         ID-17  random conditional
#> 86                                         ID-18  random conditional
#> 87                                         ID-19  random conditional
#> 88                                         ID-20  random conditional
#> 89                                         ID-21  random conditional
#> 90                                         ID-22  random conditional
#> 91                                         ID-23  random conditional
#> 92                                         ID-24  random conditional
#> 93                                         ID-25  random conditional
#> 94                                         ID-26  random conditional
#> 95                                         ID-27  random conditional
#> 96                                         ID-28  random conditional
#> 97                                         ID-29  random conditional
#> 98                                         ID-30  random conditional
#> 99                                            mu   fixed       extra
#> 100                      Sepal.Width-Sepal.Width   fixed       extra
#> 101                      Petal.Width-Petal.Width   fixed       extra
#> 102                                         sig2   fixed       extra
#> 103                                    g_Species   fixed       extra
#> 104                                         g_ID   fixed       extra
#> 105                                 g_continuous   fixed       extra
#>                                Cleaned_Parameter
#> 1                                 Species-setosa
#> 2                             Species-versicolor
#> 3                              Species-virginica
#> 4                                    Sepal.Width
#> 5                                    Petal.Width
#> 6                                           ID-1
#> 7                                           ID-2
#> 8                                           ID-3
#> 9                                           ID-4
#> 10                                          ID-5
#> 11                                          ID-6
#> 12                                          ID-7
#> 13                                          ID-8
#> 14                                          ID-9
#> 15                                         ID-10
#> 16                                         ID-11
#> 17                                         ID-12
#> 18                                         ID-13
#> 19                                         ID-14
#> 20                                         ID-15
#> 21                                         ID-16
#> 22                                         ID-17
#> 23                                         ID-18
#> 24                                         ID-19
#> 25                                         ID-20
#> 26                                         ID-21
#> 27                                         ID-22
#> 28                                         ID-23
#> 29                                         ID-24
#> 30                                         ID-25
#> 31                                         ID-26
#> 32                                         ID-27
#> 33                                         ID-28
#> 34                                         ID-29
#> 35                                         ID-30
#> 36      Species:Sepal.Width-setosa.&.Sepal.Width
#> 37  Species:Sepal.Width-versicolor.&.Sepal.Width
#> 38   Species:Sepal.Width-virginica.&.Sepal.Width
#> 39                              Sepal.Width:ID-1
#> 40                              Sepal.Width:ID-2
#> 41                              Sepal.Width:ID-3
#> 42                              Sepal.Width:ID-4
#> 43                              Sepal.Width:ID-5
#> 44                              Sepal.Width:ID-6
#> 45                              Sepal.Width:ID-7
#> 46                              Sepal.Width:ID-8
#> 47                              Sepal.Width:ID-9
#> 48                             Sepal.Width:ID-10
#> 49                             Sepal.Width:ID-11
#> 50                             Sepal.Width:ID-12
#> 51                             Sepal.Width:ID-13
#> 52                             Sepal.Width:ID-14
#> 53                             Sepal.Width:ID-15
#> 54                             Sepal.Width:ID-16
#> 55                             Sepal.Width:ID-17
#> 56                             Sepal.Width:ID-18
#> 57                             Sepal.Width:ID-19
#> 58                             Sepal.Width:ID-20
#> 59                             Sepal.Width:ID-21
#> 60                             Sepal.Width:ID-22
#> 61                             Sepal.Width:ID-23
#> 62                             Sepal.Width:ID-24
#> 63                             Sepal.Width:ID-25
#> 64                             Sepal.Width:ID-26
#> 65                             Sepal.Width:ID-27
#> 66                             Sepal.Width:ID-28
#> 67                             Sepal.Width:ID-29
#> 68                             Sepal.Width:ID-30
#> 69                                          ID-1
#> 70                                          ID-2
#> 71                                          ID-3
#> 72                                          ID-4
#> 73                                          ID-5
#> 74                                          ID-6
#> 75                                          ID-7
#> 76                                          ID-8
#> 77                                          ID-9
#> 78                                         ID-10
#> 79                                         ID-11
#> 80                                         ID-12
#> 81                                         ID-13
#> 82                                         ID-14
#> 83                                         ID-15
#> 84                                         ID-16
#> 85                                         ID-17
#> 86                                         ID-18
#> 87                                         ID-19
#> 88                                         ID-20
#> 89                                         ID-21
#> 90                                         ID-22
#> 91                                         ID-23
#> 92                                         ID-24
#> 93                                         ID-25
#> 94                                         ID-26
#> 95                                         ID-27
#> 96                                         ID-28
#> 97                                         ID-29
#> 98                                         ID-30
#> 99                                            mu
#> 100                      Sepal.Width-Sepal.Width
#> 101                      Petal.Width-Petal.Width
#> 102                                         sig2
#> 103                                    g_Species
#> 104                                         g_ID
#> 105                                 g_continuous

Created on 2020-09-17 by the reprex package (v0.3.0)

@strengejacke
Copy link
Member

The issue in the above examples is:

#> Warning in rscale[rscaleTypes == "continuous"] <- rscaleCont: number of items to
#> replace is not a multiple of replacement length

@IndrajeetPatil

This comment has been minimized.

@strengejacke

This comment has been minimized.

@IndrajeetPatil

This comment has been minimized.

@strengejacke

This comment has been minimized.

@IndrajeetPatil

This comment has been minimized.

@IndrajeetPatil

This comment has been minimized.

@strengejacke

This comment has been minimized.

@IndrajeetPatil

This comment has been minimized.

@strengejacke

This comment has been minimized.

@IndrajeetPatil

This comment has been minimized.

@mattansb

This comment has been minimized.

@strengejacke strengejacke added the Low priority 😴 This issue can be easily workaround or happens only in edge cases label Nov 14, 2020
@strengejacke

This comment has been minimized.

@IndrajeetPatil

This comment has been minimized.

@strengejacke

This comment has been minimized.

@IndrajeetPatil
Copy link
Member Author

Any possibility we can get this fixed before the next release cycle?

@strengejacke
Copy link
Member

I can't even remember the exact issue we had here... ^^

@mattansb
Copy link
Member

mattansb commented Jan 3, 2021

The issue was to match a prior to each parameter 🧶

@strengejacke
Copy link
Member

library(parameters)
library(BayesFactor)
iris$ID <- factor(rep(1:30, each = 5))
m1 <- lmBF(Sepal.Length ~ Species * Sepal.Width + Petal.Width + ID + Sepal.Width:ID, data = iris,
           rscaleCont = c(Sepal.Width = 0.123, Petal.Width = 0.321),
           whichRandom = c("ID","Sepal.Width:ID"))

model_parameters(m1)
#> # Extra Parameters
#> 
#> Parameter               |     pd |              Prior
#> -----------------------------------------------------
#> mu                      | 98.95% |                   
#> Sepal.Width-Sepal.Width | 99.12% | Cauchy (0 +- 0.12)
#> Petal.Width-Petal.Width | 99.08% | Cauchy (0 +- 0.32)
#> sig2                    |   100% |                   
#> g_Species               |   100% |                   
#> g_ID                    |   100% |                   
#> g_continuous            |   100% |                   
#> 
#> # Fixed Effects
#> 
#> Parameter                                    |     pd |              Prior
#> --------------------------------------------------------------------------
#> Species-setosa                               | 98.90% | Cauchy (0 +- 0.50)
#> Species-versicolor                           | 98.98% | Cauchy (0 +- 0.50)
#> Species-virginica                            | 98.98% | Cauchy (0 +- 0.50)
#> ID-1                                         | 99.00% | Cauchy (0 +- 1.00)
#> ID-1                                         | 99.00% | Cauchy (0 +- 1.00)
#> ID-2                                         | 98.90% | Cauchy (0 +- 1.00)
#> ID-2                                         | 98.90% | Cauchy (0 +- 1.00)
#> ID-3                                         | 98.98% | Cauchy (0 +- 1.00)
#> ID-3                                         | 98.98% | Cauchy (0 +- 1.00)
#> ID-4                                         | 98.98% | Cauchy (0 +- 1.00)
#> ID-4                                         | 98.98% | Cauchy (0 +- 1.00)
#> ID-5                                         | 98.92% | Cauchy (0 +- 1.00)
#> ID-5                                         | 98.92% | Cauchy (0 +- 1.00)
#> ID-6                                         | 99.08% | Cauchy (0 +- 1.00)
#> ID-6                                         | 99.08% | Cauchy (0 +- 1.00)
#> ID-7                                         | 98.98% | Cauchy (0 +- 1.00)
#> ID-7                                         | 98.98% | Cauchy (0 +- 1.00)
#> ID-8                                         | 98.98% | Cauchy (0 +- 1.00)
#> ID-8                                         | 98.98% | Cauchy (0 +- 1.00)
#> ID-9                                         | 98.95% | Cauchy (0 +- 1.00)
#> ID-9                                         | 98.95% | Cauchy (0 +- 1.00)
#> ID-10                                        | 98.98% | Cauchy (0 +- 1.00)
#> ID-10                                        | 98.98% | Cauchy (0 +- 1.00)
#> ID-11                                        | 98.98% | Cauchy (0 +- 1.00)
#> ID-11                                        | 98.98% | Cauchy (0 +- 1.00)
#> ID-12                                        | 98.90% | Cauchy (0 +- 1.00)
#> ID-12                                        | 98.90% | Cauchy (0 +- 1.00)
#> ID-13                                        | 99.08% | Cauchy (0 +- 1.00)
#> ID-13                                        | 99.08% | Cauchy (0 +- 1.00)
#> ID-14                                        | 99.10% | Cauchy (0 +- 1.00)
#> ID-14                                        | 99.10% | Cauchy (0 +- 1.00)
#> ID-15                                        | 99.02% | Cauchy (0 +- 1.00)
#> ID-15                                        | 99.02% | Cauchy (0 +- 1.00)
#> ID-16                                        | 99.02% | Cauchy (0 +- 1.00)
#> ID-16                                        | 99.02% | Cauchy (0 +- 1.00)
#> ID-17                                        | 99.00% | Cauchy (0 +- 1.00)
#> ID-17                                        | 99.00% | Cauchy (0 +- 1.00)
#> ID-18                                        | 99.17% | Cauchy (0 +- 1.00)
#> ID-18                                        | 99.17% | Cauchy (0 +- 1.00)
#> ID-19                                        | 99.02% | Cauchy (0 +- 1.00)
#> ID-19                                        | 99.02% | Cauchy (0 +- 1.00)
#> ID-20                                        | 98.90% | Cauchy (0 +- 1.00)
#> ID-20                                        | 98.90% | Cauchy (0 +- 1.00)
#> ID-21                                        | 98.90% | Cauchy (0 +- 1.00)
#> ID-21                                        | 98.90% | Cauchy (0 +- 1.00)
#> ID-22                                        | 99.02% | Cauchy (0 +- 1.00)
#> ID-22                                        | 99.02% | Cauchy (0 +- 1.00)
#> ID-23                                        | 99.02% | Cauchy (0 +- 1.00)
#> ID-23                                        | 99.02% | Cauchy (0 +- 1.00)
#> ID-24                                        | 98.95% | Cauchy (0 +- 1.00)
#> ID-24                                        | 98.95% | Cauchy (0 +- 1.00)
#> ID-25                                        | 99.00% | Cauchy (0 +- 1.00)
#> ID-25                                        | 99.00% | Cauchy (0 +- 1.00)
#> ID-26                                        | 99.12% | Cauchy (0 +- 1.00)
#> ID-26                                        | 99.12% | Cauchy (0 +- 1.00)
#> ID-27                                        | 98.95% | Cauchy (0 +- 1.00)
#> ID-27                                        | 98.95% | Cauchy (0 +- 1.00)
#> ID-28                                        | 98.92% | Cauchy (0 +- 1.00)
#> ID-28                                        | 98.92% | Cauchy (0 +- 1.00)
#> ID-29                                        | 98.95% | Cauchy (0 +- 1.00)
#> ID-29                                        | 98.95% | Cauchy (0 +- 1.00)
#> ID-30                                        | 99.02% | Cauchy (0 +- 1.00)
#> ID-30                                        | 99.02% | Cauchy (0 +- 1.00)
#> Species:Sepal.Width-setosa.&.Sepal.Width     | 98.95% | Cauchy (0 +- 0.12)
#> Species:Sepal.Width-versicolor.&.Sepal.Width | 98.92% | Cauchy (0 +- 0.12)
#> Species:Sepal.Width-virginica.&.Sepal.Width  | 99.05% | Cauchy (0 +- 0.12)
#> Sepal.Width:ID-1                             | 99.08% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-2                             | 98.92% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-3                             | 98.92% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-4                             | 99.10% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-5                             | 98.90% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-6                             | 99.10% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-7                             | 98.98% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-8                             | 99.05% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-9                             | 99.08% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-10                            | 98.92% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-11                            | 98.92% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-12                            | 99.05% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-13                            | 98.98% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-14                            | 98.92% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-15                            | 99.17% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-16                            | 98.98% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-17                            | 99.10% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-18                            | 99.17% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-19                            | 98.98% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-20                            | 99.00% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-21                            | 99.00% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-22                            | 98.98% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-23                            | 98.98% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-24                            | 99.20% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-25                            | 99.17% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-26                            | 98.95% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-27                            | 98.95% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-28                            | 98.92% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-29                            | 98.98% | Cauchy (0 +- 1.00)
#> Sepal.Width:ID-30                            | 99.10% | Cauchy (0 +- 1.00)
#> Petal.Width                                  |        | Cauchy (0 +- 0.32)
#> Sepal.Width                                  |        | Cauchy (0 +- 0.12)
#> 
#> # Random Effects
#> 
#> Parameter |     pd |           Prior
#> ------------------------------------
#> ID-1      | 99.00% | Cauchy (0 +- 1)
#> ID-1      | 99.00% | Cauchy (0 +- 1)
#> ID-2      | 98.90% | Cauchy (0 +- 1)
#> ID-2      | 98.90% | Cauchy (0 +- 1)
#> ID-3      | 98.98% | Cauchy (0 +- 1)
#> ID-3      | 98.98% | Cauchy (0 +- 1)
#> ID-4      | 98.98% | Cauchy (0 +- 1)
#> ID-4      | 98.98% | Cauchy (0 +- 1)
#> ID-5      | 98.92% | Cauchy (0 +- 1)
#> ID-5      | 98.92% | Cauchy (0 +- 1)
#> ID-6      | 99.08% | Cauchy (0 +- 1)
#> ID-6      | 99.08% | Cauchy (0 +- 1)
#> ID-7      | 98.98% | Cauchy (0 +- 1)
#> ID-7      | 98.98% | Cauchy (0 +- 1)
#> ID-8      | 98.98% | Cauchy (0 +- 1)
#> ID-8      | 98.98% | Cauchy (0 +- 1)
#> ID-9      | 98.95% | Cauchy (0 +- 1)
#> ID-9      | 98.95% | Cauchy (0 +- 1)
#> ID-10     | 98.98% | Cauchy (0 +- 1)
#> ID-10     | 98.98% | Cauchy (0 +- 1)
#> ID-11     | 98.98% | Cauchy (0 +- 1)
#> ID-11     | 98.98% | Cauchy (0 +- 1)
#> ID-12     | 98.90% | Cauchy (0 +- 1)
#> ID-12     | 98.90% | Cauchy (0 +- 1)
#> ID-13     | 99.08% | Cauchy (0 +- 1)
#> ID-13     | 99.08% | Cauchy (0 +- 1)
#> ID-14     | 99.10% | Cauchy (0 +- 1)
#> ID-14     | 99.10% | Cauchy (0 +- 1)
#> ID-15     | 99.02% | Cauchy (0 +- 1)
#> ID-15     | 99.02% | Cauchy (0 +- 1)
#> ID-16     | 99.02% | Cauchy (0 +- 1)
#> ID-16     | 99.02% | Cauchy (0 +- 1)
#> ID-17     | 99.00% | Cauchy (0 +- 1)
#> ID-17     | 99.00% | Cauchy (0 +- 1)
#> ID-18     | 99.17% | Cauchy (0 +- 1)
#> ID-18     | 99.17% | Cauchy (0 +- 1)
#> ID-19     | 99.02% | Cauchy (0 +- 1)
#> ID-19     | 99.02% | Cauchy (0 +- 1)
#> ID-20     | 98.90% | Cauchy (0 +- 1)
#> ID-20     | 98.90% | Cauchy (0 +- 1)
#> ID-21     | 98.90% | Cauchy (0 +- 1)
#> ID-21     | 98.90% | Cauchy (0 +- 1)
#> ID-22     | 99.02% | Cauchy (0 +- 1)
#> ID-22     | 99.02% | Cauchy (0 +- 1)
#> ID-23     | 99.02% | Cauchy (0 +- 1)
#> ID-23     | 99.02% | Cauchy (0 +- 1)
#> ID-24     | 98.95% | Cauchy (0 +- 1)
#> ID-24     | 98.95% | Cauchy (0 +- 1)
#> ID-25     | 99.00% | Cauchy (0 +- 1)
#> ID-25     | 99.00% | Cauchy (0 +- 1)
#> ID-26     | 99.12% | Cauchy (0 +- 1)
#> ID-26     | 99.12% | Cauchy (0 +- 1)
#> ID-27     | 98.95% | Cauchy (0 +- 1)
#> ID-27     | 98.95% | Cauchy (0 +- 1)
#> ID-28     | 98.92% | Cauchy (0 +- 1)
#> ID-28     | 98.92% | Cauchy (0 +- 1)
#> ID-29     | 98.95% | Cauchy (0 +- 1)
#> ID-29     | 98.95% | Cauchy (0 +- 1)
#> ID-30     | 99.02% | Cauchy (0 +- 1)
#> ID-30     | 99.02% | Cauchy (0 +- 1)



data(puzzles)

result = anovaBF(RT ~ shape*color + ID, data = puzzles, whichRandom = "ID",
                 whichModels = 'top', progress=FALSE)

model_parameters(result)
#> Multiple `BFBayesFactor` models detected - posteriors are extracted from the first numerator model.
#> See help("get_parameters", package = "insight").
#> Multiple `BFBayesFactor` models detected - posteriors are extracted from the first numerator model.
#> See help("get_parameters", package = "insight").
#> # Extra Parameters
#> 
#> Parameter | Median |         89% CI |   pd | % in ROPE |    BF
#> --------------------------------------------------------------
#> mu        |  45.00 | [43.91, 46.10] | 100% |        0% |  2.75
#> sig2      |   1.76 | [ 1.12,  2.45] | 100% |        0% | 0.265
#> g_shape   |   0.35 | [ 0.01,  2.23] | 100% |    44.73% |  2.75
#> g_color   |   0.36 | [ 0.02,  2.32] | 100% |    43.67% | 0.253
#> g_ID      |   2.64 | [ 0.76,  5.23] | 100% |        0% | 0.265
#> 
#> # Fixed Effects
#> 
#> Parameter             | Median |         89% CI |     pd | % in ROPE |              Prior |    BF
#> -------------------------------------------------------------------------------------------------
#> shape [round]         |   0.43 | [ 0.14,  0.74] | 99.00% |    12.69% | Cauchy (0 +- 0.50) | 0.253
#> shape [square]        |  -0.43 | [-0.74, -0.14] | 99.00% |    12.69% | Cauchy (0 +- 0.50) | 0.265
#> color                 |  -0.43 | [-0.73, -0.14] | 98.92% |    12.66% | Cauchy (0 +- 0.50) |  2.75
#> color [monochromatic] |   0.43 | [ 0.14,  0.73] | 98.92% |    12.66% | Cauchy (0 +- 0.50) | 0.253
#> 
#> # Random Effects
#> 
#> Parameter | Median |         89% CI |     pd | % in ROPE |           Prior |    BF
#> ----------------------------------------------------------------------------------
#> ID [1]    |   2.48 | [ 1.11,  3.96] | 99.62% |        0% | Cauchy (0 +- 1) | 0.265
#> ID [2]    |   0.48 | [-0.87,  1.99] | 70.33% |    21.68% | Cauchy (0 +- 1) |  2.75
#> ID [3]    |   0.92 | [-0.42,  2.43] | 85.50% |    15.45% | Cauchy (0 +- 1) | 0.253
#> ID [4]    |   0.46 | [-0.94,  1.95] | 70.03% |    22.04% | Cauchy (0 +- 1) | 0.265
#> ID [5]    |   3.19 | [ 1.75,  4.64] | 99.98% |        0% | Cauchy (0 +- 1) |  2.75
#> ID [6]    |   0.47 | [-0.93,  1.86] | 69.88% |    22.52% | Cauchy (0 +- 1) | 0.253
#> ID [7]    |  -3.14 | [-4.60, -1.70] | 99.98% |        0% | Cauchy (0 +- 1) | 0.265
#> ID [8]    |  -0.18 | [-1.70,  1.19] | 58.27% |    25.67% | Cauchy (0 +- 1) |  2.75
#> ID [9]    |  -2.47 | [-3.98, -1.07] | 99.67% |        0% | Cauchy (0 +- 1) | 0.253
#> ID [10]   |   0.69 | [-0.82,  2.03] | 77.03% |    19.77% | Cauchy (0 +- 1) | 0.265
#> ID [11]   |   0.67 | [-0.73,  2.13] | 77.62% |    18.81% | Cauchy (0 +- 1) |  2.75
#> ID [12]   |  -3.35 | [-4.95, -2.03] | 99.98% |        0% | Cauchy (0 +- 1) | 0.253

Created on 2021-01-03 by the reprex package (v0.3.0)

@mattansb
Copy link
Member

mattansb commented Jan 4, 2021

In the first example,

#> mu                      | 98.95% |                   
#> Sepal.Width-Sepal.Width | 99.12% | Cauchy (0 +- 0.12)
#> Petal.Width-Petal.Width | 99.08% | Cauchy (0 +- 0.32)

Are fixed effects, and all the ID and Sepal.Width:ID parameters are random effects (some of which are doubled an also appear in the random effects part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 investigators ❔❓ Need to look further into this issue Bug 🐛 Something isn't working Low priority 😴 This issue can be easily workaround or happens only in edge cases
Projects
None yet
Development

No branches or pull requests

4 participants