diff options
author | Ken Kellner <ken@kenkellner.com> | 2019-02-15 09:45:56 -0500 |
---|---|---|
committer | Ken Kellner <ken@kenkellner.com> | 2019-02-15 09:45:56 -0500 |
commit | 7e32a53a89710f3d3007aaeb33197d80d01ab210 (patch) | |
tree | 6badf9644fdd40143e356635d267c1724a7474a4 | |
parent | fd856a819f689ef2070e1707a7d68ceb9c3f5d2b (diff) |
Improve pp.check function
-rw-r--r-- | R/ppcheck.R | 29 | ||||
-rw-r--r-- | man/ppcheck.Rd | 13 |
2 files changed, 30 insertions, 12 deletions
diff --git a/R/ppcheck.R b/R/ppcheck.R index 7276d99..b500d8c 100644 --- a/R/ppcheck.R +++ b/R/ppcheck.R @@ -1,15 +1,30 @@ -pp.check <- function(x, actual, new){ +pp.check <- function(x, observed, simulated, xlab=NULL, ylab=NULL, main=NULL){ if(class(x)!="jagsUI"){stop('Requires jagsUI object as input')} devAskNewPage(ask=FALSE) - actual <- eval(parse(text=paste('x$sims.list$',actual,sep=""))) - new <- eval(parse(text=paste('x$sims.list$',new,sep=""))) + observed <- eval(parse(text=paste('x$sims.list$',observed,sep=""))) + simulated <- eval(parse(text=paste('x$sims.list$',simulated,sep=""))) - bpval <- mean(actual>new) + bpval <- mean(simulated>observed) + + if(is.null(xlab)){ + xlab <- 'Observed Data' + } + if(is.null(ylab)){ + ylab <- 'Simulated Data' + } + if(is.null(main)){ + main <- paste('Posterior Predictive Check','\n', + 'Bayesian P-value =',round(bpval,2)) + } + + minval <- min(c(observed,simulated)) + maxval <- max(c(observed,simulated)) + plotrange <- c(minval,maxval) - plot(x = actual, y = new, xlab="Actual Dataset", ylab="Simulated Dataset", - main = paste('Posterior Predictive Check','\n','Bayesian P-value =',round(bpval,2))) + plot(x = observed, y = simulated, xlab=xlab, ylab=ylab, main=main, + xlim=plotrange,ylim=plotrange) abline(1,1) -}
\ No newline at end of file +} diff --git a/man/ppcheck.Rd b/man/ppcheck.Rd index 384429d..e74fa6a 100644 --- a/man/ppcheck.Rd +++ b/man/ppcheck.Rd @@ -5,12 +5,15 @@ \title{Posterior Predictive Checks for Bayesian Analyses fit in JAGS} \usage{ - pp.check(x, actual, new)} + pp.check(x, observed, simulated, xlab=NULL, ylab=NULL, main=NULL)} \arguments{ \item{x}{A jagsUI object generated using the \code{jags} function} - \item{actual}{The name of the parameter (as a string, in the JAGS model) representing the fit of the actual dataset (e.g. residuals)} - \item{new}{The name of the corresponding parameter (as a string, in the JAGS model) representing the fit of the new 'ideal' dataset} + \item{observed}{The name of the parameter (as a string, in the JAGS model) representing the fit of the observed data (e.g. residuals)} + \item{simulated}{The name of the corresponding parameter (as a string, in the JAGS model) representing the fit of the new simulated data} + \item{xlab}{Customize x-axis label} + \item{ylab}{Customize y-axis label} + \item{main}{Customize plot title} } \description{ @@ -89,6 +92,6 @@ out #Posterior predictive check plot -pp.check(out, actual = 'fit', new = 'fit.new') +pp.check(out, observed = 'fit', simulated = 'fit.new') -}
\ No newline at end of file +} |