Skip to content

Possible bug with estimate_grouplevel() for brms model #229

@jmgirard

Description

@jmgirard

Both type = "random" and type = "total" seem to return the same estimate, but I think total should be the random + fixed.

library(brms)
library(modelbased)

data("klein2000", package = "multilevel")

fit <- brm(
  COHES ~ 1 + POSAFF + (1 + POSAFF | GRPID),
  data = klein2000,
  prior = set_prior("normal(0,1)", class = "b"),
  chains = 4,
  cores = 4
)
#> Compiling Stan program...
#> Start sampling

estimate_grouplevel(fit, type = "random") |> head(5)
#> Group |       Level |             Parameter |   Component | Median |        95% CI |     pd |  Rhat |     ESS
#> -------------------------------------------------------------------------------------------------------------
#> GRPID | (Intercept) |   sd_GRPID__Intercept | conditional |   1.22 | [ 0.96, 1.56] |   100% | 1.001 | 1373.00
#> GRPID |     GRPID.1 |  r_GRPID[1,Intercept] | conditional |   0.95 | [-0.14, 1.96] | 95.45% | 0.999 | 4860.00
#> GRPID |     GRPID.1 |     r_GRPID[1,POSAFF] | conditional |  -0.07 | [-0.60, 0.19] | 74.40% | 1.000 | 3342.00
#> GRPID |    GRPID.10 | r_GRPID[10,Intercept] | conditional |  -0.44 | [-1.48, 0.61] | 79.17% | 1.000 | 4104.00
#> GRPID |    GRPID.10 |    r_GRPID[10,POSAFF] | conditional |   0.01 | [-0.28, 0.38] | 58.65% | 1.000 | 4718.00

estimate_grouplevel(fit, type = "total") |> head(5)
#> Group |       Level |             Parameter |   Component | Median |     pd |  Rhat |     ESS
#> ---------------------------------------------------------------------------------------------
#> GRPID | (Intercept) |   sd_GRPID__Intercept | conditional |   1.22 |   100% | 1.001 | 1373.00
#> GRPID |     GRPID.1 |  r_GRPID[1,Intercept] | conditional |   0.95 | 95.45% | 0.999 | 4860.00
#> GRPID |     GRPID.1 |     r_GRPID[1,POSAFF] | conditional |  -0.07 | 74.40% | 1.000 | 3342.00
#> GRPID |    GRPID.10 | r_GRPID[10,Intercept] | conditional |  -0.44 | 79.17% | 1.000 | 4104.00
#> GRPID |    GRPID.10 |    r_GRPID[10,POSAFF] | conditional |   0.01 | 58.65% | 1.000 | 4718.00

Created on 2023-06-08 with reprex v2.0.2

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions