Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Ropenbt/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions Ropenbt/LICENSE
14 changes: 13 additions & 1 deletion Ropenbt/NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export(openbt)
S3method(predict, openbt)
export(predict.openbt)
export(vartivity.openbt)
export(sobol.openbt)
export(mopareto.openbt)
Expand All @@ -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")
Expand Down
40 changes: 26 additions & 14 deletions Ropenbt/R/openbt.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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")
Expand All @@ -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)
}

Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 6 additions & 2 deletions Ropenbt/man/openbt.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.}
Expand All @@ -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.}
Expand Down
4 changes: 3 additions & 1 deletion Ropenbt/man/predict.openbt.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.}
Expand Down
Loading