mvrm {BNSP}R Documentation

Bayesian semiparametric analysis of multivariate continuous responses, with variable selection

Description

Implements an MCMC algorithm for posterior sampling based on a semiparametric model for continuous multivariate responses and additive models for the mean and variance functions. The model utilizes spike-slab priors for variable selection and regularization. See ‘Details’ section for a full description of the model.

Usage

mvrm(formula, distribution = "normal", data = list(), centre = TRUE, sweeps, 
burn = 0, thin = 1, seed, StorageDir, c.betaPrior = "IG(0.5, 0.5 * n * p)", 
pi.muPrior = "Beta(1, 1)", c.alphaPrior = "IG(1.1, 1.1)", sigmaPrior = "HN(2)", 
pi.sigmaPrior = "Beta(1, 1)", c.psiPrior = "HN(1)", phiPrior = "HN(2)", 
pi.omegaPrior = "Beta(1, 1)", mu.RPrior = "N(0, 1)", sigma.RPrior = "HN(1)", 
corr.Model = c("common", nClust = 1), DP.concPrior = "Gamma(5, 2)", 
breaksPrior = "SBeta(1, 2)", tuneCbeta, tuneCalpha, tuneAlpha, tuneSigma2, 
tuneCpsi, tunePsi, tunePhi, tuneR, tuneSigma2R, tuneHar, tuneBreaks, tunePeriod, tau, 
FT = 1, compDeviance = FALSE, ...) 

Arguments

formula

a formula defining the responses and the covariates in the mean and variance models e.g. y1 | y2 ~ x | z or for smooth effects y1 | y2 ~ sm(x) | sm(z). The package uses the extended formula notation, where the responses are defined on the left of ~ and the mean and variance models on the right.

distribution

The distribution for the response variables. Currently two options are supported: "normal" and "t".

data

a data frame.

centre

Binary indicator. If set equal to TRUE, the design matrices are centred, to have column mean equl to zero, otherwise, if set to FALSE, the columns are not centred.

sweeps

total number of posterior samples, including those discarded in burn-in period (see argument burn) and those discarded by the thinning process (see argument thin).

burn

length of burn-in period.

thin

thinning parameter.

seed

optional seed for the random generator.

StorageDir

a required directory to store files with the posterior samples of models parameters.

c.betaPrior

The inverse Gamma prior of cβc_{\beta}. The default is "IG(0.5,0.5*n*p)", that is, an inverse Gamma with parameters 1/21/2 and np/2np/2, where nn is the number of sampling units and pp is the length of the response vector.

pi.muPrior

The Beta prior of πμ\pi_{\mu}. The default is "Beta(1,1)". It can be of dimension 11, of dimension KK (the number of effects that enter the mean model), or of dimension pKpK

c.alphaPrior

The prior of cαc_{\alpha}. The default is "IG(1.1,1.1)". Half-normal priors for cα\sqrt{c_{\alpha}} are also available, declared using "HN(a)", where "a" is a positive number. It can be of dimension 11 or pp (the length of the multivariate response).

sigmaPrior

The prior of σ\sigma. The default is "HN(2)", a half-normal prior for σ\sigma with variance equal to two, σN(0,2)I[σ>0]\sigma \sim N(0,2) I[\sigma>0]. Inverse Gamma priors for σ2\sigma^2 are also available, declared using "IG(a,b)". It can be of dimension 11 or pp (the length of the multivariate response).

pi.sigmaPrior

The Beta prior of πσ\pi_{\sigma}. The default is "Beta(1,1)". It can be of dimension 11, of dimension QQ (the number of effects that enter the variance model), or of dimension pQpQ

c.psiPrior

The prior of cψc_{\psi}. The default is half-normal for cψ\sqrt{c_{\psi}}, declared using "HN(a)", where "a" is a positive number. The default value for "a" is one. Inverse-gamma priors are also available and they can be declared using "IG(a,b)", where "a" and "b" are positive constants. The prior can be of dimension 11 or pp (the length of the multivariate response).

phiPrior

The prior of varphi2varphi^2. The default is half-normal for varphivarphi, declared using "HN(a)", where "a" is a positive number. The default value for "a" is two. Inverse-gamma priors are also available and they can be declared using "IG(a,b)", where "a" and "b" are positive constants. The prior can be of dimension 11 or pp (the length of the multivariate response).

