stan-dev / rstanarm

rstanarm R package for Bayesian applied regression modeling
https://mc-stan.org/rstanarm
GNU General Public License v3.0
388 stars 132 forks source link

Error using stan_glmer from rstanarm #446

Open DianaDaInLee opened 4 years ago

DianaDaInLee commented 4 years ago

Summary:

I'm trying to run the MRP demo provided at https://cran.r-project.org/web/packages/rstanarm/vignettes/mrp.html but am getting an error when running stan_glmer().

Description:

I run the same model using the same sample data from the website:

fit <- stan_glmer(
  cat_pref ~ factor(male) + factor(male) * factor(age) + 
    (1 | state) + (1 | age) + (1 | eth) + (1 | income),
  family = binomial(link = "logit"),
  data = sample
)

but get the following error:

SAMPLING FOR MODEL 'bernoulli' NOW (CHAIN 1).
Chain 1: empty_nested() must be true before calling recover_memory()
[1] "Error in sampler$call_sampler(args_list[[i]]) : "              "  empty_nested() must be true before calling recover_memory()"
error occurred during calling the sampler; sampling not done
Error in check_stanfit(stanfit) : 
  Invalid stanfit object produced please report bug
Error in dimnamesGets(x, value) : 
  invalid dimnames given for “dgCMatrix” object

I tried re-installing rstanarm using install.packages("rstanarm", type = "source") as suggested in the other post but it did not work.

RStanARM Version:

packageVersion("rstanarm") [1] ‘2.19.3’

R Version:

Version 1.2.1335 © 2009-2019 RStudio, Inc.

Operating System:

macOS Catalina Version 10.15.5

jgabry commented 4 years ago

Sorry you're getting an error. I see that you're running RStudio version 1.2.1335 but can you also share which version of R itself you have? You can check that by seeing what print(R.version.string) says.

DianaDaInLee commented 4 years ago

Hello -

My R version is: "R version 3.6.1 (2019-07-05)"

Thanks for your help!

jgabry commented 4 years ago

Hmm, I have R 4.0.2 and Catalina and it's working ok, and I don't know of any reason why it wouldn't be ok with R 3.6.1.

@bgoodri Have you seen examples of rstan/rstanarm not working with Catalina and R 3.6? Or has this error

Chain 1: empty_nested() must be true before calling recover_memory() [1] "Error in sampler$call_sampler(args_list[[i]]) : " " empty_nested() must be true before calling recover_memory()"

come up before?

bgoodri commented 4 years ago

Yes, it is different with R 3.6.1 due to using llvm rather than Xcode. You are probably going to have to install rstanarm from source to avoid running into the exception problem.

On Mon, Jul 20, 2020 at 1:21 PM Jonah Gabry notifications@github.com wrote:

Hmm, I have R 4.0.2 and Catalina and it's working ok, and I don't know of any reason why it wouldn't be ok with R 3.6.1.

@bgoodri https://github.com/bgoodri Have you seen examples of rstan/rstanarm not working with Catalina and R 3.6? Or has this error

Chain 1: empty_nested() must be true before calling recover_memory() [1] "Error in sampler$call_sampler(args_list[[i]]) : " " empty_nested() must be true before calling recover_memory()"

come up before?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstanarm/issues/446#issuecomment-661212242, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZ2XKVC23MWL42F4KR2FZLR4R4LFANCNFSM4PANGLBQ .

DianaDaInLee commented 4 years ago

I tried re-installing the package using 'install.packages("rstanarm", type = "source")' after seeing this post: https://discourse.mc-stan.org/t/new-user-struggling-to-get-rstanarm-running/13151/2

But it still resulted in the same error. Maybe I missed a subtle detail when re-installing the package. Below is the step I took to re-install the package. Could you please let me know if I've missed any necessary steps?

  1. Run install.packages("Rcpp", repos = "https://rcppcore.github.io/drat")
  2. Run remove.packages("rstan") if (file.exists(".RData")) file.remove(".RData")
  3. Restart R
  4. Run Sys.setenv(MAKEFLAGS = "-j4")
  5. Run install.packages("rstan", type = "source")
  6. install.packages("rstanarm", type = "source")
  7. Restart R to run the model - still get an error

Thanks,

