MyNixOS website logo
Description

Functions for Stochastic Search Variable Selection (SSVS).

Functions for performing stochastic search variable selection (SSVS) for binary and continuous outcomes and visualizing the results. SSVS is a Bayesian variable selection method used to estimate the probability that individual predictors should be included in a regression model. Using MCMC estimation, the method samples thousands of regression models in order to characterize the model uncertainty regarding both the predictor set and the regression parameters. For details see Bainter, McCauley, Wager, and Losin (2020) Improving practices for selecting a subset of important predictors in psychology: An application to predicting pain, Advances in Methods and Practices in Psychological Science 3(1), 66-80 <DOI:10.1177/2515245919885617>.

SSVS

R-CMD-check

The goal of {SSVS} is to provide functions for performing stochastic search variable selection (SSVS) for binary and continuous outcomes and visualizing the results. SSVS is a Bayesian variable selection method used to estimate the probability that individual predictors should be included in a regression model. Using MCMC estimation, the method samples thousands of regression models in order to characterize the model uncertainty regarding both the predictor set and the regression parameters.

Installation

You can install the development version of {SSVS} from GitHub with:

# install.packages("remotes")
remotes::install_github("sabainter/SSVS")

Example 1 - continuous response variable

Consider a simple example using SSVS on the mtcars dataset to predict quarter mile times. We first specify our response variable (“qsec”), then choose our predictors and run the ssvs() function.

library(SSVS)
outcome <- 'qsec'
predictors <- c('cyl', 'disp', 'hp', 'drat', 'wt',
 'vs', 'am', 'gear', 'carb','mpg')

results <- ssvs(data = mtcars, x = predictors, y = outcome, progress = FALSE)

The results can be summarized and printed using the summary() function. This will display both the MIP for each predictor, as well as the probable range of values for each coefficient.

summary_results <- summary(results, interval = 0.9, ordered = TRUE)
VariableMIPAvg BetaLower CI (90%)Upper CI (90%)Avg Nonzero Beta
wt0.84331.04330.00001.95131.2372
vs0.75120.63990.00001.19820.8519
hp0.5413-0.4995-1.33490.0000-0.9228
cyl0.4551-0.5173-1.76700.0005-1.1367
am0.4240-0.3107-1.08050.0000-0.7328
disp0.4130-0.4553-1.81700.0012-1.1023
carb0.3938-0.2890-1.00680.0000-0.7338
gear0.2013-0.0918-0.54640.0002-0.4560
mpg0.15840.0563-0.00010.41600.3557
drat0.1003-0.0180-0.00080.0000-0.1794

The MIPs for each predictor can then be visualized using the plot() function.

plot(results)

Example 2 - binary response variable

In the example above, the response variable was a continuous variable. The same workflow can be used for binary variables by specifying continuous = FALSE to the ssvs() function.

As an example, let’s create a binary variable:

library(AER)
data(Affairs)
Affairs$hadaffair[Affairs$affairs > 0] <- 1
Affairs$hadaffair[Affairs$affairs == 0] <- 0

Then define the outcome and predictors.

outcome <- "hadaffair"
predictors <- c("gender", "age", "yearsmarried", "children", "religiousness", "education", "occupation", "rating")

And finally run the model:

results <- ssvs(data = Affairs, x = predictors, y = outcome, continuous = FALSE, progress = FALSE)

Now the results can be summarized or visualized in the same manner.

summary_results <- summary(results, interval = 0.9, ordered = TRUE)
VariableMIPAvg BetaLower CI (90%)Upper CI (90%)Avg Nonzero Beta
rating0.9993-0.5553-0.7173-0.4027-0.5557
religiousness0.4024-0.1332-0.40320.0000-0.3309
children0.09550.02680.00000.00000.2804
yearsmarried0.08990.02720.00000.00000.3020
gender0.00750.00080.00000.00000.1092
occupation0.00630.00060.00000.00000.0986
age0.0058-0.00070.00000.0000-0.1202
education0.00410.00040.00000.00000.1011
plot(results)

Interactive version

You can launch an interactive (shiny) web application that lets you run SSVS analyses without programming. Simply install this package and run SSVS::launch() in an R console.

Metadata

Version

2.0.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD 13
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd13
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd13
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows