vdorie / blme

Bayesian Linear Mixed Effect Models
41 stars 8 forks source link

level.dim does not work for bglmer #12

Closed mgoplerud closed 4 years ago

mgoplerud commented 4 years ago

Hello! I'm trying to play around with using level.dim to give programmatic arguments to a wishart prior (e.g. level.dim + 2). I find that for bglmer (not blmer), it fails to run. A reprex is below. I will fork the package and see if I can figure out the issue. It appears in both the CRAN and GitHub versions. Thanks so much!


library(lme4)
#> Loading required package: Matrix
library(blme)
library(lattice)
#level.dim works as a complex argument
gm1a <- blmer(incidence ~ period + (1 | herd),
              cbpp, cov.prior = wishart(df = level.dim))
#> Warning in log(diag(Lambda.t)): NaNs produced
#level dim does not work for binomial
gm1a <- bglmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
               cbpp, binomial, 
               cov.prior = wishart(df = level.dim))
#> Error in eval(matchedCall$df): object 'level.dim' not found
#level dim does not work for poisson
gm1a <- bglmer(incidence ~ period + (1 | herd),
               cbpp, poisson, 
               cov.prior = wishart(df = level.dim))
#> Error in eval(matchedCall$df): object 'level.dim' not found

Created on 2020-11-02 by the reprex package (v0.3.0)

vdorie commented 4 years ago

Thanks for the report. Hopefully I've fixed it in 73deec4, but please let me know if you encounter any other issues.

mgoplerud commented 4 years ago

Awesome! That seems to work. I've noted another small issue but I think I found a "hack" to fix it

library(lme4)
#> Loading required package: Matrix
library(blme)
library(lattice)
cbpp$noise <- rnorm(nrow(cbpp))
#Works for bglmer with wishart
gm1a <- bglmer(cbind(incidence, size - incidence) ~ period + (1 + noise | herd),
               cbpp, binomial, 
               cov.prior = wishart(df = level.dim))
#> boundary (singular) fit: see ?isSingular
#Error for invwishart
gm1a <- bglmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
               cbpp, binomial, 
               cov.prior = invwishart(df = level.dim))
#> Error in blme:::deparseCommonScale(common.scale): object 'common.scale' not found
#A "hack" that works
common.scale <- FALSE
gm1a <- bglmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
               cbpp, binomial, 
               cov.prior = invwishart(df = level.dim))

Created on 2020-11-02 by the reprex package (v0.3.0)

vdorie commented 4 years ago

Thanks again, fixed in c61f689.