aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Kellner <ken@kenkellner.com>2018-01-12 16:27:56 -0500
committerKen Kellner <ken@kenkellner.com>2018-01-12 16:27:56 -0500
commitc8c643fd0ae5e7ffabbe0ac15d65557ddfd06467 (patch)
treeba75e04a55ebfd669f67499b4cb67939f6e4c931
parent1d8724ff88e6f843f690511b156e970334ed300e (diff)
Should fix #20 and #18 but more testing needed
-rw-r--r--R/orderparams.R4
-rw-r--r--R/processoutput.R22
2 files changed, 17 insertions, 9 deletions
diff --git a/R/orderparams.R b/R/orderparams.R
index 9a25835..f50c5c6 100644
--- a/R/orderparams.R
+++ b/R/orderparams.R
@@ -12,8 +12,8 @@ order.params <- function(samples,parameters.to.save,DIC,verbose=TRUE){
DIC <- FALSE
}
- samples <- samples[,params]
+ samples <- samples[,params, drop=FALSE]
return(samples)
-} \ No newline at end of file
+}
diff --git a/R/processoutput.R b/R/processoutput.R
index f46a36d..bcf1d19 100644
--- a/R/processoutput.R
+++ b/R/processoutput.R
@@ -2,9 +2,10 @@
process.output <- function(x,DIC,params.omit,verbose=TRUE) {
if(verbose){cat('Calculating statistics.......','\n')}
-
-#Get parameter names
+
+# Get parameter names
params <- colnames(x[[1]])
+
#Get number of chains
m <- length(x)
@@ -35,7 +36,9 @@ calcneff <- function(x,n,m){
W <- mean(s2)
#Non-degenerate case
- if ((W > 1.e-8) && (m > 1)) {
+ if (is.na(W)){
+ n.eff <- NA
+ } else if ((W > 1.e-8) && (m > 1)) {
B <- n*var(xdot)
sig2hat <- ((n-1)*W + B)/n
n.eff <- round(m*n*min(sig2hat/B,1),0)
@@ -71,7 +74,10 @@ calc.stats <- function(i){
#Get all samples
sims.list[[i]] <<- mat[,expand==i]
-
+
+ #if every iteration is NA, don't do anything else
+ if(all(is.na(sims.list[[i]]))){return(NA)}
+
#If more than 1 chain, calculate rhat
#Done separately for each element of non-scalar parameter to avoid errors
if(m > 1 && (!i%in%params.omit)){
@@ -103,11 +109,13 @@ calc.stats <- function(i){
#If parameter is a scalar
} else {
-
+
if(m > 1 && (!i%in%params.omit)){rhat[[i]] <<- gelman.diag(x[,i],autoburnin=FALSE)$psrf[1]}
-
+
sims.list[[i]] <<- mat[,i]
-
+
+ if(all(is.na(sims.list[[i]]))){return(NA)}
+
means[[i]] <<- mean(sims.list[[i]])
if(!i%in%params.omit){
se[[i]] <<- sd(sims.list[[i]])