pi.omegaPrior

The Beta prior of πω\pi_{\omega}. The default is "Beta(1,1)". It can be of dimension 11, of dimension BB (the number of effects that enter the shape parameter model), or of dimension pBpB

mu.RPrior

The normal prior for μR\mu_{R}. The default is the standard normal distribution.

sigma.RPrior

The half normal prior for σR\sigma_{R}. The default is the half normal distribution with variance one.

corr.Model

Specifies the model for the correlation matrix RR. The three choices supported are "common", that specifies a common correlations model, "groupC", that specifies a grouped correlations model, and "groupV", that specifies a grouped variables model. When the model chosen is either "groupC" or "groupV", the upper limit on the number of clusters can also be specified, using corr.Model = c("groupC", nClust = d) or corr.Model = c("groupV", nClust = p). If the number of clusters is left unspecified, for the "groupV" model, it is taken to be pp, the number of responses. For the "groupC" model, it is taken to be d=p(p1)/2d = p(p-1)/2, the number of free elements in the correlation matrix.

DP.concPrior

The Gamma prior for the Dirichlet process concentration parameter.

breaksPrior

The prior for the shifts associated with the growth break points. The shift is taken to have a scaled Beta prior with support the (0, p) interval, where p is the period of the sin curve. The default SBeta(1, 2) is a scaled Beta(1, 2) distribution supported in the (0, p) interval. The shifts are in increasing order.

tuneCbeta

Starting value of the tuning parameter for sampling cβc_{\beta}. Defaults at 20.

tuneCalpha

Starting value of the tuning parameter for sampling cαc_{\alpha}. Defaults at 1.

tuneAlpha

Starting value of the tuning parameter for sampling regression coefficients of the variance model α\alpha. Defaults at 5.

tuneSigma2

Starting value of the tuning parameter for sampling variances σj2\sigma^2_j. Defaults at 1.

tuneCpsi

Starting value of the tuning parameter for sampling cψc_{\psi}. Defaults at 1.

tunePsi

Starting value of the tuning parameter for sampling ψ\psi. Defaults at 5.

tunePhi

Starting value of the tuning parameter for sampling φ\varphi. Defaults at 0.5.

tuneR

Starting value of the tuning parameter for sampling correlation matrices. Defaults at 40(p+2)340*(p+2)^3.

tuneSigma2R

Starting value of the tuning parameter for sampling σR2\sigma_{R}^2. Defaults at 1.

tuneHar

Starting value of the tuning parameter for sampling the regression coefficients of the harmonics. Defaults at 100.

tuneBreaks

Starting value of the tuning parameter for sampling the shift parameters associated with growth breaks. Defaults at 0.01 times the period of the sin wave.

tunePeriod

Starting value of the tuning parameter for sampling the period parameter of the sin curve. Defaults to 0.01.

tau

The tautau of the shadow prior. Defaults at 0.01.

FT

Binary indicator. If set equal to 1, the Fisher's z transform of the correlations is modelled, otherwise if set equal to 0, the untransformed correlations are modelled.

compDeviance

Binary indicator. If set equal to 1, the deviance is computed.

...

Other options that will be ignored.

Details

Function mvrm returns samples from the posterior distributions of the parameters of a regression model with normally distributed multivariate responses and mean and variance functions modeled in terms of covariates. For instance, in the presence of two responses (y1,y2y_1, y_2) and two covariates in the mean model (u1,u2u_1, u_2) and two in the variance model (w1,w2w_1, w_2), we may choose to fit

μu=β0+β1u1+fμ(u2), \mu_u = \beta_0 + \beta_1 u_1 + f_{\mu}(u_2),

log(σW2)=α0+α1w1+fσ(w2), \log(\sigma^2_W) = \alpha_0 + \alpha_1 w_1 + f_{\sigma}(w_2),

parametrically modelling the effects of u1u_1 and w1w_1 and non-parametrically modelling the effects of u2u_2 and w2w_2. Smooth functions, such as fμf_{\mu} and fσf_{\sigma}, are represented by basis function expansion,

fμ(u2)=jβjϕj(u2), f_{\mu}(u_2) = \sum_{j} \beta_{j} \phi_{j}(u_2),

