diff --git a/R/generics.R b/R/generics.R index 656cf9a1..4377dcce 100644 --- a/R/generics.R +++ b/R/generics.R @@ -4,8 +4,8 @@ #' packages that interface with on CmdStanR. Developers can define methods on #' top of these generics to coerce objects into CmdStanR's fitted model objects. #' -#' @param object to be coerced -#' @param ... additional arguments +#' @param object The object to be coerced. +#' @param ... Additional arguments to pass to methods. #' #' @name cmdstan_coercion NULL diff --git a/_pkgdown.yml b/_pkgdown.yml index b9f89cf3..8e28d1fc 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -76,12 +76,13 @@ articles: - articles-online-only/opencl reference: - - title: "Package description" + - title: "Package overview and global options" desc: > An overview of the package and how it differs from [RStan](https://mc-stan.org/rstan). contents: - cmdstanr-package + - cmdstanr_global_options - title: "Installing and setting the path to CmdStan" desc: > Install CmdStan, assuming the necessary C++ toolchain. @@ -106,7 +107,7 @@ reference: - CmdStanGQ - CmdStanDiagnose - starts_with("fit-method") - - title: "Other tools for working with CmdStan" + - title: "Other tools" contents: - read_cmdstan_csv - write_stan_json @@ -114,6 +115,7 @@ reference: - draws_to_csv - as_mcmc.list - as_draws.CmdStanMCMC + - cmdstan_coercion - title: "Using CmdStanR with knitr and R Markdown" contents: - register_knitr_engine diff --git a/docs/404.html b/docs/404.html index 4499f2e6..becc3d45 100644 --- a/docs/404.html +++ b/docs/404.html @@ -12,7 +12,7 @@ - + @@ -39,7 +39,7 @@ cmdstanr - 0.7.0 + 0.8.1 @@ -147,12 +147,12 @@

Page not found (404)

diff --git a/docs/CONTRIBUTING.html b/docs/CONTRIBUTING.html index ce8b14b1..af3c28f4 100644 --- a/docs/CONTRIBUTING.html +++ b/docs/CONTRIBUTING.html @@ -1,5 +1,5 @@ -Contributing to cmdstanr • cmdstanrContributing to cmdstanr • cmdstanr @@ -17,7 +17,7 @@ cmdstanr - 0.7.0 + 0.8.1 @@ -144,11 +144,11 @@

Code of Conduct
-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.9.

diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 8f4c7007..347bf272 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -1,5 +1,5 @@ -License • cmdstanrLicense • cmdstanr @@ -17,7 +17,7 @@ cmdstanr - 0.7.0 + 0.8.1 @@ -116,11 +116,11 @@

License

diff --git a/docs/LICENSE.html b/docs/LICENSE.html index 9cfe0b94..8cb6242d 100644 --- a/docs/LICENSE.html +++ b/docs/LICENSE.html @@ -1,5 +1,5 @@ -BSD 3-Clause License • cmdstanrBSD 3-Clause License • cmdstanr @@ -17,7 +17,7 @@ cmdstanr - 0.7.0 + 0.8.1 @@ -122,11 +122,11 @@

BSD 3-Clause License

diff --git a/docs/articles/articles-online-only/opencl.html b/docs/articles/articles-online-only/opencl.html index af47c06b..df160a0a 100644 --- a/docs/articles/articles-online-only/opencl.html +++ b/docs/articles/articles-online-only/opencl.html @@ -12,7 +12,7 @@ - + @@ -40,7 +40,7 @@ cmdstanr - 0.7.0 + 0.8.1 @@ -226,8 +226,8 @@

Compiling a model with OpenCLhere for a -list of functions with OpenCL support.

+OpenCL. Check here +for a list of functions with OpenCL support.

To build the model with OpenCL support, add cpp_options = list(stan_opencl = TRUE) at the compilation step.

@@ -287,12 +287,12 @@

Running models with OpenCL

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.9.

diff --git a/docs/articles/cmdstanr-internals.html b/docs/articles/cmdstanr-internals.html index cc89ad19..d034b318 100644 --- a/docs/articles/cmdstanr-internals.html +++ b/docs/articles/cmdstanr-internals.html @@ -12,7 +12,7 @@ - + @@ -40,7 +40,7 @@ cmdstanr - 0.7.0 + 0.8.1 @@ -172,21 +172,21 @@

Immediate compilationmod$print()
data {
   int<lower=0> N;
-  array[N] int<lower=0,upper=1> y;
+  array[N] int<lower=0, upper=1> y;
 }
 parameters {
-  real<lower=0,upper=1> theta;
+  real<lower=0, upper=1> theta;
 }
 model {
-  theta ~ beta(1,1);  // uniform prior on interval 0,1
+  theta ~ beta(1, 1); // uniform prior on interval 0,1
   y ~ bernoulli(theta);
 }
 mod$stan_file()
-
[1] "/Users/jgabry/.cmdstan/cmdstan-2.33.1/examples/bernoulli/bernoulli.stan"
+
[1] "/Users/jgabry/.cmdstan/cmdstan-2.35.0/examples/bernoulli/bernoulli.stan"
 mod$exe_file()
-
[1] "/Users/jgabry/.cmdstan/cmdstan-2.33.1/examples/bernoulli/bernoulli"
+
[1] "/Users/jgabry/.cmdstan/cmdstan-2.35.0/examples/bernoulli/bernoulli"

Subsequently, if you create a CmdStanModel object from the same Stan file then compilation will be skipped (assuming the file hasn’t changed).

@@ -220,7 +220,7 @@

Delayed compilation
 mod$compile()
 mod$exe_file()
-
[1] "/Users/jgabry/.cmdstan/cmdstan-2.33.1/examples/bernoulli/bernoulli"
+
[1] "/Users/jgabry/.cmdstan/cmdstan-2.35.0/examples/bernoulli/bernoulli"

Pedantic check @@ -278,7 +278,7 @@

Pedantic check$compile() method directly if using the delayed compilation approach described above).

mod_pedantic <- cmdstan_model(stan_file_pedantic, pedantic = TRUE)
-Warning in '/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpXOnqh8/model-74281eb75594.stan', line 11, column 14: A
+Warning in '/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2hQnhs/model-9a1418059d6f.stan', line 11, column 14: A
     poisson distribution is given parameter lambda as a rate parameter
     (argument 1), but lambda was not constrained to be strictly positive.
 Warning: The parameter lambda has no priors. This means either no prior is
@@ -288,7 +288,7 @@ 

Pedantic checkpedantic argument to the $check_syntax() method.

mod_pedantic$check_syntax(pedantic = TRUE)
-Warning in '/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpXOnqh8/model_febb1e69c7387a0e64cf13583e078104.stan', line 11, column 14: A
+Warning in '/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2hQnhs/model_febb1e69c7387a0e64cf13583e078104.stan', line 11, column 14: A
     poisson distribution is given parameter lambda as a rate parameter
     (argument 1), but lambda was not constrained to be strictly positive.
 Warning: The parameter lambda has no priors. This means either no prior is
@@ -300,18 +300,18 @@ 

Pedantic check
file.remove(mod_pedantic$exe_file()) # delete compiled executable
-[1] TRUE
-rm(mod_pedantic)
-
-mod_pedantic <- cmdstan_model(stan_file_pedantic, compile = FALSE)
-mod_pedantic$check_syntax(pedantic = TRUE)
-Warning in '/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpXOnqh8/model_febb1e69c7387a0e64cf13583e078104.stan', line 11, column 14: A
-    poisson distribution is given parameter lambda as a rate parameter
-    (argument 1), but lambda was not constrained to be strictly positive.
-Warning: The parameter lambda has no priors. This means either no prior is
-    provided, or the prior(s) depend on data variables. In the later case,
-    this may be a false positive.
-Stan program is syntactically correct
+[1] TRUE

+
rm(mod_pedantic)
+
+mod_pedantic <- cmdstan_model(stan_file_pedantic, compile = FALSE)
+mod_pedantic$check_syntax(pedantic = TRUE)
+Warning in '/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2hQnhs/model_febb1e69c7387a0e64cf13583e078104.stan', line 11, column 14: A
+    poisson distribution is given parameter lambda as a rate parameter
+    (argument 1), but lambda was not constrained to be strictly positive.
+Warning: The parameter lambda has no priors. This means either no prior is
+    provided, or the prior(s) depend on data variables. In the later case,
+    this may be a false positive.
+Stan program is syntactically correct

Stan model variables @@ -320,7 +320,7 @@

Stan model variables
+
 stan_file_variables <- write_stan_file("
 data {
   int<lower=1> J;
@@ -351,47 +351,47 @@ 

Stan model variables
+
 names(variables)
[1] "parameters"             "included_files"         "data"                  
 [4] "transformed_parameters" "generated_quantities"  
-
+
 names(variables$data)
[1] "J"     "sigma" "y"    
-
+
 names(variables$parameters)
[1] "mu"        "tau"       "theta_raw"
-
+
 names(variables$transformed_parameters)
[1] "theta"
-
+
 names(variables$generated_quantities)
character(0)

Each variable is represented as a list containing the type information (currently limited to real or int) and the number of dimensions.

-
+
 variables$data$J
$type
 [1] "int"
 
 $dimensions
 [1] 0
-
+
 variables$data$sigma
$type
 [1] "real"
 
 $dimensions
 [1] 1
-
+
 variables$parameters$tau
$type
 [1] "real"
 
 $dimensions
 [1] 0
-
+
 variables$transformed_parameters$theta
$type
 [1] "real"
@@ -405,7 +405,7 @@ 

Executable location
+
 mod <- cmdstan_model(stan_file, dir = "path/to/directory/for/executable")

@@ -427,20 +427,20 @@

Named list of R objectsN, the number of data points, and y an integer array of observations.

-
+
 mod$print()
data {
   int<lower=0> N;
-  array[N] int<lower=0,upper=1> y;
+  array[N] int<lower=0, upper=1> y;
 }
 parameters {
-  real<lower=0,upper=1> theta;
+  real<lower=0, upper=1> theta;
 }
 model {
-  theta ~ beta(1,1);  // uniform prior on interval 0,1
+  theta ~ beta(1, 1); // uniform prior on interval 0,1
   y ~ bernoulli(theta);
 }
-
+
 # data block has 'N' and 'y'
 data_list <- list(N = 10, y = c(0,1,0,0,0,0,0,0,0,1))
 fit <- mod$sample(data = data_list)
@@ -448,7 +448,7 @@

Named list of R objectswrite_stan_json(). This happens internally, but it is also possible to call write_stan_json() directly.

-
+
 data_list <- list(N = 10, y = c(0,1,0,0,0,0,0,0,0,1))
 json_file <- tempfile(fileext = ".json")
 write_stan_json(data_list, json_file)
@@ -465,7 +465,7 @@ 

JSON filewrite_stan_json():

-
+
 fit <- mod$sample(data = json_file)
@@ -475,7 +475,7 @@

R dump filerstan::stan_rdump():

-
+
 rdump_file <- tempfile(fileext = ".data.R")
 rstan::stan_rdump(names(data_list), file = rdump_file, envir = list2env(data_list))
 cat(readLines(rdump_file), sep = "\n")
@@ -488,31 +488,31 @@ 

Writing CmdStan output to CSV

Default temporary files

-
+
 data_list <- list(N = 10, y = c(0,1,0,0,0,0,0,0,0,1))
 fit <- mod$sample(data = data_list)

When fitting a model, the default behavior is to write the output from CmdStan to CSV files in a temporary directory.

-
+
 fit$output_files()
-
[1] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpXOnqh8/bernoulli-202312131009-1-37e810.csv"
-[2] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpXOnqh8/bernoulli-202312131009-2-37e810.csv"
-[3] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpXOnqh8/bernoulli-202312131009-3-37e810.csv"
-[4] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpXOnqh8/bernoulli-202312131009-4-37e810.csv"
+
[1] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2hQnhs/bernoulli-202407021546-1-2808db.csv"
+[2] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2hQnhs/bernoulli-202407021546-2-2808db.csv"
+[3] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2hQnhs/bernoulli-202407021546-3-2808db.csv"
+[4] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2hQnhs/bernoulli-202407021546-4-2808db.csv"

These files will be lost if you end your R session or if you remove the fit object and force (or wait for) garbage collection.

-
+
 files <- fit$output_files()
 file.exists(files)
[1] TRUE TRUE TRUE TRUE
-
+
 rm(fit)
 gc()
-
          used (Mb) gc trigger  (Mb) limit (Mb) max used  (Mb)
-Ncells 1260600 67.4    2436292 130.2         NA  2436292 130.2
-Vcells 2212085 16.9    8388608  64.0      32768  3459642  26.4
-
+
          used (Mb) gc trigger  (Mb) limit (Mb) max used (Mb)
+Ncells 1155803 61.8    2350794 125.6         NA  1542121 82.4
+Vcells 2048173 15.7    8388608  64.0      32768  2851724 21.8
+
 file.exists(files)
[1] FALSE FALSE FALSE FALSE
@@ -523,10 +523,10 @@

Non-temporary files
+
 # see ?save_output_files for info on optional arguments
 fit$save_output_files(dir = "path/to/directory")
-
+
 fit <- mod$sample(
   data = data_list,
   output_dir = "path/to/directory"
@@ -546,7 +546,7 @@ 

Lazy CSV readingfit object, notice how the Private slot draws_ is NULL, indicating that the CSV files haven’t yet been read into R.

-
+
 str(fit)
Classes 'CmdStanMCMC', 'CmdStanFit', 'R6' <CmdStanMCMC>
   Inherits from: <CmdStanFit>
@@ -555,6 +555,7 @@ 

Lazy CSV readingLazy CSV readingLazy CSV readingLazy CSV readingLazy CSV reading

After we call a method that requires the draws then if we reexamine the structure of the object we will see that the draws_ slot in Private is no longer empty.

-
+
 
Classes 'CmdStanMCMC', 'CmdStanFit', 'R6' <CmdStanMCMC>
@@ -617,6 +621,7 @@ 

Lazy CSV readingLazy CSV readingLazy CSV readingLazy CSV readingLazy CSV reading

For models with many parameters, transformed parameters, or generated @@ -678,19 +686,19 @@

read_cmdstan_csv()read_cmdstan_csv() function is used to read the CmdStan CSV files into R. This function is exposed to users, so you can also call it directly.

-
+
 # see ?read_cmdstan_csv for info on optional arguments controlling
 # what information is read in
 csv_contents <- read_cmdstan_csv(fit$output_files())
 str(csv_contents)
List of 8
- $ metadata                       :List of 40
+ $ metadata                       :List of 42
   ..$ stan_version_major  : num 2
-  ..$ stan_version_minor  : num 33
+  ..$ stan_version_minor  : num 35
   ..$ stan_version_patch  : num 0
-  ..$ start_datetime      : chr "2023-12-13 17:09:13 UTC"
+  ..$ start_datetime      : chr "2024-07-02 21:46:33 UTC"
   ..$ method              : chr "sample"
-  ..$ save_warmup         : num 0
+  ..$ save_warmup         : int 0
   ..$ thin                : num 1
   ..$ gamma               : num 0.05
   ..$ kappa               : num 0.75
@@ -698,6 +706,7 @@ 

read_cmdstan_csv()read_cmdstan_csv()read_cmdstan_csv()read_cmdstan_csv()as_cmdstan_fit()

If you need to manually create fitted model objects from CmdStan CSV files use as_cmdstan_fit().

-
+
 fit2 <- as_cmdstan_fit(fit$output_files())

This is pointless in our case since we have the original fit object, but this function can be used to create fitted @@ -783,32 +793,32 @@

Saving and

CmdStanR does not yet provide a special method for processing these files but they can be read into R using R’s standard CSV reading functions.

-
-fit <- mod$sample(data = data_list, save_latent_dynamics = TRUE)
+fit <- mod$sample(data = data_list, save_latent_dynamics = TRUE)
+
 fit$latent_dynamics_files()
-
[1] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpXOnqh8/bernoulli-diagnostic-202312131009-1-425883.csv"
-[2] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpXOnqh8/bernoulli-diagnostic-202312131009-2-425883.csv"
-[3] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpXOnqh8/bernoulli-diagnostic-202312131009-3-425883.csv"
-[4] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpXOnqh8/bernoulli-diagnostic-202312131009-4-425883.csv"
-
+
[1] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2hQnhs/bernoulli-diagnostic-202407021546-1-54a823.csv"
+[2] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2hQnhs/bernoulli-diagnostic-202407021546-2-54a823.csv"
+[3] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2hQnhs/bernoulli-diagnostic-202407021546-3-54a823.csv"
+[4] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2hQnhs/bernoulli-diagnostic-202407021546-4-54a823.csv"
+
 # read one of the files in
 x <- utils::read.csv(fit$latent_dynamics_files()[1], comment.char = "#")
 head(x)
      lp__ accept_stat__ stepsize__ treedepth__ n_leapfrog__ divergent__
-1 -9.73111      1.000000   0.932232           2            3           0
-2 -6.75346      1.000000   0.932232           1            3           0
-3 -8.48107      0.665681   0.932232           1            3           0
-4 -7.74234      1.000000   0.932232           1            1           0
-5 -6.82333      1.000000   0.932232           2            3           0
-6 -6.82333      0.784555   0.932232           1            3           0
-  energy__      theta   p_theta   g_theta
-1 10.97150  0.3939970 -2.155610  4.166930
-2  9.05119 -1.0295100 -2.933880  0.158161
-3  8.61284  0.0530292  0.702591  3.159050
-4  8.45793 -0.2148440  1.637290  2.357940
-5  7.76204 -1.3633100  1.875250 -0.555575
-6  8.04989 -1.3633100 -2.143570 -0.555575
+1 -6.77025 0.987691 0.980824 2 3 0 +2 -7.20991 0.932461 0.980824 2 3 0 +3 -7.66830 0.933065 0.980824 1 1 0 +4 -7.37078 1.000000 0.980824 1 1 0 +5 -7.59961 0.948892 0.980824 2 3 0 +6 -7.95801 0.940559 0.980824 2 3 0 + energy__ theta p_theta g_theta +1 7.08007 -0.959636 -1.160790 0.323414 +2 7.21726 -1.779880 0.178790 -1.268180 +3 7.67261 -2.089350 -0.136971 -1.678370 +4 7.66302 -1.898700 -1.127370 -1.436940 +5 8.20617 -2.047820 -1.624180 -1.628720 +6 8.67205 -2.252980 1.762220 -1.858880

The column lp__ is also provided via fit$draws(), and the columns accept_stat__, stepsize__, treedepth__, @@ -816,15 +826,15 @@

Saving and energy__ are also provided by fit$sampler_diagnostics(), but there are several columns unique to the latent dynamics file.

-
+
 head(x[, c("theta", "p_theta", "g_theta")])
-
       theta   p_theta   g_theta
-1  0.3939970 -2.155610  4.166930
-2 -1.0295100 -2.933880  0.158161
-3  0.0530292  0.702591  3.159050
-4 -0.2148440  1.637290  2.357940
-5 -1.3633100  1.875250 -0.555575
-6 -1.3633100 -2.143570 -0.555575
+
      theta   p_theta   g_theta
+1 -0.959636 -1.160790  0.323414
+2 -1.779880  0.178790 -1.268180
+3 -2.089350 -0.136971 -1.678370
+4 -1.898700 -1.127370 -1.436940
+5 -2.047820 -1.624180 -1.628720
+6 -2.252980  1.762220 -1.858880

Our model has a single parameter theta and the three columns above correspond to theta in the unconstrained space (theta on the constrained @@ -867,22 +877,24 @@

Troubleshooting and debugging to TRUE.

-
+
 options("cmdstanr_verbose"=TRUE)
 
 mod <- cmdstan_model(stan_file, force_recompile = TRUE)
Running make \
-  /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpXOnqh8/model-742871ce8467 \
+  /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2hQnhs/model-9a14560da326 \
   "STANCFLAGS +=  --name='bernoulli_model'"
 
 --- Translating Stan model to C++ code ---
-bin/stanc --name='bernoulli_model' --o=/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpXOnqh8/model-742871ce8467.hpp /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpXOnqh8/model-742871ce8467.stan
+bin/stanc --name='bernoulli_model' --o=/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2hQnhs/model-9a14560da326.hpp /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2hQnhs/model-9a14560da326.stan
+
+--- Compiling C++ code ---
+clang++ -Wno-deprecated-declarations -Wno-deprecated-declarations -std=c++17 -Wno-unknown-warning-option -Wno-tautological-compare -Wno-sign-compare -D_REENTRANT -Wno-ignored-attributes      -I stan/lib/stan_math/lib/tbb_2020.3/include    -O3 -I src -I stan/src -I stan/lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.4.0 -I stan/lib/stan_math/lib/boost_1.84.0 -I stan/lib/stan_math/lib/sundials_6.1.1/include -I stan/lib/stan_math/lib/sundials_6.1.1/src/sundials    -DBOOST_DISABLE_ASSERTS          -c -include-pch stan/src/stan/model/model_header.hpp.gch/model_header_15_0.hpp.gch -x c++ -o /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2hQnhs/model-9a14560da326.o /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2hQnhs/model-9a14560da326.hpp
 
---- Compiling, linking C++ code ---
-clang++ -Wno-deprecated-declarations -Wno-deprecated-declarations -std=c++1y -Wno-unknown-warning-option -Wno-tautological-compare -Wno-sign-compare -D_REENTRANT -Wno-ignored-attributes      -I stan/lib/stan_math/lib/tbb_2020.3/include    -O3 -I src -I stan/src -I stan/lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.4.0 -I stan/lib/stan_math/lib/boost_1.78.0 -I stan/lib/stan_math/lib/sundials_6.1.1/include -I stan/lib/stan_math/lib/sundials_6.1.1/src/sundials    -DBOOST_DISABLE_ASSERTS          -c -include-pch stan/src/stan/model/model_header_13_0.hpp.gch -x c++ -o /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpXOnqh8/model-742871ce8467.o /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpXOnqh8/model-742871ce8467.hpp
-clang++ -Wno-deprecated-declarations -Wno-deprecated-declarations -std=c++1y -Wno-unknown-warning-option -Wno-tautological-compare -Wno-sign-compare -D_REENTRANT -Wno-ignored-attributes      -I stan/lib/stan_math/lib/tbb_2020.3/include    -O3 -I src -I stan/src -I stan/lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.4.0 -I stan/lib/stan_math/lib/boost_1.78.0 -I stan/lib/stan_math/lib/sundials_6.1.1/include -I stan/lib/stan_math/lib/sundials_6.1.1/src/sundials    -DBOOST_DISABLE_ASSERTS               -Wl,-L,"/Users/jgabry/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/tbb" -Wl,-rpath,"/Users/jgabry/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/tbb"        /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpXOnqh8/model-742871ce8467.o src/cmdstan/main.o       -Wl,-L,"/Users/jgabry/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/tbb" -Wl,-rpath,"/Users/jgabry/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/tbb"     stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_nvecserial.a stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_cvodes.a stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_idas.a stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_kinsol.a  stan/lib/stan_math/lib/tbb/libtbb.dylib stan/lib/stan_math/lib/tbb/libtbbmalloc.dylib stan/lib/stan_math/lib/tbb/libtbbmalloc_proxy.dylib -o /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpXOnqh8/model-742871ce8467
-rm -f /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpXOnqh8/model-742871ce8467.o
-
+--- Linking model ---
+clang++ -Wno-deprecated-declarations -Wno-deprecated-declarations -std=c++17 -Wno-unknown-warning-option -Wno-tautological-compare -Wno-sign-compare -D_REENTRANT -Wno-ignored-attributes      -I stan/lib/stan_math/lib/tbb_2020.3/include    -O3 -I src -I stan/src -I stan/lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.4.0 -I stan/lib/stan_math/lib/boost_1.84.0 -I stan/lib/stan_math/lib/sundials_6.1.1/include -I stan/lib/stan_math/lib/sundials_6.1.1/src/sundials    -DBOOST_DISABLE_ASSERTS               -Wl,-L,"/Users/jgabry/.cmdstan/cmdstan-2.35.0/stan/lib/stan_math/lib/tbb"   -Wl,-rpath,"/Users/jgabry/.cmdstan/cmdstan-2.35.0/stan/lib/stan_math/lib/tbb"      /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2hQnhs/model-9a14560da326.o src/cmdstan/main.o       -ltbb   stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_nvecserial.a stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_cvodes.a stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_idas.a stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_kinsol.a  stan/lib/stan_math/lib/tbb/libtbb.dylib stan/lib/stan_math/lib/tbb/libtbbmalloc.dylib stan/lib/stan_math/lib/tbb/libtbbmalloc_proxy.dylib -o /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2hQnhs/model-9a14560da326
+rm /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2hQnhs/model-9a14560da326.hpp /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2hQnhs/model-9a14560da326.o
+
 fit <- mod$sample(
   data = data_list,
   chains = 1,
@@ -891,28 +903,29 @@ 

Troubleshooting and debugging)

Running MCMC with 1 chain...
 
-Running ./bernoulli 'id=1' random 'seed=90958316' data \
-  'file=/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpXOnqh8/standata-742874baeb02.json' \
+Running ./bernoulli 'id=1' random 'seed=707272264' data \
+  'file=/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2hQnhs/standata-9a144d3dc244.json' \
   output \
-  'file=/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpXOnqh8/bernoulli-202312131009-1-4db120.csv' \
-  'profile_file=/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpXOnqh8/bernoulli-profile-202312131009-1-1c1f83.csv' \
+  'file=/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2hQnhs/bernoulli-202407021546-1-38ac27.csv' \
+  'profile_file=/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmp2hQnhs/bernoulli-profile-202407021546-1-910909.csv' \
   'method=sample' 'num_samples=100' 'num_warmup=100' 'save_warmup=0' \
   'algorithm=hmc' 'engine=nuts' adapt 'engaged=1'
 Chain 1 method = sample (Default) 
 Chain 1   sample 
 Chain 1     num_samples = 100 
 Chain 1     num_warmup = 100 
-Chain 1     save_warmup = 0 (Default) 
+Chain 1     save_warmup = false (Default) 
 Chain 1     thin = 1 (Default) 
 Chain 1     adapt 
-Chain 1       engaged = 1 (Default) 
-Chain 1       gamma = 0.050000000000000003 (Default) 
-Chain 1       delta = 0.80000000000000004 (Default) 
+Chain 1       engaged = true (Default) 
+Chain 1       gamma = 0.05 (Default) 
+Chain 1       delta = 0.8 (Default) 
 Chain 1       kappa = 0.75 (Default) 
 Chain 1       t0 = 10 (Default) 
 Chain 1       init_buffer = 75 (Default) 
 Chain 1       term_buffer = 50 (Default) 
 Chain 1       window = 25 (Default) 
+Chain 1       save_metric = false (Default) 
 Chain 1     algorithm = hmc (Default) 
 Chain 1       hmc 
 Chain 1         engine = nuts (Default) 
@@ -925,19 +938,20 @@ 

Troubleshooting and debuggingTroubleshooting and debuggingTroubleshooting and debugging

-

Developed by Jonah Gabry, Rok Češnovar, Andrew Johnson.

+

Developed by Jonah Gabry, Rok Češnovar, Andrew Johnson, Steve Bronder.

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.9.

diff --git a/docs/articles/cmdstanr.html b/docs/articles/cmdstanr.html index cac1ca1b..06f9ad3c 100644 --- a/docs/articles/cmdstanr.html +++ b/docs/articles/cmdstanr.html @@ -12,7 +12,7 @@ - + @@ -26,7 +26,7 @@ - +
@@ -49,7 +49,7 @@
  • - +
  • @@ -64,7 +64,7 @@
  • - +
    @@ -133,15 +133,15 @@

    Getting started with CmdStanR

    Jonah Gabry, Rok Češnovar, and Andrew Johnson

    - - + + Source: vignettes/cmdstanr.Rmd
    - - + +

    Introduction

    @@ -154,7 +154,7 @@

    Introduction
     # we recommend running this is a fresh R session or restarting your current session
    -install.packages("cmdstanr", repos = c("https://stan-dev.r-universe.dev", getOption("repos")))

    +install.packages("cmdstanr", repos = c('https://stan-dev.r-universe.dev', getOption("repos")))

    We can now load the package like any other R package. We’ll also load the bayesplot and posterior packages to use later in examples.

    @@ -214,10 +214,10 @@

    Installing CmdStancmdstan_version():

    -
    [1] "/Users/jgabry/.cmdstan/cmdstan-2.33.1"
    +
    [1] "/Users/jgabry/.cmdstan/cmdstan-2.35.0"
    -
    [1] "2.33.1"
    +
    [1] "2.35.0"

    Compiling a model @@ -241,20 +241,20 @@

    Compiling a modelmod$print()

    data {
       int<lower=0> N;
    -  array[N] int<lower=0,upper=1> y;
    +  array[N] int<lower=0, upper=1> y;
     }
     parameters {
    -  real<lower=0,upper=1> theta;
    +  real<lower=0, upper=1> theta;
     }
     model {
    -  theta ~ beta(1,1);  // uniform prior on interval 0,1
    +  theta ~ beta(1, 1); // uniform prior on interval 0,1
       y ~ bernoulli(theta);
     }

    The path to the compiled executable is returned by the $exe_file() method:

     mod$exe_file()
    -
    [1] "/Users/jgabry/.cmdstan/cmdstan-2.33.1/examples/bernoulli/bernoulli"
    +
    [1] "/Users/jgabry/.cmdstan/cmdstan-2.35.0/examples/bernoulli/bernoulli"

    Running MCMC @@ -277,30 +277,30 @@

    Running MCMC)

    Running MCMC with 4 parallel chains...
     
    -Chain 1 Iteration:    1 / 2000 [  0%]  (Warmup)
    -Chain 1 Iteration:  500 / 2000 [ 25%]  (Warmup)
    -Chain 1 Iteration: 1000 / 2000 [ 50%]  (Warmup)
    -Chain 1 Iteration: 1001 / 2000 [ 50%]  (Sampling)
    -Chain 1 Iteration: 1500 / 2000 [ 75%]  (Sampling)
    -Chain 1 Iteration: 2000 / 2000 [100%]  (Sampling)
    -Chain 2 Iteration:    1 / 2000 [  0%]  (Warmup)
    -Chain 2 Iteration:  500 / 2000 [ 25%]  (Warmup)
    -Chain 2 Iteration: 1000 / 2000 [ 50%]  (Warmup)
    -Chain 2 Iteration: 1001 / 2000 [ 50%]  (Sampling)
    -Chain 2 Iteration: 1500 / 2000 [ 75%]  (Sampling)
    -Chain 2 Iteration: 2000 / 2000 [100%]  (Sampling)
    -Chain 3 Iteration:    1 / 2000 [  0%]  (Warmup)
    -Chain 3 Iteration:  500 / 2000 [ 25%]  (Warmup)
    -Chain 3 Iteration: 1000 / 2000 [ 50%]  (Warmup)
    -Chain 3 Iteration: 1001 / 2000 [ 50%]  (Sampling)
    -Chain 3 Iteration: 1500 / 2000 [ 75%]  (Sampling)
    -Chain 3 Iteration: 2000 / 2000 [100%]  (Sampling)
    -Chain 4 Iteration:    1 / 2000 [  0%]  (Warmup)
    -Chain 4 Iteration:  500 / 2000 [ 25%]  (Warmup)
    -Chain 4 Iteration: 1000 / 2000 [ 50%]  (Warmup)
    -Chain 4 Iteration: 1001 / 2000 [ 50%]  (Sampling)
    -Chain 4 Iteration: 1500 / 2000 [ 75%]  (Sampling)
    -Chain 4 Iteration: 2000 / 2000 [100%]  (Sampling)
    +Chain 1 Iteration:    1 / 2000 [  0%]  (Warmup) 
    +Chain 1 Iteration:  500 / 2000 [ 25%]  (Warmup) 
    +Chain 1 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
    +Chain 1 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
    +Chain 1 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
    +Chain 1 Iteration: 2000 / 2000 [100%]  (Sampling) 
    +Chain 2 Iteration:    1 / 2000 [  0%]  (Warmup) 
    +Chain 2 Iteration:  500 / 2000 [ 25%]  (Warmup) 
    +Chain 2 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
    +Chain 2 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
    +Chain 2 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
    +Chain 2 Iteration: 2000 / 2000 [100%]  (Sampling) 
    +Chain 3 Iteration:    1 / 2000 [  0%]  (Warmup) 
    +Chain 3 Iteration:  500 / 2000 [ 25%]  (Warmup) 
    +Chain 3 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
    +Chain 3 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
    +Chain 3 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
    +Chain 3 Iteration: 2000 / 2000 [100%]  (Sampling) 
    +Chain 4 Iteration:    1 / 2000 [  0%]  (Warmup) 
    +Chain 4 Iteration:  500 / 2000 [ 25%]  (Warmup) 
    +Chain 4 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
    +Chain 4 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
    +Chain 4 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
    +Chain 4 Iteration: 2000 / 2000 [100%]  (Sampling) 
     Chain 1 finished in 0.0 seconds.
     Chain 2 finished in 0.0 seconds.
     Chain 3 finished in 0.0 seconds.
    @@ -347,17 +347,17 @@ 

    Summaries from the posterior packa posterior::default_summary_measures(), extra_quantiles = ~posterior::quantile2(., probs = c(.0275, .975)) )

    -
      variable  mean median   sd  mad    q5   q95 rhat ess_bulk ess_tail
    -1     lp__ -7.27  -7.00 0.71 0.34 -8.70 -6.75    1     1852     2114
    -2    theta  0.25   0.23 0.12 0.12  0.08  0.47    1     1611     1678
    +
      variable  mean median   sd  mad     q5   q95 rhat ess_bulk ess_tail
    +1     lp__ -7.31  -7.01 0.81 0.34 -8.871 -6.75    1     1404     1631
    +2    theta  0.26   0.24 0.13 0.13  0.079  0.49    1     1130     1314
      variable  mean   sd
    -1    theta  0.25 0.12
    -2     lp__ -7.27 0.71
    +1 theta 0.26 0.13 +2 lp__ -7.31 0.81

      variable pr_lt_half
    -1    theta       0.97
    -
      variable  mean median   sd  mad    q5   q95  q2.75 q97.5
    -1     lp__ -7.27  -7.00 0.71 0.34 -8.70 -6.75 -9.165 -6.75
    -2    theta  0.25   0.23 0.12 0.12  0.08  0.47  0.065  0.52
    +1 theta 0.96
    +
      variable  mean median   sd  mad     q5   q95  q2.75 q97.5
    +1     lp__ -7.31  -7.01 0.81 0.34 -8.871 -6.75 -9.443 -6.75
    +2    theta  0.26   0.24 0.13 0.13  0.079  0.49  0.063  0.54

    CmdStan’s stansummary utility @@ -384,7 +384,7 @@

    Extracting draws# iterations x chains x variables draws_arr <- fit$draws() # or format="array" str(draws_arr)

    -
     'draws_array' num [1:1000, 1:4, 1:2] -6.78 -6.9 -7.05 -6.85 -6.75 ...
    +
     'draws_array' num [1:1000, 1:4, 1:2] -7.01 -7.89 -7.41 -6.75 -6.91 ...
      - attr(*, "dimnames")=List of 3
       ..$ iteration: chr [1:1000] "1" "2" "3" "4" ...
       ..$ chain    : chr [1:4] "1" "2" "3" "4"
    @@ -394,8 +394,8 @@ 

    Extracting drawsdraws_df <- fit$draws(format = "df") str(draws_df)

    draws_df [4,000 × 5] (S3: draws_df/draws/tbl_df/tbl/data.frame)
    - $ lp__      : num [1:4000] -6.78 -6.9 -7.05 -6.85 -6.75 ...
    - $ theta     : num [1:4000] 0.284 0.186 0.162 0.196 0.252 ...
    + $ lp__      : num [1:4000] -7.01 -7.89 -7.41 -6.75 -6.91 ...
    + $ theta     : num [1:4000] 0.168 0.461 0.409 0.249 0.185 ...
      $ .chain    : int [1:4000] 1 1 1 1 1 1 1 1 1 1 ...
      $ .iteration: int [1:4000] 1 2 3 4 5 6 7 8 9 10 ...
      $ .draw     : int [1:4000] 1 2 3 4 5 6 7 8 9 10 ...
    @@ -403,16 +403,16 @@

    Extracting drawsprint(draws_df)

    # A draws_df: 1000 iterations, 4 chains, and 2 variables
        lp__ theta
    -1  -6.8  0.28
    -2  -6.9  0.19
    -3  -7.0  0.16
    -4  -6.9  0.20
    -5  -6.7  0.25
    -6  -7.1  0.36
    -7  -9.0  0.55
    -8  -7.2  0.15
    -9  -6.8  0.23
    -10 -7.5  0.42
    +1  -7.0  0.17
    +2  -7.9  0.46
    +3  -7.4  0.41
    +4  -6.7  0.25
    +5  -6.9  0.18
    +6  -6.9  0.33
    +7  -7.2  0.15
    +8  -6.8  0.29
    +9  -6.8  0.24
    +10 -6.8  0.24
     # ... with 3990 more draws
     # ... hidden reserved variables {'.chain', '.iteration', '.draw'}

    To convert an existing draws object to a different format use the @@ -426,6 +426,10 @@

    Extracting draws$draws() method, but in most cases the speed difference will be minor.

    +

    The vignette Working with +Posteriors has more details on posterior draws, including how to +reproduce the structured output RStan users are accustomed to getting +from rstan::extract().

    Plotting draws @@ -453,7 +457,7 @@

    Extracting di
     # this is a draws_array object from the posterior package
     str(fit$sampler_diagnostics())
    -
     'draws_array' num [1:1000, 1:4, 1:6] 1 2 2 2 2 1 1 1 1 2 ...
    +
     'draws_array' num [1:1000, 1:4, 1:6] 2 1 2 2 2 1 2 1 2 1 ...
      - attr(*, "dimnames")=List of 3
       ..$ iteration: chr [1:1000] "1" "2" "3" "4" ...
       ..$ chain    : chr [1:4] "1" "2" "3" "4"
    @@ -462,12 +466,12 @@ 

    Extracting di # this is a draws_df object from the posterior package str(fit$sampler_diagnostics(format = "df"))

    draws_df [4,000 × 9] (S3: draws_df/draws/tbl_df/tbl/data.frame)
    - $ treedepth__  : num [1:4000] 1 2 2 2 2 1 1 1 1 2 ...
    + $ treedepth__  : num [1:4000] 2 1 2 2 2 1 2 1 2 1 ...
      $ divergent__  : num [1:4000] 0 0 0 0 0 0 0 0 0 0 ...
    - $ energy__     : num [1:4000] 6.79 6.9 7.06 7 7.9 ...
    - $ accept_stat__: num [1:4000] 0.996 0.984 0.988 1 0.835 ...
    - $ stepsize__   : num [1:4000] 1.03 1.03 1.03 1.03 1.03 ...
    - $ n_leapfrog__ : num [1:4000] 1 3 3 3 3 3 1 3 3 3 ...
    + $ energy__     : num [1:4000] 8.95 8.77 7.87 7.64 6.93 ...
    + $ accept_stat__: num [1:4000] 0.688 0.811 1 0.966 0.976 ...
    + $ stepsize__   : num [1:4000] 0.905 0.905 0.905 0.905 0.905 ...
    + $ n_leapfrog__ : num [1:4000] 3 3 3 3 3 3 3 3 3 3 ...
      $ .chain       : int [1:4000] 1 1 1 1 1 1 1 1 1 1 ...
      $ .iteration   : int [1:4000] 1 2 3 4 5 6 7 8 9 10 ...
      $ .draw        : int [1:4000] 1 2 3 4 5 6 7 8 9 10 ...
    @@ -487,7 +491,7 @@

    Sampler diagnostic warnings a [1] 0 0 0 0 $ebfmi -[1] 1.0 1.3 1.1 1.2

    +[1] 1.11 0.80 1.05 0.95

    We see the number of divergences for each of the four chains, the number of times the maximum treedepth was hit for each chain, and the E-BFMI for each chain.

    @@ -496,34 +500,33 @@

    Sampler diagnostic warnings a suffers from divergences.

     fit_with_warning <- cmdstanr_example("schools")
    -
    Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
    -
    Chain 4 Exception: normal_lpdf: Scale parameter is 0, but must be positive! (in '/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmpl3ZPjU/model-76ac71f3c1fe.stan', line 14, column 2 to column 41)
    -
    Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
    -
    Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
    -
    Chain 4 
    -
    Warning: 149 of 4000 (4.0%) transitions ended with a divergence.
    +
    Warning: 374 of 4000 (9.0%) transitions ended with a divergence.
    +See https://mc-stan.org/misc/warnings for details.
    +
    Warning: 1 of 4 chains had an E-BFMI less than 0.3.
     See https://mc-stan.org/misc/warnings for details.

    After fitting there is a warning about divergences. We can also regenerate this warning message later using fit$diagnostic_summary().

    -
    +
     diagnostics <- fit_with_warning$diagnostic_summary()
    -
    Warning: 149 of 4000 (4.0%) transitions ended with a divergence.
    +
    Warning: 374 of 4000 (9.0%) transitions ended with a divergence.
    +See https://mc-stan.org/misc/warnings for details.
    +
    Warning: 1 of 4 chains had an E-BFMI less than 0.3.
     See https://mc-stan.org/misc/warnings for details.
    -
    +
     print(diagnostics)
    $num_divergent
    -[1] 11 54 32 52
    +[1] 269  29  11  65
     
     $num_max_treedepth
     [1] 0 0 0 0
     
     $ebfmi
    -[1] 0.40 0.36 0.37 0.30
    -
    +[1] 0.15 0.34 0.38 0.37
    +
     # number of divergences reported in warning is the sum of the per chain values
     sum(diagnostics$num_divergent)
    -
    [1] 149
    +
    [1] 374

    CmdStan’s diagnose utility @@ -544,7 +547,7 @@

    Create a stanfit object
    +
     

    @@ -562,26 +565,26 @@

    Optimization$optimize().

    -
    +
     fit_mle <- mod$optimize(data = data_list, seed = 123)
    -
    Initial log joint probability = -9.51104
    -    Iter      log prob        ||dx||      ||grad||       alpha      alpha0  # evals  Notes
    -       6      -5.00402   0.000103557   2.55661e-07           1           1        9
    -Optimization terminated normally:
    -  Convergence detected: relative gradient magnitude is below tolerance
    +
    Initial log joint probability = -16.144 
    +    Iter      log prob        ||dx||      ||grad||       alpha      alpha0  # evals  Notes  
    +       6      -5.00402   0.000246518   8.73164e-07           1           1        9    
    +Optimization terminated normally:  
    +  Convergence detected: relative gradient magnitude is below tolerance 
     Finished in  0.2 seconds.
    -
    +
     fit_mle$print() # includes lp__ (log prob calculated by Stan program)
     variable estimate
         lp__     -5.00
         theta     0.20
    -
    +
     fit_mle$mle("theta")
    theta 
       0.2 

    Here’s a plot comparing the penalized MLE to the posterior distribution of theta.

    -
    +
     mcmc_hist(fit$draws("theta")) +
       vline_at(fit_mle$mle("theta"), size = 1.5)

    @@ -592,18 +595,18 @@

    OptimizationMaximum Likelihood Estimation section of the CmdStan User’s Guide for more details.

    -
    +
     fit_map <- mod$optimize(
       data = data_list,
       jacobian = TRUE,
       seed = 123
     )
    -
    Initial log joint probability = -11.0088
    -    Iter      log prob        ||dx||      ||grad||       alpha      alpha0  # evals  Notes
    -       5      -6.74802   0.000938344   1.39149e-05           1           1        8
    -Optimization terminated normally:
    -  Convergence detected: relative gradient magnitude is below tolerance
    -Finished in  0.1 seconds.
    +
    Initial log joint probability = -18.2733 
    +    Iter      log prob        ||dx||      ||grad||       alpha      alpha0  # evals  Notes  
    +       5      -6.74802   0.000708195   1.43227e-05           1           1        8    
    +Optimization terminated normally:  
    +  Convergence detected: relative gradient magnitude is below tolerance 
    +Finished in  0.2 seconds.

    Laplace Approximation @@ -621,7 +624,7 @@

    Laplace Approximationmode argument. If mode is omitted then optimization will be run internally before taking draws from the normal approximation.

    -
    +
    -
    Calculating Hessian
    -Calculating inverse of Cholesky factor
    -Generating draws
    -iteration: 0
    -iteration: 1000
    -iteration: 2000
    -iteration: 3000
    +
    Calculating Hessian 
    +Calculating inverse of Cholesky factor 
    +Generating draws 
    +iteration: 0 
    +iteration: 1000 
    +iteration: 2000 
    +iteration: 3000 
     Finished in  0.1 seconds.
    -
    +
     fit_laplace$print("theta")
     variable mean median   sd  mad   q5  q95
    -    theta 0.27   0.25 0.12 0.12 0.10 0.50
    -
    +    theta 0.27   0.25 0.12 0.12 0.10 0.51
    +
     mcmc_hist(fit_laplace$draws("theta"), binwidth = 0.025)

    @@ -652,40 +655,40 @@

    Variational (ADVI)$variational() method. For details on the ADVI algorithm see the CmdStan User’s Guide.

    -
    +
     fit_vb <- mod$variational(
       data = data_list,
       seed = 123,
       draws = 4000
     )
    -
    ------------------------------------------------------------
    -EXPERIMENTAL ALGORITHM:
    -  This procedure has not been thoroughly tested and may be unstable
    -  or buggy. The interface is subject to change.
    -------------------------------------------------------------
    -Gradient evaluation took 5e-06 seconds
    -1000 transitions using 10 leapfrog steps per transition would take 0.05 seconds.
    -Adjust your expectations accordingly!
    -Begin eta adaptation.
    -Iteration:   1 / 250 [  0%]  (Adaptation)
    -Iteration:  50 / 250 [ 20%]  (Adaptation)
    -Iteration: 100 / 250 [ 40%]  (Adaptation)
    -Iteration: 150 / 250 [ 60%]  (Adaptation)
    -Iteration: 200 / 250 [ 80%]  (Adaptation)
    -Success! Found best value [eta = 1] earlier than expected.
    -Begin stochastic gradient ascent.
    -  iter             ELBO   delta_ELBO_mean   delta_ELBO_med   notes
    -   100           -6.262             1.000            1.000
    -   200           -6.263             0.500            1.000
    -   300           -6.307             0.336            0.007   MEDIAN ELBO CONVERGED
    -Drawing a sample of size 4000 from the approximate posterior...
    -COMPLETED.
    +
    ------------------------------------------------------------ 
    +EXPERIMENTAL ALGORITHM: 
    +  This procedure has not been thoroughly tested and may be unstable 
    +  or buggy. The interface is subject to change. 
    +------------------------------------------------------------ 
    +Gradient evaluation took 1.3e-05 seconds 
    +1000 transitions using 10 leapfrog steps per transition would take 0.13 seconds. 
    +Adjust your expectations accordingly! 
    +Begin eta adaptation. 
    +Iteration:   1 / 250 [  0%]  (Adaptation) 
    +Iteration:  50 / 250 [ 20%]  (Adaptation) 
    +Iteration: 100 / 250 [ 40%]  (Adaptation) 
    +Iteration: 150 / 250 [ 60%]  (Adaptation) 
    +Iteration: 200 / 250 [ 80%]  (Adaptation) 
    +Success! Found best value [eta = 1] earlier than expected. 
    +Begin stochastic gradient ascent. 
    +  iter             ELBO   delta_ELBO_mean   delta_ELBO_med   notes  
    +   100           -6.164             1.000            1.000 
    +   200           -6.225             0.505            1.000 
    +   300           -6.186             0.339            0.010   MEDIAN ELBO CONVERGED 
    +Drawing a sample of size 4000 from the approximate posterior...  
    +COMPLETED. 
     Finished in  0.1 seconds.
    -
    +
     fit_vb$print("theta")
     variable mean median   sd  mad   q5  q95
    -    theta 0.27   0.25 0.12 0.12 0.10 0.49
    -
    +    theta 0.26   0.24 0.11 0.11 0.11 0.46
    +
     mcmc_hist(fit_vb$draws("theta"), binwidth = 0.025)

    @@ -697,31 +700,31 @@

    Variational (Pathfinder)CmdStan User’s Guide. Pathfinder is run using the $pathfinder() method.

    -
    +
     fit_pf <- mod$pathfinder(
       data = data_list,
       seed = 123,
       draws = 4000
     )
    -
    Path [1] :Initial log joint density = -11.008832
    -Path [1] : Iter      log prob        ||dx||      ||grad||     alpha      alpha0      # evals       ELBO    Best ELBO        Notes
    -              5      -6.748e+00      9.383e-04   1.391e-05    1.000e+00  1.000e+00       126 -6.264e+00 -6.264e+00
    -Path [1] :Best Iter: [3] ELBO (-6.195408) evaluations: (126)
    -Path [2] :Initial log joint density = -7.318450
    -Path [2] : Iter      log prob        ||dx||      ||grad||     alpha      alpha0      # evals       ELBO    Best ELBO        Notes
    -              4      -6.748e+00      5.414e-03   1.618e-04    1.000e+00  1.000e+00       101 -6.251e+00 -6.251e+00
    -Path [2] :Best Iter: [3] ELBO (-6.229174) evaluations: (101)
    -Path [3] :Initial log joint density = -12.374612
    -Path [3] : Iter      log prob        ||dx||      ||grad||     alpha      alpha0      # evals       ELBO    Best ELBO        Notes
    -              5      -6.748e+00      1.419e-03   2.837e-05    1.000e+00  1.000e+00       126 -6.199e+00 -6.199e+00
    -Path [3] :Best Iter: [5] ELBO (-6.199185) evaluations: (126)
    -Path [4] :Initial log joint density = -13.009824
    -Path [4] : Iter      log prob        ||dx||      ||grad||     alpha      alpha0      # evals       ELBO    Best ELBO        Notes
    -              5      -6.748e+00      1.677e-03   3.885e-05    1.000e+00  1.000e+00       126 -6.173e+00 -6.173e+00
    -Path [4] :Best Iter: [5] ELBO (-6.172860) evaluations: (126)
    -Total log probability function evaluations:4379
    +
    Path [1] :Initial log joint density = -18.273334 
    +Path [1] : Iter      log prob        ||dx||      ||grad||     alpha      alpha0      # evals       ELBO    Best ELBO        Notes  
    +              5      -6.748e+00      7.082e-04   1.432e-05    1.000e+00  1.000e+00       126 -6.145e+00 -6.145e+00                   
    +Path [1] :Best Iter: [5] ELBO (-6.145070) evaluations: (126) 
    +Path [2] :Initial log joint density = -19.192715 
    +Path [2] : Iter      log prob        ||dx||      ||grad||     alpha      alpha0      # evals       ELBO    Best ELBO        Notes  
    +              5      -6.748e+00      2.015e-04   2.228e-06    1.000e+00  1.000e+00       126 -6.223e+00 -6.223e+00                   
    +Path [2] :Best Iter: [2] ELBO (-6.170358) evaluations: (126) 
    +Path [3] :Initial log joint density = -6.774820 
    +Path [3] : Iter      log prob        ||dx||      ||grad||     alpha      alpha0      # evals       ELBO    Best ELBO        Notes  
    +              4      -6.748e+00      1.137e-04   2.596e-07    1.000e+00  1.000e+00       101 -6.178e+00 -6.178e+00                   
    +Path [3] :Best Iter: [4] ELBO (-6.177909) evaluations: (101) 
    +Path [4] :Initial log joint density = -7.949193 
    +Path [4] : Iter      log prob        ||dx||      ||grad||     alpha      alpha0      # evals       ELBO    Best ELBO        Notes  
    +              5      -6.748e+00      2.145e-04   1.301e-06    1.000e+00  1.000e+00       126 -6.197e+00 -6.197e+00                   
    +Path [4] :Best Iter: [5] ELBO (-6.197118) evaluations: (126) 
    +Total log probability function evaluations:4379 
     Finished in  0.1 seconds.
    -
    +
     fit_pf$print("theta")
     variable mean median   sd  mad   q5  q95
         theta 0.25   0.24 0.12 0.12 0.08 0.47
    @@ -729,22 +732,22 @@

    Variational (Pathfinder) -
    +
     mcmc_hist(fit_pf$draws("theta"), binwidth = 0.025) +
       ggplot2::labs(subtitle = "Approximate posterior from pathfinder") +
       ggplot2::xlim(0, 1)

    -
    +
     mcmc_hist(fit_vb$draws("theta"), binwidth = 0.025) +
       ggplot2::labs(subtitle = "Approximate posterior from variational") +
       ggplot2::xlim(0, 1)

    -
    +
     mcmc_hist(fit_laplace$draws("theta"), binwidth = 0.025) +
       ggplot2::labs(subtitle = "Approximate posterior from Laplace") +
       ggplot2::xlim(0, 1)

    -
    +
     mcmc_hist(fit$draws("theta"), binwidth = 0.025) +
       ggplot2::labs(subtitle = "Posterior from MCMC") +
       ggplot2::xlim(0, 1)
    @@ -768,7 +771,7 @@

    Saving fitted model objects
    +
     fit$save_object(file = "fit.RDS")
     
     # can be read back in using readRDS
    @@ -780,7 +783,7 @@ 

    Saving fitted model objects$save_object() and replace saveRDS with the much faster qsave() function from the qs package.

    -
    +
     # Load CmdStan output files into the fitted model object.
     fit$draws() # Load posterior draws into the object.
     try(fit$sampler_diagnostics(), silent = TRUE) # Load sampler diagnostics.
    @@ -796,7 +799,7 @@ 

    Saving fitted model objects
    +
     
     

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    + - - + diff --git a/docs/articles/cmdstanr_files/figure-html/laplace-1.png b/docs/articles/cmdstanr_files/figure-html/laplace-1.png index ed19be52..975e63a2 100644 Binary files a/docs/articles/cmdstanr_files/figure-html/laplace-1.png and b/docs/articles/cmdstanr_files/figure-html/laplace-1.png differ diff --git a/docs/articles/cmdstanr_files/figure-html/plot-compare-laplace-1.png b/docs/articles/cmdstanr_files/figure-html/plot-compare-laplace-1.png index 087e11fd..a0eca79f 100644 Binary files a/docs/articles/cmdstanr_files/figure-html/plot-compare-laplace-1.png and b/docs/articles/cmdstanr_files/figure-html/plot-compare-laplace-1.png differ diff --git a/docs/articles/cmdstanr_files/figure-html/plot-compare-mcmc-1.png b/docs/articles/cmdstanr_files/figure-html/plot-compare-mcmc-1.png index f5c674ee..6b4765df 100644 Binary files a/docs/articles/cmdstanr_files/figure-html/plot-compare-mcmc-1.png and b/docs/articles/cmdstanr_files/figure-html/plot-compare-mcmc-1.png differ diff --git a/docs/articles/cmdstanr_files/figure-html/plot-compare-pf-1.png b/docs/articles/cmdstanr_files/figure-html/plot-compare-pf-1.png index f72f9f29..d3495d11 100644 Binary files a/docs/articles/cmdstanr_files/figure-html/plot-compare-pf-1.png and b/docs/articles/cmdstanr_files/figure-html/plot-compare-pf-1.png differ diff --git a/docs/articles/cmdstanr_files/figure-html/plot-compare-vb-1.png b/docs/articles/cmdstanr_files/figure-html/plot-compare-vb-1.png index dd9d803e..d23f5c95 100644 Binary files a/docs/articles/cmdstanr_files/figure-html/plot-compare-vb-1.png and b/docs/articles/cmdstanr_files/figure-html/plot-compare-vb-1.png differ diff --git a/docs/articles/cmdstanr_files/figure-html/plot-mle-1.png b/docs/articles/cmdstanr_files/figure-html/plot-mle-1.png index 1998cf9a..8a373b96 100644 Binary files a/docs/articles/cmdstanr_files/figure-html/plot-mle-1.png and b/docs/articles/cmdstanr_files/figure-html/plot-mle-1.png differ diff --git a/docs/articles/cmdstanr_files/figure-html/plots-1.png b/docs/articles/cmdstanr_files/figure-html/plots-1.png index 4d847586..03122c05 100644 Binary files a/docs/articles/cmdstanr_files/figure-html/plots-1.png and b/docs/articles/cmdstanr_files/figure-html/plots-1.png differ diff --git a/docs/articles/cmdstanr_files/figure-html/variational-1.png b/docs/articles/cmdstanr_files/figure-html/variational-1.png index 7d8aa624..1fe52698 100644 Binary files a/docs/articles/cmdstanr_files/figure-html/variational-1.png and b/docs/articles/cmdstanr_files/figure-html/variational-1.png differ diff --git a/docs/articles/index.html b/docs/articles/index.html index c68f0512..c7286099 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -1,5 +1,5 @@ -Articles • cmdstanrArticles • cmdstanr @@ -17,7 +17,7 @@ cmdstanr - 0.7.0 + 0.8.1
    @@ -128,11 +128,11 @@

    More details

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/articles/posterior.html b/docs/articles/posterior.html index bf1156f8..a614e889 100644 --- a/docs/articles/posterior.html +++ b/docs/articles/posterior.html @@ -12,7 +12,7 @@ - + @@ -40,7 +40,7 @@ cmdstanr - 0.7.0 + 0.8.1

    @@ -147,36 +147,36 @@

    Summary statistics
     fit <- cmdstanr::cmdstanr_example("schools", method = "sample")

    -
    Warning: 411 of 4000 (10.0%) transitions ended with a divergence.
    +
    Warning: 124 of 4000 (3.0%) transitions ended with a divergence.
     See https://mc-stan.org/misc/warnings for details.
    -
    Warning: 1 of 4 chains had an E-BFMI less than 0.2.
    +
    Warning: 1 of 4 chains had an E-BFMI less than 0.3.
     See https://mc-stan.org/misc/warnings for details.
     fit$summary()
    -
       variable       mean     median       sd      mad         q5       q95
    -1      lp__ -55.581147 -56.536200 7.135791 7.809299 -66.108490 -44.17410
    -2        mu   6.053657   5.516030 3.777403 3.597633  -0.119312  12.18247
    -3       tau   4.456447   3.456865 3.641807 3.645828   0.778481  11.91315
    -4  theta[1]   8.436941   7.287125 6.350694 4.628344   0.249281  20.38983
    -5  theta[2]   6.522999   5.993620 5.308671 4.494072  -1.760367  15.64359
    -6  theta[3]   5.147676   4.349235 6.014958 5.082679  -5.803791  14.17618
    -7  theta[4]   6.189408   5.541310 5.578086 4.501730  -2.557880  15.63053
    -8  theta[5]   4.669689   4.952550 5.338198 4.271882  -5.029484  12.96141
    -9  theta[6]   5.123046   4.853110 5.623562 4.579796  -4.797084  13.70336
    -10 theta[7]   8.283195   7.324155 5.703079 4.912514   1.112880  18.94623
    -11 theta[8]   6.499894   5.594240 6.114406 4.839688  -2.747390  16.75831
    -       rhat   ess_bulk    ess_tail
    -1  1.348190   9.585696          NA
    -2  1.094243 190.870204  910.104440
    -3  1.305410  10.562073    4.833756
    -4  1.037209 205.819798 1097.512010
    -5  1.234963 615.265251 1158.714996
    -6  1.270209 429.358164 1118.125260
    -7  1.060915 288.566093 1331.398737
    -8  1.265317 356.169676 1352.544578
    -9  1.281493 482.412281 1311.140711
    -10 1.041368  75.113061  938.699910
    -11 1.069623 436.937773 1068.232198
    +
       variable       mean     median       sd      mad          q5       q95
    +1      lp__ -58.697829 -58.911800 5.056327 5.134318 -66.6875850 -49.89660
    +2        mu   6.353763   6.597480 4.381424 4.372565  -1.2281605  13.23484
    +3       tau   5.604807   4.871790 3.537844 3.371217   1.4006485  12.28454
    +4  theta[1]   9.416434   8.789030 7.469694 6.297677  -1.7534945  22.77244
    +5  theta[2]   6.708629   6.756395 5.775008 5.428570  -2.7675325  16.09375
    +6  theta[3]   5.013658   5.633410 7.082039 6.055554  -7.5991140  15.69620
    +7  theta[4]   6.479275   6.629210 6.113995 5.602212  -3.7474250  16.47548
    +8  theta[5]   4.415845   4.751705 5.837104 5.557445  -5.7668200  13.46467
    +9  theta[6]   5.316444   5.776025 6.132648 5.695771  -5.1632545  14.89951
    +10 theta[7]   9.159755   8.682990 6.276413 5.676549  -0.3210604  20.38977
    +11 theta[8]   7.114358   7.154305 6.994382 6.108230  -4.2959180  18.25591
    +       rhat  ess_bulk  ess_tail
    +1  1.018582  172.4200  135.9782
    +2  1.008425  635.3354 1168.1366
    +3  1.021625  165.4672  120.1282
    +4  1.003830 1073.3788 1319.6507
    +5  1.004990 1050.8445 1693.6799
    +6  1.007712  871.0003 1537.3018
    +7  1.003560 1027.3246 1869.0154
    +8  1.007430  780.1467 1587.7245
    +9  1.007162  917.8167 1453.6511
    +10 1.003741  956.3136 1718.3496
    +11 1.002369 1338.3238 1986.1357

    By default all variables are summaries with the follow functions:

    @@ -184,18 +184,18 @@

    Summary statistics
     fit$summary(variables = c("mu", "tau"))

    -
      variable     mean   median       sd      mad        q5      q95     rhat
    -1       mu 6.053657 5.516030 3.777403 3.597633 -0.119312 12.18247 1.094243
    -2      tau 4.456447 3.456865 3.641807 3.645828  0.778481 11.91315 1.305410
    -   ess_bulk   ess_tail
    -1 190.87020 910.104440
    -2  10.56207   4.833756
    +
      variable     mean  median       sd      mad        q5      q95     rhat
    +1       mu 6.353763 6.59748 4.381424 4.372565 -1.228160 13.23484 1.008425
    +2      tau 5.604807 4.87179 3.537844 3.371217  1.400649 12.28454 1.021625
    +  ess_bulk  ess_tail
    +1 635.3354 1168.1366
    +2 165.4672  120.1282

    We can additionally change which functions are used

     fit$summary(variables = c("mu", "tau"), mean, sd)
      variable     mean       sd
    -1       mu 6.053657 3.777403
    -2      tau 4.456447 3.641807
    +1 mu 6.353763 4.381424 +2 tau 5.604807 3.537844

    To summarize all variables with non-default functions, it is necessary to set explicitly set the variables argument, either to NULL or the full vector of variable names.

    @@ -206,17 +206,17 @@

    Summary statistics
     fit$summary(variables = NULL, "mean", "median")

       variable       mean     median
    -1      lp__ -55.581147 -56.536200
    -2        mu   6.053657   5.516030
    -3       tau   4.456447   3.456865
    -4  theta[1]   8.436941   7.287125
    -5  theta[2]   6.522999   5.993620
    -6  theta[3]   5.147676   4.349235
    -7  theta[4]   6.189408   5.541310
    -8  theta[5]   4.669689   4.952550
    -9  theta[6]   5.123046   4.853110
    -10 theta[7]   8.283195   7.324155
    -11 theta[8]   6.499894   5.594240
    +1 lp__ -58.697829 -58.911800 +2 mu 6.353763 6.597480 +3 tau 5.604807 4.871790 +4 theta[1] 9.416434 8.789030 +5 theta[2] 6.708629 6.756395 +6 theta[3] 5.013658 5.633410 +7 theta[4] 6.479275 6.629210 +8 theta[5] 4.415845 4.751705 +9 theta[6] 5.316444 5.776025 +10 theta[7] 9.159755 8.682990 +11 theta[8] 7.114358 7.154305

    Summary functions can be specified by character string, function, or using a formula (or anything else supported by rlang::as_function()). If these arguments are named, those @@ -232,32 +232,32 @@

    Summary statistics~quantile(.x, probs = c(0.1, 0.9)), Minimum = function(x) min(x) )

    -
      variable     MEAN   median    My_SD      10%       90%   Minimum
    -1       mu 6.053657 5.516030 3.777403 1.565533 10.863700 -8.554010
    -2      tau 4.456447 3.456865 3.641807 0.778481  9.666494  0.774844
    +
      variable     MEAN  median    My_SD      10%      90%   Minimum
    +1       mu 6.353763 6.59748 4.381424 0.756247 11.71914 -9.340540
    +2      tau 5.604807 4.87179 3.537844 1.723530 10.46083  0.749924

    Arguments to all summary functions can also be specified with .args.

     fit$summary(c("mu", "tau"), quantile, .args = list(probs = c(0.025, .05, .95, .975)))
      variable      2.5%        5%      95%    97.5%
    -1       mu -1.614829 -0.119312 12.18247 13.54298
    -2      tau  0.778481  0.778481 11.91315 13.43694
    +1 mu -2.926103 -1.228160 13.23484 14.96275 +2 tau 1.106000 1.400649 12.28454 14.09220

    The summary functions are applied to the array of sample values, with dimension iter_samplingxchains.

     fit$summary(variables = NULL, dim, colMeans)
       variable dim.1 dim.2          1          2          3          4
    -1      lp__  1000     4 -56.698590 -58.592226 -56.911658 -50.122112
    -2        mu  1000     4   6.836467   6.338743   6.214918   4.824501
    -3       tau  1000     4   4.751132   5.540196   4.617587   2.916872
    -4  theta[1]  1000     4   9.139180   9.470688   8.631066   6.506831
    -5  theta[2]  1000     4   7.088238   6.756565   6.691301   5.555891
    -6  theta[3]  1000     4   6.087235   5.430155   5.208329   3.864985
    -7  theta[4]  1000     4   6.963234   6.883517   6.322756   4.588127
    -8  theta[5]  1000     4   5.312623   4.530775   4.623091   4.212267
    -9  theta[6]  1000     4   5.778286   4.999767   5.497782   4.216348
    -10 theta[7]  1000     4   9.354323   9.367796   8.483796   5.926863
    -11 theta[8]  1000     4   7.269928   7.165762   6.670007   4.893880
    +1 lp__ 1000 4 -57.746884 -58.396713 -59.488281 -59.159440 +2 mu 1000 4 6.886773 6.098293 6.275602 6.154385 +3 tau 1000 4 4.969696 5.504146 6.035791 5.909594 +4 theta[1] 1000 4 9.584919 8.855289 9.788069 9.437459 +5 theta[2] 1000 4 7.218764 6.441512 6.701321 6.472920 +6 theta[3] 1000 4 6.039431 4.880572 4.532884 4.601744 +7 theta[4] 1000 4 6.923818 6.048362 6.708068 6.236851 +8 theta[5] 1000 4 5.339809 4.243510 3.959413 4.120650 +9 theta[6] 1000 4 5.971513 4.851822 5.284337 5.158102 +10 theta[7] 1000 4 9.310560 8.904282 9.350879 9.073298 +11 theta[8] 1000 4 7.380020 7.069916 7.245772 6.761726

    For this reason users may have unexpected results if they use stats::var() directly, as it will return a covariance matrix. An alternative is the distributional::variance() @@ -266,8 +266,8 @@

    Summary statistics
     fit$summary(c("mu", "tau"), posterior::variance, ~var(as.vector(.x)))

      variable posterior::variance ~var(as.vector(.x))
    -1       mu            14.26877            14.26877
    -2      tau            13.26276            13.26276
    +1 mu 19.19687 19.19687 +2 tau 12.51634 12.51634

    Summary functions need not be numeric, but these won’t work with $print().

    @@ -304,7 +304,7 @@ 

    Extracting posterior draws/samples# iterations x chains x variables draws_arr <- fit$draws() # or format="array" str(draws_arr)

    -
     'draws_array' num [1:1000, 1:4, 1:11] -61.7 -60.5 -61.8 -60.5 -66.8 ...
    +
     'draws_array' num [1:1000, 1:4, 1:11] -66.1 -61.6 -58.3 -57.5 -55.3 ...
      - attr(*, "dimnames")=List of 3
       ..$ iteration: chr [1:1000] "1" "2" "3" "4" ...
       ..$ chain    : chr [1:4] "1" "2" "3" "4"
    @@ -314,17 +314,17 @@ 

    Extracting posterior draws/samplesdraws_df <- fit$draws(format = "df") str(draws_df)

    draws_df [4,000 × 14] (S3: draws_df/draws/tbl_df/tbl/data.frame)
    - $ lp__      : num [1:4000] -61.7 -60.5 -61.8 -60.5 -66.8 ...
    - $ mu        : num [1:4000] 8.86 6.18 9.7 4.97 5.16 ...
    - $ tau       : num [1:4000] 5.6 8.77 7.58 7.37 11.97 ...
    - $ theta[1]  : num [1:4000] 16.716 14.062 6.67 6.25 -0.404 ...
    - $ theta[2]  : num [1:4000] 4.377 6.173 15.608 0.638 10.449 ...
    - $ theta[3]  : num [1:4000] 11.59 9.27 11.11 3.74 13.42 ...
    - $ theta[4]  : num [1:4000] 13.68 12.51 7.77 6.48 10.16 ...
    - $ theta[5]  : num [1:4000] -0.877 1.959 7.197 2.097 3.229 ...
    - $ theta[6]  : num [1:4000] -5.02 -4.95 5.66 5.24 14.26 ...
    - $ theta[7]  : num [1:4000] 13.38 17.44 13.69 6.65 13.77 ...
    - $ theta[8]  : num [1:4000] 10.46 5.48 -6.15 20.92 31.79 ...
    + $ lp__      : num [1:4000] -66.1 -61.6 -58.3 -57.5 -55.3 ...
    + $ mu        : num [1:4000] 1.93 8.57 4.05 9.53 9.94 ...
    + $ tau       : num [1:4000] 10.73 6.28 6.1 4.65 3.2 ...
    + $ theta[1]  : num [1:4000] 9.1 21.74 11.18 13.36 9.68 ...
    + $ theta[2]  : num [1:4000] 11.006 5.842 -0.815 17.943 11.148 ...
    + $ theta[3]  : num [1:4000] 0.4 12.17 7.94 6.17 3.94 ...
    + $ theta[4]  : num [1:4000] -3.74 14.86 6.59 9.74 7.95 ...
    + $ theta[5]  : num [1:4000] 12.97 5.5 1.32 8.77 12.83 ...
    + $ theta[6]  : num [1:4000] -11.04 1.81 6.18 6.33 6.56 ...
    + $ theta[7]  : num [1:4000] 22.21 10.53 7.75 14.3 11.54 ...
    + $ theta[8]  : num [1:4000] 14.77 -2.98 11.19 7.25 10.37 ...
      $ .chain    : int [1:4000] 1 1 1 1 1 1 1 1 1 1 ...
      $ .iteration: int [1:4000] 1 2 3 4 5 6 7 8 9 10 ...
      $ .draw     : int [1:4000] 1 2 3 4 5 6 7 8 9 10 ...
    @@ -332,23 +332,49 @@

    Extracting posterior draws/samplesprint(draws_df)

    # A draws_df: 1000 iterations, 4 chains, and 11 variables
        lp__   mu  tau theta[1] theta[2] theta[3] theta[4] theta[5]
    -1   -62  8.9  5.6     16.7     4.38     11.6   13.676    -0.88
    -2   -61  6.2  8.8     14.1     6.17      9.3   12.515     1.96
    -3   -62  9.7  7.6      6.7    15.61     11.1    7.770     7.20
    -4   -60  5.0  7.4      6.3     0.64      3.7    6.477     2.10
    -5   -67  5.2 12.0     -0.4    10.45     13.4   10.162     3.23
    -6   -63 11.1  7.9     24.6    11.68     18.8   -1.606     3.79
    -7   -61 14.7  6.1     28.9    11.15     15.3    6.780     9.95
    -8   -63 13.4  5.7     13.7    21.03      7.2   20.051    12.99
    -9   -64 16.0  8.3     20.2     2.65     11.3   19.000     3.51
    -10  -59  2.9  4.5      4.2    11.37      2.5   -0.057     6.30
    +1   -66  1.9 10.7      9.1    11.01      0.4     -3.7     13.0
    +2   -62  8.6  6.3     21.7     5.84     12.2     14.9      5.5
    +3   -58  4.1  6.1     11.2    -0.82      7.9      6.6      1.3
    +4   -58  9.5  4.6     13.4    17.94      6.2      9.7      8.8
    +5   -55  9.9  3.2      9.7    11.15      3.9      7.9     12.8
    +6   -55  9.9  4.0      8.5     8.81      6.6      9.8     12.0
    +7   -54  9.7  2.7     14.5    10.87      5.8      6.8     10.2
    +8   -52  8.7  2.2     10.5    10.42      9.4      9.8      9.4
    +9   -57 10.1  5.0     13.4    10.29     11.4      5.8     12.0
    +10  -58 10.5  5.5     14.8     9.45     13.9      5.6     12.0
     # ... with 3990 more draws, and 3 more variables
     # ... hidden reserved variables {'.chain', '.iteration', '.draw'}

    To convert an existing draws object to a different format use the posterior::as_draws_*() functions.

    To manipulate the draws objects use the various methods -described in the posterior package vignettes +described in the posterior package vignettes and documentation.

    +
    +

    Structured draws similar to rstan::extract() +

    +

    The posterior package’s rvar format +provides a multidimensional, sample-based representation of random +variables. See https://mc-stan.org/posterior/articles/rvar.html for +details. In addition to being useful in its own right, this format also +allows CmdStanR users to obtain draws in a similar format to +rstan::extract().

    +

    Suppose we have a parameter matrix[2,3] x. The +rvar format lets you interact with x as if +it’s a 2 x 3 matrix and automatically applies operations +over the many posterior draws of x. To instead directly +access the draws of x while maintaining the structure of +the matrix use posterior::draws_of(). For example:

    +
    +draws <- posterior::as_draws_rvars(fit$draws())
    +x_rvar <- draws$x
    +x_array <- posterior::draws_of(draws$x)
    +

    The object x_rvar will be an rvar that can +be used like a 2 x 3 matrix, with the draws handled behind +the scenes. The object x_array will be a +4000 x 2 x 3 array (assuming 4000 posterior +draws), which is the same as it would be after being extracted from the +list returned by rstan::extract().

    +

    @@ -364,12 +390,12 @@

    Extracting posterior draws/samples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/articles/profiling.html b/docs/articles/profiling.html index dfbed9b1..2336b31c 100644 --- a/docs/articles/profiling.html +++ b/docs/articles/profiling.html @@ -12,7 +12,7 @@ - + @@ -40,7 +40,7 @@ cmdstanr - 0.7.0 + 0.8.1

    @@ -249,12 +249,12 @@

    Accessing the profiling info
     fit$profiles()
    [[1]]
    -        name   thread_id total_time forward_time reverse_time chain_stack
    -1 likelihood 0x118759e00 0.69970800   0.57529800   0.12441000       51468
    -2     priors 0x118759e00 0.00446571   0.00270154   0.00176417       34312
    +        name      thread_id total_time forward_time reverse_time chain_stack
    +1     priors 0x7ff858f85100 0.00636262    0.0041022   0.00226042       34634
    +2 likelihood 0x7ff858f85100 0.92346400    0.7530890   0.17037500       51951
       no_chain_stack autodiff_calls no_autodiff_calls
    -1       34329156          17156                 1
    -2          34312          17156                 1
    +1 34634 17317 1 +2 34651317 17317 1

    The total_time column is the total time spent inside a given profile statement. It is clear that the vast majority of time is spent in the likelihood function.

    @@ -296,12 +296,12 @@

    Comparing to a faster versio
     fit_glm$profiles()
    [[1]]
    -        name   thread_id total_time forward_time reverse_time chain_stack
    -1 likelihood 0x106ce4e00 0.38400000   0.38264800   0.00135175       52203
    -2     priors 0x106ce4e00 0.00356564   0.00237053   0.00119511       34802
    +        name      thread_id total_time forward_time reverse_time chain_stack
    +1     priors 0x7ff858f85100 0.00547866   0.00378008   0.00169859       34894
    +2 likelihood 0x7ff858f85100 0.55301400   0.55111300   0.00190093       52341
       no_chain_stack autodiff_calls no_autodiff_calls
    -1          17401          17401                 1
    -2          34802          17401                 1
    +1 34894 17447 1 +2 17447 17447 1

    We can see from the total_time column that this is much faster than the previous model.

    @@ -324,7 +324,7 @@

    Per-gradient timings, and memory profile_chain_1 <- fit$profiles()[[1]] per_gradient_timing <- profile_chain_1$total_time/profile_chain_1$autodiff_calls print(per_gradient_timing) # two elements for the two profile statements in the model

    -
    [1] 4.078503e-05 2.603002e-07
    +
    [1] 3.674205e-07 5.332702e-05

    Accessing and saving the profile files @@ -335,7 +335,7 @@

    Accessing and saving the profile $profile_files().

     fit$profile_files()
    -
    [1] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpJRtaoq/model_6580008f67848265f3dfd0e7ae3b0600-profile-202312131010-1-95e407.csv"
    +
    [1] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpEbNhyd/model_6580008f67848265f3dfd0e7ae3b0600-profile-202407021547-1-96d3d3.csv"

    These can be saved to a more permanent location with the $save_profile_files() method.

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/articles/r-markdown.html b/docs/articles/r-markdown.html index 23c674be..2f9ac3f1 100644 --- a/docs/articles/r-markdown.html +++ b/docs/articles/r-markdown.html @@ -12,7 +12,7 @@ - + @@ -40,7 +40,7 @@ cmdstanr - 0.7.0 + 0.8.1

    @@ -229,13 +229,14 @@

    Example#> #> All 4 chains finished successfully. #> Mean chain execution time: 0.0 seconds. -#> Total execution time: 0.7 seconds. - +#> Total execution time: 0.7 seconds.

    +
    +
     print(fit)
     #>  variable  mean median   sd  mad    q5   q95 rhat ess_bulk ess_tail
    -#>      lp__ -1.50  -1.17 1.24 0.96 -3.94 -0.18 1.00     1304     1536
    -#>      y[1] -0.01  -0.01 0.99 0.99 -1.67  1.60 1.00     1993     2262
    -#>      y[2] -0.07  -0.04 2.90 2.05 -4.79  4.54 1.00     2050     1420
    +#> lp__ -1.55 -1.24 1.24 1.04 -4.07 -0.18 1.00 1509 1671 +#> y[1] -0.03 -0.03 1.01 0.99 -1.69 1.68 1.00 1852 2195 +#> y[2] -0.13 -0.07 2.92 2.14 -4.92 4.65 1.00 1855 1666

    Option 3: Using both RStan and CmdStanR in the same R Markdown @@ -247,26 +248,26 @@

    project, the option to use both exists. When registering CmdStanR’s knitr engine, set override = FALSE to register the engine as a cmdstan engine:

    -
    +
     register_knitr_engine(override = FALSE)

    This will cause stan chunks to be processed by knitr’s built-in, RStan-based engine and only use CmdStanR’s knitr engine for cmdstan chunks:

    -
    ```{stan, output.var="model_obj1"}
    -// Results in a stanmodel object from RStan
    -```
    -
    -```{r}
    -rstan::sampling(model_obj1)
    -```
    -
    -```{cmdstan, output.var="model_obj2"}
    -// Results in a CmdStanModel object from CmdStanR
    -```
    -
    -```{r}
    -model_obj2$sample()
    -```
    +
    ```{stan, output.var="model_obj1"}
    +// Results in a stanmodel object from RStan
    +```
    +
    +```{r}
    +rstan::sampling(model_obj1)
    +```
    +
    +```{cmdstan, output.var="model_obj2"}
    +// Results in a CmdStanModel object from CmdStanR
    +```
    +
    +```{r}
    +model_obj2$sample()
    +```

    Caching chunks @@ -304,12 +305,12 @@

    Running interactively

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/authors.html b/docs/authors.html index 8c3fd645..fb693ea9 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -1,5 +1,5 @@ -Authors and Citation • cmdstanrAuthors and Citation • cmdstanr @@ -17,7 +17,7 @@ cmdstanr - 0.7.0 + 0.8.1

    @@ -99,12 +99,12 @@
    • -

      Jonah Gabry. Author, maintainer. +

      Jonah Gabry. Author.

    • @@ -112,7 +112,11 @@

      Authors

    • -

      Andrew Johnson. Author. +

      Andrew Johnson. Author, maintainer. +

      +
    • +
    • +

      Steve Bronder. Author.

    • @@ -144,7 +148,7 @@

      Authors

    • -

      Steve Bronder. Contributor. +

      Ven Popov. Contributor.

    @@ -156,15 +160,16 @@

    Citation

    -

    Gabry J, Češnovar R, Johnson A (2023). +

    Gabry J, Češnovar R, Johnson A, Bronder S (2024). cmdstanr: R Interface to 'CmdStan'. -https://mc-stan.org/cmdstanr/, https://discourse.mc-stan.org. +R package version 0.8.1, https://discourse.mc-stan.org, https://mc-stan.org/cmdstanr/.

    @Manual{,
       title = {cmdstanr: R Interface to 'CmdStan'},
    -  author = {Jonah Gabry and Rok Češnovar and Andrew Johnson},
    -  year = {2023},
    -  note = {https://mc-stan.org/cmdstanr/, https://discourse.mc-stan.org},
    +  author = {Jonah Gabry and Rok Češnovar and Andrew Johnson and Steve Bronder},
    +  year = {2024},
    +  note = {R package version 0.8.1, https://discourse.mc-stan.org},
    +  url = {https://mc-stan.org/cmdstanr/},
     }

    @@ -174,11 +179,11 @@

    Citation

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/index.html b/docs/index.html index 54947fb0..de070a6d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -12,18 +12,13 @@ - + - + - +
    @@ -54,7 +49,7 @@
  • - +
  • @@ -69,7 +64,7 @@
  • - +
    @@ -156,7 +151,7 @@

    Goals
  • A clean interface to Stan services so that CmdStanR can keep up with Stan releases.

  • R code that doesn’t interface directly with C++, only calls compiled executables.

  • Modularity: CmdStanR runs Stan’s algorithms and lets downstream modules do the analysis.

  • -
  • Flexible BSD-3 license.

  • +
  • Flexible BSD-3 license.

  • @@ -167,8 +162,8 @@

    Installing the R package

    You can install the latest beta release of the cmdstanr R package with

    +# we recommend running this in a fresh R session or restarting your current session +install.packages("cmdstanr", repos = c('https://stan-dev.r-universe.dev', getOption("repos")))

    This does not install the vignettes, which take a long time to build, but they are always available online at https://mc-stan.org/cmdstanr/articles/.

    To instead install the latest development version of the package from GitHub use

    @@ -233,9 +228,10 @@ 

    Citation

    Developers

      -
    • Jonah Gabry
      Author, maintainer
    • +
    • Jonah Gabry
      Author
    • Rok Češnovar
      Author
    • -
    • Andrew Johnson
      Author
    • +
    • Andrew Johnson
      Author, maintainer
    • +
    • Steve Bronder
      Author
    • More about authors...
    @@ -248,21 +244,21 @@

    Developers

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    + - - + diff --git a/docs/news/index.html b/docs/news/index.html index f702a044..b66cb1ab 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -1,5 +1,5 @@ -Changelog • cmdstanrChangelog • cmdstanr @@ -17,7 +17,7 @@ cmdstanr - 0.7.0 + 0.8.1
    @@ -102,6 +102,61 @@

    Changelog

    Source: NEWS.md
    +
    + +
    +

    Minor changes

    +
    • Added CMDSTANR_USE_RTOOLS environment variable to force stock RTools on Windows by @andrjohns in #980
    • +
    • Added support for Windows ARM64 by @andrjohns in #990
    • +
    • Automatically initialise model methods when called, add inc_warmup argument to $unconstrain_draws() by @andrjohns in #985
    • +
    +
    +

    Bugfixes

    +
    • Fix errors when using pathfinder object as initial values by @avehtari in #984
    • +
    • Fix error with $unconstrain_draws() returning incorrect assumptions in some cases by @andrjohns in #983
    • +
    • Fix spurious errors about missing CmdStan config files by @andrjohns in #981
    • +
    • Fix linking error when exposing SUNDIALS/KINSOL functions or model methods by @andrjohns in #977
    • +
    • Fix long-standing error with OneDrive paths on Windows by @andrjohns in #990
    • +
    +
    +
    + +
    +

    Major new features

    +
    • Add functionality for passing CmdStanFit objects as initial values by @SteveBronder in #937
    • +
    +
    +

    Other improvements

    +
    • Add compatibility with CmdStan 2.35 by @andrjohns in #972
    • +
    • Add show_messages and show_exceptions arguments to all methods for controlling output by @andrjohns in #897
    • +
    • Drop RcppEigen dependency, implement basic Eigen -> C++ interop by @andrjohns in #899
    • +
    • Add compatibility with CmdStan 2.34 by @andrjohns in #905 #910
    • +
    • Add a format argument to the unconstrain_draws() method to specify draws format of return by @andrjohns in #886
    • +
    • Align cmdstanr EBFMI diagnostic threshold with CmdStan by @andrjohns in #892
    • +
    • Add global option cmdstanr_print_line_numbers to add line number to model printing by @sbfnk in #967
    • +
    • Add new CmdStan arguments save_metric and save_cmdstan_config by @venpopov in #932
    • +
    • Add documentation for CmdStanR global options by @jgabry in #951
    • +
    • Add documentation for how to obtain structured output similar to rstan::extract() using a combination of cmdstanr and posterior by @jgabry in #955
    • +
    • Added coercion generics for CmdStanFit objects by @gowerc in #943
    • +
    • +psis_resample and calculate_lp arguments added to Pathfinder method by @SteveBronder in #903
    • +
    • Documentation and tests for LOO method updated by @jgabry in #923
    • +
    • Global option cmdstanr_warn_inits added to disable warnings about partially specified initial values by @jgabry in #913
    • +
    • Updates to MCMC output_dir documentation by @jgabry in #929
    • +
    +
    +

    Bugfixes

    +
    • Fix broken link in OpenCL documentation by @eipi10 in #908
    • +
    • Fix a minor typo in the README by @jgabry in #911
    • +
    • Make exported RNG functions respect changes to R’s seed by @andrjohns in #973
    • +
    • Optimisations for model methods functions by @andrjohns in #960
    • +
    • Bugfix for passing function for initial values with Pathfinder method and default num_paths by @andrjohns in #964
    • +
    • Continue with compilation if compile_stanalone=TRUE but no functions are found by @jgabry in #956
    • +
    • Update tests and CI for compatibility with MacOS ARM64 by @andrjohns in #958
    • +
    • Fix handling of inv_metric argument with only 1 parameter by @venpopov in #935
    • +
    • Fixes for compatibility with RTools44 by @andrjohns in #952 #959
    • +
    +
    diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 14ff6a17..427640f5 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -1,14 +1,14 @@ -pandoc: 3.1.1 -pkgdown: 2.0.7 +pandoc: 3.1.11 +pkgdown: 2.0.9 pkgdown_sha: ~ articles: - opencl: articles-online-only/opencl.html cmdstanr-internals: cmdstanr-internals.html cmdstanr: cmdstanr.html + opencl: articles-online-only/opencl.html posterior: posterior.html profiling: profiling.html r-markdown: r-markdown.html -last_built: 2023-12-13T17:00Z +last_built: 2024-07-02T21:30Z urls: reference: https://mc-stan.org/cmdstanr/reference article: https://mc-stan.org/cmdstanr/articles diff --git a/docs/reference/CmdStanDiagnose.html b/docs/reference/CmdStanDiagnose.html index e0d66d56..8a2a8930 100644 --- a/docs/reference/CmdStanDiagnose.html +++ b/docs/reference/CmdStanDiagnose.html @@ -1,5 +1,5 @@ -CmdStanDiagnose objects — CmdStanDiagnose • cmdstanrCmdStanDiagnose objects — CmdStanDiagnose • cmdstanrCmdStanGQ objects — CmdStanGQ • cmdstanrCmdStanGQ objects — CmdStanGQ • cmdstanrCmdStanLaplace objects — CmdStanLaplace • cmdstanrCmdStanLaplace objects — CmdStanLaplace • cmdstanrCmdStanMCMC objects — CmdStanMCMC • cmdstanrCmdStanMCMC objects — CmdStanMCMC • cmdstanrCmdStanMLE objects — CmdStanMLE • cmdstanrCmdStanMLE objects — CmdStanMLE • cmdstanrCmdStanModel objects — CmdStanModel • cmdstanrCmdStanModel objects — CmdStanModel • cmdstanrCmdStanPathfinder objects — CmdStanPathfinder • cmdstanrCmdStanPathfinder objects — CmdStanPathfinder • cmdstanrCmdStanVB objects — CmdStanVB • cmdstanrCmdStanVB objects — CmdStanVB • cmdstanrCreate a draws object from a CmdStanR fitted model object — as_draws.CmdStanMCMC • cmdstanrCreate a draws object from a CmdStanR fitted model object — as_draws.CmdStanMCMC • cmdstanrConvert CmdStanMCMC to mcmc.list — as_mcmc.list • cmdstanrConvert CmdStanMCMC to mcmc.list — as_mcmc.list • cmdstanr cmdstanr - 0.7.0 + 0.8.1
    @@ -153,11 +153,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/cmdstan_coercion.html b/docs/reference/cmdstan_coercion.html new file mode 100644 index 00000000..f0de9503 --- /dev/null +++ b/docs/reference/cmdstan_coercion.html @@ -0,0 +1,164 @@ + +Coercion methods for CmdStan objects — cmdstan_coercion • cmdstanr + + +
    +
    + + + +
    +
    + + +
    +

    These are generic functions intended to primarily be used by developers of +packages that interface with on CmdStanR. Developers can define methods on +top of these generics to coerce objects into CmdStanR's fitted model objects.

    +
    + +
    +
    as.CmdStanMCMC(object, ...)
    +
    +as.CmdStanMLE(object, ...)
    +
    +as.CmdStanLaplace(object, ...)
    +
    +as.CmdStanVB(object, ...)
    +
    +as.CmdStanPathfinder(object, ...)
    +
    +as.CmdStanGQ(object, ...)
    +
    +as.CmdStanDiagnose(object, ...)
    +
    + +
    +

    Arguments

    +
    object
    +

    The object to be coerced.

    + + +
    ...
    +

    Additional arguments to pass to methods.

    + +
    + +
    + +
    + + +
    + +
    +

    Site built with pkgdown 2.0.9.

    +
    + +
    + + + + + + + + diff --git a/docs/reference/cmdstan_default_install_path.html b/docs/reference/cmdstan_default_install_path.html index e2ca8ac8..d8ecd6d6 100644 --- a/docs/reference/cmdstan_default_install_path.html +++ b/docs/reference/cmdstan_default_install_path.html @@ -1,5 +1,5 @@ -cmdstan_default_install_path — cmdstan_default_install_path • cmdstanrcmdstan_default_install_path — cmdstan_default_install_path • cmdstanr @@ -17,7 +17,7 @@ cmdstanr - 0.7.0 + 0.8.1
    @@ -137,11 +137,11 @@

    Value

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/cmdstan_default_path.html b/docs/reference/cmdstan_default_path.html index 01f43b73..826c04c6 100644 --- a/docs/reference/cmdstan_default_path.html +++ b/docs/reference/cmdstan_default_path.html @@ -1,5 +1,5 @@ -cmdstan_default_path — cmdstan_default_path • cmdstanrcmdstan_default_path — cmdstan_default_path • cmdstanrCreate a new CmdStanModel object — cmdstan_model • cmdstanrCreate a new CmdStanModel object — cmdstan_model • cmdstanr cmdstanr - 0.7.0 + 0.8.1

    @@ -185,7 +185,7 @@

    Examples

    # Otherwise use the `path` argument to specify the location of your # CmdStan installation.) set_cmdstan_path(path = NULL) -#> CmdStan path set to: /Users/jgabry/.cmdstan/cmdstan-2.33.1 +#> CmdStan path set to: /Users/jgabry/.cmdstan/cmdstan-2.35.0 # Create a CmdStanModel object from a Stan program, # here using the example model that comes with CmdStan @@ -194,15 +194,29 @@

    Examples

    mod$print() #> data { #> int<lower=0> N; -#> array[N] int<lower=0,upper=1> y; +#> array[N] int<lower=0, upper=1> y; #> } #> parameters { -#> real<lower=0,upper=1> theta; +#> real<lower=0, upper=1> theta; #> } #> model { -#> theta ~ beta(1,1); // uniform prior on interval 0,1 +#> theta ~ beta(1, 1); // uniform prior on interval 0,1 #> y ~ bernoulli(theta); #> } +# Print with line numbers. This can be set globally using the +# `cmdstanr_print_line_numbers` option. +mod$print(line_numbers = TRUE) +#> 1: data { +#> 2: int<lower=0> N; +#> 3: array[N] int<lower=0, upper=1> y; +#> 4: } +#> 5: parameters { +#> 6: real<lower=0, upper=1> theta; +#> 7: } +#> 8: model { +#> 9: theta ~ beta(1, 1); // uniform prior on interval 0,1 +#> 10: y ~ bernoulli(theta); +#> 11: } # Data as a named list (like RStan) stan_data <- list(N = 10, y = c(0,1,0,0,0,0,0,0,0,1)) @@ -273,8 +287,8 @@

    Examples

    #> # A tibble: 2 × 10 #> variable mean median sd mad q5 q95 rhat ess_bulk ess_tail #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp__ -7.30 -7.03 0.721 0.380 -8.82 -6.75 1.00 902. 1006. -#> 2 theta 0.247 0.233 0.122 0.129 0.0786 0.470 1.00 762. 712. +#> 1 lp__ -7.30 -7.00 0.811 0.344 -8.83 -6.75 1.00 702. 776. +#> 2 theta 0.254 0.238 0.125 0.124 0.0807 0.483 1.00 634. 580. # Check sampling diagnostics fit_mcmc$diagnostic_summary() @@ -285,7 +299,7 @@

    Examples

    #> [1] 0 0 #> #> $ebfmi -#> [1] 1.017555 1.250490 +#> [1] 1.1148699 0.8012192 #> # Get posterior draws @@ -295,22 +309,22 @@

    Examples

    #> , , variable = lp__ #> #> chain -#> iteration 1 2 -#> 1 -6.8 -6.8 -#> 2 -6.9 -6.8 -#> 3 -7.0 -7.0 -#> 4 -6.9 -7.1 -#> 5 -6.7 -7.0 +#> iteration 1 2 +#> 1 -7.0 -6.8 +#> 2 -7.9 -6.9 +#> 3 -7.4 -6.8 +#> 4 -6.7 -6.8 +#> 5 -6.9 -10.2 #> #> , , variable = theta #> #> chain #> iteration 1 2 -#> 1 0.28 0.21 -#> 2 0.19 0.20 -#> 3 0.16 0.17 -#> 4 0.20 0.36 -#> 5 0.25 0.34 +#> 1 0.17 0.23 +#> 2 0.46 0.18 +#> 3 0.41 0.28 +#> 4 0.25 0.23 +#> 5 0.18 0.62 #> #> # ... with 995 more iterations @@ -318,16 +332,16 @@

    Examples

    as_draws_df(draws) #> # A draws_df: 1000 iterations, 2 chains, and 2 variables #> lp__ theta -#> 1 -6.8 0.28 -#> 2 -6.9 0.19 -#> 3 -7.0 0.16 -#> 4 -6.9 0.20 -#> 5 -6.7 0.25 -#> 6 -7.1 0.36 -#> 7 -9.0 0.55 -#> 8 -7.2 0.15 -#> 9 -6.8 0.23 -#> 10 -7.5 0.42 +#> 1 -7.0 0.17 +#> 2 -7.9 0.46 +#> 3 -7.4 0.41 +#> 4 -6.7 0.25 +#> 5 -6.9 0.18 +#> 6 -6.9 0.33 +#> 7 -7.2 0.15 +#> 8 -6.8 0.29 +#> 9 -6.8 0.24 +#> 10 -6.8 0.24 #> # ... with 1990 more draws #> # ... hidden reserved variables {'.chain', '.iteration', '.draw'} @@ -345,12 +359,12 @@

    Examples

    # and also demonstrate specifying data as a path to a file instead of a list my_data_file <- file.path(cmdstan_path(), "examples/bernoulli/bernoulli.data.json") fit_optim <- mod$optimize(data = my_data_file, seed = 123) -#> Initial log joint probability = -9.51104 +#> Initial log joint probability = -16.144 #> Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes -#> 6 -5.00402 0.000103557 2.55661e-07 1 1 9 +#> 6 -5.00402 0.000246518 8.73164e-07 1 1 9 #> Optimization terminated normally: #> Convergence detected: relative gradient magnitude is below tolerance -#> Finished in 0.1 seconds. +#> Finished in 0.2 seconds. fit_optim$summary() #> # A tibble: 2 × 2 #> variable estimate @@ -361,12 +375,12 @@

    Examples

    # Run 'optimize' again with 'jacobian=TRUE' and then draw from Laplace approximation # to the posterior fit_optim <- mod$optimize(data = my_data_file, jacobian = TRUE) -#> Initial log joint probability = -17.5452 +#> Initial log joint probability = -13.9671 #> Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes -#> 5 -6.74802 0.00115356 2.90728e-05 1 1 8 +#> 5 -6.74802 0.00195337 5.29486e-05 1 1 8 #> Optimization terminated normally: #> Convergence detected: relative gradient magnitude is below tolerance -#> Finished in 0.1 seconds. +#> Finished in 0.2 seconds. fit_laplace <- mod$laplace(data = my_data_file, mode = fit_optim, draws = 2000) #> Calculating Hessian #> Calculating inverse of Cholesky factor @@ -391,14 +405,14 @@

    Examples

    #> iteration: 1700 #> iteration: 1800 #> iteration: 1900 -#> Finished in 0.1 seconds. +#> Finished in 0.2 seconds. fit_laplace$summary() #> # A tibble: 3 × 7 -#> variable mean median sd mad q5 q95 -#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp__ -7.27 -7.00 0.705 0.338 -8.72 -6.75 -#> 2 lp_approx__ -0.527 -0.251 0.714 0.340 -2.02 -0.00142 -#> 3 theta 0.270 0.251 0.126 0.125 0.0959 0.509 +#> variable mean median sd mad q5 q95 +#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> +#> 1 lp__ -7.21 -6.97 0.646 0.293 -8.55 -6.75 +#> 2 lp_approx__ -0.466 -0.220 0.655 0.297 -1.78 -0.00205 +#> 3 theta 0.270 0.250 0.120 0.121 0.109 0.497 # Run 'variational' method to use ADVI to approximate posterior fit_vb <- mod$variational(data = stan_data, seed = 123) @@ -407,8 +421,8 @@

    Examples

    #> This procedure has not been thoroughly tested and may be unstable #> or buggy. The interface is subject to change. #> ------------------------------------------------------------ -#> Gradient evaluation took 5e-06 seconds -#> 1000 transitions using 10 leapfrog steps per transition would take 0.05 seconds. +#> Gradient evaluation took 2.3e-05 seconds +#> 1000 transitions using 10 leapfrog steps per transition would take 0.23 seconds. #> Adjust your expectations accordingly! #> Begin eta adaptation. #> Iteration: 1 / 250 [ 0%] (Adaptation) @@ -419,50 +433,50 @@

    Examples

    #> Success! Found best value [eta = 1] earlier than expected. #> Begin stochastic gradient ascent. #> iter ELBO delta_ELBO_mean delta_ELBO_med notes -#> 100 -6.262 1.000 1.000 -#> 200 -6.263 0.500 1.000 -#> 300 -6.307 0.336 0.007 MEDIAN ELBO CONVERGED +#> 100 -6.164 1.000 1.000 +#> 200 -6.225 0.505 1.000 +#> 300 -6.186 0.339 0.010 MEDIAN ELBO CONVERGED #> Drawing a sample of size 1000 from the approximate posterior... #> COMPLETED. -#> Finished in 0.1 seconds. +#> Finished in 0.2 seconds. fit_vb$summary() #> # A tibble: 3 × 7 #> variable mean median sd mad q5 q95 #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp__ -7.18 -6.94 0.588 0.259 -8.36 -6.75 -#> 2 lp_approx__ -0.515 -0.221 0.692 0.303 -2.06 -0.00257 -#> 3 theta 0.263 0.246 0.115 0.113 0.106 0.481 +#> 1 lp__ -7.14 -6.93 0.528 0.247 -8.21 -6.75 +#> 2 lp_approx__ -0.520 -0.244 0.740 0.326 -1.90 -0.00227 +#> 3 theta 0.251 0.236 0.107 0.108 0.100 0.446 mcmc_hist(fit_vb$draws("theta")) #> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. # Run 'pathfinder' method, a new alternative to the variational method fit_pf <- mod$pathfinder(data = stan_data, seed = 123) -#> Path [1] :Initial log joint density = -11.008832 +#> Path [1] :Initial log joint density = -18.273334 #> Path [1] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 9.383e-04 1.391e-05 1.000e+00 1.000e+00 126 -6.264e+00 -6.264e+00 -#> Path [1] :Best Iter: [3] ELBO (-6.195408) evaluations: (126) -#> Path [2] :Initial log joint density = -7.318450 +#> 5 -6.748e+00 7.082e-04 1.432e-05 1.000e+00 1.000e+00 126 -6.145e+00 -6.145e+00 +#> Path [1] :Best Iter: [5] ELBO (-6.145070) evaluations: (126) +#> Path [2] :Initial log joint density = -19.192715 #> Path [2] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 4 -6.748e+00 5.414e-03 1.618e-04 1.000e+00 1.000e+00 101 -6.251e+00 -6.251e+00 -#> Path [2] :Best Iter: [3] ELBO (-6.229174) evaluations: (101) -#> Path [3] :Initial log joint density = -12.374612 +#> 5 -6.748e+00 2.015e-04 2.228e-06 1.000e+00 1.000e+00 126 -6.223e+00 -6.223e+00 +#> Path [2] :Best Iter: [2] ELBO (-6.170358) evaluations: (126) +#> Path [3] :Initial log joint density = -6.774820 #> Path [3] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 1.419e-03 2.837e-05 1.000e+00 1.000e+00 126 -6.199e+00 -6.199e+00 -#> Path [3] :Best Iter: [5] ELBO (-6.199185) evaluations: (126) -#> Path [4] :Initial log joint density = -13.009824 +#> 4 -6.748e+00 1.137e-04 2.596e-07 1.000e+00 1.000e+00 101 -6.178e+00 -6.178e+00 +#> Path [3] :Best Iter: [4] ELBO (-6.177909) evaluations: (101) +#> Path [4] :Initial log joint density = -7.949193 #> Path [4] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 1.677e-03 3.885e-05 1.000e+00 1.000e+00 126 -6.173e+00 -6.173e+00 -#> Path [4] :Best Iter: [5] ELBO (-6.172860) evaluations: (126) +#> 5 -6.748e+00 2.145e-04 1.301e-06 1.000e+00 1.000e+00 126 -6.197e+00 -6.197e+00 +#> Path [4] :Best Iter: [5] ELBO (-6.197118) evaluations: (126) #> Total log probability function evaluations:4379 -#> Finished in 0.1 seconds. +#> Finished in 0.2 seconds. fit_pf$summary() #> # A tibble: 3 × 7 #> variable mean median sd mad q5 q95 #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp_approx__ -1.08 -0.728 0.886 0.304 -2.71 -0.511 -#> 2 lp__ -7.26 -6.96 0.738 0.297 -8.72 -6.75 -#> 3 theta 0.249 0.230 0.120 0.121 0.0854 0.471 +#> 1 lp_approx__ -1.07 -0.727 0.945 0.311 -2.91 -0.450 +#> 2 lp__ -7.25 -6.97 0.753 0.308 -8.78 -6.75 +#> 3 theta 0.256 0.245 0.119 0.123 0.0824 0.462 mcmc_hist(fit_pf$draws("theta")) #> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. @@ -471,48 +485,49 @@

    Examples

    # better covariance approximation, and fewer LBFGSs iterations fit_pf <- mod$pathfinder(data = stan_data, num_paths=10, single_path_draws=40, history_size=50, max_lbfgs_iters=100) -#> Path [1] :Initial log joint density = -11.515672 +#> Warning: Number of PSIS draws is larger than the total number of draws returned by the single Pathfinders. This is likely unintentional and leads to re-sampling from the same draws. +#> Path [1] :Initial log joint density = -7.405417 #> Path [1] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 1.064e-03 1.692e-05 1.000e+00 1.000e+00 126 -6.254e+00 -6.254e+00 -#> Path [1] :Best Iter: [3] ELBO (-6.213658) evaluations: (126) -#> Path [2] :Initial log joint density = -9.189304 +#> 5 -6.748e+00 9.081e-05 3.233e-07 1.000e+00 1.000e+00 126 -6.231e+00 -6.231e+00 +#> Path [1] :Best Iter: [3] ELBO (-6.194155) evaluations: (126) +#> Path [2] :Initial log joint density = -7.706381 #> Path [2] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 3.749e-04 3.327e-06 1.000e+00 1.000e+00 126 -6.289e+00 -6.289e+00 -#> Path [2] :Best Iter: [4] ELBO (-6.214534) evaluations: (126) -#> Path [3] :Initial log joint density = -13.270061 +#> 5 -6.748e+00 1.603e-04 8.100e-07 1.000e+00 1.000e+00 126 -6.209e+00 -6.209e+00 +#> Path [2] :Best Iter: [5] ELBO (-6.209214) evaluations: (126) +#> Path [3] :Initial log joint density = -8.140103 #> Path [3] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 1.767e-03 4.305e-05 1.000e+00 1.000e+00 126 -6.276e+00 -6.276e+00 -#> Path [3] :Best Iter: [3] ELBO (-6.225363) evaluations: (126) -#> Path [4] :Initial log joint density = -6.748213 +#> 5 -6.748e+00 2.528e-04 1.703e-06 1.000e+00 1.000e+00 126 -6.231e+00 -6.231e+00 +#> Path [3] :Best Iter: [3] ELBO (-6.213740) evaluations: (126) +#> Path [4] :Initial log joint density = -6.779208 #> Path [4] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 2 -6.748e+00 1.004e-02 7.315e-05 1.000e+00 1.000e+00 51 -6.200e+00 -6.200e+00 -#> Path [4] :Best Iter: [2] ELBO (-6.200114) evaluations: (51) -#> Path [5] :Initial log joint density = -7.368682 +#> 4 -6.748e+00 1.406e-04 3.696e-07 1.000e+00 1.000e+00 101 -6.183e+00 -6.183e+00 +#> Path [4] :Best Iter: [4] ELBO (-6.183257) evaluations: (101) +#> Path [5] :Initial log joint density = -6.762413 #> Path [5] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 5.377e-04 9.870e-07 1.000e+00 1.000e+00 126 -6.276e+00 -6.276e+00 -#> Path [5] :Best Iter: [3] ELBO (-6.167297) evaluations: (126) -#> Path [6] :Initial log joint density = -9.465368 +#> 3 -6.748e+00 2.209e-03 1.061e-04 1.000e+00 1.000e+00 76 -6.247e+00 -6.247e+00 +#> Path [5] :Best Iter: [2] ELBO (-6.191386) evaluations: (76) +#> Path [6] :Initial log joint density = -7.106649 #> Path [6] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 4.613e-04 4.599e-06 1.000e+00 1.000e+00 126 -6.238e+00 -6.238e+00 -#> Path [6] :Best Iter: [3] ELBO (-6.185454) evaluations: (126) -#> Path [7] :Initial log joint density = -6.856712 +#> 4 -6.748e+00 3.282e-03 7.049e-05 1.000e+00 1.000e+00 101 -6.179e+00 -6.179e+00 +#> Path [6] :Best Iter: [3] ELBO (-6.136787) evaluations: (101) +#> Path [7] :Initial log joint density = -7.037942 #> Path [7] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 4 -6.748e+00 1.028e-04 1.386e-05 9.452e-01 9.452e-01 101 -6.242e+00 -6.242e+00 -#> Path [7] :Best Iter: [3] ELBO (-6.159687) evaluations: (101) -#> Path [8] :Initial log joint density = -7.085030 +#> 4 -6.748e+00 2.570e-03 4.694e-05 1.000e+00 1.000e+00 101 -6.238e+00 -6.238e+00 +#> Path [7] :Best Iter: [3] ELBO (-6.227629) evaluations: (101) +#> Path [8] :Initial log joint density = -6.772444 #> Path [8] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 4 -6.748e+00 3.058e-03 6.268e-05 1.000e+00 1.000e+00 101 -6.221e+00 -6.221e+00 -#> Path [8] :Best Iter: [4] ELBO (-6.221460) evaluations: (101) -#> Path [9] :Initial log joint density = -7.443992 +#> 4 -6.748e+00 9.980e-05 2.088e-07 1.000e+00 1.000e+00 101 -6.208e+00 -6.208e+00 +#> Path [8] :Best Iter: [2] ELBO (-6.208417) evaluations: (101) +#> Path [9] :Initial log joint density = -17.488355 #> Path [9] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 9.951e-05 3.747e-07 1.000e+00 1.000e+00 126 -6.228e+00 -6.228e+00 -#> Path [9] :Best Iter: [2] ELBO (-6.206717) evaluations: (126) -#> Path [10] :Initial log joint density = -6.751684 +#> 5 -6.748e+00 1.187e-03 3.028e-05 1.000e+00 1.000e+00 126 -6.283e+00 -6.283e+00 +#> Path [9] :Best Iter: [2] ELBO (-6.205015) evaluations: (126) +#> Path [10] :Initial log joint density = -7.447696 #> Path [10] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 3 -6.748e+00 5.950e-04 1.461e-05 1.000e+00 1.000e+00 76 -6.209e+00 -6.209e+00 -#> Path [10] :Best Iter: [3] ELBO (-6.209430) evaluations: (76) -#> Total log probability function evaluations:1235 -#> Finished in 0.1 seconds. +#> 5 -6.748e+00 1.004e-04 3.798e-07 1.000e+00 1.000e+00 126 -6.264e+00 -6.264e+00 +#> Path [10] :Best Iter: [3] ELBO (-6.226969) evaluations: (126) +#> Total log probability function evaluations:1260 +#> Finished in 0.2 seconds. # Specifying initial values as a function fit_mcmc_w_init_fun <- mod$sample( @@ -594,7 +609,7 @@

    Examples

    #> 6 -5.00402 0.000237915 9.55309e-07 1 1 9 #> Optimization terminated normally: #> Convergence detected: relative gradient magnitude is below tolerance -#> Finished in 0.1 seconds. +#> Finished in 0.2 seconds. fit_optim_w_init_list$init() #> [[1]] #> [[1]]$theta @@ -613,11 +628,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/cmdstanr-package-1.png b/docs/reference/cmdstanr-package-1.png index 0aa41c0e..aa185638 100644 Binary files a/docs/reference/cmdstanr-package-1.png and b/docs/reference/cmdstanr-package-1.png differ diff --git a/docs/reference/cmdstanr-package-2.png b/docs/reference/cmdstanr-package-2.png index 835a8a66..4cf81fa8 100644 Binary files a/docs/reference/cmdstanr-package-2.png and b/docs/reference/cmdstanr-package-2.png differ diff --git a/docs/reference/cmdstanr-package-3.png b/docs/reference/cmdstanr-package-3.png index 8d58780f..c67b37ed 100644 Binary files a/docs/reference/cmdstanr-package-3.png and b/docs/reference/cmdstanr-package-3.png differ diff --git a/docs/reference/cmdstanr-package.html b/docs/reference/cmdstanr-package.html index 072311bb..497703b7 100644 --- a/docs/reference/cmdstanr-package.html +++ b/docs/reference/cmdstanr-package.html @@ -1,5 +1,5 @@ -CmdStanR: the R interface to CmdStan — cmdstanr-package • cmdstanrCmdStanR: the R interface to CmdStan — cmdstanr-package • cmdstanrFit models for use in examples — cmdstanr_example • cmdstanrFit models for use in examples — cmdstanr_example • cmdstanr @@ -17,7 +17,7 @@ cmdstanr - 0.7.0 + 0.8.1

    @@ -189,16 +189,16 @@

    Examples

    #> # A tibble: 105 × 10 #> variable mean median sd mad q5 q95 rhat ess_bulk #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp__ -66.0 -65.6 1.45 1.20 -68.7 -64.3 1.00 934. -#> 2 alpha 0.384 0.386 0.218 0.218 0.0341 0.748 1.00 1959. -#> 3 beta[1] -0.667 -0.661 0.247 0.248 -1.08 -0.273 1.00 1840. -#> 4 beta[2] -0.275 -0.273 0.231 0.231 -0.662 0.114 1.00 1954. -#> 5 beta[3] 0.687 0.685 0.271 0.269 0.254 1.13 1.00 2212. -#> 6 log_lik[1] -0.515 -0.509 0.101 0.0967 -0.698 -0.360 1.00 2038. -#> 7 log_lik[2] -0.402 -0.380 0.150 0.140 -0.673 -0.195 1.00 2565. -#> 8 log_lik[3] -0.498 -0.467 0.223 0.212 -0.922 -0.201 1.00 2174. -#> 9 log_lik[4] -0.449 -0.430 0.154 0.148 -0.731 -0.232 0.999 1785. -#> 10 log_lik[5] -1.19 -1.17 0.283 0.281 -1.69 -0.772 1.00 2119. +#> 1 lp__ -65.9 -65.6 1.43 1.23 -68.7 -64.3 1.00 890. +#> 2 alpha 0.377 0.375 0.220 0.220 0.0153 0.743 1.00 2007. +#> 3 beta[1] -0.670 -0.663 0.247 0.244 -1.10 -0.273 1.00 1880. +#> 4 beta[2] -0.268 -0.269 0.223 0.218 -0.637 0.106 1.00 1834. +#> 5 beta[3] 0.684 0.681 0.271 0.271 0.243 1.14 1.00 2163. +#> 6 log_lik[1] -0.516 -0.511 0.101 0.0973 -0.694 -0.363 1.00 2030. +#> 7 log_lik[2] -0.398 -0.38 0.143 0.141 -0.661 -0.204 1.00 2280. +#> 8 log_lik[3] -0.493 -0.463 0.216 0.196 -0.883 -0.197 1.00 1914. +#> 9 log_lik[4] -0.450 -0.430 0.153 0.148 -0.730 -0.229 1.00 2150. +#> 10 log_lik[5] -1.19 -1.16 0.288 0.283 -1.70 -0.769 1.00 2194. #> # ℹ 95 more rows #> # ℹ 1 more variable: ess_tail <dbl> @@ -211,7 +211,7 @@

    Examples

    #> 2 alpha 0.364 #> 3 beta[1] -0.632 #> 4 beta[2] -0.259 -#> 5 beta[3] 0.648 +#> 5 beta[3] 0.649 #> 6 log_lik[1] -0.515 #> 7 log_lik[2] -0.394 #> 8 log_lik[3] -0.469 @@ -222,18 +222,18 @@

    Examples

    fit_logistic_vb <- cmdstanr_example("logistic", method = "variational") fit_logistic_vb$summary() #> # A tibble: 106 × 7 -#> variable mean median sd mad q5 q95 -#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp__ -66.5 -66.0 1.82 1.62 -69.9 -64.3 -#> 2 lp_approx__ -1.96 -1.62 1.41 1.19 -4.62 -0.318 -#> 3 alpha 0.503 0.492 0.219 0.222 0.144 0.876 -#> 4 beta[1] -0.582 -0.568 0.301 0.288 -1.10 -0.0916 -#> 5 beta[2] -0.278 -0.275 0.185 0.183 -0.592 0.0118 -#> 6 beta[3] 0.688 0.696 0.301 0.307 0.211 1.18 -#> 7 log_lik[1] -0.480 -0.475 0.0981 0.0994 -0.648 -0.332 -#> 8 log_lik[2] -0.466 -0.443 0.190 0.185 -0.836 -0.197 -#> 9 log_lik[3] -0.470 -0.443 0.195 0.188 -0.838 -0.209 -#> 10 log_lik[4] -0.495 -0.480 0.152 0.148 -0.776 -0.277 +#> variable mean median sd mad q5 q95 +#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> +#> 1 lp__ -66.2 -65.8 1.56 1.32 -69.2 -64.3 +#> 2 lp_approx__ -1.94 -1.61 1.34 1.15 -4.56 -0.362 +#> 3 alpha 0.448 0.454 0.184 0.186 0.144 0.745 +#> 4 beta[1] -0.710 -0.711 0.297 0.296 -1.20 -0.230 +#> 5 beta[2] -0.211 -0.214 0.213 0.218 -0.546 0.131 +#> 6 beta[3] 0.719 0.717 0.272 0.278 0.285 1.18 +#> 7 log_lik[1] -0.478 -0.474 0.0839 0.0865 -0.622 -0.351 +#> 8 log_lik[2] -0.391 -0.364 0.154 0.141 -0.698 -0.180 +#> 9 log_lik[3] -0.408 -0.382 0.181 0.171 -0.755 -0.162 +#> 10 log_lik[4] -0.483 -0.471 0.145 0.142 -0.745 -0.272 #> # ℹ 96 more rows print_example_program("schools") @@ -254,23 +254,25 @@

    Examples

    #> target += normal_lpdf(y | theta, sigma); #> } fit_schools_mcmc <- cmdstanr_example("schools") -#> Warning: 146 of 4000 (4.0%) transitions ended with a divergence. +#> Warning: 679 of 4000 (17.0%) transitions ended with a divergence. +#> See https://mc-stan.org/misc/warnings for details. +#> Warning: 2 of 4 chains had an E-BFMI less than 0.3. #> See https://mc-stan.org/misc/warnings for details. fit_schools_mcmc$summary() #> # A tibble: 11 × 10 -#> variable mean median sd mad q5 q95 rhat ess_bulk ess_tail -#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp__ -58.4 -58.5 5.06 5.42 -66.4 -50.2 1.02 139. 71.0 -#> 2 mu 6.36 6.39 4.24 4.27 -0.684 13.0 1.01 487. 345. -#> 3 tau 5.42 4.61 3.53 3.33 1.25 12.3 1.02 136. 67.5 -#> 4 theta[1] 9.11 8.41 7.20 6.29 -1.35 21.8 1.01 774. 601. -#> 5 theta[2] 6.65 6.69 5.88 5.59 -2.86 16.2 1.01 1011. 2093. -#> 6 theta[3] 5.38 5.61 6.74 6.18 -5.83 15.9 1.01 863. 1953. -#> 7 theta[4] 6.59 6.59 6.01 5.73 -2.94 16.6 1.01 946. 2109. -#> 8 theta[5] 4.37 4.72 5.66 5.51 -5.63 12.8 1.01 745. 2276. -#> 9 theta[6] 5.28 5.49 5.96 5.60 -4.99 14.6 1.01 879. 1751. -#> 10 theta[7] 9.06 8.65 6.17 5.72 -0.151 20.1 1.01 678. 1072. -#> 11 theta[8] 6.91 6.84 6.86 6.09 -4.10 17.8 1.01 939. 2286. +#> variable mean median sd mad q5 q95 rhat ess_bulk ess_tail +#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> +#> 1 lp__ -55.2 -56.2 7.20 8.44 -65.7 -44.5 1.35 9.26 502. +#> 2 mu 5.92 4.83 3.74 2.79 0.0739 12.5 1.14 269. 979. +#> 3 tau 4.29 3.34 3.72 3.44 0.650 11.7 1.35 9.24 5.53 +#> 4 theta[1] 8.28 6.13 6.22 3.70 0.148 20.3 1.19 199. 1448. +#> 5 theta[2] 6.41 5.49 5.11 3.45 -1.72 15.4 1.10 460. 1260. +#> 6 theta[3] 5.14 4.33 5.96 3.94 -5.01 15.0 1.23 782. 1447. +#> 7 theta[4] 5.87 4.59 5.16 3.49 -2.48 15.2 1.31 730. 948. +#> 8 theta[5] 4.56 4.37 5.04 4.04 -4.72 12.5 1.28 643. 1270. +#> 9 theta[6] 5.08 4.56 5.20 3.35 -3.77 13.6 1.12 659. 1302. +#> 10 theta[7] 8.06 6.46 5.45 3.53 0.928 18.2 1.05 73.8 1255. +#> 11 theta[8] 6.38 5.50 6.15 3.54 -2.77 17.5 1.11 260. 1699. print_example_program("schools_ncp") #> data { @@ -295,38 +297,40 @@

    Examples

    fit_schools_ncp_mcmc <- cmdstanr_example("schools_ncp") fit_schools_ncp_mcmc$summary() #> # A tibble: 19 × 10 -#> variable mean median sd mad q5 q95 rhat ess_bulk ess_tail -#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp__ -46.9 -4.66e+1 2.49 2.36 -51.6 -43.6 1.00 1229. 1844. -#> 2 mu 6.43 6.46e+0 4.08 3.93 -0.238 13.1 1.00 2985. 2197. -#> 3 tau 4.74 4.03e+0 3.70 3.41 0.334 11.9 1.00 1724. 1496. -#> 4 theta_r… 0.351 3.53e-1 0.979 0.955 -1.26 1.96 1.00 3404. 2385. -#> 5 theta_r… 0.0484 6.67e-2 0.924 0.913 -1.49 1.53 1.00 3680. 2435. -#> 6 theta_r… -0.131 -1.50e-1 0.962 0.938 -1.71 1.50 1.00 3067. 2557. -#> 7 theta_r… 0.0221 5.18e-3 0.919 0.905 -1.49 1.59 1.00 3748. 2583. -#> 8 theta_r… -0.273 -3.14e-1 0.931 0.892 -1.77 1.34 1.00 4139. 2891. -#> 9 theta_r… -0.157 -1.57e-1 0.930 0.929 -1.69 1.36 1.00 3560. 2797. -#> 10 theta_r… 0.363 4.01e-1 0.924 0.911 -1.15 1.87 1.00 3687. 2941. -#> 11 theta_r… 0.0558 7.25e-2 0.951 0.924 -1.55 1.65 1.00 4077. 2555. -#> 12 theta[1] 8.85 8.09e+0 6.85 5.77 -0.638 21.2 1.00 2994. 2531. -#> 13 theta[2] 6.79 6.75e+0 5.59 5.01 -2.46 15.9 1.00 4593. 3367. -#> 14 theta[3] 5.40 5.88e+0 6.64 5.63 -5.94 15.5 1.00 3448. 3181. -#> 15 theta[4] 6.65 6.62e+0 5.69 5.09 -2.25 16.0 1.00 4537. 3155. -#> 16 theta[5] 4.78 5.06e+0 5.54 5.26 -4.69 13.2 1.00 3996. 3191. -#> 17 theta[6] 5.44 5.63e+0 5.97 5.29 -4.66 14.8 1.00 3934. 2877. -#> 18 theta[7] 8.83 8.37e+0 5.98 5.56 0.141 19.4 1.00 4104. 3336. -#> 19 theta[8] 6.89 6.73e+0 6.34 5.33 -3.03 17.1 1.00 3988. 3025. +#> variable mean median sd mad q5 q95 rhat ess_bulk +#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> +#> 1 lp__ -46.9 -46.6 2.41 2.29 -51.3 -43.5 1.00 1454. +#> 2 mu 6.51 6.48 4.11 4.18 -0.0368 13.3 1.00 3392. +#> 3 tau 4.77 3.96 3.63 3.48 0.449 11.8 1.00 2260. +#> 4 theta_raw[1] 0.377 0.379 0.975 0.954 -1.26 1.95 1.00 4065. +#> 5 theta_raw[2] 0.0526 0.0555 0.895 0.884 -1.43 1.53 1.00 3436. +#> 6 theta_raw[3] -0.143 -0.156 0.970 0.957 -1.73 1.48 1.00 3686. +#> 7 theta_raw[4] 0.0219 0.0261 0.906 0.930 -1.48 1.50 1.00 3671. +#> 8 theta_raw[5] -0.263 -0.285 0.920 0.904 -1.76 1.29 1.00 4086. +#> 9 theta_raw[6] -0.130 -0.144 0.930 0.917 -1.64 1.42 1.00 4353. +#> 10 theta_raw[7] 0.369 0.376 0.918 0.911 -1.15 1.87 1.00 3860. +#> 11 theta_raw[8] 0.0659 0.0592 0.971 0.988 -1.51 1.69 1.00 3781. +#> 12 theta[1] 9.01 8.30 6.74 5.76 -0.246 21.2 1.00 3647. +#> 13 theta[2] 6.88 6.83 5.35 4.89 -1.89 15.7 1.00 4377. +#> 14 theta[3] 5.45 5.79 6.51 5.55 -5.90 15.5 1.00 3662. +#> 15 theta[4] 6.73 6.60 5.73 5.22 -2.58 16.1 1.00 3999. +#> 16 theta[5] 4.91 5.16 5.52 4.90 -4.78 13.6 1.00 4517. +#> 17 theta[6] 5.64 5.91 6.01 5.33 -4.77 15.0 1.00 4197. +#> 18 theta[7] 8.87 8.36 5.95 5.37 0.312 19.6 1.00 3846. +#> 19 theta[8] 7.06 6.77 6.80 5.70 -3.70 18.3 1.00 3866. +#> # ℹ 1 more variable: ess_tail <dbl> # optimization fails for hierarchical model cmdstanr_example("schools", "optimize", quiet = FALSE) -#> Initial log joint probability = -56.2449 +#> Initial log joint probability = -53.966 #> Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes -#> 99 121.706 0.109668 2.48002e+09 1 1 174 +#> 99 123.351 0.058381 2.09576e+09 0.5049 0.5049 181 #> Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes -#> 187 244.785 0.253817 8.00296 1e-12 0.001 400 LS failed, Hessian reset -#> Line search failed to achieve a sufficient decrease, no more progress can be made +#> 184 248.826 0.4674 3.92933e+16 1e-12 0.001 384 LS failed, Hessian reset #> Chain 1 Optimization terminated with error: +#> Chain 1 Line search failed to achieve a sufficient decrease, no more progress can be made #> Warning: Fitting finished unexpectedly! Use the $output() method for more information. +#> Finished in 0.2 seconds. #> Error: Fitting failed. Unable to print. # } @@ -340,11 +344,11 @@

    Examples

    diff --git a/docs/reference/cmdstanr_global_options.html b/docs/reference/cmdstanr_global_options.html new file mode 100644 index 00000000..879820a9 --- /dev/null +++ b/docs/reference/cmdstanr_global_options.html @@ -0,0 +1,166 @@ + +CmdStanR global options — cmdstanr_global_options • cmdstanr + + +
    +
    + + + +
    +
    + + +
    +

    These options can be set via options() for an entire R session.

    +
    + + +
    +

    Details

    + +
    • cmdstanr_draws_format: Which format provided by the posterior +package should be used when returning the posterior or approximate posterior +draws? The default depends on the model fitting method. See +draws for more details.

    • +
    • cmdstanr_force_recompile: Should the default be to recompile models +even if there were no Stan code changes since last compiled? See +compile for more details. The default is FALSE.

    • +
    • cmdstanr_max_rows: The maximum number of rows of output to print when +using the $print() method. The default is 10.

    • +
    • cmdstanr_no_ver_check: Should the check for a more recent version of +CmdStan be disabled? The default is FALSE.

    • +
    • cmdstanr_output_dir: The directory where CmdStan should write its output +CSV files when fitting models. The default is a temporary directory. Files in +a temporary directory are removed as part of R garbage collection, while +files in an explicitly defined directory are not automatically deleted.

    • +
    • cmdstanr_verbose: Should more information be printed +when compiling or running models, including showing how CmdStan was called +internally? The default is FALSE.

    • +
    • cmdstanr_warn_inits: Should a warning be thrown if initial values are +only provided for a subset of parameters? The default is TRUE.

    • +
    • cmdstanr_write_stan_file_dir: The directory where write_stan_file() +should write Stan files. The default is a temporary directory. Files in +a temporary directory are removed as part of R garbage collection, while +files in an explicitly defined directory are not automatically deleted.

    • +
    • mc.cores: The number of cores to use for various parallelization tasks +(e.g. running MCMC chains, installing CmdStan). The default depends on the +use case and is documented with the methods that make use of mc.cores.

    • +
    + +
    + +
    + + +
    + + + + + + + + diff --git a/docs/reference/draws_to_csv.html b/docs/reference/draws_to_csv.html index 355224d7..2ce97f97 100644 --- a/docs/reference/draws_to_csv.html +++ b/docs/reference/draws_to_csv.html @@ -1,7 +1,5 @@ -Write posterior draws objects to CSV files suitable for running standalone generated -quantities with CmdStan. — draws_to_csv • cmdstanrWrite posterior draws objects to CSV files suitable for running standalone generated quantities with CmdStan. — draws_to_csv • cmdstanrCmdStan knitr engine for Stan — eng_cmdstan • cmdstanrCmdStan knitr engine for Stan — eng_cmdstan • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -144,11 +144,11 @@

    Examples

    diff --git a/docs/reference/fit-method-cmdstan_summary.html b/docs/reference/fit-method-cmdstan_summary.html index 47d7f8f7..6bbc2727 100644 --- a/docs/reference/fit-method-cmdstan_summary.html +++ b/docs/reference/fit-method-cmdstan_summary.html @@ -1,5 +1,5 @@ -Run CmdStan's stansummary and diagnose utilities — fit-method-cmdstan_summary • cmdstanrRun CmdStan's stansummary and diagnose utilities — fit-method-cmdstan_summary • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -149,7 +149,7 @@

    Examples

    # \dontrun{
     fit <- cmdstanr_example("logistic")
     fit$cmdstan_diagnose()
    -#> Processing csv files: /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/logistic-202312131001-1-2718e9.csv, /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/logistic-202312131001-2-2718e9.csv, /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/logistic-202312131001-3-2718e9.csv, /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/logistic-202312131001-4-2718e9.csv
    +#> Processing csv files: /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/logistic-202407021533-1-42dde2.csv, /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/logistic-202407021533-2-42dde2.csv, /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/logistic-202407021533-3-42dde2.csv, /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/logistic-202407021533-4-42dde2.csv
     #> 
     #> Checking sampler transitions treedepth.
     #> Treedepth satisfactory for all transitions.
    @@ -169,123 +169,123 @@ 

    Examples

    #> Inference for Stan model: logistic_model #> 4 chains: each with iter=(1000,1000,1000,1000); warmup=(0,0,0,0); thin=(1,1,1,1); 4000 iterations saved. #> -#> Warmup took (0.022, 0.023, 0.023, 0.023) seconds, 0.091 seconds total -#> Sampling took (0.071, 0.070, 0.070, 0.070) seconds, 0.28 seconds total +#> Warmup took (0.043, 0.046, 0.042, 0.041) seconds, 0.17 seconds total +#> Sampling took (0.15, 0.15, 0.16, 0.15) seconds, 0.61 seconds total #> #> Mean MCSE StdDev 5% 50% 95% N_Eff N_Eff/s R_hat #> -#> lp__ -6.6e+01 3.1e-02 1.4 -69 -6.6e+01 -6.4e+01 2120 7545 1.0 -#> accept_stat__ 0.91 1.4e-03 0.10 0.69 0.95 1.0 5437 19350 1.0e+00 -#> stepsize__ 0.74 2.1e-02 0.030 0.70 0.75 0.78 2.0 7.1 1.1e+13 -#> treedepth__ 2.4 8.8e-03 0.53 2.0 2.0 3.0 3601 12815 1.0e+00 -#> n_leapfrog__ 5.3 3.3e-02 2.0 3.0 7.0 7.0 3773 13428 1.0e+00 +#> lp__ -6.6e+01 3.3e-02 1.4 -69 -6.6e+01 -6.4e+01 1837 3007 1.0 +#> accept_stat__ 0.90 0.011 0.12 0.65 0.94 1.0 123 202 1.0e+00 +#> stepsize__ 0.77 0.038 0.054 0.73 0.77 0.86 2.0 3.3 1.9e+13 +#> treedepth__ 2.3 0.10 0.51 2.0 2.0 3.0 26 42 1.1e+00 +#> n_leapfrog__ 4.9 0.35 2.0 3.0 3.0 7.0 34 55 1.0e+00 #> divergent__ 0.00 nan 0.00 0.00 0.00 0.00 nan nan nan -#> energy__ 68 4.9e-02 2.0 65 68 72 1750 6227 1.0e+00 +#> energy__ 68 0.049 2.0 65 68 72 1652 2704 1.0e+00 #> -#> alpha 3.8e-01 3.5e-03 0.22 0.026 3.8e-01 7.5e-01 3978 14156 1.00 -#> beta[1] -6.7e-01 4.1e-03 0.26 -1.1 -6.6e-01 -2.6e-01 3779 13447 1.0 -#> beta[2] -2.7e-01 3.5e-03 0.23 -0.64 -2.7e-01 1.0e-01 4061 14450 1.0 -#> beta[3] 6.7e-01 4.3e-03 0.27 0.24 6.7e-01 1.1e+00 3879 13804 1.00 -#> log_lik[1] -5.1e-01 1.5e-03 0.097 -0.68 -5.1e-01 -3.7e-01 3951 14060 1.00 -#> log_lik[2] -4.1e-01 2.3e-03 0.15 -0.69 -3.9e-01 -1.9e-01 4167 14830 1.00 -#> log_lik[3] -4.9e-01 3.3e-03 0.21 -0.88 -4.6e-01 -2.1e-01 4010 14272 1.00 -#> log_lik[4] -4.5e-01 2.5e-03 0.15 -0.72 -4.4e-01 -2.4e-01 3751 13350 1.0 -#> log_lik[5] -1.2e+00 4.4e-03 0.28 -1.7 -1.2e+00 -7.6e-01 4068 14476 1.0 -#> log_lik[6] -5.9e-01 3.0e-03 0.19 -0.96 -5.7e-01 -3.2e-01 4275 15213 1.0 -#> log_lik[7] -6.4e-01 2.0e-03 0.13 -0.86 -6.4e-01 -4.5e-01 4183 14885 1.0 -#> log_lik[8] -2.8e-01 2.3e-03 0.14 -0.55 -2.5e-01 -1.1e-01 3659 13021 1.0 -#> log_lik[9] -6.9e-01 2.7e-03 0.17 -1.0 -6.7e-01 -4.4e-01 4128 14690 1.0 -#> log_lik[10] -7.3e-01 3.6e-03 0.22 -1.1 -7.1e-01 -4.1e-01 3894 13857 1.00 -#> log_lik[11] -2.8e-01 2.1e-03 0.13 -0.54 -2.6e-01 -1.1e-01 3822 13601 1.00 -#> log_lik[12] -5.0e-01 3.8e-03 0.24 -0.95 -4.6e-01 -1.9e-01 3952 14065 1.00 -#> log_lik[13] -6.6e-01 3.3e-03 0.21 -1.0 -6.4e-01 -3.5e-01 4181 14878 1.0 -#> log_lik[14] -3.6e-01 2.6e-03 0.17 -0.67 -3.2e-01 -1.4e-01 4021 14308 1.00 -#> log_lik[15] -2.8e-01 1.7e-03 0.10 -0.47 -2.6e-01 -1.3e-01 3858 13730 1.00 -#> log_lik[16] -2.8e-01 1.5e-03 0.091 -0.44 -2.7e-01 -1.5e-01 3706 13189 1.00 -#> log_lik[17] -1.6e+00 5.0e-03 0.30 -2.1 -1.6e+00 -1.1e+00 3612 12854 1.0 -#> log_lik[18] -4.8e-01 1.8e-03 0.11 -0.68 -4.7e-01 -3.1e-01 4081 14523 1.0 -#> log_lik[19] -2.3e-01 1.3e-03 0.079 -0.37 -2.2e-01 -1.2e-01 3751 13347 1.0 -#> log_lik[20] -1.1e-01 1.3e-03 0.078 -0.26 -9.4e-02 -2.8e-02 3798 13516 1.00 -#> log_lik[21] -2.1e-01 1.5e-03 0.091 -0.39 -2.0e-01 -9.3e-02 3626 12906 1.00 -#> log_lik[22] -5.7e-01 2.4e-03 0.15 -0.86 -5.5e-01 -3.5e-01 4061 14452 1.0 -#> log_lik[23] -3.3e-01 2.3e-03 0.15 -0.61 -3.1e-01 -1.4e-01 3872 13780 1.0 -#> log_lik[24] -1.4e-01 1.1e-03 0.069 -0.27 -1.2e-01 -5.1e-02 3743 13321 1.00 -#> log_lik[25] -4.6e-01 1.9e-03 0.12 -0.68 -4.5e-01 -2.8e-01 3975 14145 1.0 -#> log_lik[26] -1.5e+00 5.8e-03 0.35 -2.1 -1.5e+00 -1.0e+00 3699 13164 1.0 -#> log_lik[27] -3.1e-01 2.0e-03 0.13 -0.55 -2.9e-01 -1.4e-01 3831 13633 1.00 -#> log_lik[28] -4.4e-01 1.4e-03 0.086 -0.59 -4.4e-01 -3.1e-01 3970 14130 1.0 -#> log_lik[29] -7.3e-01 3.4e-03 0.22 -1.1 -7.1e-01 -4.0e-01 4258 15153 1.0 -#> log_lik[30] -6.9e-01 3.1e-03 0.20 -1.1 -6.8e-01 -4.0e-01 4121 14666 1.00 -#> log_lik[31] -4.9e-01 2.6e-03 0.17 -0.81 -4.7e-01 -2.5e-01 4046 14398 1.0 -#> log_lik[32] -4.2e-01 1.7e-03 0.11 -0.62 -4.1e-01 -2.6e-01 3986 14185 1.0 -#> log_lik[33] -4.1e-01 2.0e-03 0.13 -0.65 -4.0e-01 -2.2e-01 4122 14669 1.0 -#> log_lik[34] -6.5e-02 9.1e-04 0.054 -0.17 -5.0e-02 -1.3e-02 3544 12612 1.0 -#> log_lik[35] -5.9e-01 2.8e-03 0.18 -0.92 -5.7e-01 -3.2e-01 4411 15696 1.0 -#> log_lik[36] -3.3e-01 2.2e-03 0.14 -0.58 -3.0e-01 -1.4e-01 4001 14239 1.0 -#> log_lik[37] -6.9e-01 3.4e-03 0.22 -1.1 -6.7e-01 -3.7e-01 4045 14394 1.0 -#> log_lik[38] -3.2e-01 2.4e-03 0.15 -0.60 -2.9e-01 -1.2e-01 3854 13717 1.0 -#> log_lik[39] -1.8e-01 1.7e-03 0.11 -0.38 -1.5e-01 -5.2e-02 3915 13934 1.00 -#> log_lik[40] -6.8e-01 2.1e-03 0.13 -0.92 -6.7e-01 -4.8e-01 4145 14752 1.0 -#> log_lik[41] -1.1e+00 4.2e-03 0.26 -1.6 -1.1e+00 -7.3e-01 3929 13983 1.0 -#> log_lik[42] -9.3e-01 3.2e-03 0.20 -1.3 -9.1e-01 -6.3e-01 3967 14116 1.0 -#> log_lik[43] -4.1e-01 4.0e-03 0.26 -0.91 -3.4e-01 -1.0e-01 4191 14913 1.0 -#> log_lik[44] -1.2e+00 3.1e-03 0.19 -1.5 -1.2e+00 -9.0e-01 3709 13201 1.00 -#> log_lik[45] -3.6e-01 1.8e-03 0.11 -0.56 -3.4e-01 -1.9e-01 4009 14267 1.00 -#> log_lik[46] -5.9e-01 2.0e-03 0.13 -0.82 -5.8e-01 -3.8e-01 4248 15119 1.00 -#> log_lik[47] -3.1e-01 2.2e-03 0.13 -0.55 -2.9e-01 -1.3e-01 3696 13153 1.0 -#> log_lik[48] -3.2e-01 1.4e-03 0.085 -0.47 -3.2e-01 -2.0e-01 3847 13691 1.0 -#> log_lik[49] -3.2e-01 1.3e-03 0.082 -0.46 -3.1e-01 -2.0e-01 3716 13223 1.00 -#> log_lik[50] -1.3e+00 5.4e-03 0.33 -1.9 -1.3e+00 -8.1e-01 3859 13734 1.0 -#> log_lik[51] -2.9e-01 1.6e-03 0.096 -0.46 -2.8e-01 -1.5e-01 3714 13218 1.0 -#> log_lik[52] -8.4e-01 2.2e-03 0.14 -1.1 -8.3e-01 -6.2e-01 3985 14182 1.00 -#> log_lik[53] -4.0e-01 2.1e-03 0.13 -0.66 -3.9e-01 -2.1e-01 3970 14127 1.00 -#> log_lik[54] -3.7e-01 2.2e-03 0.14 -0.62 -3.5e-01 -1.8e-01 4008 14263 1.00 -#> log_lik[55] -3.9e-01 2.2e-03 0.14 -0.65 -3.7e-01 -1.9e-01 4107 14614 1.00 -#> log_lik[56] -3.2e-01 3.2e-03 0.20 -0.70 -2.8e-01 -9.3e-02 3745 13326 1.0 -#> log_lik[57] -6.5e-01 1.8e-03 0.12 -0.85 -6.5e-01 -4.8e-01 3918 13943 1.0 -#> log_lik[58] -9.4e-01 5.3e-03 0.35 -1.6 -9.0e-01 -4.5e-01 4317 15364 1.0 -#> log_lik[59] -1.4e+00 5.7e-03 0.35 -2.0 -1.3e+00 -8.4e-01 3801 13527 1.0 -#> log_lik[60] -9.8e-01 2.5e-03 0.16 -1.3 -9.7e-01 -7.4e-01 3902 13886 1.00 -#> log_lik[61] -5.4e-01 1.5e-03 0.097 -0.70 -5.3e-01 -3.9e-01 4078 14513 1.00 -#> log_lik[62] -8.9e-01 5.0e-03 0.31 -1.5 -8.5e-01 -4.4e-01 3852 13708 1.00 -#> log_lik[63] -1.2e-01 1.3e-03 0.077 -0.27 -9.9e-02 -3.2e-02 3330 11849 1.00 -#> log_lik[64] -9.0e-01 3.8e-03 0.25 -1.4 -8.8e-01 -5.3e-01 4445 15817 1.00 -#> log_lik[65] -2.0e+00 9.8e-03 0.61 -3.1 -2.0e+00 -1.1e+00 3783 13462 1.00 -#> log_lik[66] -5.1e-01 2.1e-03 0.13 -0.74 -4.9e-01 -3.1e-01 4154 14782 1.0 -#> log_lik[67] -2.8e-01 1.4e-03 0.085 -0.43 -2.7e-01 -1.6e-01 3827 13618 1.0 -#> log_lik[68] -1.1e+00 3.8e-03 0.24 -1.5 -1.0e+00 -6.8e-01 4102 14597 1.00 -#> log_lik[69] -4.3e-01 1.4e-03 0.085 -0.58 -4.3e-01 -3.0e-01 3842 13673 1.0 -#> log_lik[70] -6.4e-01 3.6e-03 0.24 -1.1 -6.1e-01 -3.1e-01 4371 15555 1.00 -#> log_lik[71] -6.1e-01 3.2e-03 0.21 -0.99 -5.9e-01 -3.1e-01 4401 15663 1.0 -#> log_lik[72] -4.6e-01 2.7e-03 0.17 -0.79 -4.5e-01 -2.2e-01 4214 14996 1.0 -#> log_lik[73] -1.5e+00 6.1e-03 0.37 -2.1 -1.4e+00 -9.2e-01 3671 13065 1.0 -#> log_lik[74] -9.5e-01 3.0e-03 0.19 -1.3 -9.4e-01 -6.7e-01 3944 14035 1.00 -#> log_lik[75] -1.2e+00 6.4e-03 0.39 -1.8 -1.1e+00 -5.9e-01 3678 13088 1.00 -#> log_lik[76] -3.7e-01 2.1e-03 0.13 -0.62 -3.5e-01 -1.8e-01 3976 14151 1.00 -#> log_lik[77] -8.8e-01 2.2e-03 0.14 -1.1 -8.8e-01 -6.6e-01 4034 14357 1.0 -#> log_lik[78] -4.8e-01 2.7e-03 0.17 -0.79 -4.6e-01 -2.4e-01 4097 14581 1.00 -#> log_lik[79] -7.6e-01 2.9e-03 0.18 -1.1 -7.4e-01 -4.8e-01 3889 13840 1.0 -#> log_lik[80] -5.5e-01 3.0e-03 0.20 -0.91 -5.2e-01 -2.7e-01 4407 15683 1.00 -#> log_lik[81] -1.7e-01 1.7e-03 0.10 -0.37 -1.4e-01 -4.8e-02 3780 13450 1.0 -#> log_lik[82] -2.3e-01 2.3e-03 0.14 -0.51 -2.0e-01 -6.3e-02 3943 14031 1.00 -#> log_lik[83] -3.4e-01 1.3e-03 0.081 -0.48 -3.4e-01 -2.2e-01 3766 13404 1.00 -#> log_lik[84] -2.7e-01 1.5e-03 0.090 -0.44 -2.6e-01 -1.4e-01 3767 13405 1.00 -#> log_lik[85] -1.3e-01 1.2e-03 0.075 -0.28 -1.1e-01 -4.1e-02 3780 13453 1.00 -#> log_lik[86] -1.1e+00 5.0e-03 0.32 -1.7 -1.1e+00 -6.4e-01 4173 14850 1.00 -#> log_lik[87] -8.3e-01 2.0e-03 0.13 -1.1 -8.2e-01 -6.2e-01 4183 14887 1.00 -#> log_lik[88] -7.8e-01 3.8e-03 0.24 -1.2 -7.5e-01 -4.2e-01 4157 14794 1.0 -#> log_lik[89] -1.3e+00 5.1e-03 0.32 -1.9 -1.2e+00 -7.9e-01 3879 13805 1.00 -#> log_lik[90] -2.6e-01 2.2e-03 0.14 -0.52 -2.4e-01 -9.4e-02 4008 14262 1.0 -#> log_lik[91] -3.9e-01 2.1e-03 0.13 -0.63 -3.8e-01 -2.1e-01 4144 14746 1.0 -#> log_lik[92] -1.5e+00 5.6e-03 0.34 -2.1 -1.5e+00 -9.7e-01 3829 13625 1.00 -#> log_lik[93] -7.5e-01 3.4e-03 0.21 -1.1 -7.2e-01 -4.4e-01 3888 13835 1.00 -#> log_lik[94] -3.2e-01 1.4e-03 0.087 -0.47 -3.1e-01 -1.9e-01 3803 13533 1.00 -#> log_lik[95] -3.9e-01 1.9e-03 0.12 -0.60 -3.8e-01 -2.2e-01 3889 13841 1.0 -#> log_lik[96] -1.6e+00 4.8e-03 0.29 -2.1 -1.6e+00 -1.1e+00 3601 12815 1.00 -#> log_lik[97] -4.3e-01 1.6e-03 0.10 -0.61 -4.2e-01 -2.7e-01 4067 14472 1.0 -#> log_lik[98] -1.0e+00 5.6e-03 0.37 -1.7 -1.0e+00 -5.2e-01 4342 15452 1.0 -#> log_lik[99] -7.0e-01 2.2e-03 0.15 -0.96 -6.9e-01 -4.7e-01 4351 15484 1.00 -#> log_lik[100] -3.9e-01 1.5e-03 0.097 -0.55 -3.8e-01 -2.4e-01 4019 14301 1.00 +#> alpha 3.8e-01 3.5e-03 0.22 0.023 3.8e-01 7.4e-01 3919 6414 1.0 +#> beta[1] -6.7e-01 3.8e-03 0.25 -1.1 -6.7e-01 -2.6e-01 4387 7180 1.0 +#> beta[2] -2.7e-01 3.5e-03 0.23 -0.64 -2.7e-01 1.1e-01 4209 6889 1.00 +#> beta[3] 6.8e-01 4.3e-03 0.26 0.25 6.7e-01 1.1e+00 3682 6026 1.00 +#> log_lik[1] -5.1e-01 1.5e-03 0.099 -0.69 -5.1e-01 -3.6e-01 4109 6725 1.0 +#> log_lik[2] -4.0e-01 2.2e-03 0.15 -0.67 -3.8e-01 -2.0e-01 4736 7751 1.0 +#> log_lik[3] -5.0e-01 3.4e-03 0.22 -0.90 -4.6e-01 -2.0e-01 4043 6617 1.0 +#> log_lik[4] -4.5e-01 2.4e-03 0.15 -0.73 -4.3e-01 -2.4e-01 3941 6450 1.0 +#> log_lik[5] -1.2e+00 4.5e-03 0.28 -1.7 -1.2e+00 -7.7e-01 3844 6291 1.00 +#> log_lik[6] -5.9e-01 2.9e-03 0.19 -0.93 -5.7e-01 -3.2e-01 4123 6748 1.00 +#> log_lik[7] -6.4e-01 1.9e-03 0.13 -0.87 -6.3e-01 -4.5e-01 4625 7569 1.0 +#> log_lik[8] -2.8e-01 2.1e-03 0.13 -0.53 -2.5e-01 -1.1e-01 3984 6520 1.00 +#> log_lik[9] -6.9e-01 2.6e-03 0.17 -0.99 -6.8e-01 -4.4e-01 4294 7028 1.0 +#> log_lik[10] -7.4e-01 3.7e-03 0.23 -1.2 -7.1e-01 -4.0e-01 3964 6488 1.0 +#> log_lik[11] -2.8e-01 2.1e-03 0.12 -0.51 -2.6e-01 -1.2e-01 3501 5729 1.00 +#> log_lik[12] -5.0e-01 3.5e-03 0.23 -0.93 -4.6e-01 -1.9e-01 4348 7116 1.0 +#> log_lik[13] -6.6e-01 3.2e-03 0.21 -1.0 -6.3e-01 -3.5e-01 4224 6914 1.00 +#> log_lik[14] -3.6e-01 2.7e-03 0.17 -0.68 -3.3e-01 -1.3e-01 4013 6568 1.0 +#> log_lik[15] -2.8e-01 1.8e-03 0.11 -0.47 -2.6e-01 -1.3e-01 3538 5790 1.00 +#> log_lik[16] -2.8e-01 1.4e-03 0.086 -0.43 -2.7e-01 -1.5e-01 3558 5822 1.00 +#> log_lik[17] -1.6e+00 4.8e-03 0.29 -2.1 -1.6e+00 -1.2e+00 3654 5981 1.0 +#> log_lik[18] -4.8e-01 1.6e-03 0.11 -0.67 -4.7e-01 -3.1e-01 4457 7294 1.00 +#> log_lik[19] -2.3e-01 1.2e-03 0.075 -0.37 -2.3e-01 -1.2e-01 3731 6107 1.00 +#> log_lik[20] -1.1e-01 1.4e-03 0.080 -0.26 -9.3e-02 -2.7e-02 3471 5681 1.0 +#> log_lik[21] -2.1e-01 1.5e-03 0.086 -0.37 -2.0e-01 -9.3e-02 3393 5554 1.00 +#> log_lik[22] -5.7e-01 2.3e-03 0.15 -0.83 -5.6e-01 -3.5e-01 4157 6803 1.00 +#> log_lik[23] -3.3e-01 2.1e-03 0.14 -0.60 -3.1e-01 -1.4e-01 4351 7120 1.00 +#> log_lik[24] -1.4e-01 1.1e-03 0.066 -0.26 -1.2e-01 -5.2e-02 3635 5949 1.00 +#> log_lik[25] -4.6e-01 1.8e-03 0.12 -0.68 -4.5e-01 -2.8e-01 4638 7591 1.0 +#> log_lik[26] -1.5e+00 5.1e-03 0.34 -2.1 -1.5e+00 -1.0e+00 4383 7173 1.00 +#> log_lik[27] -3.1e-01 2.0e-03 0.12 -0.52 -2.9e-01 -1.4e-01 3553 5815 1.00 +#> log_lik[28] -4.4e-01 1.3e-03 0.083 -0.59 -4.4e-01 -3.2e-01 4086 6688 1.0 +#> log_lik[29] -7.3e-01 3.4e-03 0.23 -1.1 -7.0e-01 -3.9e-01 4476 7326 1.00 +#> log_lik[30] -6.9e-01 2.9e-03 0.19 -1.0 -6.8e-01 -4.1e-01 4511 7383 1.0 +#> log_lik[31] -4.9e-01 2.6e-03 0.16 -0.78 -4.7e-01 -2.6e-01 3899 6381 1.00 +#> log_lik[32] -4.2e-01 1.8e-03 0.11 -0.61 -4.1e-01 -2.7e-01 3671 6009 1.00 +#> log_lik[33] -4.1e-01 1.9e-03 0.13 -0.65 -4.0e-01 -2.3e-01 4622 7564 1.0 +#> log_lik[34] -6.4e-02 8.5e-04 0.050 -0.16 -5.0e-02 -1.3e-02 3474 5686 1.00 +#> log_lik[35] -5.9e-01 2.6e-03 0.18 -0.92 -5.7e-01 -3.2e-01 4937 8080 1.00 +#> log_lik[36] -3.2e-01 1.9e-03 0.13 -0.57 -3.1e-01 -1.5e-01 4737 7753 1.00 +#> log_lik[37] -7.0e-01 3.5e-03 0.23 -1.1 -6.7e-01 -3.7e-01 4158 6805 1.0 +#> log_lik[38] -3.1e-01 2.4e-03 0.15 -0.60 -2.9e-01 -1.2e-01 4035 6604 1.00 +#> log_lik[39] -1.8e-01 1.8e-03 0.11 -0.39 -1.5e-01 -5.2e-02 3644 5964 1.0 +#> log_lik[40] -6.8e-01 1.9e-03 0.13 -0.91 -6.7e-01 -4.8e-01 4470 7316 1.0 +#> log_lik[41] -1.1e+00 4.1e-03 0.25 -1.6 -1.1e+00 -7.6e-01 3765 6162 1.00 +#> log_lik[42] -9.3e-01 3.0e-03 0.20 -1.3 -9.1e-01 -6.3e-01 4354 7127 1.0 +#> log_lik[43] -4.1e-01 3.7e-03 0.26 -0.91 -3.5e-01 -1.0e-01 4788 7836 1.00 +#> log_lik[44] -1.2e+00 3.1e-03 0.19 -1.5 -1.2e+00 -8.9e-01 3623 5929 1.0 +#> log_lik[45] -3.6e-01 1.8e-03 0.12 -0.57 -3.4e-01 -1.9e-01 4021 6581 1.0 +#> log_lik[46] -5.8e-01 1.9e-03 0.13 -0.81 -5.7e-01 -3.9e-01 4786 7833 1.0 +#> log_lik[47] -3.1e-01 2.0e-03 0.13 -0.55 -2.9e-01 -1.4e-01 4246 6949 1.0 +#> log_lik[48] -3.2e-01 1.3e-03 0.082 -0.47 -3.2e-01 -2.0e-01 4166 6819 1.00 +#> log_lik[49] -3.2e-01 1.3e-03 0.079 -0.46 -3.1e-01 -2.0e-01 3546 5804 1.00 +#> log_lik[50] -1.3e+00 4.9e-03 0.33 -1.9 -1.3e+00 -8.0e-01 4492 7352 1.00 +#> log_lik[51] -2.9e-01 1.4e-03 0.093 -0.46 -2.8e-01 -1.6e-01 4451 7284 1.00 +#> log_lik[52] -8.4e-01 2.2e-03 0.14 -1.1 -8.3e-01 -6.2e-01 4245 6948 1.0 +#> log_lik[53] -4.0e-01 2.1e-03 0.13 -0.63 -3.9e-01 -2.2e-01 3748 6134 1.00 +#> log_lik[54] -3.7e-01 2.2e-03 0.14 -0.63 -3.5e-01 -1.7e-01 4130 6759 1.0 +#> log_lik[55] -3.9e-01 2.0e-03 0.14 -0.64 -3.7e-01 -2.0e-01 4649 7608 1.0 +#> log_lik[56] -3.2e-01 2.8e-03 0.19 -0.69 -2.8e-01 -9.5e-02 4610 7546 1.00 +#> log_lik[57] -6.6e-01 1.8e-03 0.12 -0.86 -6.5e-01 -4.7e-01 4203 6879 1.0 +#> log_lik[58] -9.5e-01 5.3e-03 0.36 -1.6 -9.0e-01 -4.4e-01 4498 7362 1.00 +#> log_lik[59] -1.4e+00 5.4e-03 0.34 -2.0 -1.3e+00 -8.4e-01 4097 6706 1.0 +#> log_lik[60] -9.8e-01 2.5e-03 0.16 -1.3 -9.7e-01 -7.3e-01 4050 6628 1.0 +#> log_lik[61] -5.4e-01 1.5e-03 0.098 -0.71 -5.3e-01 -3.9e-01 4382 7171 1.0 +#> log_lik[62] -8.8e-01 4.7e-03 0.31 -1.4 -8.4e-01 -4.4e-01 4166 6818 1.00 +#> log_lik[63] -1.2e-01 1.2e-03 0.072 -0.25 -1.0e-01 -3.2e-02 3346 5477 1.00 +#> log_lik[64] -9.0e-01 3.7e-03 0.25 -1.4 -8.8e-01 -5.3e-01 4389 7183 1.00 +#> log_lik[65] -2.0e+00 9.9e-03 0.58 -3.0 -2.0e+00 -1.1e+00 3440 5629 1.00 +#> log_lik[66] -5.1e-01 2.2e-03 0.14 -0.75 -5.0e-01 -3.1e-01 3804 6226 1.00 +#> log_lik[67] -2.8e-01 1.3e-03 0.081 -0.42 -2.7e-01 -1.6e-01 4007 6558 1.00 +#> log_lik[68] -1.1e+00 3.7e-03 0.24 -1.5 -1.0e+00 -7.0e-01 4155 6800 1.00 +#> log_lik[69] -4.3e-01 1.4e-03 0.084 -0.58 -4.3e-01 -3.1e-01 3753 6142 1.00 +#> log_lik[70] -6.4e-01 3.5e-03 0.24 -1.1 -6.1e-01 -3.1e-01 4500 7365 1.00 +#> log_lik[71] -6.1e-01 3.0e-03 0.21 -0.99 -5.8e-01 -3.1e-01 4571 7481 1.00 +#> log_lik[72] -4.6e-01 2.6e-03 0.17 -0.78 -4.4e-01 -2.2e-01 4261 6974 1.00 +#> log_lik[73] -1.5e+00 5.8e-03 0.37 -2.1 -1.5e+00 -9.2e-01 4023 6585 1.0 +#> log_lik[74] -9.5e-01 3.1e-03 0.20 -1.3 -9.4e-01 -6.5e-01 4106 6721 1.00 +#> log_lik[75] -1.1e+00 5.9e-03 0.38 -1.9 -1.1e+00 -5.9e-01 4198 6870 1.00 +#> log_lik[76] -3.7e-01 2.2e-03 0.14 -0.63 -3.5e-01 -1.8e-01 3982 6517 1.0 +#> log_lik[77] -8.8e-01 2.2e-03 0.14 -1.1 -8.7e-01 -6.6e-01 4043 6618 1.0 +#> log_lik[78] -4.8e-01 2.5e-03 0.17 -0.79 -4.6e-01 -2.5e-01 4533 7418 1.00 +#> log_lik[79] -7.6e-01 3.0e-03 0.19 -1.1 -7.5e-01 -4.8e-01 4054 6635 1.0 +#> log_lik[80] -5.4e-01 2.8e-03 0.19 -0.89 -5.2e-01 -2.7e-01 4782 7827 1.0 +#> log_lik[81] -1.6e-01 1.6e-03 0.10 -0.37 -1.4e-01 -4.9e-02 4161 6810 1.0 +#> log_lik[82] -2.2e-01 2.1e-03 0.14 -0.49 -1.9e-01 -6.5e-02 4340 7103 1.0 +#> log_lik[83] -3.4e-01 1.3e-03 0.081 -0.48 -3.4e-01 -2.2e-01 3663 5996 1.0 +#> log_lik[84] -2.7e-01 1.5e-03 0.092 -0.44 -2.6e-01 -1.5e-01 3524 5767 1.00 +#> log_lik[85] -1.3e-01 1.3e-03 0.076 -0.28 -1.1e-01 -4.1e-02 3532 5780 1.0 +#> log_lik[86] -1.1e+00 4.8e-03 0.32 -1.7 -1.1e+00 -6.6e-01 4283 7011 1.0 +#> log_lik[87] -8.2e-01 1.9e-03 0.13 -1.0 -8.2e-01 -6.3e-01 4347 7115 1.0 +#> log_lik[88] -7.8e-01 3.7e-03 0.24 -1.2 -7.5e-01 -4.3e-01 4170 6825 1.00 +#> log_lik[89] -1.3e+00 5.0e-03 0.32 -1.8 -1.2e+00 -7.9e-01 4012 6566 1.0 +#> log_lik[90] -2.6e-01 2.1e-03 0.14 -0.53 -2.4e-01 -9.3e-02 4313 7058 1.00 +#> log_lik[91] -3.9e-01 1.9e-03 0.13 -0.63 -3.7e-01 -2.1e-01 4620 7562 1.0 +#> log_lik[92] -1.5e+00 5.7e-03 0.34 -2.1 -1.5e+00 -9.8e-01 3518 5758 1.00 +#> log_lik[93] -7.4e-01 3.5e-03 0.22 -1.1 -7.2e-01 -4.2e-01 3871 6336 1.00 +#> log_lik[94] -3.2e-01 1.4e-03 0.088 -0.48 -3.1e-01 -1.9e-01 3732 6107 1.0 +#> log_lik[95] -3.9e-01 1.8e-03 0.11 -0.58 -3.8e-01 -2.3e-01 3830 6269 1.00 +#> log_lik[96] -1.6e+00 4.8e-03 0.28 -2.1 -1.6e+00 -1.1e+00 3457 5657 1.0 +#> log_lik[97] -4.3e-01 1.5e-03 0.10 -0.61 -4.2e-01 -2.8e-01 4740 7758 1.00 +#> log_lik[98] -1.0e+00 5.5e-03 0.37 -1.7 -1.0e+00 -5.1e-01 4582 7499 1.00 +#> log_lik[99] -6.9e-01 2.1e-03 0.14 -0.95 -6.8e-01 -4.8e-01 4565 7472 1.0 +#> log_lik[100] -3.9e-01 1.5e-03 0.096 -0.56 -3.8e-01 -2.5e-01 4243 6945 1.0 #> #> Samples were drawn using hmc with nuts. #> For each parameter, N_Eff is a crude measure of effective sample size, @@ -303,11 +303,11 @@

    Examples

    diff --git a/docs/reference/fit-method-code.html b/docs/reference/fit-method-code.html index e2080e07..cdf0e851 100644 --- a/docs/reference/fit-method-code.html +++ b/docs/reference/fit-method-code.html @@ -1,5 +1,5 @@ -Return Stan code — fit-method-code • cmdstanrReturn Stan code — fit-method-code • cmdstanr @@ -17,7 +17,7 @@ cmdstanr - 0.7.0 + 0.8.1 @@ -183,11 +183,11 @@

    Examples

    diff --git a/docs/reference/fit-method-constrain_variables.html b/docs/reference/fit-method-constrain_variables.html index 122d2d4b..ed77fc8a 100644 --- a/docs/reference/fit-method-constrain_variables.html +++ b/docs/reference/fit-method-constrain_variables.html @@ -1,5 +1,5 @@ -Transform a set of unconstrained parameter values to the constrained scale — fit-method-constrain_variables • cmdstanrTransform a set of unconstrained parameter values to the constrained scale — fit-method-constrain_variables • cmdstanrSampler diagnostic summaries and warnings — fit-method-diagnostic_summary • cmdstanrSampler diagnostic summaries and warnings — fit-method-diagnostic_summary • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -161,29 +161,33 @@

    See also

    Examples

    # \dontrun{
     fit <- cmdstanr_example("schools")
    -#> Warning: 91 of 4000 (2.0%) transitions ended with a divergence.
    +#> Warning: 235 of 4000 (6.0%) transitions ended with a divergence.
    +#> See https://mc-stan.org/misc/warnings for details.
    +#> Warning: 2 of 4 chains had an E-BFMI less than 0.3.
     #> See https://mc-stan.org/misc/warnings for details.
     fit$diagnostic_summary()
    -#> Warning: 91 of 4000 (2.0%) transitions ended with a divergence.
    +#> Warning: 235 of 4000 (6.0%) transitions ended with a divergence.
    +#> See https://mc-stan.org/misc/warnings for details.
    +#> Warning: 2 of 4 chains had an E-BFMI less than 0.3.
     #> See https://mc-stan.org/misc/warnings for details.
     #> $num_divergent
    -#> [1] 12 18 11 50
    +#> [1] 104  30  98   3
     #> 
     #> $num_max_treedepth
     #> [1] 0 0 0 0
     #> 
     #> $ebfmi
    -#> [1] 0.3003970 0.2974182 0.3438194 0.4920025
    +#> [1] 0.4564907 0.4041931 0.2577905 0.2642813
     #> 
     fit$diagnostic_summary(quiet = TRUE)
     #> $num_divergent
    -#> [1] 12 18 11 50
    +#> [1] 104  30  98   3
     #> 
     #> $num_max_treedepth
     #> [1] 0 0 0 0
     #> 
     #> $ebfmi
    -#> [1] 0.3003970 0.2974182 0.3438194 0.4920025
    +#> [1] 0.4564907 0.4041931 0.2577905 0.2642813
     #> 
     # }
     
    @@ -197,11 +201,11 @@ 

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/fit-method-draws-1.png b/docs/reference/fit-method-draws-1.png index a6899fc4..b241904b 100644 Binary files a/docs/reference/fit-method-draws-1.png and b/docs/reference/fit-method-draws-1.png differ diff --git a/docs/reference/fit-method-draws-2.png b/docs/reference/fit-method-draws-2.png index fb93238c..b9abe398 100644 Binary files a/docs/reference/fit-method-draws-2.png and b/docs/reference/fit-method-draws-2.png differ diff --git a/docs/reference/fit-method-draws.html b/docs/reference/fit-method-draws.html index b257cb5d..c7816907 100644 --- a/docs/reference/fit-method-draws.html +++ b/docs/reference/fit-method-draws.html @@ -1,5 +1,5 @@ -Extract posterior draws — fit-method-draws • cmdstanrExtract posterior draws — fit-method-draws • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -203,7 +203,7 @@

    Examples

    dim(draws) #> [1] 1000 4 105 str(draws) -#> 'draws_array' num [1:1000, 1:4, 1:105] -64.2 -65.3 -65.3 -64.7 -64.8 ... +#> 'draws_array' num [1:1000, 1:4, 1:105] -65 -66.8 -64.9 -66.9 -66.5 ... #> - attr(*, "dimnames")=List of 3 #> ..$ iteration: chr [1:1000] "1" "2" "3" "4" ... #> ..$ chain : chr [1:4] "1" "2" "3" "4" @@ -214,13 +214,13 @@

    Examples

    head(posterior::as_draws_matrix(draws)) #> # A draws_matrix: 6 iterations, 1 chains, and 105 variables #> variable -#> draw lp__ alpha beta[1] beta[2] beta[3] log_lik[1] log_lik[2] log_lik[3] -#> 1 -64 0.28 -0.73 -0.16 0.73 -0.53 -0.30 -0.39 -#> 2 -65 0.19 -0.42 -0.13 0.37 -0.59 -0.48 -0.53 -#> 3 -65 0.61 -0.93 -0.25 0.83 -0.40 -0.34 -0.30 -#> 4 -65 0.42 -0.81 -0.32 0.94 -0.50 -0.28 -0.41 -#> 5 -65 0.36 -0.41 -0.20 0.39 -0.52 -0.56 -0.52 -#> 6 -67 0.55 -0.24 -0.43 0.24 -0.49 -0.87 -0.75 +#> draw lp__ alpha beta[1] beta[2] beta[3] log_lik[1] log_lik[2] log_lik[3] +#> 1 -65 0.363 -0.70 -0.26 1.04 -0.53 -0.24 -0.40 +#> 2 -67 0.522 -0.55 -0.61 1.18 -0.54 -0.30 -0.65 +#> 3 -65 0.607 -0.57 -0.41 0.82 -0.46 -0.44 -0.49 +#> 4 -67 -0.012 -0.52 -0.11 0.25 -0.65 -0.44 -0.59 +#> 5 -67 0.715 -0.77 -0.34 1.14 -0.41 -0.29 -0.32 +#> 6 -65 0.473 -0.42 -0.41 0.76 -0.52 -0.45 -0.60 #> # ... with 97 more variables # or can specify 'format' argument to avoid manual conversion @@ -229,13 +229,13 @@

    Examples

    head(draws) #> # A draws_matrix: 6 iterations, 1 chains, and 105 variables #> variable -#> draw lp__ alpha beta[1] beta[2] beta[3] log_lik[1] log_lik[2] log_lik[3] -#> 1 -64 0.28 -0.73 -0.16 0.73 -0.53 -0.30 -0.39 -#> 2 -65 0.19 -0.42 -0.13 0.37 -0.59 -0.48 -0.53 -#> 3 -65 0.61 -0.93 -0.25 0.83 -0.40 -0.34 -0.30 -#> 4 -65 0.42 -0.81 -0.32 0.94 -0.50 -0.28 -0.41 -#> 5 -65 0.36 -0.41 -0.20 0.39 -0.52 -0.56 -0.52 -#> 6 -67 0.55 -0.24 -0.43 0.24 -0.49 -0.87 -0.75 +#> draw lp__ alpha beta[1] beta[2] beta[3] log_lik[1] log_lik[2] log_lik[3] +#> 1 -65 0.363 -0.70 -0.26 1.04 -0.53 -0.24 -0.40 +#> 2 -67 0.522 -0.55 -0.61 1.18 -0.54 -0.30 -0.65 +#> 3 -65 0.607 -0.57 -0.41 0.82 -0.46 -0.44 -0.49 +#> 4 -67 -0.012 -0.52 -0.11 0.25 -0.65 -0.44 -0.59 +#> 5 -67 0.715 -0.77 -0.34 1.14 -0.41 -0.29 -0.32 +#> 6 -65 0.473 -0.42 -0.41 0.76 -0.52 -0.45 -0.60 #> # ... with 97 more variables # can select specific parameters @@ -244,12 +244,12 @@

    Examples

    #> , , variable = alpha #> #> chain -#> iteration 1 2 3 4 -#> 1 0.28 0.27 0.62 0.10 -#> 2 0.19 0.70 0.49 0.71 -#> 3 0.61 0.26 0.89 0.14 -#> 4 0.42 0.39 0.58 0.39 -#> 5 0.36 0.39 0.58 0.48 +#> iteration 1 2 3 4 +#> 1 0.363 0.52 0.50 -0.0071 +#> 2 0.522 0.50 0.46 0.3258 +#> 3 0.607 0.19 0.25 0.2788 +#> 4 -0.012 0.13 0.41 0.2299 +#> 5 0.715 0.48 0.40 0.6308 #> #> # ... with 995 more iterations fit$draws("beta") # selects entire vector beta @@ -258,31 +258,31 @@

    Examples

    #> #> chain #> iteration 1 2 3 4 -#> 1 -0.73 -0.46 -0.82 -0.55 -#> 2 -0.42 -0.92 -1.18 -1.08 -#> 3 -0.93 -0.52 -0.63 -0.42 -#> 4 -0.81 -0.86 -0.30 -0.72 -#> 5 -0.41 -0.86 -0.30 -0.86 +#> 1 -0.70 -0.74 -0.87 -0.37 +#> 2 -0.55 -0.71 -0.58 -0.84 +#> 3 -0.57 -0.85 -0.59 -0.37 +#> 4 -0.52 -0.66 -0.60 -0.53 +#> 5 -0.77 -0.40 -0.55 -0.68 #> #> , , variable = beta[2] #> #> chain -#> iteration 1 2 3 4 -#> 1 -0.16 -0.31 -0.88 -0.18 -#> 2 -0.13 -0.27 -0.69 -0.21 -#> 3 -0.25 -0.39 -0.38 -0.37 -#> 4 -0.32 -0.43 -0.52 -0.36 -#> 5 -0.20 -0.43 -0.52 -0.42 +#> iteration 1 2 3 4 +#> 1 -0.26 -0.12 -0.28 -0.474 +#> 2 -0.61 -0.12 -0.51 -0.487 +#> 3 -0.41 -0.10 -0.22 -0.069 +#> 4 -0.11 -0.14 -0.13 -0.094 +#> 5 -0.34 -0.08 -0.58 -0.328 #> #> , , variable = beta[3] #> #> chain #> iteration 1 2 3 4 -#> 1 0.73 0.28 0.87 0.93 -#> 2 0.37 1.26 0.75 0.45 -#> 3 0.83 0.28 0.88 0.83 -#> 4 0.94 0.64 0.71 0.48 -#> 5 0.39 0.64 0.71 0.41 +#> 1 1.04 0.96 0.78 0.75 +#> 2 1.18 0.90 0.40 0.81 +#> 3 0.82 0.29 1.27 0.64 +#> 4 0.25 0.45 0.97 0.64 +#> 5 1.14 0.18 0.54 0.66 #> #> # ... with 995 more iterations fit$draws(c("alpha", "beta[2]")) @@ -290,22 +290,22 @@

    Examples

    #> , , variable = alpha #> #> chain -#> iteration 1 2 3 4 -#> 1 0.28 0.27 0.62 0.10 -#> 2 0.19 0.70 0.49 0.71 -#> 3 0.61 0.26 0.89 0.14 -#> 4 0.42 0.39 0.58 0.39 -#> 5 0.36 0.39 0.58 0.48 +#> iteration 1 2 3 4 +#> 1 0.363 0.52 0.50 -0.0071 +#> 2 0.522 0.50 0.46 0.3258 +#> 3 0.607 0.19 0.25 0.2788 +#> 4 -0.012 0.13 0.41 0.2299 +#> 5 0.715 0.48 0.40 0.6308 #> #> , , variable = beta[2] #> #> chain -#> iteration 1 2 3 4 -#> 1 -0.16 -0.31 -0.88 -0.18 -#> 2 -0.13 -0.27 -0.69 -0.21 -#> 3 -0.25 -0.39 -0.38 -0.37 -#> 4 -0.32 -0.43 -0.52 -0.36 -#> 5 -0.20 -0.43 -0.52 -0.42 +#> iteration 1 2 3 4 +#> 1 -0.26 -0.12 -0.28 -0.474 +#> 2 -0.61 -0.12 -0.51 -0.487 +#> 3 -0.41 -0.10 -0.22 -0.069 +#> 4 -0.11 -0.14 -0.13 -0.094 +#> 5 -0.34 -0.08 -0.58 -0.328 #> #> # ... with 995 more iterations @@ -323,21 +323,21 @@

    Examples

    #> # A draws_matrix: 6 iterations, 1 chains, and 3 variables #> variable #> draw beta[1] beta[2] beta[3] -#> 1 -0.62 -0.485 0.63 -#> 2 -0.34 0.188 0.77 -#> 3 -0.63 -0.236 0.90 -#> 4 -0.65 -0.392 0.76 -#> 5 -0.57 0.028 0.44 -#> 6 -0.58 -0.299 0.69 +#> 1 -0.80 -0.25 0.98 +#> 2 -0.56 -0.31 0.57 +#> 3 -0.98 -0.35 0.66 +#> 4 -0.67 -0.78 0.49 +#> 5 -0.98 -0.38 0.75 +#> 6 -0.52 -0.52 0.37 head(fit$draws("beta", format = "df")) #> # A draws_df: 6 iterations, 1 chains, and 3 variables #> beta[1] beta[2] beta[3] -#> 1 -0.62 -0.485 0.63 -#> 2 -0.34 0.188 0.77 -#> 3 -0.63 -0.236 0.90 -#> 4 -0.65 -0.392 0.76 -#> 5 -0.57 0.028 0.44 -#> 6 -0.58 -0.299 0.69 +#> 1 -0.80 -0.25 0.98 +#> 2 -0.56 -0.31 0.57 +#> 3 -0.98 -0.35 0.66 +#> 4 -0.67 -0.78 0.49 +#> 5 -0.98 -0.38 0.75 +#> 6 -0.52 -0.52 0.37 #> # ... hidden reserved variables {'.chain', '.iteration', '.draw'} # } @@ -351,11 +351,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/fit-method-grad_log_prob.html b/docs/reference/fit-method-grad_log_prob.html index e6dae257..93ab582f 100644 --- a/docs/reference/fit-method-grad_log_prob.html +++ b/docs/reference/fit-method-grad_log_prob.html @@ -1,7 +1,5 @@ -Calculate the log-probability and the gradient w.r.t. each input for a -given vector of unconstrained parameters — fit-method-grad_log_prob • cmdstanrCalculate the log-probability and the gradient w.r.t. each input for a given vector of unconstrained parameters — fit-method-grad_log_prob • cmdstanrExtract gradients after diagnostic mode — fit-method-gradients • cmdstanrExtract gradients after diagnostic mode — fit-method-gradients • cmdstanrCalculate the log-probability , the gradient w.r.t. each input, and the hessian -for a given vector of unconstrained parameters — fit-method-hessian • cmdstanrCalculate the log-probability , the gradient w.r.t. each input, and the hessian for a given vector of unconstrained parameters — fit-method-hessian • cmdstanrExtract user-specified initial values — fit-method-init • cmdstanrExtract user-specified initial values — fit-method-init • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -140,11 +140,11 @@

    Examples

    str(fit$init()) #> List of 2 #> $ :List of 2 -#> ..$ alpha: num -0.538 -#> ..$ beta : num [1:3] -0.0289 1.8267 1.6042 +#> ..$ alpha: num -1.12 +#> ..$ beta : num [1:3] 0.398 0.421 -0.425 #> $ :List of 2 -#> ..$ alpha: num -1.4 -#> ..$ beta : num [1:3] -1.313 -1.04 0.224 +#> ..$ alpha: num -0.877 +#> ..$ beta : num [1:3] 1.3 -1.34 1.43 # partial inits (only specifying for a subset of parameters) init_list <- list( @@ -156,6 +156,8 @@

    Examples

    #> Missing init values for the following parameters: #> - chain 1: theta_raw #> - chain 2: theta_raw +#> +#> To disable this message use options(cmdstanr_warn_inits = FALSE). # only user-specified inits returned str(fit$init()) @@ -178,11 +180,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/fit-method-init_model_methods.html b/docs/reference/fit-method-init_model_methods.html index d27c2170..83a00fb4 100644 --- a/docs/reference/fit-method-init_model_methods.html +++ b/docs/reference/fit-method-init_model_methods.html @@ -1,11 +1,9 @@ -Compile additional methods for accessing the model log-probability function -and parameter constraining and unconstraining. — fit-method-init_model_methods • cmdstanrCompile additional methods for accessing the model log-probability function and parameter constraining and unconstraining. — fit-method-init_model_methods • cmdstanrExtract inverse metric (mass matrix) after MCMC — fit-method-inv_metric • cmdstanrExtract inverse metric (mass matrix) after MCMC — fit-method-inv_metric • cmdstanr @@ -17,7 +17,7 @@ cmdstanr - 0.7.0 + 0.8.1 @@ -139,76 +139,76 @@

    Examples

    fit <- cmdstanr_example("logistic") fit$inv_metric() #> $`1` -#> [,1] [,2] [,3] [,4] -#> [1,] 0.0435508 0.0000000 0.0000000 0.0000000 -#> [2,] 0.0000000 0.0607469 0.0000000 0.0000000 -#> [3,] 0.0000000 0.0000000 0.0503494 0.0000000 -#> [4,] 0.0000000 0.0000000 0.0000000 0.0672705 +#> [,1] [,2] [,3] [,4] +#> [1,] 0.041261 0.0000000 0.0000000 0.0000000 +#> [2,] 0.000000 0.0524298 0.0000000 0.0000000 +#> [3,] 0.000000 0.0000000 0.0481435 0.0000000 +#> [4,] 0.000000 0.0000000 0.0000000 0.0732764 #> #> $`2` -#> [,1] [,2] [,3] [,4] -#> [1,] 0.0532065 0.0000000 0.0000000 0.0000000 -#> [2,] 0.0000000 0.0574785 0.0000000 0.0000000 -#> [3,] 0.0000000 0.0000000 0.0512835 0.0000000 -#> [4,] 0.0000000 0.0000000 0.0000000 0.0641874 +#> [,1] [,2] [,3] [,4] +#> [1,] 0.0476774 0.0000000 0.000000 0.0000000 +#> [2,] 0.0000000 0.0504326 0.000000 0.0000000 +#> [3,] 0.0000000 0.0000000 0.052821 0.0000000 +#> [4,] 0.0000000 0.0000000 0.000000 0.0711489 #> #> $`3` -#> [,1] [,2] [,3] [,4] -#> [1,] 0.0502858 0.0000000 0.0000000 0.0000000 -#> [2,] 0.0000000 0.0629888 0.0000000 0.0000000 -#> [3,] 0.0000000 0.0000000 0.0512933 0.0000000 -#> [4,] 0.0000000 0.0000000 0.0000000 0.0661664 +#> [,1] [,2] [,3] [,4] +#> [1,] 0.0465449 0.000000 0.0000000 0.0000000 +#> [2,] 0.0000000 0.058276 0.0000000 0.0000000 +#> [3,] 0.0000000 0.000000 0.0462442 0.0000000 +#> [4,] 0.0000000 0.000000 0.0000000 0.0746648 #> #> $`4` -#> [,1] [,2] [,3] [,4] -#> [1,] 0.0453724 0.000000 0.00000 0.0000000 -#> [2,] 0.0000000 0.061371 0.00000 0.0000000 -#> [3,] 0.0000000 0.000000 0.04017 0.0000000 -#> [4,] 0.0000000 0.000000 0.00000 0.0682251 +#> [,1] [,2] [,3] [,4] +#> [1,] 0.043908 0.0000000 0.000000 0.0000000 +#> [2,] 0.000000 0.0657091 0.000000 0.0000000 +#> [3,] 0.000000 0.0000000 0.048942 0.0000000 +#> [4,] 0.000000 0.0000000 0.000000 0.0632482 #> fit$inv_metric(matrix=FALSE) #> $`1` -#> [1] 0.0435508 0.0607469 0.0503494 0.0672705 +#> [1] 0.0412610 0.0524298 0.0481435 0.0732764 #> #> $`2` -#> [1] 0.0532065 0.0574785 0.0512835 0.0641874 +#> [1] 0.0476774 0.0504326 0.0528210 0.0711489 #> #> $`3` -#> [1] 0.0502858 0.0629888 0.0512933 0.0661664 +#> [1] 0.0465449 0.0582760 0.0462442 0.0746648 #> #> $`4` -#> [1] 0.0453724 0.0613710 0.0401700 0.0682251 +#> [1] 0.0439080 0.0657091 0.0489420 0.0632482 #> fit <- cmdstanr_example("logistic", metric = "dense_e") fit$inv_metric() #> $`1` #> [,1] [,2] [,3] [,4] -#> [1,] 0.04487240 -0.00665557 0.00248036 -0.00336473 -#> [2,] -0.00665557 0.05394230 -0.00841737 -0.00815855 -#> [3,] 0.00248036 -0.00841737 0.04945140 -0.01015960 -#> [4,] -0.00336473 -0.00815855 -0.01015960 0.07289150 +#> [1,] 0.05192450 -0.00808928 0.00233609 0.00537011 +#> [2,] -0.00808928 0.05617200 -0.00192090 -0.00711062 +#> [3,] 0.00233609 -0.00192090 0.04964080 -0.01391690 +#> [4,] 0.00537011 -0.00711062 -0.01391690 0.07126540 #> #> $`2` -#> [,1] [,2] [,3] [,4] -#> [1,] 0.044891100 -0.00756532 0.00352846 -0.000462971 -#> [2,] -0.007565320 0.06064960 -0.00809279 -0.004813840 -#> [3,] 0.003528460 -0.00809279 0.05892730 -0.016947100 -#> [4,] -0.000462971 -0.00481384 -0.01694710 0.063878300 +#> [,1] [,2] [,3] [,4] +#> [1,] 0.044604400 0.000608339 0.00107581 0.00451756 +#> [2,] 0.000608339 0.058117400 -0.01088670 -0.00141863 +#> [3,] 0.001075810 -0.010886700 0.04437890 -0.00650639 +#> [4,] 0.004517560 -0.001418630 -0.00650639 0.06984850 #> #> $`3` -#> [,1] [,2] [,3] [,4] -#> [1,] 0.047806100 0.000761202 0.00579535 0.00494546 -#> [2,] 0.000761202 0.062074500 -0.00488086 -0.01014510 -#> [3,] 0.005795350 -0.004880860 0.05170230 -0.00609765 -#> [4,] 0.004945460 -0.010145100 -0.00609765 0.07081120 +#> [,1] [,2] [,3] [,4] +#> [1,] 0.04180740 -0.001275980 0.005750270 0.00305686 +#> [2,] -0.00127598 0.054490900 -0.000483551 -0.00770396 +#> [3,] 0.00575027 -0.000483551 0.044247700 -0.01478120 +#> [4,] 0.00305686 -0.007703960 -0.014781200 0.06501070 #> #> $`4` -#> [,1] [,2] [,3] [,4] -#> [1,] 0.04387350 0.004639300 0.001929550 0.00526756 -#> [2,] 0.00463930 0.064076200 -0.000902685 -0.00609741 -#> [3,] 0.00192955 -0.000902685 0.045911200 -0.00859578 -#> [4,] 0.00526756 -0.006097410 -0.008595780 0.07087270 +#> [,1] [,2] [,3] [,4] +#> [1,] 4.17467e-02 -0.000269914 4.51726e-05 0.00472656 +#> [2,] -2.69914e-04 0.061160800 -1.36053e-02 -0.00637189 +#> [3,] 4.51726e-05 -0.013605300 4.96363e-02 -0.00759941 +#> [4,] 4.72656e-03 -0.006371890 -7.59941e-03 0.06762740 #> # } @@ -222,11 +222,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/fit-method-log_prob.html b/docs/reference/fit-method-log_prob.html index 561ca052..74b7e2f2 100644 --- a/docs/reference/fit-method-log_prob.html +++ b/docs/reference/fit-method-log_prob.html @@ -1,5 +1,5 @@ -Calculate the log-probability given a provided vector of unconstrained parameters. — fit-method-log_prob • cmdstanrCalculate the log-probability given a provided vector of unconstrained parameters. — fit-method-log_prob • cmdstanrLeave-one-out cross-validation (LOO-CV) — fit-method-loo • cmdstanrLeave-one-out cross-validation (LOO-CV) — fit-method-loo • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -131,8 +131,9 @@

    Arguments

    r_eff

    (multiple options) How to handle the r_eff argument for loo():

    • TRUE (the default) will automatically call loo::relative_eff.array() to compute the r_eff argument to pass to loo::loo.array().

    • -
    • FALSE or NULL will avoid computing r_eff (which can sometimes be slow) -but will result in a warning from the loo package.

    • +
    • FALSE or NULL will avoid computing r_eff (which can sometimes be slow), +but the reported ESS and MCSE estimates can be over-optimistic if the +posterior draws are not (near) independent.

    • If r_eff is anything else, that object will be passed as the r_eff argument to loo::loo.array().

    @@ -178,16 +179,17 @@

    Examples

    loo_result <- fit$loo(cores = 2) print(loo_result) #> -#> Computed from 4000 by 100 log-likelihood matrix +#> Computed from 4000 by 100 log-likelihood matrix. #> #> Estimate SE #> elpd_loo -63.7 4.1 #> p_loo 3.9 0.5 #> looic 127.4 8.2 #> ------ -#> Monte Carlo SE of elpd_loo is 0.0. +#> MCSE of elpd_loo is 0.0. +#> MCSE and ESS estimates assume MCMC draws (r_eff in [0.9, 1.4]). #> -#> All Pareto k estimates are good (k < 0.5). +#> All Pareto k estimates are good (k < 0.7). #> See help('pareto-k-diagnostic') for details. # } @@ -201,11 +203,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/fit-method-lp-1.png b/docs/reference/fit-method-lp-1.png index 980bd46b..7016ed34 100644 Binary files a/docs/reference/fit-method-lp-1.png and b/docs/reference/fit-method-lp-1.png differ diff --git a/docs/reference/fit-method-lp.html b/docs/reference/fit-method-lp.html index bca9a329..180e4c9a 100644 --- a/docs/reference/fit-method-lp.html +++ b/docs/reference/fit-method-lp.html @@ -1,5 +1,5 @@ -Extract log probability (target) — fit-method-lp • cmdstanrExtract log probability (target) — fit-method-lp • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -170,7 +170,7 @@

    Examples

    # \dontrun{
     fit_mcmc <- cmdstanr_example("logistic")
     head(fit_mcmc$lp())
    -#> [1] -65.6405 -64.4734 -65.4431 -64.9703 -65.8088 -65.6905
    +#> [1] -64.8724 -65.7859 -65.2974 -66.5566 -66.7795 -67.0780
     
     fit_mle <- cmdstanr_example("logistic", method = "optimize")
     fit_mle$lp()
    @@ -191,11 +191,11 @@ 

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/fit-method-metadata.html b/docs/reference/fit-method-metadata.html index 01634904..aefeb0b6 100644 --- a/docs/reference/fit-method-metadata.html +++ b/docs/reference/fit-method-metadata.html @@ -1,5 +1,5 @@ -Extract metadata from CmdStan CSV files — fit-method-metadata • cmdstanrExtract metadata from CmdStan CSV files — fit-method-metadata • cmdstanrExtract (penalized) maximum likelihood estimate after optimization — fit-method-mle • cmdstanrExtract (penalized) maximum likelihood estimate after optimization — fit-method-mle • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -148,13 +148,13 @@

    Examples

    fit <- cmdstanr_example("logistic", method = "optimize") fit$mle("alpha") #> alpha -#> 0.364472 +#> 0.364419 fit$mle("beta") #> beta[1] beta[2] beta[3] -#> -0.631560 -0.258925 0.648500 +#> -0.631543 -0.258962 0.648511 fit$mle("beta[2]") #> beta[2] -#> -0.258925 +#> -0.258962 # }
    @@ -167,11 +167,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/fit-method-num_chains.html b/docs/reference/fit-method-num_chains.html index c2dd85e5..0cce33e5 100644 --- a/docs/reference/fit-method-num_chains.html +++ b/docs/reference/fit-method-num_chains.html @@ -1,5 +1,5 @@ -Extract number of chains after MCMC — fit-method-num_chains • cmdstanrExtract number of chains after MCMC — fit-method-num_chains • cmdstanr @@ -17,7 +17,7 @@ cmdstanr - 0.7.0 + 0.8.1 @@ -140,11 +140,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/fit-method-output.html b/docs/reference/fit-method-output.html index ba2dc64f..9d6e9076 100644 --- a/docs/reference/fit-method-output.html +++ b/docs/reference/fit-method-output.html @@ -1,5 +1,5 @@ -Access console output — fit-method-output • cmdstanrAccess console output — fit-method-output • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -143,17 +143,18 @@

    Examples

    #> sample #> num_samples = 1000 (Default) #> num_warmup = 1000 (Default) -#> save_warmup = 0 (Default) +#> save_warmup = false (Default) #> thin = 1 (Default) #> adapt -#> engaged = 1 (Default) -#> gamma = 0.050000000000000003 (Default) -#> delta = 0.80000000000000004 (Default) +#> engaged = true (Default) +#> gamma = 0.05 (Default) +#> delta = 0.8 (Default) #> kappa = 0.75 (Default) #> t0 = 10 (Default) #> init_buffer = 75 (Default) #> term_buffer = 50 (Default) #> window = 25 (Default) +#> save_metric = false (Default) #> algorithm = hmc (Default) #> hmc #> engine = nuts (Default) @@ -166,21 +167,22 @@

    Examples

    #> num_chains = 1 (Default) #> id = 1 (Default) #> data -#> file = /private/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmps9TW4l/temp_libpath5800f91909/cmdstanr/logistic.data.json +#> file = /private/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpBGNQRs/temp_libpath45223306cea5/cmdstanr/logistic.data.json #> init = 2 (Default) #> random -#> seed = 1467887685 +#> seed = 1162623978 #> output -#> file = /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/logistic-202312131004-1-910e87.csv +#> file = /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/logistic-202407021538-1-35ac7c.csv #> diagnostic_file = (Default) #> refresh = 100 (Default) #> sig_figs = -1 (Default) -#> profile_file = /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/logistic-profile-202312131004-1-90a553.csv +#> profile_file = /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/logistic-profile-202407021538-1-88cb05.csv +#> save_cmdstan_config = false (Default) #> num_threads = 1 (Default) #> #> -#> Gradient evaluation took 1.9e-05 seconds -#> 1000 transitions using 10 leapfrog steps per transition would take 0.19 seconds. +#> Gradient evaluation took 5.1e-05 seconds +#> 1000 transitions using 10 leapfrog steps per transition would take 0.51 seconds. #> Adjust your expectations accordingly! #> #> @@ -207,16 +209,16 @@

    Examples

    #> Iteration: 1900 / 2000 [ 95%] (Sampling) #> Iteration: 2000 / 2000 [100%] (Sampling) #> -#> Elapsed Time: 0.022 seconds (Warm-up) -#> 0.072 seconds (Sampling) -#> 0.094 seconds (Total) +#> Elapsed Time: 0.028 seconds (Warm-up) +#> 0.097 seconds (Sampling) +#> 0.125 seconds (Total) out <- fit_mcmc$output() str(out) #> List of 4 -#> $ : chr [1:73] "" "method = sample (Default)" " sample" " num_samples = 1000 (Default)" ... -#> $ : chr [1:73] "" "method = sample (Default)" " sample" " num_samples = 1000 (Default)" ... -#> $ : chr [1:73] "" "method = sample (Default)" " sample" " num_samples = 1000 (Default)" ... -#> $ : chr [1:73] "" "method = sample (Default)" " sample" " num_samples = 1000 (Default)" ... +#> $ : chr [1:75] "" "method = sample (Default)" " sample" " num_samples = 1000 (Default)" ... +#> $ : chr [1:75] "" "method = sample (Default)" " sample" " num_samples = 1000 (Default)" ... +#> $ : chr [1:75] "" "method = sample (Default)" " sample" " num_samples = 1000 (Default)" ... +#> $ : chr [1:75] "" "method = sample (Default)" " sample" " num_samples = 1000 (Default)" ... fit_mle <- cmdstanr_example("logistic", method = "optimize") fit_mle$output() @@ -226,32 +228,33 @@

    Examples

    #> algorithm = lbfgs (Default) #> lbfgs #> init_alpha = 0.001 (Default) -#> tol_obj = 9.9999999999999998e-13 (Default) +#> tol_obj = 1e-12 (Default) #> tol_rel_obj = 10000 (Default) #> tol_grad = 1e-08 (Default) -#> tol_rel_grad = 10000000 (Default) +#> tol_rel_grad = 1e+07 (Default) #> tol_param = 1e-08 (Default) #> history_size = 5 (Default) -#> jacobian = 0 (Default) +#> jacobian = false (Default) #> iter = 2000 (Default) -#> save_iterations = 0 (Default) +#> save_iterations = false (Default) #> id = 1 (Default) #> data -#> file = /private/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmps9TW4l/temp_libpath5800f91909/cmdstanr/logistic.data.json +#> file = /private/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpBGNQRs/temp_libpath45223306cea5/cmdstanr/logistic.data.json #> init = 2 (Default) #> random -#> seed = 44204223 +#> seed = 212160042 #> output -#> file = /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/logistic-202312131004-1-75dd88.csv +#> file = /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/logistic-202407021538-1-18b979.csv #> diagnostic_file = (Default) #> refresh = 100 (Default) #> sig_figs = -1 (Default) -#> profile_file = /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/logistic-profile-202312131004-1-5c2d53.csv +#> profile_file = /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/logistic-profile-202407021538-1-3c00bf.csv +#> save_cmdstan_config = false (Default) #> num_threads = 1 (Default) #> -#> Initial log joint probability = -80.1217 +#> Initial log joint probability = -125.672 #> Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes -#> 7 -63.9218 0.00150318 0.00093398 1 1 9 +#> 7 -63.9218 0.000372447 0.00126853 1 1 10 #> Optimization terminated normally: #> Convergence detected: relative gradient magnitude is below tolerance @@ -267,23 +270,24 @@

    Examples

    #> elbo_samples = 100 (Default) #> eta = 1 (Default) #> adapt -#> engaged = 1 (Default) +#> engaged = true (Default) #> iter = 50 (Default) #> tol_rel_obj = 0.01 (Default) #> eval_elbo = 100 (Default) #> output_samples = 1000 (Default) #> id = 1 (Default) #> data -#> file = /private/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmps9TW4l/temp_libpath5800f91909/cmdstanr/logistic.data.json +#> file = /private/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpBGNQRs/temp_libpath45223306cea5/cmdstanr/logistic.data.json #> init = 2 (Default) #> random -#> seed = 244304498 +#> seed = 490142728 #> output -#> file = /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/logistic-202312131004-1-3b4b11.csv +#> file = /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/logistic-202407021538-1-81868f.csv #> diagnostic_file = (Default) #> refresh = 100 (Default) #> sig_figs = -1 (Default) -#> profile_file = /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/logistic-profile-202312131004-1-85d291.csv +#> profile_file = /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/logistic-profile-202407021538-1-385cb7.csv +#> save_cmdstan_config = false (Default) #> num_threads = 1 (Default) #> #> ------------------------------------------------------------ @@ -294,8 +298,8 @@

    Examples

    #> #> #> -#> Gradient evaluation took 1.9e-05 seconds -#> 1000 transitions using 10 leapfrog steps per transition would take 0.19 seconds. +#> Gradient evaluation took 2.5e-05 seconds +#> 1000 transitions using 10 leapfrog steps per transition would take 0.25 seconds. #> Adjust your expectations accordingly! #> #> @@ -309,9 +313,9 @@

    Examples

    #> #> Begin stochastic gradient ascent. #> iter ELBO delta_ELBO_mean delta_ELBO_med notes -#> 100 -66.299 1.000 1.000 -#> 200 -66.336 0.500 1.000 -#> 300 -66.628 0.335 0.004 MEDIAN ELBO CONVERGED +#> 100 -66.510 1.000 1.000 +#> 200 -66.168 0.503 1.000 +#> 300 -66.153 0.335 0.005 MEDIAN ELBO CONVERGED #> #> Drawing a sample of size 1000 from the approximate posterior... #> COMPLETED. @@ -327,11 +331,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/fit-method-profiles.html b/docs/reference/fit-method-profiles.html index 7c4e4b8c..3cde575e 100644 --- a/docs/reference/fit-method-profiles.html +++ b/docs/reference/fit-method-profiles.html @@ -1,5 +1,5 @@ -Return profiling data — fit-method-profiles • cmdstanrReturn profiling data — fit-method-profiles • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -175,36 +175,36 @@

    Examples

    fit$profiles() #> [[1]] -#> name thread_id total_time forward_time reverse_time chain_stack -#> 1 gq 0x10efcde00 0.000375429 0.000375429 0.000000000 0 -#> 2 likelihood 0x10efcde00 0.001165040 0.000834157 0.000330887 7169 +#> name thread_id total_time forward_time reverse_time chain_stack +#> 1 gq 0x7ff858f85100 0.000442373 0.000442373 0.000000000 0 +#> 2 likelihood 0x7ff858f85100 0.001250430 0.000907142 0.000343284 6721 #> no_chain_stack autodiff_calls no_autodiff_calls #> 1 0 0 1000 -#> 2 7169 7169 1 +#> 2 6721 6721 1 #> #> [[2]] -#> name thread_id total_time forward_time reverse_time chain_stack -#> 1 gq 0x10d0b0e00 0.000407951 0.000407951 0.000000000 0 -#> 2 likelihood 0x10d0b0e00 0.001283690 0.000915781 0.000367905 7155 +#> name thread_id total_time forward_time reverse_time chain_stack +#> 1 gq 0x7ff858f85100 0.000468161 0.000468161 0.000000000 0 +#> 2 likelihood 0x7ff858f85100 0.001255240 0.000911108 0.000344131 6792 #> no_chain_stack autodiff_calls no_autodiff_calls #> 1 0 0 1000 -#> 2 7155 7155 1 +#> 2 6792 6792 1 #> #> [[3]] -#> name thread_id total_time forward_time reverse_time chain_stack -#> 1 gq 0x106bb1e00 0.000399315 0.000399315 0.000000000 0 -#> 2 likelihood 0x106bb1e00 0.001242900 0.000887379 0.000355522 6879 +#> name thread_id total_time forward_time reverse_time chain_stack +#> 1 gq 0x7ff858f85100 0.000458935 0.000458935 0.000000000 0 +#> 2 likelihood 0x7ff858f85100 0.001356490 0.000992885 0.000363606 7163 #> no_chain_stack autodiff_calls no_autodiff_calls #> 1 0 0 1000 -#> 2 6879 6879 1 +#> 2 7163 7163 1 #> #> [[4]] -#> name thread_id total_time forward_time reverse_time chain_stack -#> 1 gq 0x111b21e00 0.000516567 0.000516567 0.000000000 0 -#> 2 likelihood 0x111b21e00 0.001479350 0.001061390 0.000417962 6892 +#> name thread_id total_time forward_time reverse_time chain_stack +#> 1 gq 0x7ff858f85100 0.000489173 0.000489173 0.000000000 0 +#> 2 likelihood 0x7ff858f85100 0.001301980 0.000949488 0.000352494 6979 #> no_chain_stack autodiff_calls no_autodiff_calls #> 1 0 0 1000 -#> 2 6892 6892 1 +#> 2 6979 6979 1 #> # } @@ -218,11 +218,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/fit-method-return_codes.html b/docs/reference/fit-method-return_codes.html index 83a654e0..ad9659f7 100644 --- a/docs/reference/fit-method-return_codes.html +++ b/docs/reference/fit-method-return_codes.html @@ -1,5 +1,5 @@ -Extract return codes from CmdStan — fit-method-return_codes • cmdstanrExtract return codes from CmdStan — fit-method-return_codes • cmdstanrExtract sampler diagnostics after MCMC — fit-method-sampler_diagnostics • cmdstanrExtract sampler diagnostics after MCMC — fit-method-sampler_diagnostics • cmdstanrSave fitted model object to a file — fit-method-save_object • cmdstanrSave fitted model object to a file — fit-method-save_object • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -146,18 +146,18 @@

    Examples

    fit <- readRDS(temp_rds_file) fit$summary() #> # A tibble: 105 × 10 -#> variable mean median sd mad q5 q95 rhat ess_bulk -#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp__ -65.9 -65.6 1.40 1.17 -68.7 -64.3 1.00 1893. -#> 2 alpha 0.380 0.380 0.218 0.216 0.0231 0.740 1.00 4801. -#> 3 beta[1] -0.668 -0.659 0.248 0.247 -1.09 -0.273 1.00 4573. -#> 4 beta[2] -0.271 -0.267 0.224 0.229 -0.634 0.0845 1.00 4645. -#> 5 beta[3] 0.678 0.666 0.266 0.259 0.248 1.12 1.00 4505. -#> 6 log_lik[1] -0.515 -0.508 0.0990 0.0965 -0.689 -0.362 1.00 4844. -#> 7 log_lik[2] -0.403 -0.384 0.147 0.139 -0.669 -0.199 1.00 4585. -#> 8 log_lik[3] -0.495 -0.459 0.218 0.202 -0.898 -0.206 1.00 4890. -#> 9 log_lik[4] -0.452 -0.433 0.153 0.150 -0.726 -0.239 1.00 4491. -#> 10 log_lik[5] -1.18 -1.16 0.278 0.275 -1.67 -0.765 1.00 5130. +#> variable mean median sd mad q5 q95 rhat ess_bulk +#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> +#> 1 lp__ -66.0 -65.7 1.42 1.27 -68.7 -64.3 1.00 2381. +#> 2 alpha 0.379 0.377 0.223 0.224 0.0200 0.754 1.00 4356. +#> 3 beta[1] -0.663 -0.664 0.252 0.252 -1.08 -0.250 1.00 4356. +#> 4 beta[2] -0.270 -0.263 0.223 0.215 -0.645 0.0924 1.00 4293. +#> 5 beta[3] 0.686 0.676 0.269 0.263 0.261 1.15 1.00 4246. +#> 6 log_lik[1] -0.516 -0.511 0.101 0.101 -0.692 -0.364 1.00 4361. +#> 7 log_lik[2] -0.401 -0.381 0.149 0.144 -0.676 -0.193 1.00 4797. +#> 8 log_lik[3] -0.494 -0.460 0.214 0.203 -0.897 -0.207 1.00 4344. +#> 9 log_lik[4] -0.450 -0.431 0.154 0.150 -0.725 -0.233 1.00 4169. +#> 10 log_lik[5] -1.19 -1.17 0.280 0.279 -1.67 -0.767 1.00 4463. #> # ℹ 95 more rows #> # ℹ 1 more variable: ess_tail <dbl> # } @@ -172,11 +172,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/fit-method-save_output_files.html b/docs/reference/fit-method-save_output_files.html index 8fb2b772..6b521c25 100644 --- a/docs/reference/fit-method-save_output_files.html +++ b/docs/reference/fit-method-save_output_files.html @@ -1,5 +1,5 @@ -Save output and data files — fit-method-save_output_files • cmdstanrSave output and data files — fit-method-save_output_files • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -135,13 +135,21 @@

    Save output and data files

    save_data_file(dir = ".", basename = NULL, timestamp = TRUE, random = TRUE) +save_config_files(dir = ".", basename = NULL, timestamp = TRUE, random = TRUE) + +save_metric_files(dir = ".", basename = NULL, timestamp = TRUE, random = TRUE) + output_files(include_failed = FALSE) profile_files(include_failed = FALSE) latent_dynamics_files(include_failed = FALSE) -data_file()
    +data_file() + +config_files(include_failed = FALSE) + +metric_files(include_failed = FALSE)
    @@ -197,6 +205,12 @@

    Details

    For $save_profile_files() everything is the same as for $save_output_files() except "-profile-" is included in the new file name after basename.

    +

    For $save_metric_files() everything is the same as for +$save_output_files() except "-metric-" is included in the new +file name after basename.

    +

    For $save_config_files() everything is the same as for +$save_output_files() except "-config-" is included in the new +file name after basename.

    For $save_data_file() no id is included in the file name because even with multiple MCMC chains the data file is the same.

    @@ -210,33 +224,33 @@

    Examples

    # \dontrun{
     fit <- cmdstanr_example()
     fit$output_files()
    -#> [1] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/logistic-202312131005-1-212881.csv"
    -#> [2] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/logistic-202312131005-2-212881.csv"
    -#> [3] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/logistic-202312131005-3-212881.csv"
    -#> [4] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/logistic-202312131005-4-212881.csv"
    +#> [1] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/logistic-202407021539-1-615e63.csv"
    +#> [2] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/logistic-202407021539-2-615e63.csv"
    +#> [3] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/logistic-202407021539-3-615e63.csv"
    +#> [4] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/logistic-202407021539-4-615e63.csv"
     fit$data_file()
    -#> [1] "/private/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/Rtmps9TW4l/temp_libpath5800f91909/cmdstanr/logistic.data.json"
    +#> [1] "/private/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpBGNQRs/temp_libpath45223306cea5/cmdstanr/logistic.data.json"
     
     # just using tempdir for the example
     my_dir <- tempdir()
     fit$save_output_files(dir = my_dir, basename = "banana")
     #> Moved 4 files and set internal paths to new locations:
    -#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/banana-202312131005-1-932dd0.csv
    -#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/banana-202312131005-2-932dd0.csv
    -#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/banana-202312131005-3-932dd0.csv
    -#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/banana-202312131005-4-932dd0.csv
    +#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/banana-202407021539-1-897d5b.csv
    +#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/banana-202407021539-2-897d5b.csv
    +#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/banana-202407021539-3-897d5b.csv
    +#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/banana-202407021539-4-897d5b.csv
     fit$save_output_files(dir = my_dir, basename = "tomato", timestamp = FALSE)
     #> Moved 4 files and set internal paths to new locations:
    -#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/tomato-1-1f5444.csv
    -#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/tomato-2-1f5444.csv
    -#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/tomato-3-1f5444.csv
    -#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/tomato-4-1f5444.csv
    +#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/tomato-1-4291b8.csv
    +#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/tomato-2-4291b8.csv
    +#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/tomato-3-4291b8.csv
    +#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/tomato-4-4291b8.csv
     fit$save_output_files(dir = my_dir, basename = "lettuce", timestamp = FALSE, random = FALSE)
     #> Moved 4 files and set internal paths to new locations:
    -#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/lettuce-1.csv
    -#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/lettuce-2.csv
    -#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/lettuce-3.csv
    -#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/lettuce-4.csv
    +#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/lettuce-1.csv
    +#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/lettuce-2.csv
    +#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/lettuce-3.csv
    +#> - /var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/lettuce-4.csv
     # }
     
     
    @@ -249,11 +263,11 @@

    Examples

    diff --git a/docs/reference/fit-method-summary.html b/docs/reference/fit-method-summary.html index 14110b92..a1ceadd7 100644 --- a/docs/reference/fit-method-summary.html +++ b/docs/reference/fit-method-summary.html @@ -1,5 +1,5 @@ -Compute a summary table of estimates and diagnostics — fit-method-summary • cmdstanrCompute a summary table of estimates and diagnostics — fit-method-summary • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -165,36 +165,36 @@

    Examples

    #> # A tibble: 105 × 10 #> variable mean median sd mad q5 q95 rhat ess_bulk #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp__ -66.0 -65.7 1.48 1.23 -68.9 -64.3 1.00 1956. -#> 2 alpha 0.382 0.381 0.221 0.222 0.0263 0.744 1.00 3982. -#> 3 beta[1] -0.665 -0.661 0.252 0.253 -1.09 -0.264 1.00 4131. -#> 4 beta[2] -0.274 -0.280 0.226 0.226 -0.640 0.0976 1.00 3816. -#> 5 beta[3] 0.675 0.673 0.268 0.265 0.238 1.12 1.00 3963. -#> 6 log_lik[1] -0.514 -0.508 0.0987 0.0980 -0.686 -0.364 1.00 3980. -#> 7 log_lik[2] -0.408 -0.385 0.153 0.142 -0.690 -0.197 1.00 4263. -#> 8 log_lik[3] -0.498 -0.467 0.217 0.204 -0.889 -0.206 1.00 3904. -#> 9 log_lik[4] -0.453 -0.436 0.152 0.148 -0.732 -0.236 1.00 3847. -#> 10 log_lik[5] -1.18 -1.16 0.285 0.281 -1.68 -0.749 1.00 4407. +#> 1 lp__ -66.0 -65.6 1.45 1.26 -68.7 -64.3 1.00 1922. +#> 2 alpha 0.378 0.373 0.221 0.218 0.0220 0.750 1.00 4329. +#> 3 beta[1] -0.669 -0.660 0.252 0.257 -1.09 -0.264 1.00 3807. +#> 4 beta[2] -0.279 -0.273 0.223 0.223 -0.649 0.0786 1.00 3937. +#> 5 beta[3] 0.677 0.669 0.267 0.257 0.248 1.13 1.00 3914. +#> 6 log_lik[1] -0.516 -0.510 0.0985 0.0955 -0.690 -0.361 1.00 4145. +#> 7 log_lik[2] -0.404 -0.386 0.148 0.137 -0.677 -0.198 1.00 4343. +#> 8 log_lik[3] -0.502 -0.466 0.215 0.206 -0.908 -0.213 1.00 4197. +#> 9 log_lik[4] -0.447 -0.432 0.150 0.147 -0.720 -0.233 1.00 3438. +#> 10 log_lik[5] -1.18 -1.16 0.280 0.281 -1.68 -0.753 1.00 4471. #> # ℹ 95 more rows #> # ℹ 1 more variable: ess_tail <dbl> fit$print() #> variable mean median sd mad q5 q95 rhat ess_bulk ess_tail -#> lp__ -66.00 -65.68 1.48 1.23 -68.89 -64.30 1.00 1956 2665 -#> alpha 0.38 0.38 0.22 0.22 0.03 0.74 1.00 3981 3124 -#> beta[1] -0.66 -0.66 0.25 0.25 -1.09 -0.26 1.00 4131 3206 -#> beta[2] -0.27 -0.28 0.23 0.23 -0.64 0.10 1.00 3815 2736 -#> beta[3] 0.67 0.67 0.27 0.26 0.24 1.12 1.00 3963 3257 -#> log_lik[1] -0.51 -0.51 0.10 0.10 -0.69 -0.36 1.00 3979 2841 -#> log_lik[2] -0.41 -0.39 0.15 0.14 -0.69 -0.20 1.00 4263 3051 -#> log_lik[3] -0.50 -0.47 0.22 0.20 -0.89 -0.21 1.00 3904 3141 -#> log_lik[4] -0.45 -0.44 0.15 0.15 -0.73 -0.24 1.00 3847 2904 -#> log_lik[5] -1.18 -1.16 0.28 0.28 -1.68 -0.75 1.00 4406 3095 +#> lp__ -65.96 -65.63 1.45 1.26 -68.70 -64.28 1.00 1922 2690 +#> alpha 0.38 0.37 0.22 0.22 0.02 0.75 1.00 4329 2617 +#> beta[1] -0.67 -0.66 0.25 0.26 -1.09 -0.26 1.00 3806 3246 +#> beta[2] -0.28 -0.27 0.22 0.22 -0.65 0.08 1.00 3937 2974 +#> beta[3] 0.68 0.67 0.27 0.26 0.25 1.13 1.00 3913 3133 +#> log_lik[1] -0.52 -0.51 0.10 0.10 -0.69 -0.36 1.00 4145 3089 +#> log_lik[2] -0.40 -0.39 0.15 0.14 -0.68 -0.20 1.00 4342 3107 +#> log_lik[3] -0.50 -0.47 0.22 0.21 -0.91 -0.21 1.00 4196 3253 +#> log_lik[4] -0.45 -0.43 0.15 0.15 -0.72 -0.23 1.00 3437 2969 +#> log_lik[5] -1.18 -1.16 0.28 0.28 -1.68 -0.75 1.00 4471 3204 #> #> # showing 10 of 105 rows (change via 'max_rows' argument or 'cmdstanr_max_rows' option) fit$print(max_rows = 2) # same as print(fit, max_rows = 2) #> variable mean median sd mad q5 q95 rhat ess_bulk ess_tail -#> lp__ -66.00 -65.68 1.48 1.23 -68.89 -64.30 1.00 1956 2665 -#> alpha 0.38 0.38 0.22 0.22 0.03 0.74 1.00 3981 3124 +#> lp__ -65.96 -65.63 1.45 1.26 -68.70 -64.28 1.00 1922 2690 +#> alpha 0.38 0.37 0.22 0.22 0.02 0.75 1.00 4329 2617 #> #> # showing 2 of 105 rows (change via 'max_rows' argument or 'cmdstanr_max_rows' option) @@ -203,29 +203,29 @@

    Examples

    #> # A tibble: 3 × 10 #> variable mean median sd mad q5 q95 rhat ess_bulk ess_tail #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 beta[1] -0.665 -0.661 0.252 0.253 -1.09 -0.264 1.00 4131. 3207. -#> 2 beta[2] -0.274 -0.280 0.226 0.226 -0.640 0.0976 1.00 3816. 2736. -#> 3 beta[3] 0.675 0.673 0.268 0.265 0.238 1.12 1.00 3963. 3257. +#> 1 beta[1] -0.669 -0.660 0.252 0.257 -1.09 -0.264 1.00 3807. 3246. +#> 2 beta[2] -0.279 -0.273 0.223 0.223 -0.649 0.0786 1.00 3937. 2974. +#> 3 beta[3] 0.677 0.669 0.267 0.257 0.248 1.13 1.00 3914. 3133. fit$print(c("alpha", "beta[2]")) #> variable mean median sd mad q5 q95 rhat ess_bulk ess_tail -#> alpha 0.38 0.38 0.22 0.22 0.03 0.74 1.00 3981 3124 -#> beta[2] -0.27 -0.28 0.23 0.23 -0.64 0.10 1.00 3815 2736 +#> alpha 0.38 0.37 0.22 0.22 0.02 0.75 1.00 4329 2617 +#> beta[2] -0.28 -0.27 0.22 0.22 -0.65 0.08 1.00 3937 2974 # include all variables but only certain summaries fit$summary(NULL, c("mean", "sd")) #> # A tibble: 105 × 3 #> variable mean sd #> <chr> <dbl> <dbl> -#> 1 lp__ -66.0 1.48 -#> 2 alpha 0.382 0.221 -#> 3 beta[1] -0.665 0.252 -#> 4 beta[2] -0.274 0.226 -#> 5 beta[3] 0.675 0.268 -#> 6 log_lik[1] -0.514 0.0987 -#> 7 log_lik[2] -0.408 0.153 -#> 8 log_lik[3] -0.498 0.217 -#> 9 log_lik[4] -0.453 0.152 -#> 10 log_lik[5] -1.18 0.285 +#> 1 lp__ -66.0 1.45 +#> 2 alpha 0.378 0.221 +#> 3 beta[1] -0.669 0.252 +#> 4 beta[2] -0.279 0.223 +#> 5 beta[3] 0.677 0.267 +#> 6 log_lik[1] -0.516 0.0985 +#> 7 log_lik[2] -0.404 0.148 +#> 8 log_lik[3] -0.502 0.215 +#> 9 log_lik[4] -0.447 0.150 +#> 10 log_lik[5] -1.18 0.280 #> # ℹ 95 more rows # can use functions created from formulas @@ -234,9 +234,9 @@

    Examples

    #> # A tibble: 3 × 2 #> variable prob_gt_0 #> <chr> <dbl> -#> 1 beta[1] 0.00325 -#> 2 beta[2] 0.114 -#> 3 beta[3] 0.997 +#> 1 beta[1] 0.0015 +#> 2 beta[2] 0.102 +#> 3 beta[3] 0.993 # can combine user-specified functions with # the default summary functions @@ -248,10 +248,10 @@

    Examples

    #> # A tibble: 4 × 10 #> variable mean median sd mad q2.5 q97.5 rhat ess_bulk ess_tail #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 alpha 0.382 0.381 0.221 0.222 -0.0413 0.821 1.00 3982. 3124. -#> 2 beta[1] -0.665 -0.661 0.252 0.253 -1.18 -0.185 1.00 4131. 3207. -#> 3 beta[2] -0.274 -0.280 0.226 0.226 -0.715 0.168 1.00 3816. 2736. -#> 4 beta[3] 0.675 0.673 0.268 0.265 0.170 1.20 1.00 3963. 3257. +#> 1 alpha 0.378 0.373 0.221 0.218 -0.0434 0.812 1.00 4329. 2618. +#> 2 beta[1] -0.669 -0.660 0.252 0.257 -1.17 -0.191 1.00 3807. 3246. +#> 3 beta[2] -0.279 -0.273 0.223 0.223 -0.728 0.143 1.00 3937. 2974. +#> 4 beta[3] 0.677 0.669 0.267 0.257 0.164 1.22 1.00 3914. 3133. # the functions need to calculate the appropriate # value for a matrix input @@ -282,11 +282,11 @@

    Examples

    diff --git a/docs/reference/fit-method-time.html b/docs/reference/fit-method-time.html index c0a070b8..a966e10d 100644 --- a/docs/reference/fit-method-time.html +++ b/docs/reference/fit-method-time.html @@ -1,5 +1,5 @@ -Report timing of CmdStan runs — fit-method-time • cmdstanrReport timing of CmdStan runs — fit-method-time • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -140,36 +140,36 @@

    Examples

    fit_mcmc <- cmdstanr_example("logistic", method = "sample") fit_mcmc$time() #> $total -#> [1] 0.554847 +#> [1] 1.020517 #> #> $chains #> chain_id warmup sampling total -#> 1 1 0.023 0.071 0.094 -#> 2 2 0.022 0.066 0.088 -#> 3 3 0.023 0.071 0.094 -#> 4 4 0.023 0.071 0.094 +#> 1 1 0.030 0.101 0.131 +#> 2 2 0.027 0.095 0.122 +#> 3 3 0.031 0.099 0.130 +#> 4 4 0.026 0.112 0.138 #> fit_vb <- cmdstanr_example("logistic", method = "variational") fit_vb$time() #> $total -#> [1] 0.1302531 +#> [1] 0.1371388 #> fit_mle <- cmdstanr_example("logistic", method = "optimize", jacobian = TRUE) fit_mle$time() #> $total -#> [1] 0.1320548 +#> [1] 0.1316919 #> # use fit_mle to draw samples from laplace approximation fit_laplace <- cmdstanr_example("logistic", method = "laplace", mode = fit_mle) fit_laplace$time() # just time for drawing sample not for running optimize #> $total -#> [1] 0.126792 +#> [1] 0.131767 #> fit_laplace$time()$total + fit_mle$time()$total # total time -#> [1] 0.2588468 +#> [1] 0.263459 # } @@ -182,11 +182,11 @@

    Examples

    diff --git a/docs/reference/fit-method-unconstrain_draws.html b/docs/reference/fit-method-unconstrain_draws.html index b849e0ba..761b9f8e 100644 --- a/docs/reference/fit-method-unconstrain_draws.html +++ b/docs/reference/fit-method-unconstrain_draws.html @@ -1,5 +1,5 @@ -Transform all parameter draws to the unconstrained scale — fit-method-unconstrain_draws • cmdstanrTransform all parameter draws to the unconstrained scale — fit-method-unconstrain_draws • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -118,7 +118,12 @@

    Transform all parameter draws to the unconstrained scale

    -
    unconstrain_draws(files = NULL, draws = NULL)
    +
    unconstrain_draws(
    +  files = NULL,
    +  draws = NULL,
    +  format = getOption("cmdstanr_draws_format", "draws_array"),
    +  inc_warmup = FALSE
    +)
    @@ -131,6 +136,16 @@

    Arguments

    draws

    A posterior::draws_* object.

    + +
    format
    +

    (string) The format of the returned draws. Must be a valid +format from the posterior package.

    + + +
    inc_warmup
    +

    (logical) Should warmup draws be included? Defaults to +FALSE.

    +

    See also

    @@ -143,8 +158,6 @@

    See also

    Examples

    # \dontrun{
     fit_mcmc <- cmdstanr_example("logistic", method = "sample", force_recompile = TRUE)
    -fit_mcmc$init_model_methods()
    -#> Compiling additional model methods...
     
     # Unconstrain all internal draws
     unconstrained_internal_draws <- fit_mcmc$unconstrain_draws()
    @@ -166,11 +179,11 @@ 

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/fit-method-unconstrain_variables.html b/docs/reference/fit-method-unconstrain_variables.html index f2b96cab..9ad0b93b 100644 --- a/docs/reference/fit-method-unconstrain_variables.html +++ b/docs/reference/fit-method-unconstrain_variables.html @@ -1,5 +1,5 @@ -Transform a set of parameter values to the unconstrained scale — fit-method-unconstrain_variables • cmdstanrTransform a set of parameter values to the unconstrained scale — fit-method-unconstrain_variables • cmdstanrReturn the variable skeleton for relist — fit-method-variable_skeleton • cmdstanrReturn the variable skeleton for relist — fit-method-variable_skeleton • cmdstanrFunction reference • cmdstanrFunction reference • cmdstanr @@ -17,7 +17,7 @@ cmdstanr - 0.7.0 + 0.8.1
    @@ -102,13 +102,17 @@

    Reference

    + + - + @@ -253,8 +256,7 @@

    Fitted model objects and methods

    - + @@ -262,8 +264,7 @@

    Fitted model objects and methods

    - + @@ -277,7 +278,7 @@

    Fitted model objects and methods

    - + @@ -369,6 +369,10 @@

    Other tools for working with CmdSt

    as_draws(<CmdStanMCMC>) as_draws(<CmdStanMLE>) as_draws(<CmdStanLaplace>) as_draws(<CmdStanVB>) as_draws(<CmdStanGQ>) as_draws(<CmdStanPathfinder>)

    + +
    -

    Package description

    +

    Package overview and global options

    An overview of the package and how it differs from RStan.

    cmdstanr-package cmdstanr CmdStanR

    CmdStanR: the R interface to CmdStan

    +

    cmdstanr_global_options

    +

    CmdStanR global options

    Installing and setting the path to CmdStan

    Install CmdStan, assuming the necessary C++ toolchain.

    @@ -244,8 +248,7 @@

    Fitted model objects and methods

    grad_log_prob()

    Calculate the log-probability and the gradient w.r.t. each input for a -given vector of unconstrained parameters

    Calculate the log-probability and the gradient w.r.t. each input for a given vector of unconstrained parameters

    gradients()

    hessian()

    Calculate the log-probability , the gradient w.r.t. each input, and the hessian -for a given vector of unconstrained parameters

    Calculate the log-probability , the gradient w.r.t. each input, and the hessian for a given vector of unconstrained parameters

    init()

    init_model_methods()

    Compile additional methods for accessing the model log-probability function -and parameter constraining and unconstraining.

    Compile additional methods for accessing the model log-probability function and parameter constraining and unconstraining.

    inv_metric()

    Leave-one-out cross-validation (LOO-CV)

    -

    lp() lp_approx() lp_approx()

    +

    lp() lp_approx()

    Extract log probability (target)

    @@ -313,7 +314,7 @@

    Fitted model objects and methods

    Save fitted model object to a file

    -

    save_output_files() save_latent_dynamics_files() save_profile_files() save_data_file() output_files() profile_files() latent_dynamics_files() data_file()

    +

    save_output_files() save_latent_dynamics_files() save_profile_files() save_data_file() save_config_files() save_metric_files() output_files() profile_files() latent_dynamics_files() data_file() config_files() metric_files()

    Save output and data files

    @@ -341,7 +342,7 @@

    Fitted model objects and methods

    Expose Stan functions to R

    -

    Other tools for working with CmdStan

    +

    Other tools

    @@ -359,8 +360,7 @@

    Other tools for working with CmdSt

    draws_to_csv()

    Write posterior draws objects to CSV files suitable for running standalone generated -quantities with CmdStan.

    Write posterior draws objects to CSV files suitable for running standalone generated quantities with CmdStan.

    as_mcmc.list()

    Create a draws object from a CmdStanR fitted model object

    +

    as.CmdStanMCMC() as.CmdStanMLE() as.CmdStanLaplace() as.CmdStanVB() as.CmdStanPathfinder() as.CmdStanGQ() as.CmdStanDiagnose()

    +

    Coercion methods for CmdStan objects

    Using CmdStanR with knitr and R Markdown

    @@ -390,11 +394,11 @@

    Using CmdStanR with knitr and
    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/install_cmdstan.html b/docs/reference/install_cmdstan.html index f63b9b78..8f4dbe2a 100644 --- a/docs/reference/install_cmdstan.html +++ b/docs/reference/install_cmdstan.html @@ -1,5 +1,5 @@ -Install CmdStan or clean and rebuild an existing installation — install_cmdstan • cmdstanrInstall CmdStan or clean and rebuild an existing installation — install_cmdstan • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -291,11 +291,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/model-method-check_syntax.html b/docs/reference/model-method-check_syntax.html index 6ec6f59e..36f1d1d8 100644 --- a/docs/reference/model-method-check_syntax.html +++ b/docs/reference/model-method-check_syntax.html @@ -1,5 +1,5 @@ -Check syntax of a Stan program — model-method-check_syntax • cmdstanrCheck syntax of a Stan program — model-method-check_syntax • cmdstanrCompile a Stan program — model-method-compile • cmdstanrCompile a Stan program — model-method-compile • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -146,9 +146,9 @@

    Compile a Stan program

    stanc_options = list(), force_recompile = getOption("cmdstanr_force_recompile", default = FALSE), compile_model_methods = FALSE, - compile_hessian_method = FALSE, compile_standalone = FALSE, dry_run = FALSE, + compile_hessian_method = FALSE, threads = FALSE ) @@ -215,11 +215,6 @@

    Arguments

    unconstrain_variables()).

    -
    compile_hessian_method
    -

    (logical) Should the (experimental) hessian() method be -be compiled with the model methods?

    - -
    compile_standalone

    (logical) Should functions in the Stan model be compiled for use in R? If TRUE the functions will be available via the @@ -233,6 +228,11 @@

    Arguments

    but skip the actual C++ compilation. Used to speedup tests.

    +
    compile_hessian_method
    +

    (logical) Should the (experimental) hessian() method be +be compiled with the model methods?

    + +
    threads

    Deprecated and will be removed in a future release. Please turn on threading via cpp_options = list(stan_threads = TRUE) instead.

    @@ -270,8 +270,8 @@

    See also

    model-method-laplace, model-method-optimize, model-method-pathfinder, -model-method-sample_mpi, model-method-sample, +model-method-sample_mpi, model-method-variables, model-method-variational

    @@ -286,12 +286,12 @@

    Examples

    mod <- cmdstan_model(file, compile = FALSE) mod$compile() mod$exe_file() -#> [1] "/Users/jgabry/.cmdstan/cmdstan-2.33.1/examples/bernoulli/bernoulli" +#> [1] "/Users/jgabry/.cmdstan/cmdstan-2.35.0/examples/bernoulli/bernoulli" # turn on threading support (for using functions that support within-chain parallelization) mod$compile(force_recompile = TRUE, cpp_options = list(stan_threads = TRUE)) mod$exe_file() -#> [1] "/Users/jgabry/.cmdstan/cmdstan-2.33.1/examples/bernoulli/bernoulli" +#> [1] "/Users/jgabry/.cmdstan/cmdstan-2.35.0/examples/bernoulli/bernoulli" # turn on pedantic mode (new in Stan v2.24) file_pedantic <- write_stan_file(" @@ -303,7 +303,7 @@

    Examples

    } ") mod <- cmdstan_model(file_pedantic, pedantic = TRUE) -#> Warning in '/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/model-5f0d242e1d46.stan', line 6, column 2: Parameter +#> Warning in '/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/model-59c030d64420.stan', line 6, column 2: Parameter #> sigma is given a exponential distribution, which has strictly positive #> support, but sigma was not constrained to be strictly positive. @@ -319,11 +319,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/model-method-diagnose.html b/docs/reference/model-method-diagnose.html index 9a09d308..1ad592ef 100644 --- a/docs/reference/model-method-diagnose.html +++ b/docs/reference/model-method-diagnose.html @@ -1,5 +1,5 @@ -Run Stan's diagnose method — model-method-diagnose • cmdstanrRun Stan's diagnose method — model-method-diagnose • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -120,7 +120,7 @@

    Run Stan's diagnose method

    data = NULL, seed = NULL, init = NULL, - output_dir = NULL, + output_dir = getOption("cmdstanr_output_dir"), output_basename = NULL, epsilon = NULL, error = NULL @@ -132,8 +132,8 @@

    Arguments

    data

    (multiple options) The data to use for the variables specified in the data block of the Stan program. One of the following:

    • A named list of R objects with the names corresponding to variables -declared in the data block of the Stan program. Internally this list is then -written to JSON for CmdStan using write_stan_json(). See +declared in the data block of the Stan program. Internally this list is +then written to JSON for CmdStan using write_stan_json(). See write_stan_json() for details on the conversions performed on R objects before they are passed to Stan.

    • A path to a data file compatible with CmdStan (JSON or R dump). See the @@ -146,18 +146,17 @@

      Arguments

      (positive integer(s)) A seed for the (P)RNG to pass to CmdStan. In the case of multi-chain sampling the single seed will automatically be augmented by the the run (chain) ID so that each chain uses a different -seed. The exception is the transformed data block, which defaults to -using same seed for all chains so that the same data is generated for all -chains if RNG functions are used. The only time seed should be specified -as a vector (one element per chain) is if RNG functions are used in -transformed data and the goal is to generate different data for each -chain.

      +seed. The exception is the transformed data block, which defaults to using +same seed for all chains so that the same data is generated for all chains +if RNG functions are used. The only time seed should be specified as a +vector (one element per chain) is if RNG functions are used in transformed +data and the goal is to generate different data for each chain.

    init

    (multiple options) The initialization method to use for the -variables declared in the parameters block of the Stan program. One of -the following:

    • A real number x>0. This initializes all parameters randomly between +variables declared in the parameters block of the Stan program. One of the +following:

      • A real number x>0. This initializes all parameters randomly between [-x,x] on the unconstrained parameter space.;

      • The number 0. This initializes all parameters to 0;

      • A character vector of paths (one per chain) to JSON or Rdump files @@ -171,24 +170,50 @@

        Arguments

        initial values. See Examples.

      • A function that returns a single list with names corresponding to the parameters for which you are specifying initial values. The function can -take no arguments or a single argument chain_id. For MCMC, if the function -has argument chain_id it will be supplied with the chain id (from 1 to -number of chains) when called to generate the initial values. See +take no arguments or a single argument chain_id. For MCMC, if the +function has argument chain_id it will be supplied with the chain id +(from 1 to number of chains) when called to generate the initial values. +See Examples.

      • +
      • A CmdStanMCMC, CmdStanMLE, CmdStanVB, CmdStanPathfinder, +or CmdStanLaplace fit object. +If the fit object's parameters are only a subset of the model +parameters then the other parameters will be drawn by Stan's default +initialization. The fit object must have at least some parameters that are the +same name and dimensions as the current Stan model. For the sample and +pathfinder method, if the fit object has fewer draws than the requested +number of chains/paths then the inits will be drawn using sampling with +replacement. Otherwise sampling without replacement will be used. +When a CmdStanPathfinder fit object is used as the init, if +. psis_resample was set to FALSE and calculate_lp was +set to TRUE (default), then resampling without replacement with Pareto +smoothed weights will be used. If psis_resample was set to TRUE or +calculate_lp was set to FALSE then sampling without replacement with +uniform weights will be used to select the draws. +PSIS resampling is used to select the draws for CmdStanVB, +and CmdStanLaplace fit objects.

      • +
      • A type inheriting from posterior::draws. If the draws object has less +samples than the number of requested chains/paths then the inits will be +drawn using sampling with replacement. Otherwise sampling without +replacement will be used. If the draws object's parameters are only a subset +of the model parameters then the other parameters will be drawn by Stan's +default initialization. The fit object must have at least some parameters +that are the same name and dimensions as the current Stan model.

    output_dir

    (string) A path to a directory where CmdStan should write -its output CSV files. For interactive use this can typically be left at -NULL (temporary directory) since CmdStanR makes the CmdStan output -(posterior draws and diagnostics) available in R via methods of the fitted -model objects. The behavior of output_dir is as follows:

    • If NULL (the default), then the CSV files are written to a temporary +its output CSV files. For MCMC there will be one file per chain; for other +methods there will be a single file. For interactive use this can typically +be left at NULL (temporary directory) since CmdStanR makes the CmdStan +output (posterior draws and diagnostics) available in R via methods of the +fitted model objects. This can be set for an entire R session using +options(cmdstanr_output_dir). The behavior of output_dir is as follows:

      • If NULL (the default), then the CSV files are written to a temporary directory and only saved permanently if the user calls one of the $save_* methods of the fitted model object (e.g., $save_output_files()). These temporary -files are removed when the fitted model object is -garbage collected (manually or automatically).

      • +files are removed when the fitted model object is garbage collected (manually or automatically).

      • If a path, then the files are created in output_dir with names corresponding to the defaults used by $save_output_files().

    @@ -232,8 +257,8 @@

    See also

    model-method-laplace, model-method-optimize, model-method-pathfinder, -model-method-sample_mpi, model-method-sample, +model-method-sample_mpi, model-method-variables, model-method-variational

    @@ -245,11 +270,11 @@

    Examples

    # retrieve the gradients test$gradients() -#> param_idx value model finite_diff error -#> 1 0 -1.0700800 30.35590 30.35590 -8.78525e-09 -#> 2 1 0.5670250 -22.14500 -22.14500 9.99824e-09 -#> 3 2 0.0466329 -10.07860 -10.07860 1.68498e-08 -#> 4 3 1.1724800 -5.09201 -5.09201 2.79421e-10 +#> param_idx value model finite_diff error +#> 1 0 0.591940 0.00146498 0.00146493 4.91040e-08 +#> 2 1 1.390710 -30.34660000 -30.34660000 -4.69705e-09 +#> 3 2 -0.987687 11.19930000 11.19930000 1.90498e-08 +#> 4 3 -1.426340 28.46830000 28.46830000 1.54688e-08 # } @@ -262,11 +287,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/model-method-expose_functions.html b/docs/reference/model-method-expose_functions.html index c4f4d0d1..6032f96f 100644 --- a/docs/reference/model-method-expose_functions.html +++ b/docs/reference/model-method-expose_functions.html @@ -1,5 +1,5 @@ -Expose Stan functions to R — model-method-expose_functions • cmdstanrExpose Stan functions to R — model-method-expose_functions • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -156,8 +156,8 @@

    See also

    model-method-laplace, model-method-optimize, model-method-pathfinder, -model-method-sample_mpi, model-method-sample, +model-method-sample_mpi, model-method-variables, model-method-variational

    @@ -182,7 +182,6 @@

    Examples

    ) mod <- cmdstan_model(stan_file) mod$expose_functions() -#> Compiling standalone functions... mod$functions$a_plus_b(1, 2) #> [1] 3 @@ -215,11 +214,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/model-method-format.html b/docs/reference/model-method-format.html index 3e6ef100..92f6c52d 100644 --- a/docs/reference/model-method-format.html +++ b/docs/reference/model-method-format.html @@ -1,5 +1,5 @@ -Run stanc's auto-formatter on the model code. — model-method-format • cmdstanrRun stanc's auto-formatter on the model code. — model-method-format • cmdstanrRun Stan's standalone generated quantities method — model-method-generate-quantities • cmdstanrRun Stan's standalone generated quantities method — model-method-generate-quantities • cmdstanrRun Stan's Laplace algorithm — model-method-laplace • cmdstanrRun Stan's Laplace algorithm — model-method-laplace • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -136,7 +136,7 @@

    Run Stan's Laplace algorithm

    refresh = NULL, init = NULL, save_latent_dynamics = FALSE, - output_dir = NULL, + output_dir = getOption("cmdstanr_output_dir"), output_basename = NULL, sig_figs = NULL, threads = NULL, @@ -144,7 +144,10 @@

    Run Stan's Laplace algorithm

    mode = NULL, opt_args = NULL, jacobian = TRUE, - draws = NULL + draws = NULL, + show_messages = TRUE, + show_exceptions = TRUE, + save_cmdstan_config = NULL ) @@ -153,8 +156,8 @@

    Arguments

    data

    (multiple options) The data to use for the variables specified in the data block of the Stan program. One of the following:

    • A named list of R objects with the names corresponding to variables -declared in the data block of the Stan program. Internally this list is then -written to JSON for CmdStan using write_stan_json(). See +declared in the data block of the Stan program. Internally this list is +then written to JSON for CmdStan using write_stan_json(). See write_stan_json() for details on the conversions performed on R objects before they are passed to Stan.

    • A path to a data file compatible with CmdStan (JSON or R dump). See the @@ -167,12 +170,11 @@

      Arguments

      (positive integer(s)) A seed for the (P)RNG to pass to CmdStan. In the case of multi-chain sampling the single seed will automatically be augmented by the the run (chain) ID so that each chain uses a different -seed. The exception is the transformed data block, which defaults to -using same seed for all chains so that the same data is generated for all -chains if RNG functions are used. The only time seed should be specified -as a vector (one element per chain) is if RNG functions are used in -transformed data and the goal is to generate different data for each -chain.

      +seed. The exception is the transformed data block, which defaults to using +same seed for all chains so that the same data is generated for all chains +if RNG functions are used. The only time seed should be specified as a +vector (one element per chain) is if RNG functions are used in transformed +data and the goal is to generate different data for each chain.

    refresh
    @@ -183,8 +185,8 @@

    Arguments

    init

    (multiple options) The initialization method to use for the -variables declared in the parameters block of the Stan program. One of -the following:

    • A real number x>0. This initializes all parameters randomly between +variables declared in the parameters block of the Stan program. One of the +following:

      • A real number x>0. This initializes all parameters randomly between [-x,x] on the unconstrained parameter space.;

      • The number 0. This initializes all parameters to 0;

      • A character vector of paths (one per chain) to JSON or Rdump files @@ -198,10 +200,35 @@

        Arguments

        initial values. See Examples.

      • A function that returns a single list with names corresponding to the parameters for which you are specifying initial values. The function can -take no arguments or a single argument chain_id. For MCMC, if the function -has argument chain_id it will be supplied with the chain id (from 1 to -number of chains) when called to generate the initial values. See +take no arguments or a single argument chain_id. For MCMC, if the +function has argument chain_id it will be supplied with the chain id +(from 1 to number of chains) when called to generate the initial values. +See Examples.

      • +
      • A CmdStanMCMC, CmdStanMLE, CmdStanVB, CmdStanPathfinder, +or CmdStanLaplace fit object. +If the fit object's parameters are only a subset of the model +parameters then the other parameters will be drawn by Stan's default +initialization. The fit object must have at least some parameters that are the +same name and dimensions as the current Stan model. For the sample and +pathfinder method, if the fit object has fewer draws than the requested +number of chains/paths then the inits will be drawn using sampling with +replacement. Otherwise sampling without replacement will be used. +When a CmdStanPathfinder fit object is used as the init, if +. psis_resample was set to FALSE and calculate_lp was +set to TRUE (default), then resampling without replacement with Pareto +smoothed weights will be used. If psis_resample was set to TRUE or +calculate_lp was set to FALSE then sampling without replacement with +uniform weights will be used to select the draws. +PSIS resampling is used to select the draws for CmdStanVB, +and CmdStanLaplace fit objects.

      • +
      • A type inheriting from posterior::draws. If the draws object has less +samples than the number of requested chains/paths then the inits will be +drawn using sampling with replacement. Otherwise sampling without +replacement will be used. If the draws object's parameters are only a subset +of the model parameters then the other parameters will be drawn by Stan's +default initialization. The fit object must have at least some parameters +that are the same name and dimensions as the current Stan model.

    @@ -211,15 +238,16 @@

    Arguments

    output_dir

    (string) A path to a directory where CmdStan should write -its output CSV files. For interactive use this can typically be left at -NULL (temporary directory) since CmdStanR makes the CmdStan output -(posterior draws and diagnostics) available in R via methods of the fitted -model objects. The behavior of output_dir is as follows:

    • If NULL (the default), then the CSV files are written to a temporary +its output CSV files. For MCMC there will be one file per chain; for other +methods there will be a single file. For interactive use this can typically +be left at NULL (temporary directory) since CmdStanR makes the CmdStan +output (posterior draws and diagnostics) available in R via methods of the +fitted model objects. This can be set for an entire R session using +options(cmdstanr_output_dir). The behavior of output_dir is as follows:

      • If NULL (the default), then the CSV files are written to a temporary directory and only saved permanently if the user calls one of the $save_* methods of the fitted model object (e.g., $save_output_files()). These temporary -files are removed when the fitted model object is -garbage collected (manually or automatically).

      • +files are removed when the fitted model object is garbage collected (manually or automatically).

      • If a path, then the files are created in output_dir with names corresponding to the defaults used by $save_output_files().

    @@ -248,10 +276,10 @@

    Arguments

    opencl_ids
    -

    (integer vector of length 2) The platform and -device IDs of the OpenCL device to use for fitting. The model must -be compiled with cpp_options = list(stan_opencl = TRUE) for this -argument to have an effect.

    +

    (integer vector of length 2) The platform and device IDs of +the OpenCL device to use for fitting. The model must be compiled with +cpp_options = list(stan_opencl = TRUE) for this argument to have an +effect.

    mode
    @@ -283,6 +311,30 @@

    Arguments

    draws

    (positive integer) The number of draws to take.

    + +
    show_messages
    +

    (logical) When TRUE (the default), prints all output +during the execution process, such as iteration numbers and elapsed times. +If the output is silenced then the $output() method +of the resulting fit object can be used to display the silenced messages.

    + + +
    show_exceptions
    +

    (logical) When TRUE (the default), prints all +informational messages, for example rejection of the current proposal. +Disable if you wish to silence these messages, but this is not usually +recommended unless you are very confident that the model is correct up to +numerical error. If the messages are silenced then the +$output() method of the resulting fit object can be +used to display the silenced messages.

    + + +
    save_cmdstan_config
    +

    (logical) When TRUE (the default), call CmdStan +with argument "output save_config=1" to save a json file which contains +the argument tree and extra information (equivalent to the output CSV file +header). This option is only available in CmdStan 2.34.0 and later.

    +
    @@ -320,24 +372,24 @@

    Examples

    mod$print() #> data { #> int<lower=0> N; -#> array[N] int<lower=0,upper=1> y; +#> array[N] int<lower=0, upper=1> y; #> } #> parameters { -#> real<lower=0,upper=1> theta; +#> real<lower=0, upper=1> theta; #> } #> model { -#> theta ~ beta(1,1); // uniform prior on interval 0,1 +#> theta ~ beta(1, 1); // uniform prior on interval 0,1 #> y ~ bernoulli(theta); #> } stan_data <- list(N = 10, y = c(0,1,0,0,0,0,0,0,0,1)) fit_mode <- mod$optimize(data = stan_data, jacobian = TRUE) -#> Initial log joint probability = -8.0994 +#> Initial log joint probability = -7.3571 #> Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes -#> 5 -6.74802 0.000245062 1.61833e-06 1 1 8 +#> 5 -6.74802 0.000511122 9.02231e-07 1 1 8 #> Optimization terminated normally: #> Convergence detected: relative gradient magnitude is below tolerance -#> Finished in 0.1 seconds. +#> Finished in 0.3 seconds. fit_laplace <- mod$laplace(data = stan_data, mode = fit_mode) #> Calculating Hessian #> Calculating inverse of Cholesky factor @@ -352,20 +404,20 @@

    Examples

    #> iteration: 700 #> iteration: 800 #> iteration: 900 -#> Finished in 0.1 seconds. +#> Finished in 0.2 seconds. fit_laplace$summary() #> # A tibble: 3 × 7 -#> variable mean median sd mad q5 q95 -#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp__ -7.25 -6.97 0.724 0.305 -8.72 -6.75 -#> 2 lp_approx__ -0.516 -0.225 0.747 0.306 -1.93 -0.00324 -#> 3 theta 0.267 0.250 0.124 0.120 0.0954 0.499 +#> variable mean median sd mad q5 q95 +#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> +#> 1 lp__ -7.24 -6.97 0.734 0.309 -8.50 -6.75 +#> 2 lp_approx__ -0.491 -0.223 0.698 0.309 -1.80 -0.00200 +#> 3 theta 0.271 0.250 0.123 0.123 0.103 0.487 # if mode isn't specified optimize is run internally first fit_laplace <- mod$laplace(data = stan_data) -#> Initial log joint probability = -15.1067 +#> Initial log joint probability = -11.0359 #> Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes -#> 5 -6.74802 0.00203152 6.06231e-05 1 1 8 +#> 5 -6.74802 0.000945646 1.40836e-05 1 1 8 #> Optimization terminated normally: #> Convergence detected: relative gradient magnitude is below tolerance #> Finished in 0.1 seconds. @@ -385,11 +437,11 @@

    Examples

    #> Finished in 0.1 seconds. fit_laplace$summary() #> # A tibble: 3 × 7 -#> variable mean median sd mad q5 q95 -#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp__ -7.28 -6.98 0.782 0.316 -8.84 -6.75 -#> 2 lp_approx__ -0.531 -0.231 0.756 0.320 -1.96 -0.00280 -#> 3 theta 0.273 0.251 0.128 0.123 0.0984 0.510 +#> variable mean median sd mad q5 q95 +#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> +#> 1 lp__ -7.26 -6.97 0.744 0.306 -8.73 -6.75 +#> 2 lp_approx__ -0.516 -0.226 0.742 0.306 -1.93 -0.00178 +#> 3 theta 0.270 0.250 0.126 0.121 0.103 0.513 # plot approximate posterior bayesplot::mcmc_hist(fit_laplace$draws("theta")) @@ -408,11 +460,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/model-method-optimize-1.png b/docs/reference/model-method-optimize-1.png index 0aa41c0e..aa185638 100644 Binary files a/docs/reference/model-method-optimize-1.png and b/docs/reference/model-method-optimize-1.png differ diff --git a/docs/reference/model-method-optimize-2.png b/docs/reference/model-method-optimize-2.png index 835a8a66..4cf81fa8 100644 Binary files a/docs/reference/model-method-optimize-2.png and b/docs/reference/model-method-optimize-2.png differ diff --git a/docs/reference/model-method-optimize-3.png b/docs/reference/model-method-optimize-3.png index 8d58780f..c67b37ed 100644 Binary files a/docs/reference/model-method-optimize-3.png and b/docs/reference/model-method-optimize-3.png differ diff --git a/docs/reference/model-method-optimize.html b/docs/reference/model-method-optimize.html index 78b2a042..ff5a7c21 100644 --- a/docs/reference/model-method-optimize.html +++ b/docs/reference/model-method-optimize.html @@ -1,5 +1,5 @@ -Run Stan's optimization algorithms — model-method-optimize • cmdstanrRun Stan's optimization algorithms — model-method-optimize • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -132,7 +132,7 @@

    Run Stan's optimization algorithms

    refresh = NULL, init = NULL, save_latent_dynamics = FALSE, - output_dir = NULL, + output_dir = getOption("cmdstanr_output_dir"), output_basename = NULL, sig_figs = NULL, threads = NULL, @@ -146,7 +146,10 @@

    Run Stan's optimization algorithms

    tol_grad = NULL, tol_rel_grad = NULL, tol_param = NULL, - history_size = NULL + history_size = NULL, + show_messages = TRUE, + show_exceptions = TRUE, + save_cmdstan_config = NULL ) @@ -155,8 +158,8 @@

    Arguments

    data

    (multiple options) The data to use for the variables specified in the data block of the Stan program. One of the following:

    • A named list of R objects with the names corresponding to variables -declared in the data block of the Stan program. Internally this list is then -written to JSON for CmdStan using write_stan_json(). See +declared in the data block of the Stan program. Internally this list is +then written to JSON for CmdStan using write_stan_json(). See write_stan_json() for details on the conversions performed on R objects before they are passed to Stan.

    • A path to a data file compatible with CmdStan (JSON or R dump). See the @@ -169,12 +172,11 @@

      Arguments

      (positive integer(s)) A seed for the (P)RNG to pass to CmdStan. In the case of multi-chain sampling the single seed will automatically be augmented by the the run (chain) ID so that each chain uses a different -seed. The exception is the transformed data block, which defaults to -using same seed for all chains so that the same data is generated for all -chains if RNG functions are used. The only time seed should be specified -as a vector (one element per chain) is if RNG functions are used in -transformed data and the goal is to generate different data for each -chain.

      +seed. The exception is the transformed data block, which defaults to using +same seed for all chains so that the same data is generated for all chains +if RNG functions are used. The only time seed should be specified as a +vector (one element per chain) is if RNG functions are used in transformed +data and the goal is to generate different data for each chain.

    refresh
    @@ -185,8 +187,8 @@

    Arguments

    init

    (multiple options) The initialization method to use for the -variables declared in the parameters block of the Stan program. One of -the following:

    • A real number x>0. This initializes all parameters randomly between +variables declared in the parameters block of the Stan program. One of the +following:

      • A real number x>0. This initializes all parameters randomly between [-x,x] on the unconstrained parameter space.;

      • The number 0. This initializes all parameters to 0;

      • A character vector of paths (one per chain) to JSON or Rdump files @@ -200,10 +202,35 @@

        Arguments

        initial values. See Examples.

      • A function that returns a single list with names corresponding to the parameters for which you are specifying initial values. The function can -take no arguments or a single argument chain_id. For MCMC, if the function -has argument chain_id it will be supplied with the chain id (from 1 to -number of chains) when called to generate the initial values. See +take no arguments or a single argument chain_id. For MCMC, if the +function has argument chain_id it will be supplied with the chain id +(from 1 to number of chains) when called to generate the initial values. +See Examples.

      • +
      • A CmdStanMCMC, CmdStanMLE, CmdStanVB, CmdStanPathfinder, +or CmdStanLaplace fit object. +If the fit object's parameters are only a subset of the model +parameters then the other parameters will be drawn by Stan's default +initialization. The fit object must have at least some parameters that are the +same name and dimensions as the current Stan model. For the sample and +pathfinder method, if the fit object has fewer draws than the requested +number of chains/paths then the inits will be drawn using sampling with +replacement. Otherwise sampling without replacement will be used. +When a CmdStanPathfinder fit object is used as the init, if +. psis_resample was set to FALSE and calculate_lp was +set to TRUE (default), then resampling without replacement with Pareto +smoothed weights will be used. If psis_resample was set to TRUE or +calculate_lp was set to FALSE then sampling without replacement with +uniform weights will be used to select the draws. +PSIS resampling is used to select the draws for CmdStanVB, +and CmdStanLaplace fit objects.

      • +
      • A type inheriting from posterior::draws. If the draws object has less +samples than the number of requested chains/paths then the inits will be +drawn using sampling with replacement. Otherwise sampling without +replacement will be used. If the draws object's parameters are only a subset +of the model parameters then the other parameters will be drawn by Stan's +default initialization. The fit object must have at least some parameters +that are the same name and dimensions as the current Stan model.

    @@ -212,8 +239,8 @@

    Arguments

    about the latent dynamics be written to temporary diagnostic CSV files? This argument replaces CmdStan's diagnostic_file argument and the content written to CSV is controlled by the user's CmdStan installation and not -CmdStanR (for some algorithms no content may be written). The default -is FALSE, which is appropriate for almost every use case. To save the +CmdStanR (for some algorithms no content may be written). The default is +FALSE, which is appropriate for almost every use case. To save the temporary files created when save_latent_dynamics=TRUE see the $save_latent_dynamics_files() method.

    @@ -221,15 +248,16 @@

    Arguments

    output_dir

    (string) A path to a directory where CmdStan should write -its output CSV files. For interactive use this can typically be left at -NULL (temporary directory) since CmdStanR makes the CmdStan output -(posterior draws and diagnostics) available in R via methods of the fitted -model objects. The behavior of output_dir is as follows:

    • If NULL (the default), then the CSV files are written to a temporary +its output CSV files. For MCMC there will be one file per chain; for other +methods there will be a single file. For interactive use this can typically +be left at NULL (temporary directory) since CmdStanR makes the CmdStan +output (posterior draws and diagnostics) available in R via methods of the +fitted model objects. This can be set for an entire R session using +options(cmdstanr_output_dir). The behavior of output_dir is as follows:

      • If NULL (the default), then the CSV files are written to a temporary directory and only saved permanently if the user calls one of the $save_* methods of the fitted model object (e.g., $save_output_files()). These temporary -files are removed when the fitted model object is -garbage collected (manually or automatically).

      • +files are removed when the fitted model object is garbage collected (manually or automatically).

      • If a path, then the files are created in output_dir with names corresponding to the defaults used by $save_output_files().

    @@ -258,10 +286,10 @@

    Arguments

    opencl_ids
    -

    (integer vector of length 2) The platform and -device IDs of the OpenCL device to use for fitting. The model must -be compiled with cpp_options = list(stan_opencl = TRUE) for this -argument to have an effect.

    +

    (integer vector of length 2) The platform and device IDs of +the OpenCL device to use for fitting. The model must be compiled with +cpp_options = list(stan_opencl = TRUE) for this argument to have an +effect.

    algorithm
    @@ -315,6 +343,30 @@

    Arguments

    (positive integer) The size of the history used when approximating the Hessian. Only available for L-BFGS.

    + +
    show_messages
    +

    (logical) When TRUE (the default), prints all output +during the execution process, such as iteration numbers and elapsed times. +If the output is silenced then the $output() method +of the resulting fit object can be used to display the silenced messages.

    + + +
    show_exceptions
    +

    (logical) When TRUE (the default), prints all +informational messages, for example rejection of the current proposal. +Disable if you wish to silence these messages, but this is not usually +recommended unless you are very confident that the model is correct up to +numerical error. If the messages are silenced then the +$output() method of the resulting fit object can be +used to display the silenced messages.

    + + +
    save_cmdstan_config
    +

    (logical) When TRUE (the default), call CmdStan +with argument "output save_config=1" to save a json file which contains +the argument tree and extra information (equivalent to the output CSV file +header). This option is only available in CmdStan 2.34.0 and later.

    +
    @@ -358,7 +410,7 @@

    Examples

    # Otherwise use the `path` argument to specify the location of your # CmdStan installation.) set_cmdstan_path(path = NULL) -#> CmdStan path set to: /Users/jgabry/.cmdstan/cmdstan-2.33.1 +#> CmdStan path set to: /Users/jgabry/.cmdstan/cmdstan-2.35.0 # Create a CmdStanModel object from a Stan program, # here using the example model that comes with CmdStan @@ -367,15 +419,29 @@

    Examples

    mod$print() #> data { #> int<lower=0> N; -#> array[N] int<lower=0,upper=1> y; +#> array[N] int<lower=0, upper=1> y; #> } #> parameters { -#> real<lower=0,upper=1> theta; +#> real<lower=0, upper=1> theta; #> } #> model { -#> theta ~ beta(1,1); // uniform prior on interval 0,1 +#> theta ~ beta(1, 1); // uniform prior on interval 0,1 #> y ~ bernoulli(theta); #> } +# Print with line numbers. This can be set globally using the +# `cmdstanr_print_line_numbers` option. +mod$print(line_numbers = TRUE) +#> 1: data { +#> 2: int<lower=0> N; +#> 3: array[N] int<lower=0, upper=1> y; +#> 4: } +#> 5: parameters { +#> 6: real<lower=0, upper=1> theta; +#> 7: } +#> 8: model { +#> 9: theta ~ beta(1, 1); // uniform prior on interval 0,1 +#> 10: y ~ bernoulli(theta); +#> 11: } # Data as a named list (like RStan) stan_data <- list(N = 10, y = c(0,1,0,0,0,0,0,0,0,1)) @@ -446,8 +512,8 @@

    Examples

    #> # A tibble: 2 × 10 #> variable mean median sd mad q5 q95 rhat ess_bulk ess_tail #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp__ -7.30 -7.03 0.721 0.380 -8.82 -6.75 1.00 902. 1006. -#> 2 theta 0.247 0.233 0.122 0.129 0.0786 0.470 1.00 762. 712. +#> 1 lp__ -7.30 -7.00 0.811 0.344 -8.83 -6.75 1.00 702. 776. +#> 2 theta 0.254 0.238 0.125 0.124 0.0807 0.483 1.00 634. 580. # Check sampling diagnostics fit_mcmc$diagnostic_summary() @@ -458,7 +524,7 @@

    Examples

    #> [1] 0 0 #> #> $ebfmi -#> [1] 1.017555 1.250490 +#> [1] 1.1148699 0.8012192 #> # Get posterior draws @@ -468,22 +534,22 @@

    Examples

    #> , , variable = lp__ #> #> chain -#> iteration 1 2 -#> 1 -6.8 -6.8 -#> 2 -6.9 -6.8 -#> 3 -7.0 -7.0 -#> 4 -6.9 -7.1 -#> 5 -6.7 -7.0 +#> iteration 1 2 +#> 1 -7.0 -6.8 +#> 2 -7.9 -6.9 +#> 3 -7.4 -6.8 +#> 4 -6.7 -6.8 +#> 5 -6.9 -10.2 #> #> , , variable = theta #> #> chain #> iteration 1 2 -#> 1 0.28 0.21 -#> 2 0.19 0.20 -#> 3 0.16 0.17 -#> 4 0.20 0.36 -#> 5 0.25 0.34 +#> 1 0.17 0.23 +#> 2 0.46 0.18 +#> 3 0.41 0.28 +#> 4 0.25 0.23 +#> 5 0.18 0.62 #> #> # ... with 995 more iterations @@ -491,16 +557,16 @@

    Examples

    as_draws_df(draws) #> # A draws_df: 1000 iterations, 2 chains, and 2 variables #> lp__ theta -#> 1 -6.8 0.28 -#> 2 -6.9 0.19 -#> 3 -7.0 0.16 -#> 4 -6.9 0.20 -#> 5 -6.7 0.25 -#> 6 -7.1 0.36 -#> 7 -9.0 0.55 -#> 8 -7.2 0.15 -#> 9 -6.8 0.23 -#> 10 -7.5 0.42 +#> 1 -7.0 0.17 +#> 2 -7.9 0.46 +#> 3 -7.4 0.41 +#> 4 -6.7 0.25 +#> 5 -6.9 0.18 +#> 6 -6.9 0.33 +#> 7 -7.2 0.15 +#> 8 -6.8 0.29 +#> 9 -6.8 0.24 +#> 10 -6.8 0.24 #> # ... with 1990 more draws #> # ... hidden reserved variables {'.chain', '.iteration', '.draw'} @@ -518,9 +584,9 @@

    Examples

    # and also demonstrate specifying data as a path to a file instead of a list my_data_file <- file.path(cmdstan_path(), "examples/bernoulli/bernoulli.data.json") fit_optim <- mod$optimize(data = my_data_file, seed = 123) -#> Initial log joint probability = -9.51104 +#> Initial log joint probability = -16.144 #> Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes -#> 6 -5.00402 0.000103557 2.55661e-07 1 1 9 +#> 6 -5.00402 0.000246518 8.73164e-07 1 1 9 #> Optimization terminated normally: #> Convergence detected: relative gradient magnitude is below tolerance #> Finished in 0.1 seconds. @@ -534,12 +600,12 @@

    Examples

    # Run 'optimize' again with 'jacobian=TRUE' and then draw from Laplace approximation # to the posterior fit_optim <- mod$optimize(data = my_data_file, jacobian = TRUE) -#> Initial log joint probability = -7.17234 +#> Initial log joint probability = -11.9711 #> Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes -#> 5 -6.74802 0.000196979 1.66919e-07 1 1 8 +#> 5 -6.74802 0.00123686 2.20415e-05 1 1 8 #> Optimization terminated normally: #> Convergence detected: relative gradient magnitude is below tolerance -#> Finished in 0.1 seconds. +#> Finished in 0.2 seconds. fit_laplace <- mod$laplace(data = my_data_file, mode = fit_optim, draws = 2000) #> Calculating Hessian #> Calculating inverse of Cholesky factor @@ -564,14 +630,14 @@

    Examples

    #> iteration: 1700 #> iteration: 1800 #> iteration: 1900 -#> Finished in 0.1 seconds. +#> Finished in 0.2 seconds. fit_laplace$summary() #> # A tibble: 3 × 7 -#> variable mean median sd mad q5 q95 -#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp__ -7.26 -6.98 0.759 0.313 -8.67 -6.75 -#> 2 lp_approx__ -0.521 -0.232 0.759 0.318 -2.07 -0.00238 -#> 3 theta 0.266 0.248 0.125 0.123 0.0975 0.496 +#> variable mean median sd mad q5 q95 +#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> +#> 1 lp__ -7.23 -6.96 0.697 0.297 -8.63 -6.75 +#> 2 lp_approx__ -0.491 -0.213 0.686 0.296 -1.89 -0.00171 +#> 3 theta 0.268 0.249 0.123 0.118 0.102 0.507 # Run 'variational' method to use ADVI to approximate posterior fit_vb <- mod$variational(data = stan_data, seed = 123) @@ -580,8 +646,8 @@

    Examples

    #> This procedure has not been thoroughly tested and may be unstable #> or buggy. The interface is subject to change. #> ------------------------------------------------------------ -#> Gradient evaluation took 6e-06 seconds -#> 1000 transitions using 10 leapfrog steps per transition would take 0.06 seconds. +#> Gradient evaluation took 1.2e-05 seconds +#> 1000 transitions using 10 leapfrog steps per transition would take 0.12 seconds. #> Adjust your expectations accordingly! #> Begin eta adaptation. #> Iteration: 1 / 250 [ 0%] (Adaptation) @@ -592,9 +658,9 @@

    Examples

    #> Success! Found best value [eta = 1] earlier than expected. #> Begin stochastic gradient ascent. #> iter ELBO delta_ELBO_mean delta_ELBO_med notes -#> 100 -6.262 1.000 1.000 -#> 200 -6.263 0.500 1.000 -#> 300 -6.307 0.336 0.007 MEDIAN ELBO CONVERGED +#> 100 -6.164 1.000 1.000 +#> 200 -6.225 0.505 1.000 +#> 300 -6.186 0.339 0.010 MEDIAN ELBO CONVERGED #> Drawing a sample of size 1000 from the approximate posterior... #> COMPLETED. #> Finished in 0.1 seconds. @@ -602,40 +668,40 @@

    Examples

    #> # A tibble: 3 × 7 #> variable mean median sd mad q5 q95 #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp__ -7.18 -6.94 0.588 0.259 -8.36 -6.75 -#> 2 lp_approx__ -0.515 -0.221 0.692 0.303 -2.06 -0.00257 -#> 3 theta 0.263 0.246 0.115 0.113 0.106 0.481 +#> 1 lp__ -7.14 -6.93 0.528 0.247 -8.21 -6.75 +#> 2 lp_approx__ -0.520 -0.244 0.740 0.326 -1.90 -0.00227 +#> 3 theta 0.251 0.236 0.107 0.108 0.100 0.446 mcmc_hist(fit_vb$draws("theta")) #> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. # Run 'pathfinder' method, a new alternative to the variational method fit_pf <- mod$pathfinder(data = stan_data, seed = 123) -#> Path [1] :Initial log joint density = -11.008832 +#> Path [1] :Initial log joint density = -18.273334 #> Path [1] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 9.383e-04 1.391e-05 1.000e+00 1.000e+00 126 -6.264e+00 -6.264e+00 -#> Path [1] :Best Iter: [3] ELBO (-6.195408) evaluations: (126) -#> Path [2] :Initial log joint density = -7.318450 +#> 5 -6.748e+00 7.082e-04 1.432e-05 1.000e+00 1.000e+00 126 -6.145e+00 -6.145e+00 +#> Path [1] :Best Iter: [5] ELBO (-6.145070) evaluations: (126) +#> Path [2] :Initial log joint density = -19.192715 #> Path [2] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 4 -6.748e+00 5.414e-03 1.618e-04 1.000e+00 1.000e+00 101 -6.251e+00 -6.251e+00 -#> Path [2] :Best Iter: [3] ELBO (-6.229174) evaluations: (101) -#> Path [3] :Initial log joint density = -12.374612 +#> 5 -6.748e+00 2.015e-04 2.228e-06 1.000e+00 1.000e+00 126 -6.223e+00 -6.223e+00 +#> Path [2] :Best Iter: [2] ELBO (-6.170358) evaluations: (126) +#> Path [3] :Initial log joint density = -6.774820 #> Path [3] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 1.419e-03 2.837e-05 1.000e+00 1.000e+00 126 -6.199e+00 -6.199e+00 -#> Path [3] :Best Iter: [5] ELBO (-6.199185) evaluations: (126) -#> Path [4] :Initial log joint density = -13.009824 +#> 4 -6.748e+00 1.137e-04 2.596e-07 1.000e+00 1.000e+00 101 -6.178e+00 -6.178e+00 +#> Path [3] :Best Iter: [4] ELBO (-6.177909) evaluations: (101) +#> Path [4] :Initial log joint density = -7.949193 #> Path [4] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 1.677e-03 3.885e-05 1.000e+00 1.000e+00 126 -6.173e+00 -6.173e+00 -#> Path [4] :Best Iter: [5] ELBO (-6.172860) evaluations: (126) +#> 5 -6.748e+00 2.145e-04 1.301e-06 1.000e+00 1.000e+00 126 -6.197e+00 -6.197e+00 +#> Path [4] :Best Iter: [5] ELBO (-6.197118) evaluations: (126) #> Total log probability function evaluations:4379 #> Finished in 0.1 seconds. fit_pf$summary() #> # A tibble: 3 × 7 #> variable mean median sd mad q5 q95 #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp_approx__ -1.08 -0.728 0.886 0.304 -2.71 -0.511 -#> 2 lp__ -7.26 -6.96 0.738 0.297 -8.72 -6.75 -#> 3 theta 0.249 0.230 0.120 0.121 0.0854 0.471 +#> 1 lp_approx__ -1.07 -0.727 0.945 0.311 -2.91 -0.450 +#> 2 lp__ -7.25 -6.97 0.753 0.308 -8.78 -6.75 +#> 3 theta 0.256 0.245 0.119 0.123 0.0824 0.462 mcmc_hist(fit_pf$draws("theta")) #> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. @@ -644,47 +710,49 @@

    Examples

    # better covariance approximation, and fewer LBFGSs iterations fit_pf <- mod$pathfinder(data = stan_data, num_paths=10, single_path_draws=40, history_size=50, max_lbfgs_iters=100) -#> Path [1] :Initial log joint density = -16.937625 +#> Warning: Number of PSIS draws is larger than the total number of draws returned by the single Pathfinders. This is likely unintentional and leads to re-sampling from the same draws. +#> Path [1] :Initial log joint density = -14.241761 #> Path [1] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 1.488e-03 4.162e-05 1.000e+00 1.000e+00 126 -6.227e+00 -6.227e+00 -#> Path [1] :Best Iter: [2] ELBO (-6.211714) evaluations: (126) -#> Path [2] :Initial log joint density = -6.798413 +#> 5 -6.748e+00 2.000e-03 5.597e-05 1.000e+00 1.000e+00 126 -6.236e+00 -6.236e+00 +#> Path [1] :Best Iter: [5] ELBO (-6.235525) evaluations: (126) +#> Path [2] :Initial log joint density = -13.402374 #> Path [2] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 3 -6.748e+00 3.762e-03 4.627e-05 9.519e-01 9.519e-01 76 -6.195e+00 -6.195e+00 -#> Path [2] :Best Iter: [3] ELBO (-6.194747) evaluations: (76) -#> Path [3] :Initial log joint density = -7.054440 +#> 5 -6.748e+00 1.810e-03 4.511e-05 1.000e+00 1.000e+00 126 -6.208e+00 -6.208e+00 +#> Path [2] :Best Iter: [2] ELBO (-6.203915) evaluations: (126) +#> Path [3] :Initial log joint density = -12.050800 #> Path [3] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 4 -6.748e+00 2.741e-03 5.225e-05 1.000e+00 1.000e+00 101 -6.187e+00 -6.187e+00 -#> Path [3] :Best Iter: [4] ELBO (-6.186757) evaluations: (101) -#> Path [4] :Initial log joint density = -7.467690 +#> 5 -6.748e+00 1.274e-03 2.325e-05 1.000e+00 1.000e+00 126 -6.196e+00 -6.196e+00 +#> Path [3] :Best Iter: [3] ELBO (-6.168581) evaluations: (126) +#> Path [4] :Initial log joint density = -11.907691 #> Path [4] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 1.049e-04 4.080e-07 1.000e+00 1.000e+00 126 -6.224e+00 -6.224e+00 -#> Path [4] :Best Iter: [2] ELBO (-6.213804) evaluations: (126) -#> Path [5] :Initial log joint density = -14.817294 +#> 5 -6.748e+00 1.208e-03 2.110e-05 1.000e+00 1.000e+00 126 -6.195e+00 -6.195e+00 +#> Path [4] :Best Iter: [3] ELBO (-6.184266) evaluations: (126) +#> Path [5] :Initial log joint density = -17.062583 #> Path [5] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 2.041e-03 5.999e-05 1.000e+00 1.000e+00 126 -6.271e+00 -6.271e+00 -#> Path [5] :Best Iter: [3] ELBO (-6.188344) evaluations: (126) -#> Path [6] :Initial log joint density = -7.375208 +#> 5 -6.748e+00 1.424e-03 3.915e-05 1.000e+00 1.000e+00 126 -6.229e+00 -6.229e+00 +#> Path [5] :Best Iter: [4] ELBO (-6.180989) evaluations: (126) +#> Path [6] :Initial log joint density = -7.950926 #> Path [6] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 5.530e-04 1.038e-06 1.000e+00 1.000e+00 126 -6.229e+00 -6.229e+00 -#> Path [6] :Best Iter: [2] ELBO (-6.203592) evaluations: (126) -#> Path [7] :Initial log joint density = -6.748023 +#> 5 -6.748e+00 2.149e-04 1.305e-06 1.000e+00 1.000e+00 126 -6.210e+00 -6.210e+00 +#> Path [6] :Best Iter: [4] ELBO (-6.193547) evaluations: (126) +#> Path [7] :Initial log joint density = -13.337353 #> Path [7] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 2 -6.748e+00 9.521e-04 6.579e-07 1.000e+00 1.000e+00 51 -6.231e+00 -6.231e+00 -#> Path [7] :Best Iter: [2] ELBO (-6.231405) evaluations: (51) -#> Path [8] :Initial log joint density = -11.312958 +#> 5 -6.748e+00 1.789e-03 4.411e-05 1.000e+00 1.000e+00 126 -6.275e+00 -6.275e+00 +#> Path [7] :Best Iter: [4] ELBO (-6.264759) evaluations: (126) +#> Path [8] :Initial log joint density = -6.856154 #> Path [8] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 1.017e-03 1.576e-05 1.000e+00 1.000e+00 126 -6.304e+00 -6.304e+00 -#> Path [8] :Best Iter: [3] ELBO (-6.185214) evaluations: (126) -#> Path [9] :Initial log joint density = -6.881067 +#> 4 -6.748e+00 7.559e-04 6.106e-06 1.000e+00 1.000e+00 101 -6.237e+00 -6.237e+00 +#> Path [8] :Best Iter: [2] ELBO (-6.233924) evaluations: (101) +#> Path [9] :Initial log joint density = -19.158821 #> Path [9] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 4 -6.748e+00 9.878e-04 9.538e-06 1.000e+00 1.000e+00 101 -6.173e+00 -6.173e+00 -#> Path [9] :Best Iter: [4] ELBO (-6.173184) evaluations: (101) -#> Path [10] :Initial log joint density = -7.173191 +#> 5 -6.748e+00 2.167e-04 2.482e-06 1.000e+00 1.000e+00 126 -6.251e+00 -6.251e+00 +#> Path [9] :Best Iter: [3] ELBO (-6.196829) evaluations: (126) +#> Path [10] :Initial log joint density = -6.894545 #> Path [10] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 1.980e-04 1.685e-07 1.000e+00 1.000e+00 126 -6.176e+00 -6.176e+00 -#> Path [10] :Best Iter: [5] ELBO (-6.175625) evaluations: (126) -#> Total log probability function evaluations:1235 +#> 4 -6.748e+00 1.811e-04 2.981e-05 9.341e-01 9.341e-01 101 -6.227e+00 -6.227e+00 +#> Path [10] :Best Iter: [2] ELBO (-6.144040) evaluations: (101) +#> Total log probability function evaluations:1360 +#> Pareto k value (0.73) is greater than 0.7. Importance resampling was not able to improve the approximation, which may indicate that the approximation itself is poor. #> Finished in 0.1 seconds. # Specifying initial values as a function @@ -767,7 +835,7 @@

    Examples

    #> 6 -5.00402 0.000237915 9.55309e-07 1 1 9 #> Optimization terminated normally: #> Convergence detected: relative gradient magnitude is below tolerance -#> Finished in 0.1 seconds. +#> Finished in 0.2 seconds. fit_optim_w_init_list$init() #> [[1]] #> [[1]]$theta @@ -786,11 +854,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/model-method-pathfinder-1.png b/docs/reference/model-method-pathfinder-1.png index 0aa41c0e..aa185638 100644 Binary files a/docs/reference/model-method-pathfinder-1.png and b/docs/reference/model-method-pathfinder-1.png differ diff --git a/docs/reference/model-method-pathfinder-2.png b/docs/reference/model-method-pathfinder-2.png index 835a8a66..4cf81fa8 100644 Binary files a/docs/reference/model-method-pathfinder-2.png and b/docs/reference/model-method-pathfinder-2.png differ diff --git a/docs/reference/model-method-pathfinder-3.png b/docs/reference/model-method-pathfinder-3.png index 8d58780f..c67b37ed 100644 Binary files a/docs/reference/model-method-pathfinder-3.png and b/docs/reference/model-method-pathfinder-3.png differ diff --git a/docs/reference/model-method-pathfinder.html b/docs/reference/model-method-pathfinder.html index e5caa27c..fabd8cf2 100644 --- a/docs/reference/model-method-pathfinder.html +++ b/docs/reference/model-method-pathfinder.html @@ -1,5 +1,5 @@ -Run Stan's Pathfinder Variational Inference Algorithm — model-method-pathfinder • cmdstanrRun Stan's Pathfinder Variational Inference Algorithm — model-method-pathfinder • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -144,7 +144,7 @@

    Run Stan's Pathfinder Variational Inference Algorithm

    refresh = NULL, init = NULL, save_latent_dynamics = FALSE, - output_dir = NULL, + output_dir = getOption("cmdstanr_output_dir"), output_basename = NULL, sig_figs = NULL, opencl_ids = NULL, @@ -158,10 +158,15 @@

    Run Stan's Pathfinder Variational Inference Algorithm

    history_size = NULL, single_path_draws = NULL, draws = NULL, - num_paths = NULL, + num_paths = 4, max_lbfgs_iters = NULL, num_elbo_draws = NULL, - save_single_paths = NULL + save_single_paths = NULL, + psis_resample = NULL, + calculate_lp = NULL, + show_messages = TRUE, + show_exceptions = TRUE, + save_cmdstan_config = NULL ) @@ -170,8 +175,8 @@

    Arguments

    data

    (multiple options) The data to use for the variables specified in the data block of the Stan program. One of the following:

    • A named list of R objects with the names corresponding to variables -declared in the data block of the Stan program. Internally this list is then -written to JSON for CmdStan using write_stan_json(). See +declared in the data block of the Stan program. Internally this list is +then written to JSON for CmdStan using write_stan_json(). See write_stan_json() for details on the conversions performed on R objects before they are passed to Stan.

    • A path to a data file compatible with CmdStan (JSON or R dump). See the @@ -184,12 +189,11 @@

      Arguments

      (positive integer(s)) A seed for the (P)RNG to pass to CmdStan. In the case of multi-chain sampling the single seed will automatically be augmented by the the run (chain) ID so that each chain uses a different -seed. The exception is the transformed data block, which defaults to -using same seed for all chains so that the same data is generated for all -chains if RNG functions are used. The only time seed should be specified -as a vector (one element per chain) is if RNG functions are used in -transformed data and the goal is to generate different data for each -chain.

      +seed. The exception is the transformed data block, which defaults to using +same seed for all chains so that the same data is generated for all chains +if RNG functions are used. The only time seed should be specified as a +vector (one element per chain) is if RNG functions are used in transformed +data and the goal is to generate different data for each chain.

    refresh
    @@ -200,8 +204,8 @@

    Arguments

    init

    (multiple options) The initialization method to use for the -variables declared in the parameters block of the Stan program. One of -the following:

    • A real number x>0. This initializes all parameters randomly between +variables declared in the parameters block of the Stan program. One of the +following:

      • A real number x>0. This initializes all parameters randomly between [-x,x] on the unconstrained parameter space.;

      • The number 0. This initializes all parameters to 0;

      • A character vector of paths (one per chain) to JSON or Rdump files @@ -215,10 +219,35 @@

        Arguments

        initial values. See Examples.

      • A function that returns a single list with names corresponding to the parameters for which you are specifying initial values. The function can -take no arguments or a single argument chain_id. For MCMC, if the function -has argument chain_id it will be supplied with the chain id (from 1 to -number of chains) when called to generate the initial values. See +take no arguments or a single argument chain_id. For MCMC, if the +function has argument chain_id it will be supplied with the chain id +(from 1 to number of chains) when called to generate the initial values. +See Examples.

      • +
      • A CmdStanMCMC, CmdStanMLE, CmdStanVB, CmdStanPathfinder, +or CmdStanLaplace fit object. +If the fit object's parameters are only a subset of the model +parameters then the other parameters will be drawn by Stan's default +initialization. The fit object must have at least some parameters that are the +same name and dimensions as the current Stan model. For the sample and +pathfinder method, if the fit object has fewer draws than the requested +number of chains/paths then the inits will be drawn using sampling with +replacement. Otherwise sampling without replacement will be used. +When a CmdStanPathfinder fit object is used as the init, if +. psis_resample was set to FALSE and calculate_lp was +set to TRUE (default), then resampling without replacement with Pareto +smoothed weights will be used. If psis_resample was set to TRUE or +calculate_lp was set to FALSE then sampling without replacement with +uniform weights will be used to select the draws. +PSIS resampling is used to select the draws for CmdStanVB, +and CmdStanLaplace fit objects.

      • +
      • A type inheriting from posterior::draws. If the draws object has less +samples than the number of requested chains/paths then the inits will be +drawn using sampling with replacement. Otherwise sampling without +replacement will be used. If the draws object's parameters are only a subset +of the model parameters then the other parameters will be drawn by Stan's +default initialization. The fit object must have at least some parameters +that are the same name and dimensions as the current Stan model.

    @@ -227,8 +256,8 @@

    Arguments

    about the latent dynamics be written to temporary diagnostic CSV files? This argument replaces CmdStan's diagnostic_file argument and the content written to CSV is controlled by the user's CmdStan installation and not -CmdStanR (for some algorithms no content may be written). The default -is FALSE, which is appropriate for almost every use case. To save the +CmdStanR (for some algorithms no content may be written). The default is +FALSE, which is appropriate for almost every use case. To save the temporary files created when save_latent_dynamics=TRUE see the $save_latent_dynamics_files() method.

    @@ -236,15 +265,16 @@

    Arguments

    output_dir

    (string) A path to a directory where CmdStan should write -its output CSV files. For interactive use this can typically be left at -NULL (temporary directory) since CmdStanR makes the CmdStan output -(posterior draws and diagnostics) available in R via methods of the fitted -model objects. The behavior of output_dir is as follows:

    • If NULL (the default), then the CSV files are written to a temporary +its output CSV files. For MCMC there will be one file per chain; for other +methods there will be a single file. For interactive use this can typically +be left at NULL (temporary directory) since CmdStanR makes the CmdStan +output (posterior draws and diagnostics) available in R via methods of the +fitted model objects. This can be set for an entire R session using +options(cmdstanr_output_dir). The behavior of output_dir is as follows:

      • If NULL (the default), then the CSV files are written to a temporary directory and only saved permanently if the user calls one of the $save_* methods of the fitted model object (e.g., $save_output_files()). These temporary -files are removed when the fitted model object is -garbage collected (manually or automatically).

      • +files are removed when the fitted model object is garbage collected (manually or automatically).

      • If a path, then the files are created in output_dir with names corresponding to the defaults used by $save_output_files().

    @@ -266,10 +296,10 @@

    Arguments

    opencl_ids
    -

    (integer vector of length 2) The platform and -device IDs of the OpenCL device to use for fitting. The model must -be compiled with cpp_options = list(stan_opencl = TRUE) for this -argument to have an effect.

    +

    (integer vector of length 2) The platform and device IDs of +the OpenCL device to use for fitting. The model must be compiled with +cpp_options = list(stan_opencl = TRUE) for this argument to have an +effect.

    num_threads
    @@ -339,6 +369,45 @@

    Arguments

    (logical) Whether to save the results of single pathfinder runs in multi-pathfinder.

    + +
    psis_resample
    +

    (logical) Whether to perform pareto smoothed importance sampling. +If TRUE, the number of draws returned will be equal to draws. +If FALSE, the number of draws returned will be equal to single_path_draws * num_paths.

    + + +
    calculate_lp
    +

    (logical) Whether to calculate the log probability of the draws. +If TRUE, the log probability will be calculated and given in the output. +If FALSE, the log probability will only be returned for draws used to determine the +ELBO in the pathfinder steps. All other draws will have a log probability of NA. +A value of FALSE will also turn off pareto smoothed importance sampling as the +lp calculation is needed for PSIS.

    + + +
    show_messages
    +

    (logical) When TRUE (the default), prints all output +during the execution process, such as iteration numbers and elapsed times. +If the output is silenced then the $output() method +of the resulting fit object can be used to display the silenced messages.

    + + +
    show_exceptions
    +

    (logical) When TRUE (the default), prints all +informational messages, for example rejection of the current proposal. +Disable if you wish to silence these messages, but this is not usually +recommended unless you are very confident that the model is correct up to +numerical error. If the messages are silenced then the +$output() method of the resulting fit object can be +used to display the silenced messages.

    + + +
    save_cmdstan_config
    +

    (logical) When TRUE (the default), call CmdStan +with argument "output save_config=1" to save a json file which contains +the argument tree and extra information (equivalent to the output CSV file +header). This option is only available in CmdStan 2.34.0 and later.

    +
    @@ -382,7 +451,7 @@

    Examples

    # Otherwise use the `path` argument to specify the location of your # CmdStan installation.) set_cmdstan_path(path = NULL) -#> CmdStan path set to: /Users/jgabry/.cmdstan/cmdstan-2.33.1 +#> CmdStan path set to: /Users/jgabry/.cmdstan/cmdstan-2.35.0 # Create a CmdStanModel object from a Stan program, # here using the example model that comes with CmdStan @@ -391,15 +460,29 @@

    Examples

    mod$print() #> data { #> int<lower=0> N; -#> array[N] int<lower=0,upper=1> y; +#> array[N] int<lower=0, upper=1> y; #> } #> parameters { -#> real<lower=0,upper=1> theta; +#> real<lower=0, upper=1> theta; #> } #> model { -#> theta ~ beta(1,1); // uniform prior on interval 0,1 +#> theta ~ beta(1, 1); // uniform prior on interval 0,1 #> y ~ bernoulli(theta); #> } +# Print with line numbers. This can be set globally using the +# `cmdstanr_print_line_numbers` option. +mod$print(line_numbers = TRUE) +#> 1: data { +#> 2: int<lower=0> N; +#> 3: array[N] int<lower=0, upper=1> y; +#> 4: } +#> 5: parameters { +#> 6: real<lower=0, upper=1> theta; +#> 7: } +#> 8: model { +#> 9: theta ~ beta(1, 1); // uniform prior on interval 0,1 +#> 10: y ~ bernoulli(theta); +#> 11: } # Data as a named list (like RStan) stan_data <- list(N = 10, y = c(0,1,0,0,0,0,0,0,0,1)) @@ -470,8 +553,8 @@

    Examples

    #> # A tibble: 2 × 10 #> variable mean median sd mad q5 q95 rhat ess_bulk ess_tail #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp__ -7.30 -7.03 0.721 0.380 -8.82 -6.75 1.00 902. 1006. -#> 2 theta 0.247 0.233 0.122 0.129 0.0786 0.470 1.00 762. 712. +#> 1 lp__ -7.30 -7.00 0.811 0.344 -8.83 -6.75 1.00 702. 776. +#> 2 theta 0.254 0.238 0.125 0.124 0.0807 0.483 1.00 634. 580. # Check sampling diagnostics fit_mcmc$diagnostic_summary() @@ -482,7 +565,7 @@

    Examples

    #> [1] 0 0 #> #> $ebfmi -#> [1] 1.017555 1.250490 +#> [1] 1.1148699 0.8012192 #> # Get posterior draws @@ -492,22 +575,22 @@

    Examples

    #> , , variable = lp__ #> #> chain -#> iteration 1 2 -#> 1 -6.8 -6.8 -#> 2 -6.9 -6.8 -#> 3 -7.0 -7.0 -#> 4 -6.9 -7.1 -#> 5 -6.7 -7.0 +#> iteration 1 2 +#> 1 -7.0 -6.8 +#> 2 -7.9 -6.9 +#> 3 -7.4 -6.8 +#> 4 -6.7 -6.8 +#> 5 -6.9 -10.2 #> #> , , variable = theta #> #> chain #> iteration 1 2 -#> 1 0.28 0.21 -#> 2 0.19 0.20 -#> 3 0.16 0.17 -#> 4 0.20 0.36 -#> 5 0.25 0.34 +#> 1 0.17 0.23 +#> 2 0.46 0.18 +#> 3 0.41 0.28 +#> 4 0.25 0.23 +#> 5 0.18 0.62 #> #> # ... with 995 more iterations @@ -515,16 +598,16 @@

    Examples

    as_draws_df(draws) #> # A draws_df: 1000 iterations, 2 chains, and 2 variables #> lp__ theta -#> 1 -6.8 0.28 -#> 2 -6.9 0.19 -#> 3 -7.0 0.16 -#> 4 -6.9 0.20 -#> 5 -6.7 0.25 -#> 6 -7.1 0.36 -#> 7 -9.0 0.55 -#> 8 -7.2 0.15 -#> 9 -6.8 0.23 -#> 10 -7.5 0.42 +#> 1 -7.0 0.17 +#> 2 -7.9 0.46 +#> 3 -7.4 0.41 +#> 4 -6.7 0.25 +#> 5 -6.9 0.18 +#> 6 -6.9 0.33 +#> 7 -7.2 0.15 +#> 8 -6.8 0.29 +#> 9 -6.8 0.24 +#> 10 -6.8 0.24 #> # ... with 1990 more draws #> # ... hidden reserved variables {'.chain', '.iteration', '.draw'} @@ -542,9 +625,9 @@

    Examples

    # and also demonstrate specifying data as a path to a file instead of a list my_data_file <- file.path(cmdstan_path(), "examples/bernoulli/bernoulli.data.json") fit_optim <- mod$optimize(data = my_data_file, seed = 123) -#> Initial log joint probability = -9.51104 +#> Initial log joint probability = -16.144 #> Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes -#> 6 -5.00402 0.000103557 2.55661e-07 1 1 9 +#> 6 -5.00402 0.000246518 8.73164e-07 1 1 9 #> Optimization terminated normally: #> Convergence detected: relative gradient magnitude is below tolerance #> Finished in 0.1 seconds. @@ -558,9 +641,9 @@

    Examples

    # Run 'optimize' again with 'jacobian=TRUE' and then draw from Laplace approximation # to the posterior fit_optim <- mod$optimize(data = my_data_file, jacobian = TRUE) -#> Initial log joint probability = -11.5709 +#> Initial log joint probability = -8.03582 #> Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes -#> 5 -6.74802 0.00107647 1.72219e-05 1 1 8 +#> 5 -6.74802 0.000232501 1.48433e-06 1 1 8 #> Optimization terminated normally: #> Convergence detected: relative gradient magnitude is below tolerance #> Finished in 0.1 seconds. @@ -593,9 +676,9 @@

    Examples

    #> # A tibble: 3 × 7 #> variable mean median sd mad q5 q95 #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp__ -7.23 -6.99 0.637 0.323 -8.54 -6.75 -#> 2 lp_approx__ -0.486 -0.238 0.644 0.323 -1.80 -0.00166 -#> 3 theta 0.268 0.252 0.121 0.126 0.104 0.492 +#> 1 lp__ -7.24 -6.98 0.696 0.318 -8.64 -6.75 +#> 2 lp_approx__ -0.504 -0.233 0.703 0.320 -1.97 -0.00198 +#> 3 theta 0.266 0.248 0.123 0.122 0.100 0.498 # Run 'variational' method to use ADVI to approximate posterior fit_vb <- mod$variational(data = stan_data, seed = 123) @@ -604,8 +687,8 @@

    Examples

    #> This procedure has not been thoroughly tested and may be unstable #> or buggy. The interface is subject to change. #> ------------------------------------------------------------ -#> Gradient evaluation took 6e-06 seconds -#> 1000 transitions using 10 leapfrog steps per transition would take 0.06 seconds. +#> Gradient evaluation took 1.2e-05 seconds +#> 1000 transitions using 10 leapfrog steps per transition would take 0.12 seconds. #> Adjust your expectations accordingly! #> Begin eta adaptation. #> Iteration: 1 / 250 [ 0%] (Adaptation) @@ -616,9 +699,9 @@

    Examples

    #> Success! Found best value [eta = 1] earlier than expected. #> Begin stochastic gradient ascent. #> iter ELBO delta_ELBO_mean delta_ELBO_med notes -#> 100 -6.262 1.000 1.000 -#> 200 -6.263 0.500 1.000 -#> 300 -6.307 0.336 0.007 MEDIAN ELBO CONVERGED +#> 100 -6.164 1.000 1.000 +#> 200 -6.225 0.505 1.000 +#> 300 -6.186 0.339 0.010 MEDIAN ELBO CONVERGED #> Drawing a sample of size 1000 from the approximate posterior... #> COMPLETED. #> Finished in 0.1 seconds. @@ -626,40 +709,40 @@

    Examples

    #> # A tibble: 3 × 7 #> variable mean median sd mad q5 q95 #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp__ -7.18 -6.94 0.588 0.259 -8.36 -6.75 -#> 2 lp_approx__ -0.515 -0.221 0.692 0.303 -2.06 -0.00257 -#> 3 theta 0.263 0.246 0.115 0.113 0.106 0.481 +#> 1 lp__ -7.14 -6.93 0.528 0.247 -8.21 -6.75 +#> 2 lp_approx__ -0.520 -0.244 0.740 0.326 -1.90 -0.00227 +#> 3 theta 0.251 0.236 0.107 0.108 0.100 0.446 mcmc_hist(fit_vb$draws("theta")) #> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. # Run 'pathfinder' method, a new alternative to the variational method fit_pf <- mod$pathfinder(data = stan_data, seed = 123) -#> Path [1] :Initial log joint density = -11.008832 +#> Path [1] :Initial log joint density = -18.273334 #> Path [1] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 9.383e-04 1.391e-05 1.000e+00 1.000e+00 126 -6.264e+00 -6.264e+00 -#> Path [1] :Best Iter: [3] ELBO (-6.195408) evaluations: (126) -#> Path [2] :Initial log joint density = -7.318450 +#> 5 -6.748e+00 7.082e-04 1.432e-05 1.000e+00 1.000e+00 126 -6.145e+00 -6.145e+00 +#> Path [1] :Best Iter: [5] ELBO (-6.145070) evaluations: (126) +#> Path [2] :Initial log joint density = -19.192715 #> Path [2] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 4 -6.748e+00 5.414e-03 1.618e-04 1.000e+00 1.000e+00 101 -6.251e+00 -6.251e+00 -#> Path [2] :Best Iter: [3] ELBO (-6.229174) evaluations: (101) -#> Path [3] :Initial log joint density = -12.374612 +#> 5 -6.748e+00 2.015e-04 2.228e-06 1.000e+00 1.000e+00 126 -6.223e+00 -6.223e+00 +#> Path [2] :Best Iter: [2] ELBO (-6.170358) evaluations: (126) +#> Path [3] :Initial log joint density = -6.774820 #> Path [3] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 1.419e-03 2.837e-05 1.000e+00 1.000e+00 126 -6.199e+00 -6.199e+00 -#> Path [3] :Best Iter: [5] ELBO (-6.199185) evaluations: (126) -#> Path [4] :Initial log joint density = -13.009824 +#> 4 -6.748e+00 1.137e-04 2.596e-07 1.000e+00 1.000e+00 101 -6.178e+00 -6.178e+00 +#> Path [3] :Best Iter: [4] ELBO (-6.177909) evaluations: (101) +#> Path [4] :Initial log joint density = -7.949193 #> Path [4] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 1.677e-03 3.885e-05 1.000e+00 1.000e+00 126 -6.173e+00 -6.173e+00 -#> Path [4] :Best Iter: [5] ELBO (-6.172860) evaluations: (126) +#> 5 -6.748e+00 2.145e-04 1.301e-06 1.000e+00 1.000e+00 126 -6.197e+00 -6.197e+00 +#> Path [4] :Best Iter: [5] ELBO (-6.197118) evaluations: (126) #> Total log probability function evaluations:4379 -#> Finished in 0.1 seconds. +#> Finished in 0.2 seconds. fit_pf$summary() #> # A tibble: 3 × 7 #> variable mean median sd mad q5 q95 #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp_approx__ -1.08 -0.728 0.886 0.304 -2.71 -0.511 -#> 2 lp__ -7.26 -6.96 0.738 0.297 -8.72 -6.75 -#> 3 theta 0.249 0.230 0.120 0.121 0.0854 0.471 +#> 1 lp_approx__ -1.07 -0.727 0.945 0.311 -2.91 -0.450 +#> 2 lp__ -7.25 -6.97 0.753 0.308 -8.78 -6.75 +#> 3 theta 0.256 0.245 0.119 0.123 0.0824 0.462 mcmc_hist(fit_pf$draws("theta")) #> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. @@ -668,47 +751,48 @@

    Examples

    # better covariance approximation, and fewer LBFGSs iterations fit_pf <- mod$pathfinder(data = stan_data, num_paths=10, single_path_draws=40, history_size=50, max_lbfgs_iters=100) -#> Path [1] :Initial log joint density = -14.470660 +#> Warning: Number of PSIS draws is larger than the total number of draws returned by the single Pathfinders. This is likely unintentional and leads to re-sampling from the same draws. +#> Path [1] :Initial log joint density = -6.748022 #> Path [1] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 2.026e-03 5.797e-05 1.000e+00 1.000e+00 126 -6.259e+00 -6.259e+00 -#> Path [1] :Best Iter: [4] ELBO (-6.211388) evaluations: (126) -#> Path [2] :Initial log joint density = -9.064681 +#> 2 -6.748e+00 3.660e-04 9.724e-08 1.000e+00 1.000e+00 51 -6.176e+00 -6.176e+00 +#> Path [1] :Best Iter: [2] ELBO (-6.176168) evaluations: (51) +#> Path [2] :Initial log joint density = -6.810066 #> Path [2] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 3.457e-04 2.927e-06 1.000e+00 1.000e+00 126 -6.253e+00 -6.253e+00 -#> Path [2] :Best Iter: [3] ELBO (-6.227371) evaluations: (126) -#> Path [3] :Initial log joint density = -15.152638 +#> 4 -6.748e+00 3.617e-04 1.786e-06 1.000e+00 1.000e+00 101 -6.202e+00 -6.202e+00 +#> Path [2] :Best Iter: [4] ELBO (-6.201718) evaluations: (101) +#> Path [3] :Initial log joint density = -7.451465 #> Path [3] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 2.028e-03 6.063e-05 1.000e+00 1.000e+00 126 -6.230e+00 -6.230e+00 -#> Path [3] :Best Iter: [4] ELBO (-6.211247) evaluations: (126) -#> Path [4] :Initial log joint density = -10.220491 +#> 5 -6.748e+00 1.012e-04 3.850e-07 1.000e+00 1.000e+00 126 -6.225e+00 -6.225e+00 +#> Path [3] :Best Iter: [4] ELBO (-6.186839) evaluations: (126) +#> Path [4] :Initial log joint density = -18.081755 #> Path [4] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 7.043e-04 8.900e-06 1.000e+00 1.000e+00 126 -6.194e+00 -6.194e+00 -#> Path [4] :Best Iter: [5] ELBO (-6.193620) evaluations: (126) -#> Path [5] :Initial log joint density = -6.766009 +#> 5 -6.748e+00 8.265e-04 1.795e-05 1.000e+00 1.000e+00 126 -6.189e+00 -6.189e+00 +#> Path [4] :Best Iter: [5] ELBO (-6.188909) evaluations: (126) +#> Path [5] :Initial log joint density = -7.075204 #> Path [5] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 3 -6.748e+00 2.724e-03 1.458e-04 1.000e+00 1.000e+00 76 -6.232e+00 -6.232e+00 -#> Path [5] :Best Iter: [3] ELBO (-6.232284) evaluations: (76) -#> Path [6] :Initial log joint density = -7.304442 +#> 4 -6.748e+00 2.957e-03 5.925e-05 1.000e+00 1.000e+00 101 -6.268e+00 -6.268e+00 +#> Path [5] :Best Iter: [3] ELBO (-6.207400) evaluations: (101) +#> Path [6] :Initial log joint density = -6.950110 #> Path [6] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 4.014e-04 5.879e-07 1.000e+00 1.000e+00 126 -6.247e+00 -6.247e+00 -#> Path [6] :Best Iter: [4] ELBO (-6.212233) evaluations: (126) -#> Path [7] :Initial log joint density = -7.233791 +#> 4 -6.748e+00 1.668e-03 2.284e-05 1.000e+00 1.000e+00 101 -6.226e+00 -6.226e+00 +#> Path [6] :Best Iter: [3] ELBO (-6.178796) evaluations: (101) +#> Path [7] :Initial log joint density = -10.742807 #> Path [7] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 2.804e-04 3.115e-07 1.000e+00 1.000e+00 126 -6.275e+00 -6.275e+00 -#> Path [7] :Best Iter: [4] ELBO (-6.122234) evaluations: (126) -#> Path [8] :Initial log joint density = -11.942008 +#> 5 -6.748e+00 8.636e-04 1.223e-05 1.000e+00 1.000e+00 126 -6.253e+00 -6.253e+00 +#> Path [7] :Best Iter: [2] ELBO (-6.147651) evaluations: (126) +#> Path [8] :Initial log joint density = -8.722796 #> Path [8] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 1.223e-03 2.161e-05 1.000e+00 1.000e+00 126 -6.232e+00 -6.232e+00 -#> Path [8] :Best Iter: [3] ELBO (-6.217220) evaluations: (126) -#> Path [9] :Initial log joint density = -7.438064 +#> 5 -6.748e+00 3.316e-04 2.692e-06 1.000e+00 1.000e+00 126 -6.185e+00 -6.185e+00 +#> Path [8] :Best Iter: [5] ELBO (-6.185211) evaluations: (126) +#> Path [9] :Initial log joint density = -6.756313 #> Path [9] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 9.817e-05 3.665e-07 1.000e+00 1.000e+00 126 -6.268e+00 -6.268e+00 -#> Path [9] :Best Iter: [3] ELBO (-6.213533) evaluations: (126) -#> Path [10] :Initial log joint density = -8.992806 +#> 3 -6.748e+00 1.308e-03 4.802e-05 1.000e+00 1.000e+00 76 -6.202e+00 -6.202e+00 +#> Path [9] :Best Iter: [3] ELBO (-6.201510) evaluations: (76) +#> Path [10] :Initial log joint density = -7.046682 #> Path [10] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 3.448e-04 2.904e-06 1.000e+00 1.000e+00 126 -6.247e+00 -6.247e+00 -#> Path [10] :Best Iter: [2] ELBO (-6.141839) evaluations: (126) -#> Total log probability function evaluations:1360 +#> 4 -6.748e+00 2.661e-03 4.972e-05 1.000e+00 1.000e+00 101 -6.199e+00 -6.199e+00 +#> Path [10] :Best Iter: [2] ELBO (-6.191324) evaluations: (101) +#> Total log probability function evaluations:1185 #> Finished in 0.1 seconds. # Specifying initial values as a function @@ -791,7 +875,7 @@

    Examples

    #> 6 -5.00402 0.000237915 9.55309e-07 1 1 9 #> Optimization terminated normally: #> Convergence detected: relative gradient magnitude is below tolerance -#> Finished in 0.1 seconds. +#> Finished in 0.2 seconds. fit_optim_w_init_list$init() #> [[1]] #> [[1]]$theta @@ -810,11 +894,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/model-method-sample-1.png b/docs/reference/model-method-sample-1.png index 0aa41c0e..aa185638 100644 Binary files a/docs/reference/model-method-sample-1.png and b/docs/reference/model-method-sample-1.png differ diff --git a/docs/reference/model-method-sample-2.png b/docs/reference/model-method-sample-2.png index 835a8a66..4cf81fa8 100644 Binary files a/docs/reference/model-method-sample-2.png and b/docs/reference/model-method-sample-2.png differ diff --git a/docs/reference/model-method-sample-3.png b/docs/reference/model-method-sample-3.png index 8d58780f..c67b37ed 100644 Binary files a/docs/reference/model-method-sample-3.png and b/docs/reference/model-method-sample-3.png differ diff --git a/docs/reference/model-method-sample.html b/docs/reference/model-method-sample.html index 7925e4b4..a0b5b1f3 100644 --- a/docs/reference/model-method-sample.html +++ b/docs/reference/model-method-sample.html @@ -1,5 +1,5 @@ -Run Stan's MCMC algorithms — model-method-sample • cmdstanrRun Stan's MCMC algorithms — model-method-sample • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -128,7 +128,7 @@

    Run Stan's MCMC algorithms

    refresh = NULL, init = NULL, save_latent_dynamics = FALSE, - output_dir = NULL, + output_dir = getOption("cmdstanr_output_dir"), output_basename = NULL, sig_figs = NULL, chains = 4, @@ -154,6 +154,8 @@

    Run Stan's MCMC algorithms

    show_messages = TRUE, show_exceptions = TRUE, diagnostics = c("divergences", "treedepth", "ebfmi"), + save_metric = NULL, + save_cmdstan_config = NULL, cores = NULL, num_cores = NULL, num_chains = NULL, @@ -171,8 +173,8 @@

    Arguments

    data

    (multiple options) The data to use for the variables specified in the data block of the Stan program. One of the following:

    • A named list of R objects with the names corresponding to variables -declared in the data block of the Stan program. Internally this list is then -written to JSON for CmdStan using write_stan_json(). See +declared in the data block of the Stan program. Internally this list is +then written to JSON for CmdStan using write_stan_json(). See write_stan_json() for details on the conversions performed on R objects before they are passed to Stan.

    • A path to a data file compatible with CmdStan (JSON or R dump). See the @@ -185,12 +187,11 @@

      Arguments

      (positive integer(s)) A seed for the (P)RNG to pass to CmdStan. In the case of multi-chain sampling the single seed will automatically be augmented by the the run (chain) ID so that each chain uses a different -seed. The exception is the transformed data block, which defaults to -using same seed for all chains so that the same data is generated for all -chains if RNG functions are used. The only time seed should be specified -as a vector (one element per chain) is if RNG functions are used in -transformed data and the goal is to generate different data for each -chain.

      +seed. The exception is the transformed data block, which defaults to using +same seed for all chains so that the same data is generated for all chains +if RNG functions are used. The only time seed should be specified as a +vector (one element per chain) is if RNG functions are used in transformed +data and the goal is to generate different data for each chain.

    refresh
    @@ -201,8 +202,8 @@

    Arguments

    init

    (multiple options) The initialization method to use for the -variables declared in the parameters block of the Stan program. One of -the following:

    • A real number x>0. This initializes all parameters randomly between +variables declared in the parameters block of the Stan program. One of the +following:

      • A real number x>0. This initializes all parameters randomly between [-x,x] on the unconstrained parameter space.;

      • The number 0. This initializes all parameters to 0;

      • A character vector of paths (one per chain) to JSON or Rdump files @@ -216,10 +217,35 @@

        Arguments

        initial values. See Examples.

      • A function that returns a single list with names corresponding to the parameters for which you are specifying initial values. The function can -take no arguments or a single argument chain_id. For MCMC, if the function -has argument chain_id it will be supplied with the chain id (from 1 to -number of chains) when called to generate the initial values. See +take no arguments or a single argument chain_id. For MCMC, if the +function has argument chain_id it will be supplied with the chain id +(from 1 to number of chains) when called to generate the initial values. +See Examples.

      • +
      • A CmdStanMCMC, CmdStanMLE, CmdStanVB, CmdStanPathfinder, +or CmdStanLaplace fit object. +If the fit object's parameters are only a subset of the model +parameters then the other parameters will be drawn by Stan's default +initialization. The fit object must have at least some parameters that are the +same name and dimensions as the current Stan model. For the sample and +pathfinder method, if the fit object has fewer draws than the requested +number of chains/paths then the inits will be drawn using sampling with +replacement. Otherwise sampling without replacement will be used. +When a CmdStanPathfinder fit object is used as the init, if +. psis_resample was set to FALSE and calculate_lp was +set to TRUE (default), then resampling without replacement with Pareto +smoothed weights will be used. If psis_resample was set to TRUE or +calculate_lp was set to FALSE then sampling without replacement with +uniform weights will be used to select the draws. +PSIS resampling is used to select the draws for CmdStanVB, +and CmdStanLaplace fit objects.

      • +
      • A type inheriting from posterior::draws. If the draws object has less +samples than the number of requested chains/paths then the inits will be +drawn using sampling with replacement. Otherwise sampling without +replacement will be used. If the draws object's parameters are only a subset +of the model parameters then the other parameters will be drawn by Stan's +default initialization. The fit object must have at least some parameters +that are the same name and dimensions as the current Stan model.

    @@ -228,8 +254,8 @@

    Arguments

    about the latent dynamics be written to temporary diagnostic CSV files? This argument replaces CmdStan's diagnostic_file argument and the content written to CSV is controlled by the user's CmdStan installation and not -CmdStanR (for some algorithms no content may be written). The default -is FALSE, which is appropriate for almost every use case. To save the +CmdStanR (for some algorithms no content may be written). The default is +FALSE, which is appropriate for almost every use case. To save the temporary files created when save_latent_dynamics=TRUE see the $save_latent_dynamics_files() method.

    @@ -237,15 +263,16 @@

    Arguments

    output_dir

    (string) A path to a directory where CmdStan should write -its output CSV files. For interactive use this can typically be left at -NULL (temporary directory) since CmdStanR makes the CmdStan output -(posterior draws and diagnostics) available in R via methods of the fitted -model objects. The behavior of output_dir is as follows:

    • If NULL (the default), then the CSV files are written to a temporary +its output CSV files. For MCMC there will be one file per chain; for other +methods there will be a single file. For interactive use this can typically +be left at NULL (temporary directory) since CmdStanR makes the CmdStan +output (posterior draws and diagnostics) available in R via methods of the +fitted model objects. This can be set for an entire R session using +options(cmdstanr_output_dir). The behavior of output_dir is as follows:

      • If NULL (the default), then the CSV files are written to a temporary directory and only saved permanently if the user calls one of the $save_* methods of the fitted model object (e.g., $save_output_files()). These temporary -files are removed when the fitted model object is -garbage collected (manually or automatically).

      • +files are removed when the fitted model object is garbage collected (manually or automatically).

      • If a path, then the files are created in output_dir with names corresponding to the defaults used by $save_output_files().

    @@ -293,15 +320,14 @@

    Arguments

    contrast with parallel_chains, which specifies the number of chains to run in parallel. The actual number of CPU cores used is parallel_chains*threads_per_chain. For an example of using threading see -the Stan case study -Reduce Sum: A Minimal Example.

    +the Stan case study Reduce Sum: A Minimal Example.

    opencl_ids
    -

    (integer vector of length 2) The platform and -device IDs of the OpenCL device to use for fitting. The model must -be compiled with cpp_options = list(stan_opencl = TRUE) for this -argument to have an effect.

    +

    (integer vector of length 2) The platform and device IDs of +the OpenCL device to use for fitting. The model must be compiled with +cpp_options = list(stan_opencl = TRUE) for this argument to have an +effect.

    iter_warmup
    @@ -360,13 +386,13 @@

    Arguments

    metric_file
    -

    (character vector) The paths to JSON or -Rdump files (one per chain) compatible with CmdStan that contain -precomputed inverse metrics. The metric_file argument is inherited from -CmdStan but is confusing in that the entry in JSON or Rdump file(s) must be -named inv_metric, referring to the inverse metric. We recommend instead -using CmdStanR's inv_metric argument (see below) to specify an inverse -metric directly using a vector or matrix from your R session.

    +

    (character vector) The paths to JSON or Rdump files (one +per chain) compatible with CmdStan that contain precomputed inverse +metrics. The metric_file argument is inherited from CmdStan but is +confusing in that the entry in JSON or Rdump file(s) must be named +inv_metric, referring to the inverse metric. We recommend instead using +CmdStanR's inv_metric argument (see below) to specify an inverse metric +directly using a vector or matrix from your R session.

    inv_metric
    @@ -406,10 +432,10 @@

    Arguments

    show_messages
    -

    (logical) When TRUE (the default), prints all -output during the sampling process, such as iteration numbers and elapsed times. -If the output is silenced then the $output() method of -the resulting fit object can be used to display the silenced messages.

    +

    (logical) When TRUE (the default), prints all output +during the execution process, such as iteration numbers and elapsed times. +If the output is silenced then the $output() method +of the resulting fit object can be used to display the silenced messages.

    show_exceptions
    @@ -428,8 +454,8 @@

    Arguments

    NULL can be used to prevent CmdStanR from automatically reading in the sampler diagnostics from CSV if you wish to manually read in the results and validate them yourself, for example using read_cmdstan_csv(). The -currently available diagnostics are "divergences", "treedepth", -and "ebfmi" (the default is to check all of them).

    +currently available diagnostics are "divergences", "treedepth", and +"ebfmi" (the default is to check all of them).

    These diagnostics are also available after fitting. The $sampler_diagnostics() method provides access the diagnostic values for each iteration and the @@ -440,6 +466,20 @@

    Arguments

    using the $summary() method.

    +
    save_metric
    +

    (logical) When TRUE, call CmdStan with argument +"adaptation save_metric=1" to save the adapted metric in separate JSON +file with elements "stepsize", "metric_type" and "inv_metric". The default +is TRUE. This option is only available in CmdStan 2.34.0 and later.

    + + +
    save_cmdstan_config
    +

    (logical) When TRUE (the default), call CmdStan +with argument "output save_config=1" to save a json file which contains +the argument tree and extra information (equivalent to the output CSV file +header). This option is only available in CmdStan 2.34.0 and later.

    + +
    cores, num_cores, num_chains, num_warmup, num_samples, save_extra_diagnostics, max_depth, stepsize, validate_csv

    Deprecated and will be removed in a future release.

    @@ -486,7 +526,7 @@

    Examples

    # Otherwise use the `path` argument to specify the location of your # CmdStan installation.) set_cmdstan_path(path = NULL) -#> CmdStan path set to: /Users/jgabry/.cmdstan/cmdstan-2.33.1 +#> CmdStan path set to: /Users/jgabry/.cmdstan/cmdstan-2.35.0 # Create a CmdStanModel object from a Stan program, # here using the example model that comes with CmdStan @@ -495,15 +535,29 @@

    Examples

    mod$print() #> data { #> int<lower=0> N; -#> array[N] int<lower=0,upper=1> y; +#> array[N] int<lower=0, upper=1> y; #> } #> parameters { -#> real<lower=0,upper=1> theta; +#> real<lower=0, upper=1> theta; #> } #> model { -#> theta ~ beta(1,1); // uniform prior on interval 0,1 +#> theta ~ beta(1, 1); // uniform prior on interval 0,1 #> y ~ bernoulli(theta); #> } +# Print with line numbers. This can be set globally using the +# `cmdstanr_print_line_numbers` option. +mod$print(line_numbers = TRUE) +#> 1: data { +#> 2: int<lower=0> N; +#> 3: array[N] int<lower=0, upper=1> y; +#> 4: } +#> 5: parameters { +#> 6: real<lower=0, upper=1> theta; +#> 7: } +#> 8: model { +#> 9: theta ~ beta(1, 1); // uniform prior on interval 0,1 +#> 10: y ~ bernoulli(theta); +#> 11: } # Data as a named list (like RStan) stan_data <- list(N = 10, y = c(0,1,0,0,0,0,0,0,0,1)) @@ -574,8 +628,8 @@

    Examples

    #> # A tibble: 2 × 10 #> variable mean median sd mad q5 q95 rhat ess_bulk ess_tail #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp__ -7.30 -7.03 0.721 0.380 -8.82 -6.75 1.00 902. 1006. -#> 2 theta 0.247 0.233 0.122 0.129 0.0786 0.470 1.00 762. 712. +#> 1 lp__ -7.30 -7.00 0.811 0.344 -8.83 -6.75 1.00 702. 776. +#> 2 theta 0.254 0.238 0.125 0.124 0.0807 0.483 1.00 634. 580. # Check sampling diagnostics fit_mcmc$diagnostic_summary() @@ -586,7 +640,7 @@

    Examples

    #> [1] 0 0 #> #> $ebfmi -#> [1] 1.017555 1.250490 +#> [1] 1.1148699 0.8012192 #> # Get posterior draws @@ -596,22 +650,22 @@

    Examples

    #> , , variable = lp__ #> #> chain -#> iteration 1 2 -#> 1 -6.8 -6.8 -#> 2 -6.9 -6.8 -#> 3 -7.0 -7.0 -#> 4 -6.9 -7.1 -#> 5 -6.7 -7.0 +#> iteration 1 2 +#> 1 -7.0 -6.8 +#> 2 -7.9 -6.9 +#> 3 -7.4 -6.8 +#> 4 -6.7 -6.8 +#> 5 -6.9 -10.2 #> #> , , variable = theta #> #> chain #> iteration 1 2 -#> 1 0.28 0.21 -#> 2 0.19 0.20 -#> 3 0.16 0.17 -#> 4 0.20 0.36 -#> 5 0.25 0.34 +#> 1 0.17 0.23 +#> 2 0.46 0.18 +#> 3 0.41 0.28 +#> 4 0.25 0.23 +#> 5 0.18 0.62 #> #> # ... with 995 more iterations @@ -619,16 +673,16 @@

    Examples

    as_draws_df(draws) #> # A draws_df: 1000 iterations, 2 chains, and 2 variables #> lp__ theta -#> 1 -6.8 0.28 -#> 2 -6.9 0.19 -#> 3 -7.0 0.16 -#> 4 -6.9 0.20 -#> 5 -6.7 0.25 -#> 6 -7.1 0.36 -#> 7 -9.0 0.55 -#> 8 -7.2 0.15 -#> 9 -6.8 0.23 -#> 10 -7.5 0.42 +#> 1 -7.0 0.17 +#> 2 -7.9 0.46 +#> 3 -7.4 0.41 +#> 4 -6.7 0.25 +#> 5 -6.9 0.18 +#> 6 -6.9 0.33 +#> 7 -7.2 0.15 +#> 8 -6.8 0.29 +#> 9 -6.8 0.24 +#> 10 -6.8 0.24 #> # ... with 1990 more draws #> # ... hidden reserved variables {'.chain', '.iteration', '.draw'} @@ -646,12 +700,12 @@

    Examples

    # and also demonstrate specifying data as a path to a file instead of a list my_data_file <- file.path(cmdstan_path(), "examples/bernoulli/bernoulli.data.json") fit_optim <- mod$optimize(data = my_data_file, seed = 123) -#> Initial log joint probability = -9.51104 +#> Initial log joint probability = -16.144 #> Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes -#> 6 -5.00402 0.000103557 2.55661e-07 1 1 9 +#> 6 -5.00402 0.000246518 8.73164e-07 1 1 9 #> Optimization terminated normally: #> Convergence detected: relative gradient magnitude is below tolerance -#> Finished in 0.1 seconds. +#> Finished in 0.2 seconds. fit_optim$summary() #> # A tibble: 2 × 2 #> variable estimate @@ -662,12 +716,12 @@

    Examples

    # Run 'optimize' again with 'jacobian=TRUE' and then draw from Laplace approximation # to the posterior fit_optim <- mod$optimize(data = my_data_file, jacobian = TRUE) -#> Initial log joint probability = -11.0695 +#> Initial log joint probability = -6.90422 #> Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes -#> 5 -6.74802 0.000954615 1.42918e-05 1 1 8 +#> 4 -6.74802 0.00121095 1.33942e-05 1 1 7 #> Optimization terminated normally: #> Convergence detected: relative gradient magnitude is below tolerance -#> Finished in 0.1 seconds. +#> Finished in 0.2 seconds. fit_laplace <- mod$laplace(data = my_data_file, mode = fit_optim, draws = 2000) #> Calculating Hessian #> Calculating inverse of Cholesky factor @@ -697,9 +751,9 @@

    Examples

    #> # A tibble: 3 × 7 #> variable mean median sd mad q5 q95 #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp__ -7.23 -6.97 0.710 0.297 -8.57 -6.75 -#> 2 lp_approx__ -0.490 -0.220 0.696 0.300 -1.90 -0.00171 -#> 3 theta 0.270 0.252 0.123 0.120 0.102 0.495 +#> 1 lp__ -7.23 -6.97 0.693 0.308 -8.63 -6.75 +#> 2 lp_approx__ -0.493 -0.228 0.700 0.315 -1.89 -0.00185 +#> 3 theta 0.265 0.245 0.122 0.119 0.102 0.495 # Run 'variational' method to use ADVI to approximate posterior fit_vb <- mod$variational(data = stan_data, seed = 123) @@ -708,8 +762,8 @@

    Examples

    #> This procedure has not been thoroughly tested and may be unstable #> or buggy. The interface is subject to change. #> ------------------------------------------------------------ -#> Gradient evaluation took 6e-06 seconds -#> 1000 transitions using 10 leapfrog steps per transition would take 0.06 seconds. +#> Gradient evaluation took 1.2e-05 seconds +#> 1000 transitions using 10 leapfrog steps per transition would take 0.12 seconds. #> Adjust your expectations accordingly! #> Begin eta adaptation. #> Iteration: 1 / 250 [ 0%] (Adaptation) @@ -720,9 +774,9 @@

    Examples

    #> Success! Found best value [eta = 1] earlier than expected. #> Begin stochastic gradient ascent. #> iter ELBO delta_ELBO_mean delta_ELBO_med notes -#> 100 -6.262 1.000 1.000 -#> 200 -6.263 0.500 1.000 -#> 300 -6.307 0.336 0.007 MEDIAN ELBO CONVERGED +#> 100 -6.164 1.000 1.000 +#> 200 -6.225 0.505 1.000 +#> 300 -6.186 0.339 0.010 MEDIAN ELBO CONVERGED #> Drawing a sample of size 1000 from the approximate posterior... #> COMPLETED. #> Finished in 0.1 seconds. @@ -730,40 +784,40 @@

    Examples

    #> # A tibble: 3 × 7 #> variable mean median sd mad q5 q95 #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp__ -7.18 -6.94 0.588 0.259 -8.36 -6.75 -#> 2 lp_approx__ -0.515 -0.221 0.692 0.303 -2.06 -0.00257 -#> 3 theta 0.263 0.246 0.115 0.113 0.106 0.481 +#> 1 lp__ -7.14 -6.93 0.528 0.247 -8.21 -6.75 +#> 2 lp_approx__ -0.520 -0.244 0.740 0.326 -1.90 -0.00227 +#> 3 theta 0.251 0.236 0.107 0.108 0.100 0.446 mcmc_hist(fit_vb$draws("theta")) #> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. # Run 'pathfinder' method, a new alternative to the variational method fit_pf <- mod$pathfinder(data = stan_data, seed = 123) -#> Path [1] :Initial log joint density = -11.008832 +#> Path [1] :Initial log joint density = -18.273334 #> Path [1] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 9.383e-04 1.391e-05 1.000e+00 1.000e+00 126 -6.264e+00 -6.264e+00 -#> Path [1] :Best Iter: [3] ELBO (-6.195408) evaluations: (126) -#> Path [2] :Initial log joint density = -7.318450 +#> 5 -6.748e+00 7.082e-04 1.432e-05 1.000e+00 1.000e+00 126 -6.145e+00 -6.145e+00 +#> Path [1] :Best Iter: [5] ELBO (-6.145070) evaluations: (126) +#> Path [2] :Initial log joint density = -19.192715 #> Path [2] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 4 -6.748e+00 5.414e-03 1.618e-04 1.000e+00 1.000e+00 101 -6.251e+00 -6.251e+00 -#> Path [2] :Best Iter: [3] ELBO (-6.229174) evaluations: (101) -#> Path [3] :Initial log joint density = -12.374612 +#> 5 -6.748e+00 2.015e-04 2.228e-06 1.000e+00 1.000e+00 126 -6.223e+00 -6.223e+00 +#> Path [2] :Best Iter: [2] ELBO (-6.170358) evaluations: (126) +#> Path [3] :Initial log joint density = -6.774820 #> Path [3] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 1.419e-03 2.837e-05 1.000e+00 1.000e+00 126 -6.199e+00 -6.199e+00 -#> Path [3] :Best Iter: [5] ELBO (-6.199185) evaluations: (126) -#> Path [4] :Initial log joint density = -13.009824 +#> 4 -6.748e+00 1.137e-04 2.596e-07 1.000e+00 1.000e+00 101 -6.178e+00 -6.178e+00 +#> Path [3] :Best Iter: [4] ELBO (-6.177909) evaluations: (101) +#> Path [4] :Initial log joint density = -7.949193 #> Path [4] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 1.677e-03 3.885e-05 1.000e+00 1.000e+00 126 -6.173e+00 -6.173e+00 -#> Path [4] :Best Iter: [5] ELBO (-6.172860) evaluations: (126) +#> 5 -6.748e+00 2.145e-04 1.301e-06 1.000e+00 1.000e+00 126 -6.197e+00 -6.197e+00 +#> Path [4] :Best Iter: [5] ELBO (-6.197118) evaluations: (126) #> Total log probability function evaluations:4379 #> Finished in 0.1 seconds. fit_pf$summary() #> # A tibble: 3 × 7 #> variable mean median sd mad q5 q95 #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp_approx__ -1.08 -0.728 0.886 0.304 -2.71 -0.511 -#> 2 lp__ -7.26 -6.96 0.738 0.297 -8.72 -6.75 -#> 3 theta 0.249 0.230 0.120 0.121 0.0854 0.471 +#> 1 lp_approx__ -1.07 -0.727 0.945 0.311 -2.91 -0.450 +#> 2 lp__ -7.25 -6.97 0.753 0.308 -8.78 -6.75 +#> 3 theta 0.256 0.245 0.119 0.123 0.0824 0.462 mcmc_hist(fit_pf$draws("theta")) #> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. @@ -772,48 +826,50 @@

    Examples

    # better covariance approximation, and fewer LBFGSs iterations fit_pf <- mod$pathfinder(data = stan_data, num_paths=10, single_path_draws=40, history_size=50, max_lbfgs_iters=100) -#> Path [1] :Initial log joint density = -10.398597 +#> Warning: Number of PSIS draws is larger than the total number of draws returned by the single Pathfinders. This is likely unintentional and leads to re-sampling from the same draws. +#> Path [1] :Initial log joint density = -6.999713 #> Path [1] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 7.601e-04 1.002e-05 1.000e+00 1.000e+00 126 -6.246e+00 -6.246e+00 -#> Path [1] :Best Iter: [4] ELBO (-6.213236) evaluations: (126) -#> Path [2] :Initial log joint density = -7.343771 +#> 4 -6.748e+00 4.935e-04 1.167e-04 9.085e-01 9.085e-01 101 -6.235e+00 -6.235e+00 +#> Path [1] :Best Iter: [2] ELBO (-6.220514) evaluations: (101) +#> Path [2] :Initial log joint density = -6.963421 #> Path [2] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 4 -6.748e+00 5.658e-03 1.740e-04 1.000e+00 1.000e+00 101 -6.270e+00 -6.270e+00 -#> Path [2] :Best Iter: [3] ELBO (-6.236555) evaluations: (101) -#> Path [3] :Initial log joint density = -7.253954 +#> 4 -6.748e+00 3.701e-04 7.882e-05 9.167e-01 9.167e-01 101 -6.331e+00 -6.331e+00 +#> Path [2] :Best Iter: [2] ELBO (-6.159890) evaluations: (101) +#> Path [3] :Initial log joint density = -6.794406 #> Path [3] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 4 -6.748e+00 4.780e-03 1.316e-04 1.000e+00 1.000e+00 101 -6.293e+00 -6.293e+00 -#> Path [3] :Best Iter: [3] ELBO (-6.210231) evaluations: (101) -#> Path [4] :Initial log joint density = -6.884985 +#> 4 -6.748e+00 2.434e-04 9.233e-07 1.000e+00 1.000e+00 101 -6.183e+00 -6.183e+00 +#> Path [3] :Best Iter: [4] ELBO (-6.183157) evaluations: (101) +#> Path [4] :Initial log joint density = -6.999423 #> Path [4] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 4 -6.748e+00 1.025e-03 1.015e-05 1.000e+00 1.000e+00 101 -6.254e+00 -6.254e+00 -#> Path [4] :Best Iter: [4] ELBO (-6.254382) evaluations: (101) -#> Path [5] :Initial log joint density = -10.549385 +#> 4 -6.748e+00 4.925e-04 1.164e-04 9.085e-01 9.085e-01 101 -6.107e+00 -6.107e+00 +#> Path [4] :Best Iter: [4] ELBO (-6.107025) evaluations: (101) +#> Path [5] :Initial log joint density = -17.406798 #> Path [5] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 8.063e-04 1.099e-05 1.000e+00 1.000e+00 126 -6.155e+00 -6.155e+00 -#> Path [5] :Best Iter: [5] ELBO (-6.154812) evaluations: (126) -#> Path [6] :Initial log joint density = -11.021697 +#> 5 -6.748e+00 1.234e-03 3.202e-05 1.000e+00 1.000e+00 126 -6.124e+00 -6.124e+00 +#> Path [5] :Best Iter: [5] ELBO (-6.123731) evaluations: (126) +#> Path [6] :Initial log joint density = -6.778306 #> Path [6] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 9.418e-04 1.400e-05 1.000e+00 1.000e+00 126 -6.261e+00 -6.261e+00 -#> Path [6] :Best Iter: [4] ELBO (-6.204645) evaluations: (126) -#> Path [7] :Initial log joint density = -10.721189 +#> 4 -6.748e+00 1.349e-04 3.452e-07 1.000e+00 1.000e+00 101 -6.229e+00 -6.229e+00 +#> Path [6] :Best Iter: [2] ELBO (-6.102031) evaluations: (101) +#> Path [7] :Initial log joint density = -16.742631 #> Path [7] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 8.573e-04 1.209e-05 1.000e+00 1.000e+00 126 -6.195e+00 -6.195e+00 -#> Path [7] :Best Iter: [5] ELBO (-6.194637) evaluations: (126) -#> Path [8] :Initial log joint density = -11.729882 +#> 5 -6.748e+00 1.582e-03 4.527e-05 1.000e+00 1.000e+00 126 -6.275e+00 -6.275e+00 +#> Path [7] :Best Iter: [3] ELBO (-6.151199) evaluations: (126) +#> Path [8] :Initial log joint density = -9.611781 #> Path [8] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 1.125e-03 1.854e-05 1.000e+00 1.000e+00 126 -6.195e+00 -6.195e+00 -#> Path [8] :Best Iter: [4] ELBO (-6.193964) evaluations: (126) -#> Path [9] :Initial log joint density = -8.375820 +#> 5 -6.748e+00 5.082e-04 5.350e-06 1.000e+00 1.000e+00 126 -6.224e+00 -6.224e+00 +#> Path [8] :Best Iter: [3] ELBO (-6.204548) evaluations: (126) +#> Path [9] :Initial log joint density = -6.795862 #> Path [9] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 2.924e-04 2.169e-06 1.000e+00 1.000e+00 126 -6.198e+00 -6.198e+00 -#> Path [9] :Best Iter: [2] ELBO (-6.188312) evaluations: (126) -#> Path [10] :Initial log joint density = -7.041152 +#> 3 -6.748e+00 3.609e-03 4.044e-05 9.535e-01 9.535e-01 76 -6.173e+00 -6.173e+00 +#> Path [9] :Best Iter: [3] ELBO (-6.172749) evaluations: (76) +#> Path [10] :Initial log joint density = -7.466078 #> Path [10] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 4 -6.748e+00 2.604e-03 4.795e-05 1.000e+00 1.000e+00 101 -6.233e+00 -6.233e+00 -#> Path [10] :Best Iter: [2] ELBO (-6.214834) evaluations: (101) -#> Total log probability function evaluations:1310 -#> Finished in 0.1 seconds. +#> 5 -6.748e+00 7.983e-04 1.992e-06 1.000e+00 1.000e+00 126 -6.169e+00 -6.169e+00 +#> Path [10] :Best Iter: [5] ELBO (-6.168690) evaluations: (126) +#> Total log probability function evaluations:1235 +#> Pareto k value (0.97) is greater than 0.7. Importance resampling was not able to improve the approximation, which may indicate that the approximation itself is poor. +#> Finished in 0.2 seconds. # Specifying initial values as a function fit_mcmc_w_init_fun <- mod$sample( @@ -895,7 +951,7 @@

    Examples

    #> 6 -5.00402 0.000237915 9.55309e-07 1 1 9 #> Optimization terminated normally: #> Convergence detected: relative gradient magnitude is below tolerance -#> Finished in 0.1 seconds. +#> Finished in 0.2 seconds. fit_optim_w_init_list$init() #> [[1]] #> [[1]]$theta @@ -914,11 +970,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/model-method-sample_mpi.html b/docs/reference/model-method-sample_mpi.html index 6247b07a..5aab9dce 100644 --- a/docs/reference/model-method-sample_mpi.html +++ b/docs/reference/model-method-sample_mpi.html @@ -1,5 +1,5 @@ -Run Stan's MCMC algorithms with MPI — model-method-sample_mpi • cmdstanr refresh = NULL, init = NULL, save_latent_dynamics = FALSE, - output_dir = NULL, + output_dir = getOption("cmdstanr_output_dir"), output_basename = NULL, chains = 1, chain_ids = seq_len(chains), @@ -187,6 +187,7 @@

    Run Stan's MCMC algorithms with MPI

    show_messages = TRUE, show_exceptions = TRUE, diagnostics = c("divergences", "treedepth", "ebfmi"), + save_cmdstan_config = NULL, validate_csv = TRUE ) @@ -196,8 +197,8 @@

    Arguments

    data

    (multiple options) The data to use for the variables specified in the data block of the Stan program. One of the following:

    • A named list of R objects with the names corresponding to variables -declared in the data block of the Stan program. Internally this list is then -written to JSON for CmdStan using write_stan_json(). See +declared in the data block of the Stan program. Internally this list is +then written to JSON for CmdStan using write_stan_json(). See write_stan_json() for details on the conversions performed on R objects before they are passed to Stan.

    • A path to a data file compatible with CmdStan (JSON or R dump). See the @@ -222,12 +223,11 @@

      Arguments

      (positive integer(s)) A seed for the (P)RNG to pass to CmdStan. In the case of multi-chain sampling the single seed will automatically be augmented by the the run (chain) ID so that each chain uses a different -seed. The exception is the transformed data block, which defaults to -using same seed for all chains so that the same data is generated for all -chains if RNG functions are used. The only time seed should be specified -as a vector (one element per chain) is if RNG functions are used in -transformed data and the goal is to generate different data for each -chain.

      +seed. The exception is the transformed data block, which defaults to using +same seed for all chains so that the same data is generated for all chains +if RNG functions are used. The only time seed should be specified as a +vector (one element per chain) is if RNG functions are used in transformed +data and the goal is to generate different data for each chain.

    refresh
    @@ -238,8 +238,8 @@

    Arguments

    init

    (multiple options) The initialization method to use for the -variables declared in the parameters block of the Stan program. One of -the following:

    • A real number x>0. This initializes all parameters randomly between +variables declared in the parameters block of the Stan program. One of the +following:

      • A real number x>0. This initializes all parameters randomly between [-x,x] on the unconstrained parameter space.;

      • The number 0. This initializes all parameters to 0;

      • A character vector of paths (one per chain) to JSON or Rdump files @@ -253,10 +253,35 @@

        Arguments

        initial values. See Examples.

      • A function that returns a single list with names corresponding to the parameters for which you are specifying initial values. The function can -take no arguments or a single argument chain_id. For MCMC, if the function -has argument chain_id it will be supplied with the chain id (from 1 to -number of chains) when called to generate the initial values. See +take no arguments or a single argument chain_id. For MCMC, if the +function has argument chain_id it will be supplied with the chain id +(from 1 to number of chains) when called to generate the initial values. +See Examples.

      • +
      • A CmdStanMCMC, CmdStanMLE, CmdStanVB, CmdStanPathfinder, +or CmdStanLaplace fit object. +If the fit object's parameters are only a subset of the model +parameters then the other parameters will be drawn by Stan's default +initialization. The fit object must have at least some parameters that are the +same name and dimensions as the current Stan model. For the sample and +pathfinder method, if the fit object has fewer draws than the requested +number of chains/paths then the inits will be drawn using sampling with +replacement. Otherwise sampling without replacement will be used. +When a CmdStanPathfinder fit object is used as the init, if +. psis_resample was set to FALSE and calculate_lp was +set to TRUE (default), then resampling without replacement with Pareto +smoothed weights will be used. If psis_resample was set to TRUE or +calculate_lp was set to FALSE then sampling without replacement with +uniform weights will be used to select the draws. +PSIS resampling is used to select the draws for CmdStanVB, +and CmdStanLaplace fit objects.

      • +
      • A type inheriting from posterior::draws. If the draws object has less +samples than the number of requested chains/paths then the inits will be +drawn using sampling with replacement. Otherwise sampling without +replacement will be used. If the draws object's parameters are only a subset +of the model parameters then the other parameters will be drawn by Stan's +default initialization. The fit object must have at least some parameters +that are the same name and dimensions as the current Stan model.

    @@ -265,8 +290,8 @@

    Arguments

    about the latent dynamics be written to temporary diagnostic CSV files? This argument replaces CmdStan's diagnostic_file argument and the content written to CSV is controlled by the user's CmdStan installation and not -CmdStanR (for some algorithms no content may be written). The default -is FALSE, which is appropriate for almost every use case. To save the +CmdStanR (for some algorithms no content may be written). The default is +FALSE, which is appropriate for almost every use case. To save the temporary files created when save_latent_dynamics=TRUE see the $save_latent_dynamics_files() method.

    @@ -274,15 +299,16 @@

    Arguments

    output_dir

    (string) A path to a directory where CmdStan should write -its output CSV files. For interactive use this can typically be left at -NULL (temporary directory) since CmdStanR makes the CmdStan output -(posterior draws and diagnostics) available in R via methods of the fitted -model objects. The behavior of output_dir is as follows:

    • If NULL (the default), then the CSV files are written to a temporary +its output CSV files. For MCMC there will be one file per chain; for other +methods there will be a single file. For interactive use this can typically +be left at NULL (temporary directory) since CmdStanR makes the CmdStan +output (posterior draws and diagnostics) available in R via methods of the +fitted model objects. This can be set for an entire R session using +options(cmdstanr_output_dir). The behavior of output_dir is as follows:

      • If NULL (the default), then the CSV files are written to a temporary directory and only saved permanently if the user calls one of the $save_* methods of the fitted model object (e.g., $save_output_files()). These temporary -files are removed when the fitted model object is -garbage collected (manually or automatically).

      • +files are removed when the fitted model object is garbage collected (manually or automatically).

      • If a path, then the files are created in output_dir with names corresponding to the defaults used by $save_output_files().

    @@ -362,13 +388,13 @@

    Arguments

    metric_file
    -

    (character vector) The paths to JSON or -Rdump files (one per chain) compatible with CmdStan that contain -precomputed inverse metrics. The metric_file argument is inherited from -CmdStan but is confusing in that the entry in JSON or Rdump file(s) must be -named inv_metric, referring to the inverse metric. We recommend instead -using CmdStanR's inv_metric argument (see below) to specify an inverse -metric directly using a vector or matrix from your R session.

    +

    (character vector) The paths to JSON or Rdump files (one +per chain) compatible with CmdStan that contain precomputed inverse +metrics. The metric_file argument is inherited from CmdStan but is +confusing in that the entry in JSON or Rdump file(s) must be named +inv_metric, referring to the inverse metric. We recommend instead using +CmdStanR's inv_metric argument (see below) to specify an inverse metric +directly using a vector or matrix from your R session.

    inv_metric
    @@ -416,10 +442,10 @@

    Arguments

    show_messages
    -

    (logical) When TRUE (the default), prints all -output during the sampling process, such as iteration numbers and elapsed times. -If the output is silenced then the $output() method of -the resulting fit object can be used to display the silenced messages.

    +

    (logical) When TRUE (the default), prints all output +during the execution process, such as iteration numbers and elapsed times. +If the output is silenced then the $output() method +of the resulting fit object can be used to display the silenced messages.

    show_exceptions
    @@ -438,8 +464,8 @@

    Arguments

    NULL can be used to prevent CmdStanR from automatically reading in the sampler diagnostics from CSV if you wish to manually read in the results and validate them yourself, for example using read_cmdstan_csv(). The -currently available diagnostics are "divergences", "treedepth", -and "ebfmi" (the default is to check all of them).

    +currently available diagnostics are "divergences", "treedepth", and +"ebfmi" (the default is to check all of them).

    These diagnostics are also available after fitting. The $sampler_diagnostics() method provides access the diagnostic values for each iteration and the @@ -450,6 +476,13 @@

    Arguments

    using the $summary() method.

    +
    save_cmdstan_config
    +

    (logical) When TRUE (the default), call CmdStan +with argument "output save_config=1" to save a json file which contains +the argument tree and extra information (equivalent to the output CSV file +header). This option is only available in CmdStan 2.34.0 and later.

    + +
    validate_csv

    Deprecated. Use diagnostics instead.

    @@ -504,11 +537,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/model-method-variables.html b/docs/reference/model-method-variables.html index 6df7de09..208a40b1 100644 --- a/docs/reference/model-method-variables.html +++ b/docs/reference/model-method-variables.html @@ -1,5 +1,5 @@ -Input and output variables of a Stan program — model-method-variables • cmdstanrInput and output variables of a Stan program — model-method-variables • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -144,8 +144,8 @@

    See also

    model-method-laplace, model-method-optimize, model-method-pathfinder, -model-method-sample_mpi, model-method-sample, +model-method-sample_mpi, model-method-variational

    @@ -208,11 +208,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/model-method-variational-1.png b/docs/reference/model-method-variational-1.png index 0aa41c0e..aa185638 100644 Binary files a/docs/reference/model-method-variational-1.png and b/docs/reference/model-method-variational-1.png differ diff --git a/docs/reference/model-method-variational-2.png b/docs/reference/model-method-variational-2.png index 835a8a66..4cf81fa8 100644 Binary files a/docs/reference/model-method-variational-2.png and b/docs/reference/model-method-variational-2.png differ diff --git a/docs/reference/model-method-variational-3.png b/docs/reference/model-method-variational-3.png index 8d58780f..c67b37ed 100644 Binary files a/docs/reference/model-method-variational-3.png and b/docs/reference/model-method-variational-3.png differ diff --git a/docs/reference/model-method-variational.html b/docs/reference/model-method-variational.html index ed9fcbc4..68afc88a 100644 --- a/docs/reference/model-method-variational.html +++ b/docs/reference/model-method-variational.html @@ -1,5 +1,5 @@ -Run Stan's variational approximation algorithms — model-method-variational • cmdstanrRun Stan's variational approximation algorithms — model-method-variational • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -134,7 +134,7 @@

    Run Stan's variational approximation algorithms

    refresh = NULL, init = NULL, save_latent_dynamics = FALSE, - output_dir = NULL, + output_dir = getOption("cmdstanr_output_dir"), output_basename = NULL, sig_figs = NULL, threads = NULL, @@ -149,7 +149,10 @@

    Run Stan's variational approximation algorithms

    tol_rel_obj = NULL, eval_elbo = NULL, output_samples = NULL, - draws = NULL + draws = NULL, + show_messages = TRUE, + show_exceptions = TRUE, + save_cmdstan_config = NULL ) @@ -158,8 +161,8 @@

    Arguments

    data

    (multiple options) The data to use for the variables specified in the data block of the Stan program. One of the following:

    • A named list of R objects with the names corresponding to variables -declared in the data block of the Stan program. Internally this list is then -written to JSON for CmdStan using write_stan_json(). See +declared in the data block of the Stan program. Internally this list is +then written to JSON for CmdStan using write_stan_json(). See write_stan_json() for details on the conversions performed on R objects before they are passed to Stan.

    • A path to a data file compatible with CmdStan (JSON or R dump). See the @@ -172,12 +175,11 @@

      Arguments

      (positive integer(s)) A seed for the (P)RNG to pass to CmdStan. In the case of multi-chain sampling the single seed will automatically be augmented by the the run (chain) ID so that each chain uses a different -seed. The exception is the transformed data block, which defaults to -using same seed for all chains so that the same data is generated for all -chains if RNG functions are used. The only time seed should be specified -as a vector (one element per chain) is if RNG functions are used in -transformed data and the goal is to generate different data for each -chain.

      +seed. The exception is the transformed data block, which defaults to using +same seed for all chains so that the same data is generated for all chains +if RNG functions are used. The only time seed should be specified as a +vector (one element per chain) is if RNG functions are used in transformed +data and the goal is to generate different data for each chain.

    refresh
    @@ -188,8 +190,8 @@

    Arguments

    init

    (multiple options) The initialization method to use for the -variables declared in the parameters block of the Stan program. One of -the following:

    • A real number x>0. This initializes all parameters randomly between +variables declared in the parameters block of the Stan program. One of the +following:

      • A real number x>0. This initializes all parameters randomly between [-x,x] on the unconstrained parameter space.;

      • The number 0. This initializes all parameters to 0;

      • A character vector of paths (one per chain) to JSON or Rdump files @@ -203,10 +205,35 @@

        Arguments

        initial values. See Examples.

      • A function that returns a single list with names corresponding to the parameters for which you are specifying initial values. The function can -take no arguments or a single argument chain_id. For MCMC, if the function -has argument chain_id it will be supplied with the chain id (from 1 to -number of chains) when called to generate the initial values. See +take no arguments or a single argument chain_id. For MCMC, if the +function has argument chain_id it will be supplied with the chain id +(from 1 to number of chains) when called to generate the initial values. +See Examples.

      • +
      • A CmdStanMCMC, CmdStanMLE, CmdStanVB, CmdStanPathfinder, +or CmdStanLaplace fit object. +If the fit object's parameters are only a subset of the model +parameters then the other parameters will be drawn by Stan's default +initialization. The fit object must have at least some parameters that are the +same name and dimensions as the current Stan model. For the sample and +pathfinder method, if the fit object has fewer draws than the requested +number of chains/paths then the inits will be drawn using sampling with +replacement. Otherwise sampling without replacement will be used. +When a CmdStanPathfinder fit object is used as the init, if +. psis_resample was set to FALSE and calculate_lp was +set to TRUE (default), then resampling without replacement with Pareto +smoothed weights will be used. If psis_resample was set to TRUE or +calculate_lp was set to FALSE then sampling without replacement with +uniform weights will be used to select the draws. +PSIS resampling is used to select the draws for CmdStanVB, +and CmdStanLaplace fit objects.

      • +
      • A type inheriting from posterior::draws. If the draws object has less +samples than the number of requested chains/paths then the inits will be +drawn using sampling with replacement. Otherwise sampling without +replacement will be used. If the draws object's parameters are only a subset +of the model parameters then the other parameters will be drawn by Stan's +default initialization. The fit object must have at least some parameters +that are the same name and dimensions as the current Stan model.

    @@ -215,8 +242,8 @@

    Arguments

    about the latent dynamics be written to temporary diagnostic CSV files? This argument replaces CmdStan's diagnostic_file argument and the content written to CSV is controlled by the user's CmdStan installation and not -CmdStanR (for some algorithms no content may be written). The default -is FALSE, which is appropriate for almost every use case. To save the +CmdStanR (for some algorithms no content may be written). The default is +FALSE, which is appropriate for almost every use case. To save the temporary files created when save_latent_dynamics=TRUE see the $save_latent_dynamics_files() method.

    @@ -224,15 +251,16 @@

    Arguments

    output_dir

    (string) A path to a directory where CmdStan should write -its output CSV files. For interactive use this can typically be left at -NULL (temporary directory) since CmdStanR makes the CmdStan output -(posterior draws and diagnostics) available in R via methods of the fitted -model objects. The behavior of output_dir is as follows:

    • If NULL (the default), then the CSV files are written to a temporary +its output CSV files. For MCMC there will be one file per chain; for other +methods there will be a single file. For interactive use this can typically +be left at NULL (temporary directory) since CmdStanR makes the CmdStan +output (posterior draws and diagnostics) available in R via methods of the +fitted model objects. This can be set for an entire R session using +options(cmdstanr_output_dir). The behavior of output_dir is as follows:

      • If NULL (the default), then the CSV files are written to a temporary directory and only saved permanently if the user calls one of the $save_* methods of the fitted model object (e.g., $save_output_files()). These temporary -files are removed when the fitted model object is -garbage collected (manually or automatically).

      • +files are removed when the fitted model object is garbage collected (manually or automatically).

      • If a path, then the files are created in output_dir with names corresponding to the defaults used by $save_output_files().

    @@ -261,10 +289,10 @@

    Arguments

    opencl_ids
    -

    (integer vector of length 2) The platform and -device IDs of the OpenCL device to use for fitting. The model must -be compiled with cpp_options = list(stan_opencl = TRUE) for this -argument to have an effect.

    +

    (integer vector of length 2) The platform and device IDs of +the OpenCL device to use for fitting. The model must be compiled with +cpp_options = list(stan_opencl = TRUE) for this argument to have an +effect.

    algorithm
    @@ -318,6 +346,30 @@

    Arguments

    (positive integer) Number of approximate posterior samples to draw and save.

    + +
    show_messages
    +

    (logical) When TRUE (the default), prints all output +during the execution process, such as iteration numbers and elapsed times. +If the output is silenced then the $output() method +of the resulting fit object can be used to display the silenced messages.

    + + +
    show_exceptions
    +

    (logical) When TRUE (the default), prints all +informational messages, for example rejection of the current proposal. +Disable if you wish to silence these messages, but this is not usually +recommended unless you are very confident that the model is correct up to +numerical error. If the messages are silenced then the +$output() method of the resulting fit object can be +used to display the silenced messages.

    + + +
    save_cmdstan_config
    +

    (logical) When TRUE (the default), call CmdStan +with argument "output save_config=1" to save a json file which contains +the argument tree and extra information (equivalent to the output CSV file +header). This option is only available in CmdStan 2.34.0 and later.

    +
    @@ -361,7 +413,7 @@

    Examples

    # Otherwise use the `path` argument to specify the location of your # CmdStan installation.) set_cmdstan_path(path = NULL) -#> CmdStan path set to: /Users/jgabry/.cmdstan/cmdstan-2.33.1 +#> CmdStan path set to: /Users/jgabry/.cmdstan/cmdstan-2.35.0 # Create a CmdStanModel object from a Stan program, # here using the example model that comes with CmdStan @@ -370,15 +422,29 @@

    Examples

    mod$print() #> data { #> int<lower=0> N; -#> array[N] int<lower=0,upper=1> y; +#> array[N] int<lower=0, upper=1> y; #> } #> parameters { -#> real<lower=0,upper=1> theta; +#> real<lower=0, upper=1> theta; #> } #> model { -#> theta ~ beta(1,1); // uniform prior on interval 0,1 +#> theta ~ beta(1, 1); // uniform prior on interval 0,1 #> y ~ bernoulli(theta); #> } +# Print with line numbers. This can be set globally using the +# `cmdstanr_print_line_numbers` option. +mod$print(line_numbers = TRUE) +#> 1: data { +#> 2: int<lower=0> N; +#> 3: array[N] int<lower=0, upper=1> y; +#> 4: } +#> 5: parameters { +#> 6: real<lower=0, upper=1> theta; +#> 7: } +#> 8: model { +#> 9: theta ~ beta(1, 1); // uniform prior on interval 0,1 +#> 10: y ~ bernoulli(theta); +#> 11: } # Data as a named list (like RStan) stan_data <- list(N = 10, y = c(0,1,0,0,0,0,0,0,0,1)) @@ -449,8 +515,8 @@

    Examples

    #> # A tibble: 2 × 10 #> variable mean median sd mad q5 q95 rhat ess_bulk ess_tail #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp__ -7.30 -7.03 0.721 0.380 -8.82 -6.75 1.00 902. 1006. -#> 2 theta 0.247 0.233 0.122 0.129 0.0786 0.470 1.00 762. 712. +#> 1 lp__ -7.30 -7.00 0.811 0.344 -8.83 -6.75 1.00 702. 776. +#> 2 theta 0.254 0.238 0.125 0.124 0.0807 0.483 1.00 634. 580. # Check sampling diagnostics fit_mcmc$diagnostic_summary() @@ -461,7 +527,7 @@

    Examples

    #> [1] 0 0 #> #> $ebfmi -#> [1] 1.017555 1.250490 +#> [1] 1.1148699 0.8012192 #> # Get posterior draws @@ -471,22 +537,22 @@

    Examples

    #> , , variable = lp__ #> #> chain -#> iteration 1 2 -#> 1 -6.8 -6.8 -#> 2 -6.9 -6.8 -#> 3 -7.0 -7.0 -#> 4 -6.9 -7.1 -#> 5 -6.7 -7.0 +#> iteration 1 2 +#> 1 -7.0 -6.8 +#> 2 -7.9 -6.9 +#> 3 -7.4 -6.8 +#> 4 -6.7 -6.8 +#> 5 -6.9 -10.2 #> #> , , variable = theta #> #> chain #> iteration 1 2 -#> 1 0.28 0.21 -#> 2 0.19 0.20 -#> 3 0.16 0.17 -#> 4 0.20 0.36 -#> 5 0.25 0.34 +#> 1 0.17 0.23 +#> 2 0.46 0.18 +#> 3 0.41 0.28 +#> 4 0.25 0.23 +#> 5 0.18 0.62 #> #> # ... with 995 more iterations @@ -494,16 +560,16 @@

    Examples

    as_draws_df(draws) #> # A draws_df: 1000 iterations, 2 chains, and 2 variables #> lp__ theta -#> 1 -6.8 0.28 -#> 2 -6.9 0.19 -#> 3 -7.0 0.16 -#> 4 -6.9 0.20 -#> 5 -6.7 0.25 -#> 6 -7.1 0.36 -#> 7 -9.0 0.55 -#> 8 -7.2 0.15 -#> 9 -6.8 0.23 -#> 10 -7.5 0.42 +#> 1 -7.0 0.17 +#> 2 -7.9 0.46 +#> 3 -7.4 0.41 +#> 4 -6.7 0.25 +#> 5 -6.9 0.18 +#> 6 -6.9 0.33 +#> 7 -7.2 0.15 +#> 8 -6.8 0.29 +#> 9 -6.8 0.24 +#> 10 -6.8 0.24 #> # ... with 1990 more draws #> # ... hidden reserved variables {'.chain', '.iteration', '.draw'} @@ -521,9 +587,9 @@

    Examples

    # and also demonstrate specifying data as a path to a file instead of a list my_data_file <- file.path(cmdstan_path(), "examples/bernoulli/bernoulli.data.json") fit_optim <- mod$optimize(data = my_data_file, seed = 123) -#> Initial log joint probability = -9.51104 +#> Initial log joint probability = -16.144 #> Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes -#> 6 -5.00402 0.000103557 2.55661e-07 1 1 9 +#> 6 -5.00402 0.000246518 8.73164e-07 1 1 9 #> Optimization terminated normally: #> Convergence detected: relative gradient magnitude is below tolerance #> Finished in 0.1 seconds. @@ -537,12 +603,12 @@

    Examples

    # Run 'optimize' again with 'jacobian=TRUE' and then draw from Laplace approximation # to the posterior fit_optim <- mod$optimize(data = my_data_file, jacobian = TRUE) -#> Initial log joint probability = -11.7793 +#> Initial log joint probability = -6.9339 #> Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes -#> 5 -6.74802 0.00114772 1.92382e-05 1 1 8 +#> 4 -6.74802 0.000281861 5.43768e-05 0.9238 0.9238 7 #> Optimization terminated normally: #> Convergence detected: relative gradient magnitude is below tolerance -#> Finished in 0.1 seconds. +#> Finished in 0.2 seconds. fit_laplace <- mod$laplace(data = my_data_file, mode = fit_optim, draws = 2000) #> Calculating Hessian #> Calculating inverse of Cholesky factor @@ -572,9 +638,9 @@

    Examples

    #> # A tibble: 3 × 7 #> variable mean median sd mad q5 q95 #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp__ -7.22 -6.96 0.669 0.294 -8.51 -6.75 -#> 2 lp_approx__ -0.470 -0.213 0.645 0.295 -1.81 -0.00204 -#> 3 theta 0.267 0.247 0.121 0.118 0.104 0.493 +#> 1 lp__ -7.25 -6.97 0.728 0.304 -8.74 -6.75 +#> 2 lp_approx__ -0.505 -0.230 0.714 0.313 -2.05 -0.00175 +#> 3 theta 0.271 0.250 0.125 0.120 0.105 0.511 # Run 'variational' method to use ADVI to approximate posterior fit_vb <- mod$variational(data = stan_data, seed = 123) @@ -583,8 +649,8 @@

    Examples

    #> This procedure has not been thoroughly tested and may be unstable #> or buggy. The interface is subject to change. #> ------------------------------------------------------------ -#> Gradient evaluation took 5e-06 seconds -#> 1000 transitions using 10 leapfrog steps per transition would take 0.05 seconds. +#> Gradient evaluation took 1.2e-05 seconds +#> 1000 transitions using 10 leapfrog steps per transition would take 0.12 seconds. #> Adjust your expectations accordingly! #> Begin eta adaptation. #> Iteration: 1 / 250 [ 0%] (Adaptation) @@ -595,50 +661,50 @@

    Examples

    #> Success! Found best value [eta = 1] earlier than expected. #> Begin stochastic gradient ascent. #> iter ELBO delta_ELBO_mean delta_ELBO_med notes -#> 100 -6.262 1.000 1.000 -#> 200 -6.263 0.500 1.000 -#> 300 -6.307 0.336 0.007 MEDIAN ELBO CONVERGED +#> 100 -6.164 1.000 1.000 +#> 200 -6.225 0.505 1.000 +#> 300 -6.186 0.339 0.010 MEDIAN ELBO CONVERGED #> Drawing a sample of size 1000 from the approximate posterior... #> COMPLETED. -#> Finished in 0.1 seconds. +#> Finished in 0.2 seconds. fit_vb$summary() #> # A tibble: 3 × 7 #> variable mean median sd mad q5 q95 #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp__ -7.18 -6.94 0.588 0.259 -8.36 -6.75 -#> 2 lp_approx__ -0.515 -0.221 0.692 0.303 -2.06 -0.00257 -#> 3 theta 0.263 0.246 0.115 0.113 0.106 0.481 +#> 1 lp__ -7.14 -6.93 0.528 0.247 -8.21 -6.75 +#> 2 lp_approx__ -0.520 -0.244 0.740 0.326 -1.90 -0.00227 +#> 3 theta 0.251 0.236 0.107 0.108 0.100 0.446 mcmc_hist(fit_vb$draws("theta")) #> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. # Run 'pathfinder' method, a new alternative to the variational method fit_pf <- mod$pathfinder(data = stan_data, seed = 123) -#> Path [1] :Initial log joint density = -11.008832 +#> Path [1] :Initial log joint density = -18.273334 #> Path [1] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 9.383e-04 1.391e-05 1.000e+00 1.000e+00 126 -6.264e+00 -6.264e+00 -#> Path [1] :Best Iter: [3] ELBO (-6.195408) evaluations: (126) -#> Path [2] :Initial log joint density = -7.318450 +#> 5 -6.748e+00 7.082e-04 1.432e-05 1.000e+00 1.000e+00 126 -6.145e+00 -6.145e+00 +#> Path [1] :Best Iter: [5] ELBO (-6.145070) evaluations: (126) +#> Path [2] :Initial log joint density = -19.192715 #> Path [2] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 4 -6.748e+00 5.414e-03 1.618e-04 1.000e+00 1.000e+00 101 -6.251e+00 -6.251e+00 -#> Path [2] :Best Iter: [3] ELBO (-6.229174) evaluations: (101) -#> Path [3] :Initial log joint density = -12.374612 +#> 5 -6.748e+00 2.015e-04 2.228e-06 1.000e+00 1.000e+00 126 -6.223e+00 -6.223e+00 +#> Path [2] :Best Iter: [2] ELBO (-6.170358) evaluations: (126) +#> Path [3] :Initial log joint density = -6.774820 #> Path [3] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 1.419e-03 2.837e-05 1.000e+00 1.000e+00 126 -6.199e+00 -6.199e+00 -#> Path [3] :Best Iter: [5] ELBO (-6.199185) evaluations: (126) -#> Path [4] :Initial log joint density = -13.009824 +#> 4 -6.748e+00 1.137e-04 2.596e-07 1.000e+00 1.000e+00 101 -6.178e+00 -6.178e+00 +#> Path [3] :Best Iter: [4] ELBO (-6.177909) evaluations: (101) +#> Path [4] :Initial log joint density = -7.949193 #> Path [4] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 1.677e-03 3.885e-05 1.000e+00 1.000e+00 126 -6.173e+00 -6.173e+00 -#> Path [4] :Best Iter: [5] ELBO (-6.172860) evaluations: (126) +#> 5 -6.748e+00 2.145e-04 1.301e-06 1.000e+00 1.000e+00 126 -6.197e+00 -6.197e+00 +#> Path [4] :Best Iter: [5] ELBO (-6.197118) evaluations: (126) #> Total log probability function evaluations:4379 #> Finished in 0.1 seconds. fit_pf$summary() #> # A tibble: 3 × 7 #> variable mean median sd mad q5 q95 #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 lp_approx__ -1.08 -0.728 0.886 0.304 -2.71 -0.511 -#> 2 lp__ -7.26 -6.96 0.738 0.297 -8.72 -6.75 -#> 3 theta 0.249 0.230 0.120 0.121 0.0854 0.471 +#> 1 lp_approx__ -1.07 -0.727 0.945 0.311 -2.91 -0.450 +#> 2 lp__ -7.25 -6.97 0.753 0.308 -8.78 -6.75 +#> 3 theta 0.256 0.245 0.119 0.123 0.0824 0.462 mcmc_hist(fit_pf$draws("theta")) #> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. @@ -647,48 +713,48 @@

    Examples

    # better covariance approximation, and fewer LBFGSs iterations fit_pf <- mod$pathfinder(data = stan_data, num_paths=10, single_path_draws=40, history_size=50, max_lbfgs_iters=100) -#> Path [1] :Initial log joint density = -7.711026 +#> Warning: Number of PSIS draws is larger than the total number of draws returned by the single Pathfinders. This is likely unintentional and leads to re-sampling from the same draws. +#> Path [1] :Initial log joint density = -7.129286 #> Path [1] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 1.614e-04 8.188e-07 1.000e+00 1.000e+00 126 -6.206e+00 -6.206e+00 -#> Path [1] :Best Iter: [5] ELBO (-6.205511) evaluations: (126) -#> Path [2] :Initial log joint density = -12.450513 +#> 4 -6.748e+00 3.516e-03 7.903e-05 1.000e+00 1.000e+00 101 -6.220e+00 -6.220e+00 +#> Path [1] :Best Iter: [4] ELBO (-6.220449) evaluations: (101) +#> Path [2] :Initial log joint density = -17.101498 #> Path [2] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 1.452e-03 2.960e-05 1.000e+00 1.000e+00 126 -6.251e+00 -6.251e+00 -#> Path [2] :Best Iter: [4] ELBO (-6.229238) evaluations: (126) -#> Path [3] :Initial log joint density = -7.647405 +#> 5 -6.748e+00 1.403e-03 3.837e-05 1.000e+00 1.000e+00 126 -6.233e+00 -6.233e+00 +#> Path [2] :Best Iter: [3] ELBO (-6.158188) evaluations: (126) +#> Path [3] :Initial log joint density = -7.224287 #> Path [3] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 1.466e-04 7.009e-07 1.000e+00 1.000e+00 126 -6.193e+00 -6.193e+00 -#> Path [3] :Best Iter: [3] ELBO (-6.164986) evaluations: (126) -#> Path [4] :Initial log joint density = -15.036045 +#> 5 -6.748e+00 2.662e-04 2.842e-07 1.000e+00 1.000e+00 126 -6.221e+00 -6.221e+00 +#> Path [3] :Best Iter: [2] ELBO (-6.190753) evaluations: (126) +#> Path [4] :Initial log joint density = -7.290267 #> Path [4] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 2.036e-03 6.056e-05 1.000e+00 1.000e+00 126 -6.235e+00 -6.235e+00 -#> Path [4] :Best Iter: [2] ELBO (-6.225650) evaluations: (126) -#> Path [5] :Initial log joint density = -6.760365 +#> 4 -6.748e+00 5.139e-03 1.484e-04 1.000e+00 1.000e+00 101 -6.253e+00 -6.253e+00 +#> Path [4] :Best Iter: [3] ELBO (-6.223795) evaluations: (101) +#> Path [5] :Initial log joint density = -11.338980 #> Path [5] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 3 -6.748e+00 1.911e-03 8.518e-05 1.000e+00 1.000e+00 76 -6.247e+00 -6.247e+00 -#> Path [5] :Best Iter: [3] ELBO (-6.246721) evaluations: (76) -#> Path [6] :Initial log joint density = -6.826898 +#> 5 -6.748e+00 1.023e-03 1.591e-05 1.000e+00 1.000e+00 126 -6.195e+00 -6.195e+00 +#> Path [5] :Best Iter: [5] ELBO (-6.194597) evaluations: (126) +#> Path [6] :Initial log joint density = -16.944885 #> Path [6] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 3 -6.748e+00 5.423e-03 1.282e-04 9.360e-01 9.360e-01 76 -6.169e+00 -6.169e+00 -#> Path [6] :Best Iter: [3] ELBO (-6.168890) evaluations: (76) -#> Path [7] :Initial log joint density = -8.134235 +#> 5 -6.748e+00 1.484e-03 4.148e-05 1.000e+00 1.000e+00 126 -6.227e+00 -6.227e+00 +#> Path [6] :Best Iter: [3] ELBO (-6.204972) evaluations: (126) +#> Path [7] :Initial log joint density = -6.748701 #> Path [7] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 2.517e-04 1.691e-06 1.000e+00 1.000e+00 126 -6.243e+00 -6.243e+00 -#> Path [7] :Best Iter: [3] ELBO (-6.175493) evaluations: (126) -#> Path [8] :Initial log joint density = -7.511494 +#> 3 -6.748e+00 1.200e-04 1.293e-06 1.000e+00 1.000e+00 76 -6.259e+00 -6.259e+00 +#> Path [7] :Best Iter: [2] ELBO (-6.149195) evaluations: (76) +#> Path [8] :Initial log joint density = -6.748408 #> Path [8] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 9.446e-04 2.687e-06 1.000e+00 1.000e+00 126 -6.214e+00 -6.214e+00 -#> Path [8] :Best Iter: [2] ELBO (-6.197279) evaluations: (126) -#> Path [9] :Initial log joint density = -11.516990 +#> 2 -6.748e+00 1.425e-02 1.473e-04 1.000e+00 1.000e+00 51 -6.207e+00 -6.207e+00 +#> Path [8] :Best Iter: [2] ELBO (-6.206834) evaluations: (51) +#> Path [9] :Initial log joint density = -15.458578 #> Path [9] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 1.065e-03 1.693e-05 1.000e+00 1.000e+00 126 -6.244e+00 -6.244e+00 -#> Path [9] :Best Iter: [3] ELBO (-6.194623) evaluations: (126) -#> Path [10] :Initial log joint density = -17.778190 +#> 5 -6.748e+00 1.991e-03 6.002e-05 1.000e+00 1.000e+00 126 -6.285e+00 -6.285e+00 +#> Path [9] :Best Iter: [2] ELBO (-6.192523) evaluations: (126) +#> Path [10] :Initial log joint density = -6.748883 #> Path [10] : Iter log prob ||dx|| ||grad|| alpha alpha0 # evals ELBO Best ELBO Notes -#> 5 -6.748e+00 1.013e-03 2.414e-05 1.000e+00 1.000e+00 126 -6.262e+00 -6.262e+00 -#> Path [10] :Best Iter: [4] ELBO (-6.170410) evaluations: (126) -#> Total log probability function evaluations:1310 -#> Pareto k value (0.820024) is greater than 0.7. Importance resampling was not able to improve the approximation, which may indicate that the approximation itself is poor. +#> 3 -6.748e+00 1.441e-04 1.727e-06 1.000e+00 1.000e+00 76 -6.246e+00 -6.246e+00 +#> Path [10] :Best Iter: [3] ELBO (-6.246075) evaluations: (76) +#> Total log probability function evaluations:1185 #> Finished in 0.1 seconds. # Specifying initial values as a function @@ -771,7 +837,7 @@

    Examples

    #> 6 -5.00402 0.000237915 9.55309e-07 1 1 9 #> Optimization terminated normally: #> Convergence detected: relative gradient magnitude is below tolerance -#> Finished in 0.1 seconds. +#> Finished in 0.2 seconds. fit_optim_w_init_list$init() #> [[1]] #> [[1]]$theta @@ -790,11 +856,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/read_cmdstan_csv.html b/docs/reference/read_cmdstan_csv.html index d6b8fb74..37124bfc 100644 --- a/docs/reference/read_cmdstan_csv.html +++ b/docs/reference/read_cmdstan_csv.html @@ -1,5 +1,5 @@ -Read CmdStan CSV files into R — read_cmdstan_csv • cmdstanrRead CmdStan CSV files into R — read_cmdstan_csv • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -223,10 +223,10 @@

    Examples

    fit1 <- cmdstanr_example("logistic", method = "sample", save_warmup = TRUE) csv_files <- fit1$output_files() print(csv_files) -#> [1] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/logistic-202312131008-1-642e8e.csv" -#> [2] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/logistic-202312131008-2-642e8e.csv" -#> [3] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/logistic-202312131008-3-642e8e.csv" -#> [4] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/logistic-202312131008-4-642e8e.csv" +#> [1] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/logistic-202407021545-1-30065a.csv" +#> [2] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/logistic-202407021545-2-30065a.csv" +#> [3] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/logistic-202407021545-3-30065a.csv" +#> [4] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/logistic-202407021545-4-30065a.csv" # Creating fitting model objects @@ -234,9 +234,9 @@

    Examples

    fit2 <- as_cmdstan_fit(csv_files) fit2$print("beta") #> variable mean median sd mad q5 q95 rhat ess_bulk ess_tail -#> beta[1] -0.67 -0.66 0.25 0.25 -1.09 -0.26 1.00 4234 3123 -#> beta[2] -0.28 -0.27 0.23 0.23 -0.65 0.09 1.00 4067 3185 -#> beta[3] 0.69 0.67 0.27 0.27 0.26 1.14 1.00 4291 3208 +#> beta[1] -0.68 -0.67 0.25 0.25 -1.10 -0.27 1.00 3980 2575 +#> beta[2] -0.26 -0.26 0.22 0.22 -0.64 0.09 1.00 4323 3108 +#> beta[3] 0.68 0.67 0.27 0.26 0.26 1.13 1.00 4167 3210 # Using read_cmdstan_csv # @@ -244,13 +244,13 @@

    Examples

    x <- read_cmdstan_csv(csv_files) str(x) #> List of 8 -#> $ metadata :List of 40 +#> $ metadata :List of 42 #> ..$ stan_version_major : num 2 -#> ..$ stan_version_minor : num 33 +#> ..$ stan_version_minor : num 35 #> ..$ stan_version_patch : num 0 -#> ..$ start_datetime : chr "2023-12-13 17:08:27 UTC" +#> ..$ start_datetime : chr "2024-07-02 21:45:26 UTC" #> ..$ method : chr "sample" -#> ..$ save_warmup : num 1 +#> ..$ save_warmup : int 1 #> ..$ thin : num 1 #> ..$ gamma : num 0.05 #> ..$ kappa : num 0.75 @@ -258,6 +258,7 @@

    Examples

    #> ..$ init_buffer : num 75 #> ..$ term_buffer : num 50 #> ..$ window : num 25 +#> ..$ save_metric : int 0 #> ..$ algorithm : chr "hmc" #> ..$ engine : chr "nuts" #> ..$ metric : chr "diag_e" @@ -265,16 +266,17 @@

    Examples

    #> ..$ num_chains : num 1 #> ..$ id : num [1:4] 1 2 3 4 #> ..$ init : num [1:4] 2 2 2 2 -#> ..$ seed : num 1.1e+09 +#> ..$ seed : num 2.06e+09 #> ..$ refresh : num 100 #> ..$ sig_figs : num -1 -#> ..$ profile_file : chr "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/logistic-profile-202312131008-1-0e2cb1.csv" -#> ..$ stanc_version : chr "stanc3 v2.33.1" +#> ..$ profile_file : chr "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/logistic-profile-202407021545-1-8f8eaa.csv" +#> ..$ save_cmdstan_config : int 0 +#> ..$ stanc_version : chr "stanc3 v2.35.0" #> ..$ sampler_diagnostics : chr [1:6] "accept_stat__" "stepsize__" "treedepth__" "n_leapfrog__" ... #> ..$ variables : chr [1:105] "lp__" "alpha" "beta[1]" "beta[2]" ... -#> ..$ step_size_adaptation: num [1:4] 0.761 0.758 0.859 0.765 +#> ..$ step_size_adaptation: num [1:4] 0.753 0.696 0.766 0.757 #> ..$ model_name : chr "logistic_model" -#> ..$ adapt_engaged : num 1 +#> ..$ adapt_engaged : int 1 #> ..$ adapt_delta : num 0.8 #> ..$ max_treedepth : num 10 #> ..$ step_size : num [1:4] 1 1 1 1 @@ -283,9 +285,9 @@

    Examples

    #> ..$ threads_per_chain : num 1 #> ..$ time :'data.frame': 4 obs. of 4 variables: #> .. ..$ chain_id: num [1:4] 1 2 3 4 -#> .. ..$ warmup : num [1:4] 0.071 0.073 0.072 0.069 -#> .. ..$ sampling: num [1:4] 0.068 0.068 0.065 0.068 -#> .. ..$ total : num [1:4] 0.139 0.141 0.137 0.137 +#> .. ..$ warmup : num [1:4] 0.119 0.121 0.128 0.12 +#> .. ..$ sampling: num [1:4] 0.129 0.131 0.122 0.118 +#> .. ..$ total : num [1:4] 0.248 0.252 0.25 0.238 #> ..$ stan_variable_sizes :List of 4 #> .. ..$ lp__ : num 1 #> .. ..$ alpha : num 1 @@ -297,35 +299,35 @@

    Examples

    #> ..$ total : int NA #> ..$ chains:'data.frame': 4 obs. of 4 variables: #> .. ..$ chain_id: num [1:4] 1 2 3 4 -#> .. ..$ warmup : num [1:4] 0.071 0.073 0.072 0.069 -#> .. ..$ sampling: num [1:4] 0.068 0.068 0.065 0.068 -#> .. ..$ total : num [1:4] 0.139 0.141 0.137 0.137 +#> .. ..$ warmup : num [1:4] 0.119 0.121 0.128 0.12 +#> .. ..$ sampling: num [1:4] 0.129 0.131 0.122 0.118 +#> .. ..$ total : num [1:4] 0.248 0.252 0.25 0.238 #> $ inv_metric :List of 4 -#> ..$ 1: num [1:4] 0.0469 0.0641 0.0523 0.0688 -#> ..$ 2: num [1:4] 0.0438 0.0555 0.0497 0.0685 -#> ..$ 3: num [1:4] 0.0457 0.0612 0.0451 0.0706 -#> ..$ 4: num [1:4] 0.0436 0.0627 0.0506 0.0832 +#> ..$ 1: num [1:4] 0.0537 0.06 0.0539 0.075 +#> ..$ 2: num [1:4] 0.0427 0.0583 0.0515 0.083 +#> ..$ 3: num [1:4] 0.0455 0.062 0.0441 0.0752 +#> ..$ 4: num [1:4] 0.0443 0.0707 0.0544 0.0781 #> $ step_size :List of 4 -#> ..$ 1: num 0.761 -#> ..$ 2: num 0.758 -#> ..$ 3: num 0.859 -#> ..$ 4: num 0.765 -#> $ warmup_draws : 'draws_array' num [1:1000, 1:4, 1:105] -72 -72 -72 -71.3 -68.2 ... +#> ..$ 1: num 0.753 +#> ..$ 2: num 0.696 +#> ..$ 3: num 0.766 +#> ..$ 4: num 0.757 +#> $ warmup_draws : 'draws_array' num [1:1000, 1:4, 1:105] -77.2 -77.2 -77.2 -65.2 -65.2 ... #> ..- attr(*, "dimnames")=List of 3 #> .. ..$ iteration: chr [1:1000] "1" "2" "3" "4" ... #> .. ..$ chain : chr [1:4] "1" "2" "3" "4" #> .. ..$ variable : chr [1:105] "lp__" "alpha" "beta[1]" "beta[2]" ... -#> $ post_warmup_draws : 'draws_array' num [1:1000, 1:4, 1:105] -64.3 -64.3 -65.7 -67.2 -66 ... +#> $ post_warmup_draws : 'draws_array' num [1:1000, 1:4, 1:105] -67.2 -64.2 -64.3 -65.2 -66.3 ... #> ..- attr(*, "dimnames")=List of 3 #> .. ..$ iteration: chr [1:1000] "1" "2" "3" "4" ... #> .. ..$ chain : chr [1:4] "1" "2" "3" "4" #> .. ..$ variable : chr [1:105] "lp__" "alpha" "beta[1]" "beta[2]" ... -#> $ warmup_sampler_diagnostics : 'draws_array' num [1:1000, 1:4, 1:6] 1 0 0 0.597 1 ... +#> $ warmup_sampler_diagnostics : 'draws_array' num [1:1000, 1:4, 1:6] 0.749 0 0 0.978 0.989 ... #> ..- attr(*, "dimnames")=List of 3 #> .. ..$ iteration: chr [1:1000] "1" "2" "3" "4" ... #> .. ..$ chain : chr [1:4] "1" "2" "3" "4" #> .. ..$ variable : chr [1:6] "accept_stat__" "stepsize__" "treedepth__" "n_leapfrog__" ... -#> $ post_warmup_sampler_diagnostics: 'draws_array' num [1:1000, 1:4, 1:6] 0.971 0.97 0.742 0.882 0.87 ... +#> $ post_warmup_sampler_diagnostics: 'draws_array' num [1:1000, 1:4, 1:6] 0.865 1 0.991 0.942 0.714 ... #> ..- attr(*, "dimnames")=List of 3 #> .. ..$ iteration: chr [1:1000] "1" "2" "3" "4" ... #> .. ..$ chain : chr [1:4] "1" "2" "3" "4" @@ -362,11 +364,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/read_sample_csv.html b/docs/reference/read_sample_csv.html index 3e9b12d5..9254a250 100644 --- a/docs/reference/read_sample_csv.html +++ b/docs/reference/read_sample_csv.html @@ -1,5 +1,5 @@ -Read CmdStan CSV files from sampling into R — read_sample_csv • cmdstanrRead CmdStan CSV files from sampling into R — read_sample_csv • cmdstanr @@ -17,7 +17,7 @@ cmdstanr - 0.7.0 + 0.8.1 @@ -127,11 +127,11 @@

    Arguments

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/register_knitr_engine.html b/docs/reference/register_knitr_engine.html index 5a66dd01..efda0c27 100644 --- a/docs/reference/register_knitr_engine.html +++ b/docs/reference/register_knitr_engine.html @@ -1,5 +1,5 @@ -Register CmdStanR's knitr engine for Stan — register_knitr_engine • cmdstanrRegister CmdStanR's knitr engine for Stan — register_knitr_engine • cmdstanrGet or set the file path to the CmdStan installation — set_cmdstan_path • cmdstanrGet or set the file path to the CmdStan installation — set_cmdstan_path • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -178,11 +178,11 @@

    Details

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/stan_threads.html b/docs/reference/stan_threads.html index bf8c1ef3..1875658f 100644 --- a/docs/reference/stan_threads.html +++ b/docs/reference/stan_threads.html @@ -1,5 +1,5 @@ -Set or get the number of threads used to execute Stan models — stan_threads • cmdstanrSet or get the number of threads used to execute Stan models — stan_threads • cmdstanr @@ -17,7 +17,7 @@ cmdstanr - 0.7.0 + 0.8.1 @@ -134,11 +134,11 @@

    Value

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/write_stan_file.html b/docs/reference/write_stan_file.html index e1459132..efb1bdff 100644 --- a/docs/reference/write_stan_file.html +++ b/docs/reference/write_stan_file.html @@ -1,5 +1,5 @@ -Write Stan code to a file — write_stan_file • cmdstanrWrite Stan code to a file — write_stan_file • cmdstanr cmdstanr - 0.7.0 + 0.8.1 @@ -188,7 +188,7 @@

    Examples

    f <- write_stan_file(stan_program) print(f) -#> [1] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpAMFHpW/model_7f12fc190dd23b0e462f7d73040dd97e.stan" +#> [1] "/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpiACQ3q/model_7f12fc190dd23b0e462f7d73040dd97e.stan" lines <- readLines(f) print(lines) @@ -227,11 +227,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/write_stan_json.html b/docs/reference/write_stan_json.html index b7b128ef..92151a5c 100644 --- a/docs/reference/write_stan_json.html +++ b/docs/reference/write_stan_json.html @@ -1,5 +1,5 @@ -Write data to a JSON file readable by CmdStan — write_stan_json • cmdstanrWrite data to a JSON file readable by CmdStan — write_stan_json • cmdstanr @@ -17,7 +17,7 @@ cmdstanr - 0.7.0 + 0.8.1 @@ -167,13 +167,13 @@

    Examples

    #> "N": 5, #> "K": 2, #> "x": [ -#> [0.281077678546936, -1.18908686575029], -#> [0.858726751146771, 0.46461805175525], -#> [-0.700205759803986, -0.115709696625946], -#> [1.45853659080418, 0.995745564145492], -#> [-0.671485199795285, -0.298752493529616] +#> [-1.3149626812135, -0.191761909283258], +#> [1.70603877388749, -0.282224274118901], +#> [0.177503683488102, -0.683561574477846], +#> [-0.393377531770713, 0.580194679530021], +#> [0.578306036031158, -1.06993557582488] #> ], -#> "y": [12, 6, 11, 9, 11], +#> "y": [10, 9, 8, 12, 11], #> "z": [1, 0] #> } @@ -202,11 +202,11 @@

    Examples

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/reference/write_stan_tempfile.html b/docs/reference/write_stan_tempfile.html index 10725142..efc551cd 100644 --- a/docs/reference/write_stan_tempfile.html +++ b/docs/reference/write_stan_tempfile.html @@ -1,5 +1,5 @@ -Write Stan code to a temporary file — write_stan_tempfile • cmdstanrWrite Stan code to a temporary file — write_stan_tempfile • cmdstanr @@ -17,7 +17,7 @@ cmdstanr - 0.7.0 + 0.8.1 @@ -136,11 +136,11 @@

    Arguments

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 74c96150..93d8ac08 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -102,6 +102,9 @@ https://mc-stan.org/cmdstanr/reference/as_mcmc.list.html + + https://mc-stan.org/cmdstanr/reference/cmdstan_coercion.html + https://mc-stan.org/cmdstanr/reference/cmdstan_default_install_path.html @@ -120,6 +123,9 @@ https://mc-stan.org/cmdstanr/reference/cmdstanr_example.html + + https://mc-stan.org/cmdstanr/reference/cmdstanr_global_options.html + https://mc-stan.org/cmdstanr/reference/draws_to_csv.html diff --git a/man/cmdstan_coercion.Rd b/man/cmdstan_coercion.Rd index 33a36d3a..77b87c7a 100644 --- a/man/cmdstan_coercion.Rd +++ b/man/cmdstan_coercion.Rd @@ -26,9 +26,9 @@ as.CmdStanGQ(object, ...) as.CmdStanDiagnose(object, ...) } \arguments{ -\item{object}{to be coerced} +\item{object}{The object to be coerced.} -\item{...}{additional arguments} +\item{...}{Additional arguments to pass to methods.} } \description{ These are generic functions intended to primarily be used by developers of