diff options
author | Ken Kellner <ken@kenkellner.com> | 2018-08-12 00:26:29 -0400 |
---|---|---|
committer | Ken Kellner <ken@kenkellner.com> | 2018-08-12 00:26:29 -0400 |
commit | 243d9fbd2f337cfe1b9f955eb6b7921473160970 (patch) | |
tree | cfc7bbb0bc43c9e12cb677df7afda5d9993a8ba6 | |
parent | 5da1426803c31878a88ddb683eaefb248284bbd3 (diff) |
Test fix to issue where parameter names are not sorted correctly in summary when saving only a slice
-rw-r--r-- | R/processoutput.R | 7 | ||||
-rw-r--r-- | R/summarymatrix.R | 25 |
2 files changed, 26 insertions, 6 deletions
diff --git a/R/processoutput.R b/R/processoutput.R index bcf1d19..834f0f3 100644 --- a/R/processoutput.R +++ b/R/processoutput.R @@ -73,7 +73,7 @@ calc.stats <- function(i){ if(!is.na(dim[i][1])){ #Get all samples - sims.list[[i]] <<- mat[,expand==i] + sims.list[[i]] <<- mat[,expand==i,drop=FALSE] #if every iteration is NA, don't do anything else if(all(is.na(sims.list[[i]]))){return(NA)} @@ -81,8 +81,9 @@ calc.stats <- function(i){ #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)){ - hold <- x[,expand==i] - rhat.vals <- sapply(1:dim(hold[[1]])[2],gd,hold=hold) + hold <- x[,expand==i,drop=FALSE] + nelements <- sum(expand==i) + rhat.vals <- sapply(1:nelements,gd,hold=hold) names(rhat.vals) <- colnames(hold[[1]]) rhat[[i]] <<- populate(rhat.vals,dim[[i]]) } else if (m == 1){ diff --git a/R/summarymatrix.R b/R/summarymatrix.R index 09b9a8c..8949d44 100644 --- a/R/summarymatrix.R +++ b/R/summarymatrix.R @@ -3,9 +3,28 @@ summary.matrix <- function(output,samples,n.chains,codaOnly){ hold <- unlist(output$mean[!names(output$mean)%in%codaOnly]) toremove <- which(!is.na(hold)) + + #Get rownames + rnames = c() + for (i in 1:length(output$sd)){ + if(length(output$sd[[i]])>1){ + raw.ind <- which(!is.na(output$sd[[i]]),arr.ind=T) + if(is.matrix(raw.ind)){ + ind <- apply(raw.ind,1,paste,collapse=',') + } else { + ind <- raw.ind + } + + newnames <- paste(names(output$sd)[i],'[',ind,']',sep='') + rnames <- c(rnames,newnames) + + } else { + rnames <- c(rnames,names(output$sd[i])) + } + } cleanup <- function(input,codaOnly){ - + out.raw <- unlist(input[!names(input)%in%codaOnly]) out <- out.raw[toremove] @@ -19,7 +38,7 @@ summary.matrix <- function(output,samples,n.chains,codaOnly){ cleanup(output$Rhat,codaOnly),cleanup(output$n.eff,codaOnly), cleanup(output$overlap0,codaOnly),cleanup(output$f,codaOnly)) - p <- colnames(samples[[1]]) + p <- rnames expand <- sapply(strsplit(p, "\\["), "[", 1) row.names(y) = p[!expand%in%codaOnly] names(y) = c('mean','sd','2.5%','25%','50%','75%','97.5%','Rhat','n.eff','overlap0','f') @@ -28,4 +47,4 @@ summary.matrix <- function(output,samples,n.chains,codaOnly){ } return(as.matrix(y)) -}
\ No newline at end of file +} |