fσ(w2)=jαjϕj(w2), f_{\sigma}(w_2) = \sum_{j} \alpha_{j} \phi_{j}(w_2),

where ϕ\phi are the basis functions and β\beta and α\alpha are regression coefficients.

The variance model can equivalently be expressed as

σW2=exp(α0)exp(α1w1+fσ(w2))=σ2exp(α1w1+fσ(w2)), \sigma^2_W = \exp(\alpha_0) \exp(\alpha_1 w_1 + f_{\sigma}(w_2)) = \sigma^2 \exp(\alpha_1 w_1 + f_{\sigma}(w_2)),

where σ2=exp(α0)\sigma^2 = \exp(\alpha_0). This is the parameterization that we adopt in this implementation.

Positive prior probability that the regression coefficients in the mean model are exactly zero is achieved by defining binary variables γ\gamma that take value γ=1\gamma=1 if the associated coefficient β0\beta \neq 0 and γ=0\gamma = 0 if β=0\beta = 0. Indicators δ\delta that take value δ=1\delta=1 if the associated coefficient α0\alpha \neq 0 and δ=0\delta = 0 if α=0\alpha = 0 for the variance function are defined analogously. We note that all coefficients in the mean and variance functions are subject to selection except the intercepts, β0\beta_0 and α0\alpha_0.

Prior specification:

For the vector of non-zero regression coefficients βγ\beta_{\gamma} we specify a g-prior

βγcβ,σ2,γ,α,δN(0,cβσ2(X~γX~γ)1). \beta_{\gamma} | c_{\beta}, \sigma^2, \gamma, \alpha, \delta \sim N(0,c_{\beta} \sigma^2 (\tilde{X}_{\gamma}^{\top} \tilde{X}_{\gamma} )^{-1}).

where X~\tilde{X} is a scaled version of design matrix XX of the mean model.

For the vector of non-zero regression coefficients αδ\alpha_{\delta} we specify a normal prior

αδcα,δN(0,cαI). \alpha_{\delta} | c_{\alpha}, \delta \sim N(0,c_{\alpha} I).

Independent priors are specified for the indicators variables γ\gamma and δ\delta as P(γ=1πμ)=πμP(\gamma = 1 | \pi_{\mu}) = \pi_{\mu} and P(δ=1πσ)=πσP(\delta = 1 | \pi_{\sigma}) = \pi_{\sigma}. Further, Beta priors are specified for πμ\pi_{\mu} and πσ\pi_{\sigma}

πμBeta(cμ,dμ),πσBeta(cσ,dσ). \pi_{\mu} \sim Beta(c_{\mu},d_{\mu}), \pi_{\sigma} \sim Beta(c_{\sigma},d_{\sigma}).

We note that blocks of regression coefficients associated with distinct covariate effects have their own probability of selection (πμ\pi_{\mu} or πσ\pi_{\sigma}) and this probability has its own prior distribution.

Further, we specify inverse Gamma priors for cβc_{\beta} and cαc_{\alpha}

cβIG(aβ,bβ),cαIG(aα,bα) c_{\beta} \sim IG(a_{\beta},b_{\beta}), c_{\alpha} \sim IG(a_{\alpha},b_{\alpha})

For σ2\sigma^2 we consider inverse Gamma and half-normal priors

σ2IG(aσ,bσ),σN(0,ϕσ2). \sigma^2 \sim IG(a_{\sigma},b_{\sigma}), |\sigma| \sim N(0,\phi^2_{\sigma}).

Lastly, for the elements of the correlation matrix, we specify normal distributions with mean μR\mu_R and variance σR2\sigma^2_R, with the priors on these two parameters being normal and half-normal, respectively. This is the common correlations model. Further, the grouped correlations model can be specified. It considers a mixture of normal distributions for the means μR\mu_R. The grouped correlations model can also be specified. It clusters the variables instead of the correlations.

Value

Function mvrm returns the following:

call

the matched call.

formula

model formula.

seed

the seed that was used (in case replication of the results is needed).

data

the dataset

X

the mean model design matrix.

Z

the variance model design matrix.

LG

the length of the vector of indicators γ\gamma.

LD

the length of the vector of indicators δ\delta.

mcpar

the MCMC parameters: length of burn in period, total number of samples, thinning period.

nSamples

