bps_n_rr: bps_n_rr

View source: R/RcppExports.R

bps_n_rrR Documentation

bps_n_rr

Description

Applies the Reversible Jump BPS Sampler with Velocities drawn from the Normal distribution to a Robust Regression problem with dirac spike and slab prior. Included variables are given an independent Gaussian prior with variance prior_sigma2 and mean zero, variables are given prior probabilities of inclusion ppi.

Usage

bps_n_rr(
  maxTime,
  dataX,
  datay,
  prior_sigma2,
  x0,
  theta0,
  ref = 0.1,
  rj_val = 0.5,
  ppi = 0.5,
  nmax = 1000000L,
  burn = -1L
)

Arguments

maxTime

Maximum runtime (in Seconds) of the algorithm; will terminate the code after a given computation time or nmax iterations of the algorithm is reached.

dataX

Matrix of all covariates where the i-th row corresponds to all p covariates x_i,1, ..., x_i,p of the i-th observation.

datay

Vector of n observations of a continuous response variable y.

prior_sigma2

Double for the prior variance for included variables.

x0

Initial position of the regression parameter

theta0

Initial velocity for the sampler.

ref

Refreshment rate for BPS.

rj_val

Reversible jump parameter for the PDMP method. This value is fixed over all models and is interpreted as the probability to jump to a reduced model when a parameter hits zero.

ppi

Double for the prior probability of inclusion (ppi) for each parameter.

nmax

Maximum number of iterations (simulated events) of the algorithm; will stop the algorithm when this number of iterations of the method have occured. Default value is 1e6, lower values should be chosen for memory constraints if less iterations are desired.

burn

Optional number of iterations to use for burnin. These are not stored so can be useful in memory intensive problems.

Value

Returns a list with the following objects:

times: Vector of event times where ZigZag process switchs velocity or jumps models.

positions: Matrix of positions at which event times occur, these are not samples from the PDMP.

theta: Matrix of new velocities at event times.

Examples


generate.rr.data <- function(beta, n, Sig, noise, interc = TRUE) {
p <- length(beta)-(interc == TRUE)
dataX <- MASS::mvrnorm(n=n,mu=rep(0,p),Sigma=Sig)
if(interc) {dataX <- cbind(1, dataX)}
dataY <- rep(0, n)
dataY <- dataX %*% as.vector(beta)+rnorm(n, sd = sqrt(noise))
return(list(dataX = dataX, dataY = dataY))
}
p <- 3;
n<- 120
beta <- c(0.5,0.5, rep(0,p-1))
set.seed(1)
data <- generate.rr.data(beta,n,diag(1,p+1), noise = 2, interc = FALSE)
dataX <- data$dataX; dataY <- data$dataY
## Not run: 
set.seed(1)
ppi_val <- 1/4
res <- bps_n_rr(maxTime = 1, dataX = dataX, datay = dataY,
                 prior_sigma2 = 1e2, x0 = rep(0,p+1), theta0 = rep(0,p+1),
                 rj_val = 0.6, ppi = ppi_val, nmax = 1e5, ref = 0.1, burn = -1)

plot_pdmp(res, coords = 1:3, inds = 1:1e3)

## End(Not run)

rjpdmp documentation built on March 18, 2022, 7:52 p.m.