| Title: | Bayesian Effect Fusion for Categorical Predictors |
|---|---|
| Description: | Variable selection and Bayesian effect fusion for categorical predictors in linear and logistic regression models. Effect fusion aims at the question which categories have a similar effect on the response and therefore can be fused to obtain a sparser representation of the model. Effect fusion and variable selection can be obtained either with a prior that has an interpretation as spike and slab prior on the level effect differences or with a sparse finite mixture prior on the level effects. The regression coefficients are estimated with a flat uninformative prior after model selection or by taking model averages. Posterior inference is accomplished by an MCMC sampling scheme which makes use of a data augmentation strategy (Polson, Scott & Windle (2013) <doi:10.1080/01621459.2013.829001>) based on latent Polya-Gamma random variables in the case of logistic regression. The code for data augmentation is taken from Polson et al. (2013) <doi:10.1080/01621459.2013.829001>, who own the copyright. Compatibility updates by Renova. |
| Authors: | Daniela Pauger [aut], Magdalena Leitner [aut, cre], Helga
Wagner [aut] |
| Maintainer: | Magdalena Leitner <[email protected]> |
| License: | GPL-3 |
| Version: | 1.1.3.9002 |
| Built: | 2026-11-13 19:58:32 UTC |
| Source: | https://github.com/renova-r/effectFusion |
This function computes the DIC (deviance information criterion) for the estimated model in a fusion object.
dic(x)dic(x)
x |
an object of class |
The DIC can be easily computed from the MCMC output and is defined as
, where is the average posterior deviance and
is the deviance evaluated at . are samples from the posterior of the model
and M is the number of MCMC iterations.
The DIC for the estimated model in the fusion object.
Daniela Pauger, Magdalena Leitner <[email protected]>
Spiegelhalter, D., Best, N., Carlin, B., and van der Linde, A. (2002). Bayesian Measures of Model Complexity and Fit. J. R. Statist. Soc. B, 64(4), 583-639. doi:10.1111/1467-9868.00353
## see example for effectFusion## see example for effectFusion
This function performs Bayesian variable selection and effect fusion for categorical predictors in linear and logistic regression models. Effect fusion aims at the question which categories of an ordinal or nominal predictor have a similar effect on the response and therefore can be fused to obtain a sparser representation of the model. Effect fusion and variable selection can be obtained either with a prior that has an interpretation as spike and slab prior on the level effect differences or with a sparse finite mixture prior on the level effects. The regression coefficients are estimated with a flat uninformative prior after model selection or by using model averaged results. For posterior inference, a MCMC sampling scheme is used that involves only Gibbs sampling steps. The sampling schemes for linear and logistic regression are almost identical as in the case of logistic regression a data augmentation strategy (Polson et al. (2013)) is used that requires only one additional step to sample from the Polya-Gamma distribution.
effectFusion( y, X, types, method, prior = list(), mcmc = list(), mcmcRefit = list(), family = "gaussian", modelSelection = "binder", returnBurnin = FALSE )effectFusion( y, X, types, method, prior = list(), mcmc = list(), mcmcRefit = list(), family = "gaussian", modelSelection = "binder", returnBurnin = FALSE )
y |
a vector of the response observations (continuous if |
X |
a data frame with covariates, each column representing one covariate. Ordinal and nominal covariates should
be of class |
types |
a character vector to specify the type of each covariate; 'c' indicates continuous or metric predictors, 'o' ordinal predictors and 'n' nominal predictors |
method |
controls the main prior structure that is used for effect fusion. For the prior
that has an interpretation as spike and slab prior on the level effect differences choose |
prior |
an (optional) list of prior settings and hyper-parameters for the prior (see details).
The specification of this list depends on the chosen |
mcmc |
an (optional) list of MCMC sampling options (see details) |
mcmcRefit |
an (optional) list of MCMC sampling options for the refit of the selected model (see details) |
family |
indicates whether linear (default, |
modelSelection |
if |
returnBurnin |
if |
This function provides identification of categories (of ordinal and nominal predictors) with the same effect on the response and their automatic fusion.
Two different prior versions for effect fusion and variable selection are available. The first prior version allows a priori for almost perfect as well as almost zero dependence between level effects. This prior has also an interpretation as independent spike and slab prior on all pairwise differences of level effects and correction for the linear dependence of the effect differences. Even though the prior is mainly designed for fusion of level effects, excluding some categories from the model as well as the whole covariate (variable selection) can also be easily accomplished. Excluding a category from the model corresponds to fusion of this category to the baseline and excluding the whole covariate consequently to fusion of all categories to the baseline.
The second prior is a modification of the usual spike and slab prior for the regression coefficients by combining
a spike at zero with a finite location mixture of normal components. It enables detection of categories with similar
effects on the response by clustering the regression effects. Categories with effects that are allocated to the same
cluster are fused. Due to the specification with one component located at zero also automatic exclusion of
levels and whole covariates without any effect on the outcome is provided. However, when using modelSelection = 'pam',
it is not possible to exclude whole covariates as the Silhouette coefficient does not allow for one cluster solutions. Therefore,
we recommend to use modelSelection = 'binder'.
In settings with large numbers of categories, we recommend to use the sparse finite mixture prior for computational reasons. It is important to note that the sparse finite mixture prior on the level effects does not take into account the ordering information of ordinal predictors and treats them like nominal predictors, whereas in the spike and slab case fusion is restricted to adjacent categories for ordinal predictors.
Metric predictors can be included in the model as well and variable selection will be performed also for these predictors.
If modelSelection = NULL, no final model selection is performed and model averaged results are returned. When modelSelection = 'binder' the final
model is selected by minimizing the expected posterior Binder loss for each covariate separately.
Additionally, there is a second option for the finite mixture prior (modelSelection = 'pam') which performs model selection
by identifying the optimal partition of the effects using PAM clustering and the silhouette coefficient.
For comparison purposes it is also possible to fit a full model instead of performing effect fusion (method = NULL).
All other functions provided in this package, such as dic or summary, do also work for the full model.
Details for the model specification (see arguments):
priora list (depending on used method and specified family). If method = NULL, all prior
specifications are ignored and a flat, uninformative prior is assigned to the level effects
rvariance ratio of slab to spike component; default to 50000 if family = 'gaussian' and
5000000 if family = 'binomial'. r should be chosen not too small but still small enough to avoid stickiness of MCMC. We
recommend a value of at least 20000.
g0shape parameter of inverse gamma distribution on when tau2_fix = NULL and method = 'SpikeSlab'; default
to 5. The default value is a standard choice in variable selection where the tails of spike and slab component are not too thin
to cause mixing problems in MCMC.
G0scale parameter of inverse gamma distribution on when tau2_fix = NULL and method = 'SpikeSlab'; default
to 25. G0 controls to some extend the sparsity of the model. Smaller values for G0 help to detect also small
level effect differences, but result in less fusion of categories.
tau2_fixIf tau2_fix = NULL, an inverse gamma hyper-prior is specified on .
However, the value of the slab variance can also be fixed for each covariate instead of using a hyperprior.
tau2_fix is only of interest if method = 'SpikeSlab'.
Default to NULL. Similar to the scale parameter G0, the fixed variance of the slab
component tau2_fix can control to some extend the sparsity.
e0parameter of Dirichlet hyper-prior on mixture weights when method = 'FinMix';
default to 0.01. e0 should be chosen smaller than 1 in order to encourage empty components. Small values such as
0.01 help to concentrate the model space on sparse solutions.
pprior parameter to control mixture component variances when method = 'FinMix'; values between 100 and 100000
led to good results in simulation studies; default to 100 if family = 'gaussian' and 1000 if family = 'binomial'. We recommend to try different values for this
prior parameter and compare the models using dic. When hyperprior = FALSE, larger values of p lead to less sparsity and it should be chosen
not smaller than 100. If a hyper-prior on the mixture component variances is used (hyperprior = TRUE), p
has almost no effect on the sparsity of the model and it should again be not smaller than 100.
hyperpriorlogical value if inverse gamma hyper-prior on component variance should be specified when method = 'FinMix';
default to FALSE. The hyper-prior leads to robust results concerning the specification of p
but also to very sparse solutions.
s0hyper-parameter (shape) of inverse gamma distribution on error variance, used for both
versions of method, but only for family = 'gaussian'; default to 0.
S0hyper-parameter (scale) of inverse gamma distribution on error variance, used for both
versions of method, but only for family = 'gaussian'; default to 0.
mcmca list:
Mnumber of MCMC iterations after the burn-in phase; default to 20000 for effect fusion models and 3000 for full models.
burninnumber of MCMC iterations discarded as burn-in; default to 5000 for effect fusion models and 1000 for full models.
startselnumber of MCMC iterations drawn from the model without performing effect fusion; default to 1000 for effect fusion models and 0 for full models.
mcmcRefita list (not necessary if modelSelection = NULL or method = NULL):
M_refitnumber of MCMC iterations after the burn-in phase for the refit of the selected model; default to 3000.
burnin_refitnumber of MCMC iterations discarded as burn-in for the refit of the selected model; default to 1000.
The function returns an object of class fusion with methods dic,
model, print, summary and plot.
An object of class fusion is a named list containing the following elements:
fita named list containing the samples from the posterior distributions of the parameters
depending on the used prior structure (method = 'SpikeSlab', method = 'FinMix' or method = NULL):
betaregression coefficients (intercept) and
deltaindicator variable for slab component when method = 'SpikeSlab'. The differences of
the level effects are assigned either to the spike (delta = 0) or the slab component (delta = 1). If an
effect difference is assigned to the spike component, the difference is almost zero and the corresponding level effects
should be fused.
tau2variance of slab component when method = 'SpikeSlab'. If no hyperprior on is specified, tau2 contains the fixed values for .
Slatent allocation variable for mixture components when method = 'FinMix'
etamixture component weights when method = 'FinMix'
eta0weights of components located at zero when method = 'FinMix'
mumixture component means when method = 'FinMix'
sgma2error variance of the model (only for family = 'gaussian')
fit_burnina named list containing the same elements as fit including the burnin-phase, if returnBurnin = TRUE,
NULL otherwise. The elements that correspond to the model selection procedure, e.g. delta or S, are NA for the first startsel iterations.
refita named list containing samples from the posterior distributions of the parameters of
the model refit (only if method and modelSelection are unequal to NULL):
betaregression coefficients including the intercept in the model with fused levels
sgma2error variance of the model with fused levels (only for family = 'gaussian')
X_dummy_fusedthe dummy coded design matrix with fused levels
modelvector of zeros and ones representing the selected model based on pairs of categories
methodsee arguments
familysee arguments
dataa named list containing the data y, X, the dummy coded design matrix X_dummy,
types and levelnames of ordinal and nominal predictors
modela named list containing information on the full, initial model
categoriesnumber of categories for categorical predictors
diffnumber of pairwise level effect differences
n_contnumber of metric predictors
n_ordnumber of ordinal predictors
n_nomnumber of nominal predictors
priorsee details for prior
mcmcsee details for mcmc
mcmcRefitsee details for mcmcRefit
modelSelectionsee arguments
returnBurninsee arguments
numbCoefnumber of estimated regression coefficients (based on the refitted model if effect fusion and final model selection is performed, otherwise based on model averaged results or the full model, respectively)
callfunction call
The function can be used for ordinal and/or nominal predictors and metric covariates can additionally be included in the model. Binary covariates as a special case of nominal predictors can be included as well.
The sparse finite mixture prior approach does not take into account the ordering information of ordinal predictors. Ordinal predictors are treated as nominal predictors, whereas in the spike and slab case fusion is restricted to adjacent categories for ordinal predictors.
For large models and more than 15,000 MCMC iterations, some thinning of the MCMC when using the sparse finite mixture prior is performed due to computational issues.
Daniela Pauger, Magdalena Leitner <[email protected]>, Helga Wagner, Gertraud Malsiner-Walli
Pauger, D., and Wagner, H. (2019). Bayesian Effect Fusion for Categorical Predictors. Bayesian Analysis, 14(2), 341-369. doi:10.1214/18-BA1096
Malsiner-Walli, G., Pauger, D., and Wagner, H. (2018). Effect Fusion Using Model-Based Clustering. Statistical Modelling, 18(2), 175-196. doi:10.1177/1471082X17739058
Polson, N.G., Scott, J.G., and Windle, J. (2013). Bayesian Inference for Logistic Models Using Polya-Gamma Latent Variables. Journal of the American Statistical Association, 108(504), 1339-1349. doi:10.1080/01621459.2013.829001
## Not run: # ----------- Load simulated data set 'sim1' for linear regression data(sim1) y = sim1$y X = sim1$X types = sim1$types # ----------- Bayesian effect fusion for simulated data set with spike and slab prior m1 <- effectFusion(y, X, types, method = 'SpikeSlab') # print, summarize and plot results print(m1) summary(m1) plot(m1) # evaluate model and model criteria model(m1) dic(m1) # ----------- Use finite mixture prior for comparison m2 <- effectFusion(y, X, types, method = 'FinMix') # summarize and plot results print(m2) summary(m2) plot(m2) model(m2) dic(m2) # change prior parameter specification m3 <- effectFusion(y, X, types, prior= list(p = 10^3), method = 'FinMix') plot(m3) # ------------ Use model averaged coefficient estimates m4 <- effectFusion(y, X, types, method = 'SpikeSlab', modelSelection = NULL) summary(m4) # ------------ Estimate full model for comparison purposes m5 <- effectFusion(y, X, types, method = NULL) summary(m5) plot(m5) dic(m5) # ----------- Load simulated data set 'sim3' for logistic regression data(sim3) y = sim3$y X = sim3$X types = sim3$types # ----------- Bayesian effect fusion for simulated data set with finite mixture prior m6 <- effectFusion(y, X, types, method = 'FinMix', prior = list(p = 10^4), family = 'binomial') # look at the results print(m6) summary(m6) plot(m6) model(m6) dic(m6) # ----------- Use spike and slab prior for comparison m7 <- effectFusion(y, X, types, method = 'SpikeSlab', family = 'binomial', returnBurnin = TRUE) # summarize and evaluate results print(m7) summary(m7) plot(m7) model(m7) dic(m7) ## End(Not run)## Not run: # ----------- Load simulated data set 'sim1' for linear regression data(sim1) y = sim1$y X = sim1$X types = sim1$types # ----------- Bayesian effect fusion for simulated data set with spike and slab prior m1 <- effectFusion(y, X, types, method = 'SpikeSlab') # print, summarize and plot results print(m1) summary(m1) plot(m1) # evaluate model and model criteria model(m1) dic(m1) # ----------- Use finite mixture prior for comparison m2 <- effectFusion(y, X, types, method = 'FinMix') # summarize and plot results print(m2) summary(m2) plot(m2) model(m2) dic(m2) # change prior parameter specification m3 <- effectFusion(y, X, types, prior= list(p = 10^3), method = 'FinMix') plot(m3) # ------------ Use model averaged coefficient estimates m4 <- effectFusion(y, X, types, method = 'SpikeSlab', modelSelection = NULL) summary(m4) # ------------ Estimate full model for comparison purposes m5 <- effectFusion(y, X, types, method = NULL) summary(m5) plot(m5) dic(m5) # ----------- Load simulated data set 'sim3' for logistic regression data(sim3) y = sim3$y X = sim3$X types = sim3$types # ----------- Bayesian effect fusion for simulated data set with finite mixture prior m6 <- effectFusion(y, X, types, method = 'FinMix', prior = list(p = 10^4), family = 'binomial') # look at the results print(m6) summary(m6) plot(m6) model(m6) dic(m6) # ----------- Use spike and slab prior for comparison m7 <- effectFusion(y, X, types, method = 'SpikeSlab', family = 'binomial', returnBurnin = TRUE) # summarize and evaluate results print(m7) summary(m7) plot(m7) model(m7) dic(m7) ## End(Not run)
fusion objectThe function displays for categorical covariates the selected model of an
object of class fusion as list.
model(x)model(x)
x |
an object of class |
The selected model for each categorical predictor is displayed as a list of length equal
to the number of categories after fusion. Fused categories are shown with their original labelling
in one list element.
The function is only available if effect fusion (method in effectFusion is unequal to NULL)
and final model selection (argument modelSelection in effectFusion is not NULL) is performed.
See summary.fusion for more details.
Daniela Pauger, Magdalena Leitner <[email protected]>
## see example for effectFusion## see example for effectFusion
fusion
This function provides plots of posterior means and 95%-HPD intervals for the
regression effects. Plots are based on the refitted MCMC samples of the
selected model in an object of class fusion or on model averaged results if no
final model selection was performed.
## S3 method for class 'fusion' plot(x, maxPlots = 4, ...)## S3 method for class 'fusion' plot(x, maxPlots = 4, ...)
x |
an object of class |
maxPlots |
maximum number of plots on a single page, default argument to 4 |
... |
further arguments passed to or from other methods (not used) |
If no effect fusion or no final model selection is performed, posterior means and HPD intervals are model averaged results. Otherwise, the parameters of the selected model are reestimated with a flat uninformative prior. Thus, fused categories have the same posterior mean and HPD interval. Single categories that are excluded from the model are fused to the reference category and therefore only a posterior mean at zero and no interval is plotted.
Daniela Pauger, Magdalena Leitner <[email protected]>
## see example for effectFusion## see example for effectFusion
fusion
The default print method for a fusion object.
## S3 method for class 'fusion' print(x, ...)## S3 method for class 'fusion' print(x, ...)
x |
an object of class |
... |
further arguments passed to or from other methods (not used) |
Returns basic information about the full, initial model: the number of observations, the family, the number and types of used covariates with their number of categories and MCMC options.
Daniela Pauger, Magdalena Leitner <[email protected]>
## see example for effectFusion## see example for effectFusion
The simulated data set sim1 illustrates a setting with 500 observations from a linear
regression model with normal response, 4 ordinal and 4 nominal predictors. Two regressors
have 8 and two have 4 categories for each type of covariate (ordinal and nominal). Regression
effects are set to and for the
ordinal and and for the nominal
covariates, and for h = 2, 4, 6, 8. Levels of the predictors are generated with
probabilities and for regressors with 8 and 4 levels, respectively. For more details on the
simulation setting see Pauger and Wagner (2019).
data(sim1)data(sim1)
A named list containing the following four variables:
yvector with 500 observations of a normal response variable
Xmatrix with 8 categorical predictors
betavector with coefficients used for data generation
typescharacter vector with types of covariates, 'o' for ordinal and 'n' for nominal covariates
Pauger, D., and Wagner, H. (2019). Bayesian Effect Fusion for Categorical Predictors. Bayesian Analysis, 14(2), 341-369. doi:10.1214/18-BA1096
The simulated data set sim2 illustrates a setting with 4000 observations from a linear
regression model. The model has four independent predictors with either 10 or 100 categories and
uniform prior class probabilities. The first covariate with 10 categories has three levels with no
effects, three levels with effects of size 0.5 and the remaining three levels have effects of size one.
The second covariate with 10 categories has 8 levels with no effects and only one level with an effect
of size one. The final covariate with 10 categories has only levels without any effect on the
outcome. Analogue to the first one, the covariate with 100 categories has 33 levels with
no effects, 33 levels with effects of size 0.5 and 33 levels with effects of size 1.
data(sim2)data(sim2)
A named list containing the following four variables:
yvector with 4000 observations of a normal response variable
Xmatrix with 4 categorical predictors
betavector with coefficients used for data generation
typescharacter vector with types of covariates, 'o' for ordinal and 'n' for nominal covariates
The simulated data set sim3 considers a setting with 2000 observations from a logistic
regression model. The number and types of predictors, the regression effects and the level probabilites
of the predictors are the same as for sim1. The number of observations was increased as the uncertainty
is usually higher for logistic regression compared to linear regression with normal response.
data(sim3)data(sim3)
A named list containing the following four variables:
yvector with 2000 observations of a binary response variable
Xmatrix with 8 categorical predictors
betavector with coefficients used for data generation
typescharacter vector with types of covariates, 'o' for ordinal and 'n' for nominal covariates
fusion
Returns basic information about the model and the priors, MCMC details and posterior means from the refit of the selected model or model averaged results as well as 95%-HPD intervals for the regression effects.
## S3 method for class 'fusion' summary(object, ...)## S3 method for class 'fusion' summary(object, ...)
object |
an object of class |
... |
further arguments passed to or from other methods (not used) |
The model selected with function effectFusion is refitted with a flat uninformative
prior to get estimates for the regression coefficients beta. The posterior means and 95%-HPD
intervals resulting from this refit are shown with this function. Fused categories have the same
regression coefficient estimates and the same HPD intervals.
If a full model is fitted (method in effectFusion is NULL) or no final model selection is performed
(argument modelSelection in effectFusion is NULL), the coefficient estimates are model
averaged results.
Daniela Pauger, Magdalena Leitner <[email protected]>
## see example for effectFusion## see example for effectFusion