bgoodri commented 4 years ago

What is your ~/.R/Makevars file say?

On Mon, Jul 20, 2020 at 1:46 PM dlee0324 notifications@github.com wrote:

I tried re-installing the package using 'install.packages("rstanarm", type = "source")' after seeing this post: https://discourse.mc-stan.org/t/new-user-struggling-to-get-rstanarm-running/13151/2

But it still resulted in the same error. Maybe I missed a subtle detail when re-installing the package. Below is the step I took to re-install the package. Could you please let me know if I've missed any necessary steps?

  1. Run install.packages("Rcpp", repos = " https://rcppcore.github.io/drat")
  2. Run remove.packages("rstan") if (file.exists(".RData")) file.remove(".RData")
  3. Restart R
  4. Run Sys.setenv(MAKEFLAGS = "-j4")
  5. Run install.packages("rstan", type = "source")
  6. install.packages("rstanarm", type = "source")
  7. Restart R to run the model - still get an error

Thanks,

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstanarm/issues/446#issuecomment-661236225, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZ2XKVP4FC5UGR3D57GDETR4R7HLANCNFSM4PANGLBQ .

DianaDaInLee commented 4 years ago

This is what I have under rstantools>include>sys>Makevars

STANHEADERS_SRC = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "message()" -e "cat(system.file('include', 'src', package = 'StanHeaders', mustWork = TRUE))" -e "message()" | grep "StanHeaders")

PKG_CPPFLAGS = -I"../inst/include" -I"$(STANHEADERS_SRC)" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error
PKG_CXXFLAGS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "RcppParallel::CxxFlags()") $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "StanHeaders:::CxxFlags()")
PKG_LIBS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "RcppParallel::RcppParallelLibs()") $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "StanHeaders:::LdFlags()")

CXX_STD = CXX14
bgoodri commented 4 years ago

I mean the Makevars file in your home directory, i.e. ~/.R/Makevars (there is a period before the R in that path).

On Mon, Jul 20, 2020 at 2:19 PM dlee0324 notifications@github.com wrote:

This is what I have under rstantools>include>sys>Makevars

STANHEADERS_SRC = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "message()" -e "cat(system.file('include', 'src', package = 'StanHeaders', mustWork = TRUE))" -e "message()" | grep "StanHeaders")

PKG_CPPFLAGS = -I"../inst/include" -I"$(STANHEADERS_SRC)" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error PKG_CXXFLAGS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "RcppParallel::CxxFlags()") $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "StanHeaders:::CxxFlags()") PKG_LIBS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "RcppParallel::RcppParallelLibs()") $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "StanHeaders:::LdFlags()")

CXX_STD = CXX14

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstanarm/issues/446#issuecomment-661253952, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZ2XKRHGUQCMSBS4MHIOKTR4SDBPANCNFSM4PANGLBQ .

DianaDaInLee commented 4 years ago

I don't think I have such folder in my home directory... however, I just re-run the install.packages("rstan", type = "source") from a clean slate and it seems to work now - hurray!

jgabry commented 4 years ago

Glad that it's working now!

Yes, it is different with R 3.6.1 due to using llvm rather than Xcode. You are probably going to have to install rstanarm from source to avoid running into the exception problem.

@bgoodri So does any with R 3.6.1 need to install from source? If so is there any way for them to find that out besides opening an issue here? That seems like an important piece of information.

bgoodri commented 4 years ago

I am somewhat hopeful that the rstanarm binaries for Mac on R 3.6.1 will eliminate this problem. Those had never before been built with the CRTP approach in the code now.

On Mon, Jul 20, 2020 at 4:38 PM Jonah Gabry notifications@github.com wrote:

Glad that it's working now!

Yes, it is different with R 3.6.1 due to using llvm rather than Xcode. You are probably going to have to install rstanarm from source to avoid running into the exception problem.

@bgoodri https://github.com/bgoodri So does any with R 3.6.1 need to install from source? If so is there any way for them to find that out besides opening an issue here? That seems like an important piece of information.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstanarm/issues/446#issuecomment-661320739, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZ2XKWNMU35X3XCHUGYMYDR4STM3ANCNFSM4PANGLBQ .

jgabry commented 4 years ago

Ok I hope that works!