View source: R/inv.prior.cov.R
| inv.prior.cov | R Documentation |
inv.prior.cov constructs a diagonal inverse covariance matrix for the Gaussian prior distribution based on the design matrix of covariates. This construction accounts for the number of regression parameters, especially when dealing with categorical covariates. For a linear model, it also includes an additional row and column to represent the variance of the measurement error. In the case of a survival model, it considers the parameters of the baseline hazard function as well.
inv.prior.cov(X,
lambda = 1,
L = 2,
family = c("gaussian", "binomial", "survival"),
treatment = NULL,
treat_round = NULL,
intercept = TRUE,
stratified = FALSE,
strat_par = NULL,
center_spec = NULL,
basehaz = c("weibul", "exp", "gomp", "poly", "pwexp", "unspecified"),
max_order = 2,
n_intervals = 4)
X |
design matrix of dimension |
lambda |
the vector used as the diagonal of the (inverse covariance) matrix that will be created by |
L |
the number of centers. This argument is used only when |
family |
a description of the error distribution. This is a character string naming a family of the model. In the current version of the package, the family of model can be |
treatment |
a character string representing the name or place of the binary covariate, respectively. This covariate indicates whether the patient got the new treatment ( |
treat_round |
a character string representing the |
intercept |
logical flag for having an intercept. It is not used when |
stratified |
logical flag for performing the stratified analysis. If |
strat_par |
a integer vector for indicating the stratification parameter(s). It can be used to deal with heterogeneity due to center-specific parameters. For the |
center_spec |
a vector of |
basehaz |
a character string representing one of the available baseline hazard functions; |
max_order |
an integer representing the maximum value of |
n_intervals |
an integer representing the number of intervals in the piecewise exponential baseline hazard function. This argument is only used when |
inv.prior.cov creates a diagonal matrix with the vector lambda as its diagonal. The argument stratified = TRUE should only be used to construct a matrix for the prior density in case of stratification in the fictive combined data. Never be used for the construction of the matrix for analysis in the centers.
When stratified = FALSE, the length of the vector lambda depends on the covariate matrix X, family, basehaz, and whether an “intercept” is included in the model. For example, if the design matrix X has p columns with continuous or dichotomous covariates, family = gaussian, and intercept = TRUE, then lambda should have p+2 elements. In this case, if in X there is a categorical covariate with q>2 categories, then the length of lambda increases with q-2.
All values of lambda should be non-negative as they represent the inverse of the variance of the Gaussian prior. This argument is considered as the inverse of the variance of the prior distribution for: (\beta_0, \boldsymbol{\beta}) if family = "binomial" and intercept = TRUE; (\beta_0, \boldsymbol{\beta},\sigma^2) if family = "gaussian" and intercept = TRUE; and ( \boldsymbol{\beta},\boldsymbol{\omega}) if family = "survival".
If all values in the vector lambda equal, one value is enough to be given as entry.
If lambda is a scalar, the function inv.prior.cov sets each value at the diagonal equal to lambda.
When lambda is two dimensional: if family = "binomial", the first and second values are used for the inverse of the variance of the prior distribution for the intercept (\beta_0) and regression parameters (\boldsymbol{\beta}), respectively;
If family = "gaussian", the first and second values are used for the inverse of the variance of the prior distribution for the regression parameters including the intercept (\beta_0, \boldsymbol{\beta}) and variance of the measurement error ( \sigma^2), respectively;
If family = "survival", the first and second values are used for the inverse of the variance of the prior distribution for the regression parameters (\boldsymbol{\beta}) and baseline hazard parameters ( \omega), respectively.
But if stratified = TRUE the length of the vector lambda must be equal to the number of parameters in the combined model.
If intercept = FALSE, for the binomial family the stratified analysis is not possible therefore stratified can not be TRUE.
If stratified = FALSE, both strat_par and center_spec must be NULL (the defaults), while if stratified = TRUE only one of the two must be NULL.
If stratified = TRUE and family = "survival", strat_par = 1 refers to \omega_0 when basehaz = "poly", and to \omega_1 for other baseline hazards.
The output of inv.prior.cov() can be used in the main functions MAP.estimation() and bfi().
inv.prior.cov returns a diagonal matrix. The dimension of the matrix depends on the number of columns of X, type of the covariates (continuous/dichotomous or categorical), intercept, family, and basehaz.
Hassan Pazira and Marianne Jonker
Maintainer: Hassan Pazira hassan.pazira@radboudumc.nl
Jonker M.A., Pazira H. and Coolen A.C.C. (2024). Bayesian federated inference for estimating statistical models based on non-shared multicenter data sets, Statistics in Medicine, 43(12): 2421-2438. <https://doi.org/10.1002/sim.10072>
Pazira H., Massa E., Weijers J.A.M., Coolen A.C.C. and Jonker M.A. (2025b). Bayesian Federated Inference for Survival Models, Journal of Applied Statistics (Accepted). <https://arxiv.org/abs/2404.17464>
Jonker M.A., Pazira H. and Coolen A.C.C. (2025a). Bayesian Federated Inference for regression models based on non-shared medical center data, Research Synthesis Methods, 1-41. <https://doi.org/10.1017/rsm.2025.6>
MAP.estimation
#----------------
# Data Simulation
#----------------
X <- data.frame(x1=rnorm(50), # standard normal variable
x2=sample(0:2, 50, replace=TRUE), # categorical variable
x3=sample(0:1, 50, replace=TRUE)) # dichotomous variable
X$x2 <- as.factor(X$x2)
X$x3 <- as.factor(X$x3)
# The (inverse) variance value (lambda=0.05) is assumed to be
# the same for Gaussian prior of all parameters (for non-stratified)
#-------------------------------------------------
# Inverse Covariance Matrix for the Gaussian prior
#-------------------------------------------------
# y ~ Binomial with 'intercept'
inv.prior.cov(X, lambda = 0.05, family = 'binomial')
# returns a 5-by-5 matrix
# y ~ Binomial without 'intercept'
inv.prior.cov(X, lambda = 0.05, family = "binomial", intercept = FALSE)
# a 4-by-4 matrix
# y ~ Gaussian with 'intercept'
inv.prior.cov(X, lambda = 0.05, family = 'gaussian')
# returns a 6-by-6 matrix
# Survival family with 'weibul' baseline hazard
inv.prior.cov(X, lambda = c(0.05, 0.1), family = 'survival')
# returns a 6-by-6 matrix
# Survival family with 'pwexp' baseline hazard (4 intervals)
inv.prior.cov(X, lambda = 0.05, family = 'survival', basehaz = "pwexp")
# returns a 8-by-8 matrix
# Survival family with 'poly' baseline hazard
inv.prior.cov(X, lambda = c(0.05, 0.1), family = 'survival', basehaz = "poly")
# returns a 7-by-7 matrix
#--------------------
# Stratified analysis
#--------------------
# y ~ Binomial when 'intercept' varies across 3 centers:
inv.prior.cov(X, lambda = c(.2, 1), family = 'binomial', stratified = TRUE,
strat_par = 1, L = 3)
# y ~ Gaussian when 'intercept' and 'sigma2' vary across 2 centers; y ~ Gaussian
inv.prior.cov(X, lambda = c(1, 2, 3), family = "gaussian", stratified = TRUE,
strat_par = c(1, 2))
# y ~ Gaussian when 'sigma2' varies across 2 centers (with 'intercept')
inv.prior.cov(X, lambda = c(1, 2, 3), family='gaussian', stratified = TRUE,
strat_par = 2)
# y ~ Gaussian when 'sigma2' varies across 2 centers (without 'intercept')
inv.prior.cov(X, lambda = c(2, 3), family = "gaussian", intercept = FALSE,
stratified=TRUE, strat_par = 2)
#--------------------------
# Center specific covariate
#--------------------------
# center specific covariate has K = 2 categories across 4 centers; y ~ Binomial
inv.prior.cov(X, lambda = c(0.1:2), family = 'binomial', stratified = TRUE,
center_spec = c("Iran","Netherlands","Netherlands","Iran"), L=4)
# center specific covariate has K = 3 categories across 5 centers; y ~ Gaussian
inv.prior.cov(X, lambda = c(0.5:3), family = 'gaussian', stratified = TRUE,
center_spec = c("Medium","Big","Small","Big","Small"), L = 5)
# center specific covariate has K = 4 categories across 5 centers; y ~ Gaussian
inv.prior.cov(X, lambda = 1, family = 'gaussian', stratified = TRUE,
center_spec = c(3,1:4), L=5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.