An open API service indexing awesome lists of open source software.

https://github.com/anestistouloumis/simcormultres

Simulates correlated multinomial responses conditional on a marginal model specification.
https://github.com/anestistouloumis/simcormultres

binary longitudinal-studies multinomial r simulation

Last synced: about 1 month ago
JSON representation

Simulates correlated multinomial responses conditional on a marginal model specification.

Awesome Lists containing this project

README

        

---
output: github_document
references:
- id: Touloumis2016
title: "Simulating Correlated Binary and Multinomial Responses under Marginal Model Specification: The SimCorMultRes Package"
author:
- family: Touloumis
given: Anestis
container-title: The R Journal
volume: 8
URL: 'https://journal.r-project.org/archive/2016/RJ-2016-034/index.html'
issue: 2
page: 79-91
type: article-journal
issued:
year: 2016
csl: biometrics.csl
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(
tidy = TRUE,
tidy.opts = list(width.cutoff = 80),
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```

# SimCorMultRes: Simulates Correlated Multinomial Responses

[![Github version](`r paste0("https://img.shields.io/badge/GitHub%20-", as.vector(read.dcf('DESCRIPTION')[, 'Version']),"-orange.svg")`)]("commits/master")
[![R-CMD-check](https://github.com/AnestisTouloumis/SimCorMultRes/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/AnestisTouloumis/SimCorMultRes/actions/workflows/R-CMD-check.yaml)
[![Project Status: Active The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)
[![Codecov test coverage](https://codecov.io/gh/AnestisTouloumis/SimCorMultRes/branch/master/graph/badge.svg)](https://codecov.io/gh/AnestisTouloumis/SimCorMultRes?branch=master)

[![CRAN Version](https://www.r-pkg.org/badges/version/SimCorMultRes?color=blue)](https://cran.r-project.org/package=SimCorMultRes)
[![CRAN Downloads](https://cranlogs.r-pkg.org/badges/grand-total/SimCorMultRes?color=blue)](https://cranlogs.r-pkg.org/badges/grand-total/SimCorMultRes)
[![CRAN Downloads](https://cranlogs.r-pkg.org/badges/SimCorMultRes)](https://cran.r-project.org/package=SimCorMultRes)

## Installation

You can install the release version of `SimCorMultRes`:

```{r eval=FALSE}
install.packages("SimCorMultRes")
```

The source code for the release version of `SimCorMultRes` is available on CRAN at:

- https://CRAN.R-project.org/package=SimCorMultRes

Or you can install the development version of `SimCorMultRes`:

```{r eval=FALSE}
# install.packages("devtools")
devtools::install_github("AnestisTouloumis/SimCorMultRes")
```

The source code for the development version of `SimCorMultRes` is available on github at:

- https://github.com/AnestisTouloumis/SimCorMultRes

To use `SimCorMultRes`, you should load the package as follows:

```{r}
library("SimCorMultRes")
```

## Usage and functions

This package provides five core functions to simulate correlated binary (`rbin`), nominal (`rmult.bcl`) and ordinal (`rmult.acl`, `rmult.clm` and `rmult.crm`) responses, which are drawn as realizations of a latent regression model for continuous random vectors as proposed by @Touloumis2016:

- `rbin` to simulate correlated binary responses under a marginal model with logit, probit, cloglog and cauchit link function,
- `rmult.bcl` to simulate correlated nominal multinomial responses under a marginal baseline-category logit model,
- `rmult.acl` to simulate correlated ordinal responses under a marginal adjacent-category logit model,
- `rmult.clm` to simulate correlated ordinal responses under a marginal cumulative link model,
- `rmult.crm` to simulate correlated ordinal responses under a marginal continuation-ratio link model.

All five functions, assume that you provide either the correlation matrix of the multivariate normal distribution in NORTA (via `cor.matrix`) or the values of the latent responses (via the `rlatent`). Based on a simulation study (see Section 3.5 of the vignette and dataset `simulation`), it is indicated that the correlation matrix of the multivariate normal distribution used in the NORTA method (via `cor.matrix`) can be considered a reliable approximation of the actual correlation matrix of the latent responses generated by the NORTA method. This appears to be the case irrespective of the marginal distributions of the latent responses for all the threshold approaches implemented in `SimCorMultRes`.

There are also two utility functions:

- `rnorta` for simulating continuous or discrete random vectors with prescribed marginal distributions using the NORTA method,
- `rsmvnorm` for simulating continuous random vectors from a multivariate normal distribution.

## Example

The following R code illustrates how to use the core function `rbin`:

```{r}
## See Example 3.5 in the Vignette.
set.seed(123)
## define number of random vectors
sample_size <- 100
## define size of each random vector
cluster_size <- 4
## define intercept of the binary probit regression model
beta_intercepts <- 0
## define coefficients of the explanatory variables
beta_coefficients <- 0.2
## provide explanatory variables
x <- rep(rnorm(sample_size), each = cluster_size)
## define correlation matrix for the multivariate normal distribution in NORTA
latent_correlation_matrix <- toeplitz(c(1, 0.9, 0.9, 0.9))
## use rbin function to create the desired dataset
simulated_binary_responses <- rbin(clsize = cluster_size,
intercepts = beta_intercepts,
betas = beta_coefficients,
xformula = ~ x,
cor.matrix = latent_correlation_matrix,
link = "probit")
library("gee")
binary_gee_model <- gee(y ~ x, family = binomial("probit"), id = id,
data = simulated_binary_responses$simdata)
summary(binary_gee_model)$coefficients
```

Additional examples can be found in @Touloumis2016 and in the vignette of `SimCorMultRes`. To access these two documents, run the following command:

```{r eval=FALSE}
browseVignettes("SimCorMultRes")
```

## How to cite

```{r echo=FALSE, comment=""}
citation("SimCorMultRes")
```

# References