ssvs

Documentation for SSVSforPsych Package

https://github.com/sabainter/ssvs

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    1 of 5 committers (20.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (16.3%) to scientific vocabulary
Last synced: 11 months ago · JSON representation

Repository

Documentation for SSVSforPsych Package

Basic Info
  • Host: GitHub
  • Owner: sabainter
  • License: gpl-3.0
  • Language: R
  • Default Branch: master
  • Size: 10.2 MB
Statistics
  • Stars: 8
  • Watchers: 2
  • Forks: 3
  • Open Issues: 2
  • Releases: 0
Created almost 5 years ago · Last pushed over 1 year ago
Metadata Files
Readme Changelog License

README.Rmd

---
output: github_document
editor_options: 
  markdown: 
    wrap: 72
---



```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

set.seed(1000)
```

# SSVS 



[![R-CMD-check](https://github.com/sabainter/SSVS/workflows/R-CMD-check/badge.svg)](https://github.com/sabainter/SSVS/actions)



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](https://github.com/) with:

``` r
# 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.

```{r ssvs, echo=TRUE, results='hide'}
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 the MIP for each predictor, the average coefficients 
including and excluding zeros, and credible intervals for each coefficient.

```{r summary, echo=TRUE, results='hide'}
summary_results <- summary(results, interval = 0.9, ordered = TRUE)
```

```{r table, echo=FALSE}
knitr::kable(summary_results[, 1:6], align = 'lccccc', row.names = FALSE)
```

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

```{r plot, echo =TRUE}
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:

```{r binary-data, echo=TRUE, results='hide', message=FALSE}
library(AER)
data(Affairs)
Affairs$hadaffair[Affairs$affairs > 0] <- 1
Affairs$hadaffair[Affairs$affairs == 0] <- 0
```

Then define the outcome and predictors.

```{r binary-vars, echo=TRUE}
outcome <- "hadaffair"
predictors <- c("gender", "age", "yearsmarried", "children", "religiousness", "education", "occupation", "rating")
```

And finally run the model:

```{r binary-run, echo=TRUE, message=FALSE}
results <- ssvs(data = Affairs, x = predictors, y = outcome, continuous = FALSE, progress = FALSE)
```

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

```{r binary-results, results='hide'}
summary_results <- summary(results, interval = 0.9, ordered = TRUE)
```

```{r binary-table, echo=FALSE}
knitr::kable(summary_results[, 1:6], align = 'lccccc', row.names = FALSE)
```

```{r binary-plot, echo =TRUE}
plot(results)
```

## Example 3 - SSVS with multiple imputation (MI)

First, we will use the `mice()` function from the {mice} package to
perform multiple imputation.

```{r impute-data, echo=TRUE, results='hide'}
library(mice)

# Load the mtcars dataset
data <- mtcars

# Introduce random missingness in 10% of the data
set.seed(123)  
n <- nrow(data) * ncol(data)
missing_indices <- sample(n, size = 0.1 * n, replace = FALSE)

# Convert missing indices to row-column positions
rows <- (missing_indices - 1) %% nrow(data) + 1
cols <- (missing_indices - 1) %/% nrow(data) + 1

# Assign NA to the identified positions
for (i in seq_along(rows)) {
  data[rows[i], cols[i]] <- NA
}

# Perform multiple imputation using mice
imputed_data <- mice(data, m = 5, maxit = 50, seed = 123)

# Display the results of the imputation
summary(imputed_data)

# Extract and show the first completed dataset
imputed_mtcars <- complete(imputed_data, "long")
head(imputed_mtcars)

```

We will use this multiply imputed data set for SSVS, using the `ssvs_mi()` function.

```{r ssvs-MI, echo=TRUE, results='hide'}
outcome <- 'qsec'
predictors <- c('cyl', 'disp', 'hp', 'drat', 'wt', 'vs', 'am', 'gear', 'carb','mpg')
imputation <- '.imp'
results <- ssvs_mi(data = imputed_mtcars, y = outcome, x = predictors, imp = imputation)
```

The results of SSVS with MI can be summarized with the
`summary()` and `plot()` functions. This will summarize *across imputations* for each predictor: the average MIP and the mean, minimum, maximum, and
average nonzero beta coefficients.



## 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.

GitHub Events

Total
  • Issues event: 10
  • Watch event: 1
  • Delete event: 3
  • Issue comment event: 1
  • Member event: 1
  • Push event: 25
  • Pull request review event: 3
  • Pull request event: 17
  • Fork event: 1
  • Create event: 5
Last Year
  • Issues event: 10
  • Watch event: 1
  • Delete event: 3
  • Issue comment event: 1
  • Member event: 1
  • Push event: 25
  • Pull request review event: 3
  • Pull request event: 17
  • Fork event: 1
  • Create event: 5

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 100
  • Total Committers: 5
  • Avg Commits per committer: 20.0
  • Development Distribution Score (DDS): 0.41
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Dean Attali d****i@g****m 59
mahmoud-mfahmy m****m@g****m 27
sabainter s****r@m****u 12
SBainter s****r@u****t 1
Sierra Bainter s****r@F****l 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 7
  • Total pull requests: 17
  • Average time to close issues: about 1 month
  • Average time to close pull requests: 9 days
  • Total issue authors: 3
  • Total pull request authors: 3
  • Average comments per issue: 0.29
  • Average comments per pull request: 0.0
  • Merged pull requests: 11
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 6
  • Pull requests: 15
  • Average time to close issues: 29 days
  • Average time to close pull requests: 9 days
  • Issue authors: 2
  • Pull request authors: 2
  • Average comments per issue: 0.17
  • Average comments per pull request: 0.0
  • Merged pull requests: 9
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • sabainter (5)
  • daattali (1)
  • kalibera (1)
Pull Request Authors
  • sabainter (13)
  • zhixinmao (4)
  • smasongarrison (2)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 226 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 3
  • Total maintainers: 1
cran.r-project.org: SSVS

Functions for Stochastic Search Variable Selection (SSVS)

  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 226 Last month
Rankings
Forks count: 21.9%
Stargazers count: 26.2%
Dependent packages count: 29.8%
Dependent repos count: 35.5%
Average: 36.6%
Downloads: 69.7%
Maintainers (1)
Last synced: 11 months ago

Dependencies

DESCRIPTION cran
  • R >= 2.10 depends
  • BoomSpikeSlab * imports
  • bayestestR * imports
  • checkmate * imports
  • ggplot2 * imports
  • graphics * imports
  • rlang * imports
  • stats * imports
  • AER * suggests
  • bslib * suggests
  • foreign * suggests
  • glue * suggests
  • knitr * suggests
  • psych * suggests
  • reactable * suggests
  • readxl * suggests
  • rmarkdown * suggests
  • scales * suggests
  • shiny * suggests
  • shinyWidgets * suggests
  • shinyjs * suggests
  • testthat >= 3.0.0 suggests
  • tools * suggests
  • utils * suggests
.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v2 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite