simpr

Tidyverse-friendly simulations and power analysis

https://github.com/statisfactions/simpr

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 (18.8%) to scientific vocabulary
Last synced: 11 months ago · JSON representation

Repository

Tidyverse-friendly simulations and power analysis

Basic Info
  • Host: GitHub
  • Owner: statisfactions
  • Language: R
  • Default Branch: master
  • Size: 1 MB
Statistics
  • Stars: 44
  • Watchers: 4
  • Forks: 6
  • Open Issues: 8
  • Releases: 2
Created over 6 years ago · Last pushed almost 2 years ago
Metadata Files
Readme Changelog

README.Rmd

---
output: github_document
---



```{r, echo = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)
```

```{r setup, include = FALSE}
library(simpr)
```

# [simpr](https://statisfactions.github.io/simpr/)

`simpr` provides a general, simple, and tidyverse-friendly framework for generating simulated data, fitting models on simulations, and tidying model results. The full workflow can happen in a single tidy pipeline without creating external functions, global values, or using loops. It's useful for power analysis, design analysis, simulation studies, and for teaching statistics.

  - [**Easily readable simulation specifications.**](https://statisfactions.github.io/simpr/articles/simpr.html) You can specify simulations in a few lines, including referring to other simulation variables and to simulation parameters that you're varying (such as sample size). `simpr` takes care of all the details of generating your simulation across varying parameters.

  - [**Sensibly handle errors.**](https://statisfactions.github.io/simpr/articles/simulation-errors.html) `simpr` has various options to keep going even when simulation or model-fitting hits errors, so that you don't need to start over if a single iteration hits fatal numerical issues.
  
  - [**Reproducible workflows.**](https://statisfactions.github.io/simpr/articles/reproducibility.html) Individual simulations can be reproduced exactly without needed to perform the whole simulation again.

  - [**Easy-to-use parallel processing.**](https://statisfactions.github.io/simpr/articles/optimization.html) Building on `furrr`, parallel processing for `simpr` can usually be turned on with a couple lines of code.
  
The hardest part of any simulation is designing the data-generating process and deciding what values of parameters you want to explore.  `simpr` takes care of the rest so you can focus on these central issues.

## Installation and loading

```{r installation, eval = FALSE}
## Install stable CRAN version
install.packages("simpr")

## Install latest development version
remotes::install_github("statisfactions/simpr")

library(simpr)
```

## Example simulation

The `simpr` workflow, inspired by the   [`infer`](https://infer.netlify.app) package, distills a simulation study into five primary steps:

1. `specify()` your data-generating process
  
2. `define()` parameters that you want to systematically vary across your simulation design (e.g. *n*, effect size)
  
3. `generate()` the simulation data
  
4. `fit()` models to your data (e.g. `lm()`)
  
5. `tidy_fits()` for further processing using `broom::tidy()`, such as computing power or Type I Error rates

`simpr` makes no assumptions about your data and is not specialized to any particular type of data generating process or model. If R can generate it and if R can fit models, you can use `simpr` to run your simulation.  (The tidying step is limited by the models supported `broom::tidy()`, although you can also supply your own tidying function or expression.)
  
Suppose we are calculating the power for a two-sample *t*-test where the data is log-normally distributed, which can be generated by `stats::rlnorm()`.

```{r rlnorm_example}
set.seed(100)

## Data-generating mechanism
specify(a = ~ rlnorm(n, mean = 0),
        b = ~ rlnorm(n, mean = 0.5)) %>% 
  ## Vary n from 30 to 100
  define(n = seq(30, 100, by = 10)) %>% 
  ## 100 repetitions
  generate(100) %>% 
  ## fit t-tests
  fit(t_test = ~ t.test(a, b)) %>%
  ## bring model results into a tidy tibble
  tidy_fits()
```

`specify()` creates two variables `a` and `b` that are distributed lognormally (any R expression that generates data can be used here).  The `specify` expressions refer to the sample size, `n`.  `define()` clarifies that `n` varies between 30 and 100 by 10s.  `generate()` actually does the data generation, with 100 simulated datasets for each possible value of `define()`.  `fit()` applies an arbitrary R expression to each simulated dataset, and `tidy_fits()` brings things together in a tidy tibble that can be easily aggregated and plotted to calculate bias, power, etc.

## Further resources

See `vignette("simpr")` to get started on using the package, or view the `simpr` [showcase](https://statisfactions.github.io/simpr/articles/articles/Showcase.html) for several applied examples.


Owner

  • Name: Ethan Brown
  • Login: statisfactions
  • Kind: user
  • Location: Massachusetts

GitHub Events

Total
  • Watch event: 2
Last Year
  • Watch event: 2

Committers

Last synced: over 1 year ago

All Time
  • Total Commits: 226
  • Total Committers: 5
  • Avg Commits per committer: 45.2
  • Development Distribution Score (DDS): 0.093
Past Year
  • Commits: 1
  • Committers: 1
  • Avg Commits per committer: 1.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Ethan Brown b****1@u****u 205
Jeff Bye j****e@g****m 16
Ethan Brown e****n@g****m 3
Hadley Wickham h****y@p****o 1
Davis Vaughan d****s@r****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 63
  • Total pull requests: 10
  • Average time to close issues: 6 months
  • Average time to close pull requests: 8 days
  • Total issue authors: 1
  • Total pull request authors: 3
  • Average comments per issue: 0.76
  • Average comments per pull request: 0.8
  • Merged pull requests: 7
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • statisfactions (63)
Pull Request Authors
  • jkbye (8)
  • hadley (1)
  • DavisVaughan (1)
Top Labels
Issue Labels
enhancement (10) documentation (8) bug (7) help wanted (3) good first issue (3) wontfix (3) invalid (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 257 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 5
  • Total maintainers: 1
cran.r-project.org: simpr

Flexible 'Tidyverse'-Friendly Simulations

  • Versions: 5
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 257 Last month
Rankings
Stargazers count: 8.4%
Forks count: 9.1%
Average: 24.2%
Dependent packages count: 29.8%
Dependent repos count: 35.5%
Downloads: 38.2%
Maintainers (1)
Last synced: 11 months ago

Dependencies

DESCRIPTION cran
  • R >= 4.0.0 depends
  • broom * imports
  • dplyr * imports
  • furrr * imports
  • generics * imports
  • magrittr * imports
  • purrr * imports
  • rlang * imports
  • tibble * imports
  • tidyr >= 1.2.0 imports
  • tidyselect * imports
  • MASS * suggests
  • ggplot2 * suggests
  • knitr * suggests
  • rmarkdown * suggests
  • testthat * suggests