I have found that Rate_4_Stan.R does not plot. I have run through RStudio and native R. A copy of the console result is below. Hardware details are:
OS X Yosemite 10.10.1
Hardware Overview:
Model Name: MacBook Air
Model Identifier: MacBookAir4,2
Processor Name: Intel Core i5
Processor Speed: 1.7 GHz
Number of Processors: 1
Total Number of Cores: 2
L2 Cache (per Core): 256 KB
L3 Cache: 3 MB
Memory: 4 GB
Boot ROM Version: MBA41.0077.B11
SMC Version (system): 1.73f66
Serial Number (system): C02GCAQPDJWT
Hardware UUID: 8B76916C-7101-57E6-B26E-EED12F76D2B
Thank you for your help,
Drew Yallop
R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin13.4.0 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
[Workspace loaded from ~/STAN Projects/BCM 4 Prior and Posterior Prediction/.RData]
clears workspace:
rm(list=ls())
library(rstan)
Loading required package: Rcpp
Loading required package: inline
Attaching package: ‘inline’
The following object is masked from ‘package:Rcpp’:
rstan (Version 2.5.0, packaged: 2014-10-22 14:19:22 UTC, GitRev: e52c66f42e81)
to be passed on to Stan
data <- read_rdump("Rate_4a.data.R")
Uncomment for Trompetter Data
data <- read_rdump("Rate_4b.data.R")
k <- 1
n <- 15
Uncomment for Trompetter Data
k <- 24
n <- 121
myinits <- list(
- list(theta=.5, thetaprior=.5))
parameters to be monitored:
parameters <- c("theta", "thetaprior", "postpredk", "priorpredk")
The following command calls Stan with specific options.
For a detailed description type "?stan".
samples <- stan(file="Rate_4_model.stan",
-
-
init=myinits, # If not specified, gives random inits
-
-
-
-
-
# warmup = 100, # Stands for burn-in; Default = iter/2
-
# seed = 123 # Setting seed; Default is random seed
- )
TRANSLATING MODEL 'Rate_4_model' FROM Stan CODE TO C++ CODE NOW.
COMPILING THE C++ CODE FOR MODEL 'Rate_4_model' NOW.
In file included from file13b85652cbf5.cpp:413:
In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
/Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include/rstan/stan_fit.hpp:732:15: warning: unused variable 'return_code' [-Wunused-variable]
int return_code = stan::common::do_bfgs_optimize(model, lbfgs, base_rng,
^
/Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include/rstan/stan_fit.hpp:796:15: warning: unused variable 'return_code' [-Wunused-variable]
int return_code = stan::common::do_bfgs_optimize(model, bfgs, base_rng,
^
/Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include/rstan/stan_fit.hpp:616:14: warning: unused variable 'init_log_prob' [-Wunused-variable]
double init_log_prob;
^
In file included from file13b85652cbf5.cpp:8:
In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/model/model_header.hpp:16:
In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/agrad/rev.hpp:5:
/Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/agrad/rev/chainable.hpp:87:17: warning: 'static' function 'set_zero_all_adjoints' declared in header file should be declared 'static inline' [-Wunneeded-internal-declaration]
static void set_zero_all_adjoints() {
^
In file included from file13b85652cbf5.cpp:8:
In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/model/model_header.hpp:23:
/Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/io/dump.hpp:26:14: warning: function 'product' is not needed and will not be emitted [-Wunneeded-internal-declaration]
size_t product(std::vector<size_t> dims) {
^
5 warnings generated.
SAMPLING FOR MODEL 'Rate_4_model' NOW (CHAIN 1).
Iteration: 1 / 20000 0%
Iteration: 2000 / 20000 10%
Iteration: 4000 / 20000 20%
Iteration: 6000 / 20000 30%
Iteration: 8000 / 20000 40%
Iteration: 10000 / 20000 50%
Iteration: 10001 / 20000 50%
Iteration: 12000 / 20000 60%
Iteration: 14000 / 20000 70%
Iteration: 16000 / 20000 80%
Iteration: 18000 / 20000 90%
Iteration: 20000 / 20000 100%
Elapsed Time: 0.20219 seconds (Warm-up)
#0.218085 seconds (Sampling)
#0.420275 seconds (Total)
Now the values for the monitored parameters are in the "samples" object,
ready for inspection.
print(samples)
Inference for Stan model: Rate_4_model.
1 chains, each with iter=20000; warmup=10000; thin=1;
post-warmup draws per chain=10000, total post-warmup draws=10000.
mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
theta 0.12 0.00 0.07 0.02 0.06 0.10 0.16 0.30 5346 1
thetaprior 0.49 0.00 0.29 0.02 0.24 0.49 0.75 0.97 6044 1
postpredk 1.76 0.02 1.64 0.00 0.00 1.00 3.00 6.00 6880 1
priorpredk 7.40 0.06 4.60 0.00 3.00 7.00 11.00 15.00 6492 1
lp__ -8.67 0.02 1.08 -11.51 -9.11 -8.35 -7.88 -7.58 2525 1
Samples were drawn using NUTS(diag_e) at Fri Dec 19 17:44:52 2014.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at
convergence, Rhat=1).
################Plots
theta <- extract(samples)$theta
thetaprior <- extract(samples)$thetaprior
priorpredk <- extract(samples)$priorpredk
postpredk <- extract(samples)$postpredk
layout(matrix(c(1,2),2,1))
layout.show(2)
Prior and posterior of theta
plot(density(theta, from=0, to=1), zero.line=F, axes=F, main="", xlab="",
-
ylab="", xlim=c(0,1), ylim=c(0,6))
axis(1, at=c(0,0.2,0.4,0.6,0.8,1), lab=c("0","0.2","0.4","0.6","0.8","1"),
-
mtext("Rate", side=1, line=2.25, cex=1.2)
axis(2, at=c(0,2,4,6),cex.axis=0.8)
mtext("Density", side=2, line=2.25, cex=1.2)
lines(density(thetaprior, from=0, to=1), lty=3, col="gray")
legend(0.6,5.75, c("Prior", "Posterior"), lty=c(3,1), col=c ("grey", "black"))
Prior and posterior predictive
mybreaks <- seq(from=-.5,to=n+1,by=1)
Error in seq.default(from = -0.5, to = n + 1, by = 1) :
object 'n' not found
my.at <- seq(from=0,to=n,by=1)
Error in seq.default(from = 0, to = n, by = 1) : object 'n' not found
hist(postpredk,breaks=mybreaks,freq=F, right=F, ylab="", xlab="", ylim=c(0,0.3),
-
Error in hist.default(postpredk, breaks = mybreaks, freq = F, right = F, :
object 'mybreaks' not found
axis(1, at=my.at,lab=my.at,cex.axis=0.8)
Error in axis(1, at = my.at, lab = my.at, cex.axis = 0.8) :
object 'my.at' not found
mtext("Success Count", side=1, line=2.25, cex=1.2)
axis(2,at=c(0,0.1,0.2,0.3),lab=c("0","0.1","0.2","0.3"),cex.axis=0.8)
mtext("Mass", side=2, line=2.25, cex=1.2)
hist(priorpredk, breaks=mybreaks,freq=F,right=F,add=T, lty=3,border="grey")
Error in hist.default(priorpredk, breaks = mybreaks, freq = F, right = F, :
object 'mybreaks' not found
legend(8,0.3, c("Prior", "Posterior"), lty=c(3,1),col=c("grey", "black"))