bassBasis {BASS}R Documentation

Bayesian Adaptive Spline Surfaces (BASS) with basis decomposition of response

Description

Fits a BASS model to basis coefficients under the specified basis.

Usage

bassBasis(dat, n.cores = 1, parType = "fork", ...)

Arguments

dat

list that includes elements xx, n.pc (number of basis functions), basis (dimension m x n.pc), newy (dimension n.pc x n), trunc.error (optional truncation error with dimension n x m), y.m (vector mean removed before basis decomposition with dimension m), y.s (vector sd scaled before basis decomposition with dimension m). See the documentation of bassPCA for more details.

n.cores

integer number of cores (threads) to use

parType

either "fork" or "socket". Forking is typically faster, but not compatible with Windows. If n.cores==1, parType is ignored.

...

arguements to be passed to bass function calls.

Details

Under a user defined basis decomposition, fits a bass model to each PCA basis coefficient independently, bass(dat$xx,dat$newy[i,],...) for i in 1 to n.pc, possibly in parallel. The basis does not need to be orthogonal, but independent modeling of basis coefficients should be sensible.

Value

An object of class 'bassBasis' with two elements:

mod.list

list (of length n.pc) of individual bass models

dat

same as dat above

See Also

predict.bassBasis for prediction and sobolBasis for sensitivity analysis.

Examples

## Not run: 
  ## simulate data (Friedman function)
f<-function(x){
  10*sin(pi*x[,1]*x[,2])+20*(x[,3]-.5)^2+10*x[,4]+5*x[,5]
}
## simulate data (Friedman function with first variable as functional)
sigma<-.1 # noise sd
n<-500 # number of observations
nfunc<-50 # size of functional variable grid
xfunc<-seq(0,1,length.out=nfunc) # functional grid
x<-matrix(runif(n*9),n,9) # 9 non-functional variables, only first 4 matter
X<-cbind(rep(xfunc,each=n),kronecker(rep(1,nfunc),x)) # to get y
y<-matrix(f(X),nrow=n)+rnorm(n*nfunc,0,sigma)

## fit BASS
library(parallel)
mod<-bassPCA(x,y,n.pc=5,n.cores=min(5,parallel::detectCores()))
plot(mod$mod.list[[1]])
plot(mod$mod.list[[2]])
plot(mod$mod.list[[3]])
plot(mod$mod.list[[4]])
plot(mod$mod.list[[5]])

hist(mod$dat$trunc.error)

## prediction
npred<-100
xpred<-matrix(runif(npred*9),npred,9)
Xpred<-cbind(rep(xfunc,each=npred),kronecker(rep(1,nfunc),xpred))
ypred<-matrix(f(Xpred),nrow=npred)
pred<-predict(mod,xpred,mcmc.use=1:1000) # posterior predictive samples (each is a curve)
matplot(ypred,apply(pred,2:3,mean),type='l',xlab='observed',ylab='mean prediction')
abline(a=0,b=1,col=2)
matplot(t(ypred),type='l') # actual
matplot(t(apply(pred,2:3,mean)),type='l') # mean prediction

## sensitivity
sens<-sobolBasis(mod,int.order = 2,ncores = max(parallel::detectCores()-2,1),
                 mcmc.use=1000) # for speed, only use a few samples
plot(sens)

## End(Not run)

## minimal example for CRAN testing
mod<-bassPCA(1:10,matrix(1:20,10),n.pc=2,nmcmc=2,nburn=1)

[Package BASS version 1.2.2 Index]