I have verbose set to FALSE and refresh set to -1. I have used suppressMessages/Warnings as suggested in the thread (1), and that does not seem to do anything more than setting messages and warnings settings in the knitr chunk. I have wrapped my stan() call in sink() calls, as discussed in thread (2) as such:
<<'Bayes_Stan', eval=TRUE, echo=FALSE, message=FALSE, warning=FALSE, cache=0>>=
sink(file = "a", type = c("output", "message"))
library(rstan)
LN_S <- suppressMessages(suppressWarnings(stan(file = 'Bayes.stan', data = BayesData, pars = c('mu', 'sigma', 'LR_post', 'ASL_post', 'dev'), iter = 300000, warmup = 50000, thin = 25, chains = 5, seed = 12, refresh = -1, verbose = FALSE)))
[snip extractions and assignments]
LNPlus_S <- suppressMessages(suppressWarnings(stan(file = 'BayesPlus.stan', data = BayesDataPlus, pars = c('Pars', 'LR_post', 'ASL_post', 'dev'), iter = 300000, warmup = 50000, thin = 25, chains = 5, seed = 12, refresh = -1, verbose = FALSE)))
[snip extractions and assignments]
sink()
@Regardless, my knitted output looks like:
…Therefore, the model was rebuilt in Stan (Stan Development Team, 2014a)—a Bayesian modeling language whose samplers are non-Gibbs.
##
## TRANSLATING MODEL 'Bayes' FROM Stan CODE TO C++ CODE NOW.
## COMPILING THE C++ CODE FOR MODEL 'Bayes' NOW.
## cygwin warning:
## MS-DOS style path detected: C:/R/RCurrent/R-30~1.2/etc/x64/Makeconf
## Preferred POSIX equivalent is: /cygdrive/c/R/RCurrent/R-30~1.2/etc/x64/Makeconf
## CYGWIN environment variable option "nodosfilewarning" turns off this warning.
## Consult the user's guide for more details about POSIX paths:
## http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
## C:/R/RCurrent/R-3.0.2/library/rstan/include//stansrc/stan/agrad/rev/var_stack.hpp:49:17: warning: 'void stan::agrad::free_memory()' defined but not used [-Wunused-function]
## C:/R/RCurrent/R-3.0.2/library/rstan/include//stansrc/stan/agrad/rev/chainable.hpp:87:17: warning: 'void stan::agrad::set_zero_all_adjoints()' defined but not used [-Wunused-function]
##
## TRANSLATING MODEL 'BayesPlus' FROM Stan CODE TO C++ CODE NOW.
## COMPILING THE C++ CODE FOR MODEL 'BayesPlus' NOW.
## cygwin warning:
## MS-DOS style path detected: C:/R/RCurrent/R-30~1.2/etc/x64/Makeconf
## Preferred POSIX equivalent is: /cygdrive/c/R/RCurrent/R-30~1.2/etc/x64/Makeconf
## CYGWIN environment variable option "nodosfilewarning" turns off this warning.
## Consult the user's guide for more details about POSIX paths:
## http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
## C:/R/RCurrent/R-3.0.2/library/rstan/include//stansrc/stan/agrad/rev/var_stack.hpp:49:17: warning: 'void stan::agrad::free_memory()' defined but not used [-Wunused-function]
## C:/R/RCurrent/R-3.0.2/library/rstan/include//stansrc/stan/agrad/rev/chainable.hpp:87:17: warning: 'void stan::agrad::set_zero_all_adjoints()' defined but not used [-Wunused-function]
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -0.34910650273000776:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -1.6172265406146098:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -1.2449912107872052:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -1.0263658781850085:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -1.7036664255500364:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -1.7912999475616009:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -0.67853001987262718:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -0.56723437122169695:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -1.9622578028376079:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -1.9058489407892381:0, but must be > 0!Rejecting proposed initial value with zero density.
The No-U-Turn-Sampler behind Stan is much more robust to highly autocorrelated parameters…
I am not savvy enough in either R or Stan to write wrapper codes like the one in thread (3) which may address this issue.
While I can always knit the Rnw, edit the resulting tex file to remove these lines, and re-texify that file, I would appreciate knowing if there is any way to prevent the need for such post-processing.
While I cannot get an exact sessionInfo without knitting it into the paper, loading all the packages and calls used results in the following:
R version 3.0.2 (2013-09-25) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] rstan_2.2.0 inline_0.3.13 rjags_3-12 coda_0.16-1 lattice_0.20-24 runjags_1.2.0-7 [7] scatterplot3d_0.3-35 mvtnorm_0.9-9997 nloptr_1.0.0 Rcpp_0.11.0 reshape2_1.2.2 scales_0.2.3 [13] ggplot2_0.9.3.1 loaded via a namespace (and not attached): [1] colorspace_1.2-4 dichromat_2.0-0 digest_0.6.4 grid_3.0.2 gtable_0.1.2 labeling_0.2 MASS_7.3-29 [8] munsell_0.4.2 parallel_3.0.2 plyr_1.8 proto_0.3-10 RColorBrewer_1.0-5 stats4_3.0.2 stringr_0.6.2 [15] tools_3.0.2
If there is no way at current to completely suppress messaged, would it be possible to request a future feature, such as when refresh is set to a [possibly large] negative value (instead of 0) that ALL output is suppressed and only the model and results are created?
Once again, thank you for all your collective work on such a great and powerful new tool for Bayesian analysis.
Regardless, my knitted output looks like:…Therefore, the model was rebuilt in Stan (Stan Development Team, 2014a)—a Bayesian modeling language whose samplers are non-Gibbs.
##
## TRANSLATING MODEL 'Bayes' FROM Stan CODE TO C++ CODE NOW.
## COMPILING THE C++ CODE FOR MODEL 'Bayes' NOW.
cat <- function(...) return(invisible(NULL))
## cygwin warning:
## MS-DOS style path detected: C:/R/RCurrent/R-30~1.2/etc/x64/Makeconf
## Preferred POSIX equivalent is: /cygdrive/c/R/RCurrent/R-30~1.2/etc/x64/Makeconf
## CYGWIN environment variable option "nodosfilewarning" turns off this warning.
## Consult the user's guide for more details about POSIX paths:
## http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
Sys.setenv(nodosfilewarning = "1")
## C:/R/RCurrent/R-3.0.2/library/rstan/include//stansrc/stan/agrad/rev/var_stack.hpp:49:17: warning: 'void stan::agrad::free_memory()' defined but not used [-Wunused-function]
## C:/R/RCurrent/R-3.0.2/library/rstan/include//stansrc/stan/agrad/rev/chainable.hpp:87:17: warning: 'void stan::agrad::set_zero_all_adjoints()' defined but not used [-Wunused-function]
system("sed -i '/-Wunused-function/d' a")##
## TRANSLATING MODEL 'BayesPlus' FROM Stan CODE TO C++ CODE NOW.
## COMPILING THE C++ CODE FOR MODEL 'BayesPlus' NOW.
## cygwin warning:
## MS-DOS style path detected: C:/R/RCurrent/R-30~1.2/etc/x64/Makeconf
## Preferred POSIX equivalent is: /cygdrive/c/R/RCurrent/R-30~1.2/etc/x64/Makeconf
## CYGWIN environment variable option "nodosfilewarning" turns off this warning.
## Consult the user's guide for more details about POSIX paths:
## http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
## C:/R/RCurrent/R-3.0.2/library/rstan/include//stansrc/stan/agrad/rev/var_stack.hpp:49:17: warning: 'void stan::agrad::free_memory()' defined but not used [-Wunused-function]
## C:/R/RCurrent/R-3.0.2/library/rstan/include//stansrc/stan/agrad/rev/chainable.hpp:87:17: warning: 'void stan::agrad::set_zero_all_adjoints()' defined but not used [-Wunused-function]
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -0.34910650273000776:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -1.6172265406146098:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -1.2449912107872052:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -1.0263658781850085:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -1.7036664255500364:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -1.7912999475616009:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -0.67853001987262718:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -0.56723437122169695:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -1.9622578028376079:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -1.9058489407892381:0, but must be > 0!Rejecting proposed initial value with zero density.
real<lower=0> sigma;
system("sed -i '/Error in function/d' a")The bigger problem here is that you seem to have not constrained the scale parameter to be positive. You need something like this in the parameters blockreal<lower=0> sigma;
but if there are any stray messages, you could get rid of them with another sed sweepsystem("sed -i '/Error in function/d' a")
Ben
Yes, the "Informational messages" about the covariance matrices not being numerically positive definite are usually not a big deal and can be zapped from the sinked file by sed, but I was referring to these, which all come from a lognormal(mu,sigma) statement where sigma has not been constrained to be positive.
data {
int<lower = 0> N;
real<lower = 0> LR[N];
cov_matrix[2] V;
}
parameters {
vector[2] mu;
vector[2] Pars;
cov_matrix[2] Omega;
}
model {
mu[1] ~ normal(0.0, 100.0);
mu[2] ~ uniform(0.0, 100.0);
Omega ~ inv_wishart(3, V);
Pars ~ multi_normal_prec(mu, Omega);
for (year in 1:N) {
LR[year] ~ lognormal(Pars[1], Pars[2]);
}
}
generated quantities {
real LR_post;
real ASL_post;
real dev;
LR_post <- lognormal_rng(Pars[1], Pars[2]);
ASL_post <- fmin(0.025, fmax(LR_post - 0.725, 0.0));
dev <- 0;
for (i in 1:N) {
dev <- dev - (2 * lognormal_log (LR[i], Pars[1], Pars[2]));
}
}The Stan model is:data {
int<lower = 0> N;
real<lower = 0> LR[N];
cov_matrix[2] V;
}
parameters {
vector[2] mu;
vector[2] Pars;
cov_matrix[2] Omega;
}
model {
mu[1] ~ normal(0.0, 100.0);
mu[2] ~ uniform(0.0, 100.0);
Omega ~ inv_wishart(3, V);
Pars ~ multi_normal_prec(mu, Omega);
LR ~ lognormal(Pars[1], exp(Pars[2]));
generated quantities {
real LR_post;
real ASL_post;
real dev;
LR_post <- lognormal_rng(Pars[1], exp(Pars[2]));
ASL_post <- fmin(0.025, fmax(LR_post - 0.725, 0.0));
dev <- 0;
for (i in 1:N) {
dev <- dev - (2 * lognormal_log (LR[i], Pars[1], exp(Pars[2])));
}
}
Yes, I know that Andrew et al are not big fans of DIC (and I'm using pV instead of pD as I'm not sure how to easily calculate the latter) but I need some way to compare the models :)
I can't just throw a lower=0 on mu, as the first parameter can (and should) be less than 0.
real mu_1;
real<lower=0,upper=1> mu_2;