Open alexWhitworth opened 6 years ago
The example you posted works for me. I have
R version 3.5.1 (2018-07-02)
rstan_2.17.3
loo_2.0.0
and the biggest difference is that you are using loo_1.1.0
. Try using loo_2.0.0
instead.
@avehtari Thanks--still not working. Different error. Note: I'm unable to update R given distribution via work account.
Same error (below) for both real data and simulated data.
> library(loo)
This is loo version 2.0.0.
> library(rstanarm)
Loading required package: Rcpp
rstanarm (Version 2.17.2, packaged: 2017-12-20 23:59:28 UTC)
> library(data.table)
data.table 1.11.0
> loo_f1 <- rstanarm::loo(fit1, cores= 20)
Error: is.data.frame(data) \|\| is.matrix(data) is not TRUE
I tink it's unlikely that R version would matter. Changing loo version did produce different error. The error hints that you have a "strange" data object (we know certain rae matrix/data.frame constructs can cause problems). Can you confirm that you get this error also with that betareg vignette code starting from restarted R and empty workspace?
@avehtari Correct. From fresh session:
> library(rstanarm)
> library(loo)
... vignette code ...
> loo(fit1)
Error: is.data.frame(data) || is.matrix(data) is not TRUE
> rstanarm::posterior_predict(fit1, draws= 1000, re.form= NULL, allow.new.levels= TRUE)
Error in names(object[[n]]) <- `*vtmp*` :
attempt to set an attribute on NULL
attached packages:
[1] loo_2.0.0 rstanarm_2.17.2 Rcpp_0.12.13
rstanarm_2.17.2
can you try rstanarm_2.17.4?
@avehtari Updated to 2.17.4. No change in outcome / error messages:
> loo(fit1)
Error in names(object[[n]]) <- `*vtmp*` :
attempt to set an attribute on NULL
> posterior_predict(fit1)
Error in names(object[[n]]) <- `*vtmp*` :
attempt to set an attribute on NULL
No change in outcome / error messages:
But you reported
First round: Error in names(object[[n]]) <-
vtmp:
Second round: Error: is.data.frame(data) || is.matrix(data) is not TRUE
Third round: `Error in names(object[[n]]) <-
vtmp:
I think there is change in error messages. However, this didn't give me any additional clue what is wrong. Can you try with clean R install in some other machine? We have seen before problems with corrupted R installations, so that no-one else could get the error and only re-installing all R related fixed the problem...
@avehtari
The new machine (non-clean install) returns functional results. The biggest differences here are (1): running on OS-X 10.13.4 vs Linux Centos 7 and (2) R version 3.5.0... See sessionInfo
below. I'll ping our R and STAN teams at work to take a look at this. Any help from your side would also be appreciated, thanks!
library(rstanarm)
library(loo)
sessionInfo()
SEED <- 1234
set.seed(SEED)
eta <- c(1, -0.2)
gamma <- c(1.8, 0.4)
N <- 200
x <- rnorm(N, 2, 2)
z <- rnorm(N, 0, 2)
mu <- binomial(link = logit)$linkinv(eta[1] + eta[2]*x)
phi <- binomial(link = log)$linkinv(gamma[1] + gamma[2]*z)
y <- rbeta(N, mu * phi, (1 - mu) * phi)
dat <- data.frame(cbind(y, x, z))
fit1 <- stan_betareg(y ~ x | z, data = dat, link = "logit", link.phi = "log",
chains = 1L, cores = 1L, seed = 1L, iter = 100L)
test1 <- loo(fit1)
test2 <- rstanarm::posterior_predict(fit1, draws= 50, re.form= NULL, allow.new.levels= TRUE)
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.4
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] loo_2.0.0 rstanarm_2.17.4 Rcpp_0.12.18
loaded via a namespace (and not attached):
[1] lattice_0.20-35 zoo_1.8-1 gtools_3.5.0 assertthat_0.2.0 digest_0.6.15
[6] mime_0.5 R6_2.2.2 plyr_1.8.4 ggridges_0.5.0 stats4_3.5.0
[11] ggplot2_3.0.0 colourpicker_1.0 pillar_1.2.2 rlang_0.2.1 lazyeval_0.2.1
[16] minqa_1.2.4 miniUI_0.1.1.1 nloptr_1.0.4 Matrix_1.2-14 DT_0.4
[21] shinythemes_1.1.1 splines_3.5.0 shinyjs_1.0 lme4_1.1-17 stringr_1.3.1
[26] htmlwidgets_1.2 igraph_1.2.1 munsell_0.4.3 shiny_1.1.0 compiler_3.5.0
[31] httpuv_1.4.3 rstan_2.17.3 pkgconfig_2.0.1 base64enc_0.1-3 rstantools_1.5.0
[36] htmltools_0.3.6 tidyselect_0.2.4 tibble_1.4.2 gridExtra_2.3 codetools_0.2-15
[41] matrixStats_0.54.0 threejs_0.3.1 dplyr_0.7.5 later_0.7.2 MASS_7.3-49
[46] grid_3.5.0 nlme_3.1-137 xtable_1.8-2 gtable_0.2.0 magrittr_1.5
[51] StanHeaders_2.17.2 scales_0.5.0 stringi_1.2.2 reshape2_1.4.3 promises_1.0.1
[56] bindrcpp_0.2.2 dygraphs_1.1.1.6 xts_0.10-2 tools_3.5.0 glue_1.2.0
[61] shinystan_2.5.0 markdown_0.8 purrr_0.2.4 crosstalk_1.0.0 survival_2.41-3
[66] parallel_3.5.0 rsconnect_0.8.8 inline_0.3.15 colorspace_1.3-2 bayesplot_1.5.0
[71] bindr_0.1.1
test1 <- loo(fit1)
Warning message:
Found 2 observation(s) with a pareto_k > 0.7. We recommend calling 'loo' again with argument 'k_threshold = 0.7' in order to calculate the ELPD without the assumption that these observations are negligible. This will refit the model 2 times to compute the ELPDs for the problematic observations directly.
test2 <- rstanarm::posterior_predict(fit1, draws= 50, re.form= NULL, allow.new.levels= TRUE)
@avehtari I have reinstalled R and rebooted by VM server. I get the same error. This leads me to believe it may have to do with R 3.4.1, although I am having a hard time finding the binary for 3.4.1 on CRAN
https://cran.r-project.org/bin/macosx/old/index-old.html https://cran.r-project.org/bin/macosx/
this leads me to believe it may have to do with R 3.4.1,
This did work for me for a long time with R 3.4. too, and I just switched to 3.5. about a week ago. I'll try to find a computer with R 3.4.*
@avehtari, I work with Alex and I'm not having any issues on my machine. He asked me to post my reprex
here:
library(rstanarm)
#> Loading required package: Rcpp
#> rstanarm (Version 2.17.3, packaged: 2018-02-17 05:11:16 UTC)
#> - Do not expect the default priors to remain the same in future rstanarm versions.
#> Thus, R scripts should specify priors explicitly, even if they are just the defaults.
#> - For execution on a local, multicore CPU with excess RAM we recommend calling
#> options(mc.cores = parallel::detectCores())
#> - Plotting theme set to bayesplot::theme_default().
library(loo)
#> This is loo version 1.1.0
SEED <- 1234
set.seed(SEED)
eta <- c(1, -0.2)
gamma <- c(1.8, 0.4)
N <- 200
x <- rnorm(N, 2, 2)
z <- rnorm(N, 0, 2)
mu <- binomial(link = logit)$linkinv(eta[1] + eta[2] * x)
phi <- binomial(link = log)$linkinv(gamma[1] + gamma[2] * z)
y <- rbeta(N, mu * phi, (1 - mu) * phi)
dat <- data.frame(cbind(y, x, z))
fit1 <- stan_betareg(y ~ x | z, data = dat, link = "logit", link.phi = "log",
chains = 1L, cores = 1L, seed = 1L, iter = 100L)
#>
#> SAMPLING FOR MODEL 'continuous' NOW (CHAIN 1).
#>
#> Gradient evaluation took 0 seconds
#> 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
#> Adjust your expectations accordingly!
#>
#>
#> WARNING: There aren't enough warmup iterations to fit the
#> three stages of adaptation as currently configured.
#> Reducing each adaptation stage to 15%/75%/10% of
#> the given number of warmup iterations:
#> init_buffer = 7
#> adapt_window = 38
#> term_buffer = 5
#>
#> Iteration: 1 / 100 [ 1%] (Warmup)
#> Iteration: 10 / 100 [ 10%] (Warmup)
#> Iteration: 20 / 100 [ 20%] (Warmup)
#> Iteration: 30 / 100 [ 30%] (Warmup)
#> Iteration: 40 / 100 [ 40%] (Warmup)
#> Iteration: 50 / 100 [ 50%] (Warmup)
#> Iteration: 51 / 100 [ 51%] (Sampling)
#> Iteration: 60 / 100 [ 60%] (Sampling)
#> Iteration: 70 / 100 [ 70%] (Sampling)
#> Iteration: 80 / 100 [ 80%] (Sampling)
#> Iteration: 90 / 100 [ 90%] (Sampling)
#> Iteration: 100 / 100 [100%] (Sampling)
#>
#> Elapsed Time: 0.46 seconds (Warm-up)
#> 0.6 seconds (Sampling)
#> 1.06 seconds (Total)
loo(fit1)
#> Warning: Found 5 observation(s) with a pareto_k > 0.7. We recommend calling
#> 'loo' again with argument 'k_threshold = 0.7' in order to calculate the
#> ELPD without the assumption that these observations are negligible. This
#> will refit the model 5 times to compute the ELPDs for the problematic
#> observations directly.
#> Computed from 50 by 200 log-likelihood matrix
#>
#> Estimate SE
#> elpd_loo 87.3 9.7
#> p_loo 3.1 0.4
#> looic -174.7 19.4
#>
#> Pareto k diagnostic values:
#> Count Pct
#> (-Inf, 0.5] (good) 185 92.5%
#> (0.5, 0.7] (ok) 10 5.0%
#> (0.7, 1] (bad) 3 1.5%
#> (1, Inf) (very bad) 2 1.0%
#> See help('pareto-k-diagnostic') for details.
@avehtari given Ryan's results above, I have uninstalled / reinstalled R from my computer.
This has fixed the error on posterior_predict
and rstanarm:::loo.stanreg
for my real data. But, interestingly, I still get the same errors (below) with the demo data from the vignette. I also get this error with loo
(without the call to the non-exported function).
loo(fit1) Error in names(object[[n]]) <-
*vtmp*
: attempt to set an attribute on NULL posterior_predict(fit1) Error in names(object[[n]]) <-*vtmp*
: attempt to set an attribute on NULL
Note that we are also soon to migrate our VMs at work from R 3.4.1 to 3.5.1. I can provide an update when that occurs as well
Summary:
Problems with
rstanarm:::loo.stanreg
/rstanarm::loo
fromstan_betareg
model fitDescription / reproducibility
using example data:
see: https://cran.r-project.org/web/packages/rstanarm/vignettes/betareg.html
session info