total number of posterior samples

DIR

the storage directory

Further, function mvrm creates files where the posterior samples are written. These files are (with all file names preceded by ‘BNSP.’):

alpha.txt

contains samples from the posterior of vector α\alpha. Rows represent posterior samples and columns represent the regression coefficient, and they are in the same order as the columns of design matrix Z.

beta.txt

contains samples from the posterior of vector β\beta. Rows represent posterior samples and columns represent the regression coefficients, and they are in the same order as the columns of design matrix X.

gamma.txt

contains samples from the posterior of the vector of the indicators γ\gamma. Rows represent posterior samples and columns represent the indicator variables, and they are in the same order as the columns of design matrix X.

delta.txt

contains samples from the posterior of the vector of the indicators δ\delta. Rows represent posterior samples and columns represent the indicator variables, and they are in the same order as the columns of design matrix Z.

sigma2.txt

contains samples from the posterior of the error variance σ2\sigma^2 of each response.

cbeta.txt

contains samples from the posterior of cβc_{\beta}.

calpha.txt

contains samples from the posterior of cαc_{\alpha}.

R.txt

contains samples from the posterior of the correlation matrix RR.

theta.txt

contains samples from the posterior of θ\theta of the shadow prior (probably not needed).

muR.txt

contains samples from the posterior of μR\mu_R.

sigma2R.txt

contains samples from the posterior of σR2\sigma^2_{R}.

deviance.txt

contains the deviance, minus twice the log likelihood evaluated at the sampled values of the parameters.

In addition to the above, for models that cluster the correlations we have

compAlloc.txt

The cluster at which the correlations were allocated, λkl\lambda_{kl}. These are integers from zero to the specified number of clusters minus one.

nmembers.txt

The numbers of correlations assigned to each cluster.

DPconc.txt

Contains samples from the posterior of the Dirichlet process concentration parameter.

In addition to the above, for models that cluster the variables we have

compAllocV.txt

The cluster at which the variables were allocated, λk\lambda_{k}. These are integers from zero to the specified number of clusters minus one.

nmembersV.txt

The numbers of variables assigned to each cluster.

Author(s)

Georgios Papageorgiou gpapageo@gmail.com

References

Papageorgiou, G. and Marshall, B.C. (2019). Bayesian semiparametric analysis of multivariate continuous responses, with variable selection. arXiv.

Papageorgiou, G. (2018). BNSP: an R Package for fitting Bayesian semiparametric regression models and variable selection. The R Journal, 10(2):526-548.

Chan, D., Kohn, R., Nott, D., & Kirby, C. (2006). Locally adaptive semiparametric estimation of the mean and variance functions in regression models. Journal of Computational and Graphical Statistics, 15(4), 915-936.

Examples

# Fit a mean/variance regression model on the cps71 dataset from package np. 
#This is a univariate response model
require(np)
require(ggplot2)
data(cps71)
model <- logwage ~ sm(age, k = 30, bs = "rd") | sm(age, k = 30, bs = "rd")
DIR <- getwd()
## Not run: m1 <- mvrm(formula = model, data = cps71, sweeps = 10000, burn = 5000,
                                      thin = 2, seed = 1, StorageDir = DIR)
#Print information and summarize the model
print(m1)
summary(m1)
#Summarize and plot one parameter of interest
alpha <- mvrm2mcmc(m1, "alpha")
summary(alpha)
plot(alpha)
#Obtain a plot of a term in the mean model
wagePlotOptions <- list(geom_point(data = cps71, aes(x = age, y = logwage)))
plot(x = m1, model = "mean", term = "sm(age)", plotOptions = wagePlotOptions)
plot(m1)
#Obtain predictions for new values of the predictor "age"
predict(m1, data.frame(age = c(21, 65)), interval = "credible")

# Fit a bivariate mean/variance model on the marks dataset from package ggm
# two responses: marks mechanics and vectors, and one covariate: marks on algebra 
model2 <- mechanics | vectors ~ sm(algebra, k = 5) | sm(algebra, k = 3)
m2 <- mvrm(formula = model2, data = marks, sweeps = 100000, burn = 50000, 
                       thin = 2, seed = 1, StorageDir = DIR)
plot(m2)

## End(Not run)

[Package BNSP version 2.2.3 Index]