diff --git a/Ropenbt/DESCRIPTION b/Ropenbt/DESCRIPTION index 8b79e5a..024a5fe 100644 --- a/Ropenbt/DESCRIPTION +++ b/Ropenbt/DESCRIPTION @@ -7,7 +7,7 @@ Authors@R: c(person('Matthew', 'Pratola', role=c('aut','cre','cph'),email='mprat URL: http://www.github.com/bandframework/OpenBT Description: This R package provides an R interface to the OpenBT library of Bayesian Tree models (https://www.github.com/bandframework/OpenBT). For more information and examples, refer to the README at the root of the OpenBT repository. -License: MIT +License: MIT + file LICENSE Depends: R (>= 2.10) Imports: data.table, zip, emoa, Hmisc Suggests: diff --git a/Ropenbt/LICENSE b/Ropenbt/LICENSE new file mode 120000 index 0000000..ea5b606 --- /dev/null +++ b/Ropenbt/LICENSE @@ -0,0 +1 @@ +../LICENSE \ No newline at end of file diff --git a/Ropenbt/NAMESPACE b/Ropenbt/NAMESPACE index 3a870f8..7a61346 100644 --- a/Ropenbt/NAMESPACE +++ b/Ropenbt/NAMESPACE @@ -1,5 +1,5 @@ export(openbt) -S3method(predict, openbt) +export(predict.openbt) export(vartivity.openbt) export(sobol.openbt) export(mopareto.openbt) @@ -9,6 +9,18 @@ export(makecuts.openbt) export(setvarcuts.openbt) export(calcMBD) export(calcRS) +S3method(plot, OpenBT_vartivity) +S3method(print, OpenBT_posterior) +S3method(summary, OpenBT_posterior) +S3method(print, OpenBT_predict) +S3method(summary, OpenBT_predict) +S3method(print, OpenBT_sobol) +S3method(summary, OpenBT_sobol) +S3method(plot, OpenBT_sobol) +S3method(print, OpenBT_vartivity) +S3method(summary, OpenBT_vartivity) +S3method(summary, OpenBT_cutinfo) +S3method(print, OpenBT_cutinfo) importFrom(stats,cor) importFrom("graphics", "boxplot", "par") importFrom("graphics", "abline", "lines", "plot", "points") diff --git a/Ropenbt/R/openbt.R b/Ropenbt/R/openbt.R index cfe2cb1..d114018 100644 --- a/Ropenbt/R/openbt.R +++ b/Ropenbt/R/openbt.R @@ -653,7 +653,7 @@ if(fit$modeltype==MODEL_MIXBART){ res$m.upper=apply(res$mdraws,2,quantile,q.upper) res$smean=apply(res$sdraws,2,mean) res$ssd=apply(res$sdraws,2,sd) - res$s.5=apply(res$sdraws,2,median) + res$s.5=apply(res$sdraws,2,quantile,0.5) res$s.lower=apply(res$sdraws,2,quantile,q.lower) res$s.upper=apply(res$sdraws,2,quantile,q.lower) res$pdraws=NULL @@ -2218,8 +2218,9 @@ loadRData <- function(fname) } -print.OpenBT_posterior<-function(post) +print.OpenBT_posterior<-function(x, ...) { + post = x MODEL_BT=1 MODEL_BINOMIAL=2 MODEL_POISSON=3 @@ -2262,13 +2263,15 @@ print.OpenBT_posterior<-function(post) summary(post$xicuts) } -summary.OpenBT_posterior<-function(post) +summary.OpenBT_posterior<-function(object, ...) { + post = object cat("No summary method for object.\n") } -print.OpenBT_predict<-function(pred) +print.OpenBT_predict<-function(x, ...) { + pred = x MODEL_BT=1 MODEL_BINOMIAL=2 MODEL_POISSON=3 @@ -2289,20 +2292,23 @@ print.OpenBT_predict<-function(pred) cat("Variance quantiles: ",pred$q.lower,",",pred$q.upper,"\n\n") } -summary.OpenBT_predict<-function(pred) +summary.OpenBT_predict<-function(object, ...) { + pred = object cat("No summary method for object.\n") } -print.OpenBT_sobol<-function(sobol) +print.OpenBT_sobol<-function(x, ...) { + sobol = x cat("OpenBT Sobol Indices\n") cat(ncol(sobol$vidraws), " variables.\n") cat(nrow(sobol$vidraws), " realizations.\n") } -summary.OpenBT_sobol<-function(sobol) +summary.OpenBT_sobol<-function(object, ...) { + sobol = object cat("Summary of Posterior Sobol Sensitivity Indices\n") cat("Expected Sobol Indices (Mean)\n") @@ -2316,23 +2322,26 @@ summary.OpenBT_sobol<-function(sobol) print(sobol$sij.sd) } -plot.OpenBT_sobol<-function(sobol) +plot.OpenBT_sobol<-function(x, ...) { + sobol = x par(mfrow=c(3,1)) boxplot(sobol$sidraws,ylab="Sobol Sensitivity",main="First Order Sobol Indices",xlab="Variables") boxplot(sobol$sijdraws,ylab="Sobol Sensitivity",main="Two-way Sobol Indices",xlab="Variables") boxplot(sobol$tsidraws,ylab="Sobol Sensitivity",main="Total Sobol Indices",xlab="Variables") } -print.OpenBT_vartivity<-function(vartivity) +print.OpenBT_vartivity<-function(x, ...) { + vartivity = x cat("OpenBT Variable Activity\n") cat(ncol(vartivity$vdraws), " variables.\n") cat(nrow(vartivity$vdraws), " realizations.\n") } -summary.OpenBT_vartivity<-function(vartivity) +summary.OpenBT_vartivity<-function(object, ...) { + vartivity = object cat("Summary of Posterior Variable Activity\n") p=length(vartivity$mvdraws) @@ -2374,16 +2383,18 @@ summary.OpenBT_vartivity<-function(vartivity) } } -plot.OpenBT_vartivity<-function(vartivity) +plot.OpenBT_vartivity<-function(x, ...) { + vartivity = x par(mfrow=c(1,2)) yrange=c(0,max(max(vartivity$vdraws),max(vartivity$vdrawsh))) boxplot(vartivity$vdraws,ylab="% node splits",main="Mean Trees",xlab="Variables",ylim=yrange) boxplot(vartivity$vdrawsh,ylab="% node splits",main="Variance Trees",xlab="Variables",ylim=yrange) } -summary.OpenBT_cutinfo<-function(xi) +summary.OpenBT_cutinfo<-function(object, ...) { + xi = object p=length(xi) cat("Number of variables: ",p,"\n") cat("Number of cutpoints per variable\n") @@ -2393,8 +2404,9 @@ summary.OpenBT_cutinfo<-function(xi) } } -print.OpenBT_cutinfo<-function(xi) +print.OpenBT_cutinfo<-function(x, ...) { + xi = x summary.OpenBT_cutinfo(xi) } @@ -2545,7 +2557,7 @@ mixingwts.openbt = function( #Now populate the summary stat matrices -- n X k matrices mean_matrix[,j] = apply(wt_list[[j]], 2, mean) sd_matrix[,j] = apply(wt_list[[j]], 2, sd) - med_matrix[,j] = apply(wt_list[[j]], 2, median) + med_matrix[,j] = apply(wt_list[[j]], 2, quantile,0.5) lb_matrix[,j] = apply(wt_list[[j]], 2, quantile,q.lower) ub_matrix[,j] = apply(wt_list[[j]], 2, quantile,q.upper) } diff --git a/Ropenbt/man/openbt.Rd b/Ropenbt/man/openbt.Rd index 0fc366f..267207e 100644 --- a/Ropenbt/man/openbt.Rd +++ b/Ropenbt/man/openbt.Rd @@ -6,8 +6,9 @@ The function \code{openbt()} is the main function for fitting Bayesian Regression Tree models that are provided in the OpenBT project. } \usage{ -openbt(x.train, y.train, ntree=NULL, ntreeh=NULL, ndpost=1000, - nskip=100, k=NULL, power=2.0, base=.95, tc=2, sigmav=rep(1,length(y.train)), +openbt(x.train, y.train, f.train = matrix(1, nrow=length(y.train), ncol = 2), ntree=NULL, + ntreeh=NULL, ndpost=1000, nskip=100, k=NULL, power=2.0, base=.95, tc=2, + sigmav=rep(1,length(y.train)), f.sd.train = NULL, wts.prior.info = NULL, fmean=mean(y.train), overallsd = NULL, overallnu=NULL, chv = cor(x.train,method="spearman"), pbd=.7, pb=.5, stepwpert=.1, probchv=.1, minnumbot=5, printevery=100, numcut=100, xicuts=NULL, nadapt=1000, adaptevery=100, @@ -16,6 +17,7 @@ openbt(x.train, y.train, ntree=NULL, ntreeh=NULL, ndpost=1000, \arguments{ \item{x.train}{nxp matrix of predictor variables for the training data.} \item{y.train}{nx1 vector of the observed response for the training data.} + \item{f.train}{For eventual model mixing support.} \item{ntree}{Number of trees used for the mean model.} \item{ntreeh}{Number of trees used for the variance model.} \item{ndpost}{Number of iterations to run the MCMC algorithm after burn-in.} @@ -25,6 +27,8 @@ openbt(x.train, y.train, ntree=NULL, ntreeh=NULL, ndpost=1000, \item{base}{Base parameter in the tree depth penalizing prior.} \item{tc}{Number of OpenMP threads to use.} \item{sigmav}{Initialization of square-root of variance parameter.} + \item{f.sd.train}{For eventual model mixing support.} + \item{wts.prior.info}{For eventual model mixing support.} \item{fmean}{Overall mean of the data for pre-centering the data before running the model.} \item{overallsd}{A rudimentary estimate of the process standard deviation. Used in calibrating the variance prior.} \item{overallnu}{Shape parameter for the variance prior.} diff --git a/Ropenbt/man/predict.openbt.Rd b/Ropenbt/man/predict.openbt.Rd index 0928e54..33aa46c 100644 --- a/Ropenbt/man/predict.openbt.Rd +++ b/Ropenbt/man/predict.openbt.Rd @@ -7,8 +7,9 @@ } \usage{ \method{predict}{openbt}( -object, +object=NULL, x.test=NULL, +f.test=matrix(1, nrow = 1, ncol = 2), tc=2, fmean=fit$fmean, q.lower=0.025, @@ -17,6 +18,7 @@ q.upper=0.975, ...) \arguments{ \item{object}{Object of type \code{OpenBT_posterior} from a previous call to \code{openbt()}} \item{x.test}{New input settings in the form of an \code{npred x p} matrix at which to construct predictions. Defaults to the training inputs.} + \item{f.test}{For eventual model mixing support.} \item{tc}{Number of CPU cores to use for parallel computing.} \item{fmean}{Mean-centering vector for the training data. Defaults to the value used by \code{openbt()} when fitting the model. Usually should be left to the default.} \item{q.lower}{Lower quantile to return.}