- Notifications
You must be signed in to change notification settings - Fork1
R package for multiverse analysis. Extends R package multiverse with student and analyst friendly interfaces.
mverseanalysis/mverse
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
mverse is an extension to multiverse package (Sarma et al. 2021) whichallows users create explorable multiverse analysis (Steegen et al. 2016)in R. This extension provides user friendly abstraction and a set ofexamples for researchers, educators, and students in statistics.
You can install the released version of mverse fromCRAN with:
install.packages("mverse")You can install the development version fromGitHub with:
# install.packages("devtools")devtools::install_github("mverseanalysis/mverse",build_vignettes=TRUE)
The following demonstration performs a multiverse analysis usinghurricane dataset (Jung et al. 2014) included in the library. We firstcreate 6 universes as described in Figure 1. A filterbranch with 2options and a mutatebranch with 3options results in 6universes in total. We then fit a Poisson regression model across themultiverse and inspect a coefficient estimate. Seevignette("hurricane") for a detailed analysis as well as theterminologies used.
#> Warning: Using alpha for a discrete variable is not advised.First, we start by loading the library and defining amverse objectwith the dataset of interest.
library(mverse)mv<- mverse(hurricane)
We use the*_branch() methods to define branches.filter_branch()defines filtering operations usingdplyr::filter() with differentoptions for the filter.
outliers<- filter_branch(!Name%in% c("Katrina"),!Name%in% c("Katrina","Audrey"))
mutate_branch() multiplexesdplyr::mutate() to add a new column inthe dataset.
strength<- mutate_branch(NDAM,HighestWindSpeed,Minpressure_Updated_2014)
In order to fit a Poisson regression, we need to specify the model usingR’s formula syntax and the underlying distribution usingfamily. Inmverse, we provide the specifications usingformula_branch() andfamily_branch(). In this demonstration, we only define a single optionfor both formula and family but it is possible to provide multipleoptions for them as well.
model<- formula_branch(alldeaths~strength*MasFem)distribution<- family_branch(poisson)
After defining the branches, we can add the branch objects to themverse object usingadd_*_branch() methods.
mv<-mv %>% add_filter_branch(outliers) %>% add_mutate_branch(strength) %>% add_formula_branch(model) %>% add_family_branch(distribution)
glm_mverse() multiplexesstats::glm() function and fits a GLM ineach universe according to the specifications provided byadd_fomula_branch() andadd_family_branch().
mv<-mv %>% glm_mverse()
After completing the analysis, we can extract the results usingsummary(). The method returns a table with branching options,estimates, 95% confidence intervals for all regression terms across themultiverse.
res<- summary(mv)res#> # A tibble: 24 × 16#> universe outliers_branch strength_branch model_branch distribution_branch#> <fct> <fct> <fct> <fct> <fct>#> 1 1 outliers_1 strength_1 model_1 distribution_1#> 2 1 outliers_1 strength_1 model_1 distribution_1#> 3 1 outliers_1 strength_1 model_1 distribution_1#> 4 1 outliers_1 strength_1 model_1 distribution_1#> 5 2 outliers_1 strength_2 model_1 distribution_1#> 6 2 outliers_1 strength_2 model_1 distribution_1#> 7 2 outliers_1 strength_2 model_1 distribution_1#> 8 2 outliers_1 strength_2 model_1 distribution_1#> 9 3 outliers_1 strength_3 model_1 distribution_1#> 10 3 outliers_1 strength_3 model_1 distribution_1#> # ℹ 14 more rows#> # ℹ 11 more variables: term <chr>, estimate <dbl>, std.error <dbl>,#> # statistic <dbl>, p.value <dbl>, conf.low <dbl>, conf.high <dbl>,#> # outliers_branch_code <fct>, strength_branch_code <fct>,#> # model_branch_code <fct>, distribution_branch_code <fct>
The resulting data is atibble object and we can use regulartidyverse grammar to manipulate the data. In the code below, wespecifically focus on the estimated coefficient forMasFem and itsconfidence intervals.
library(dplyr)res %>% filter(term=="MasFem") %>% select(outliers_branch,strength_branch,term,estimate,conf.low,conf.high)#> # A tibble: 6 × 6#> outliers_branch strength_branch term estimate conf.low conf.high#> <fct> <fct> <chr> <dbl> <dbl> <dbl>#> 1 outliers_1 strength_1 MasFem 0.0623 0.0427 0.0822#> 2 outliers_1 strength_2 MasFem 0.0531 -0.00942 0.116#> 3 outliers_1 strength_3 MasFem -0.845 -1.59 -0.103#> 4 outliers_2 strength_1 MasFem 0.0623 0.0427 0.0822#> 5 outliers_2 strength_2 MasFem 0.0956 0.0301 0.161#> 6 outliers_2 strength_3 MasFem -1.02 -1.81 -0.247
We can also inspect the result graphically usingspec_curve(). Themethod builds a specification curve (Simonsohn, Simmons, and Nelson2020) for a term in the regression model specified byvar. The methodalso allows multiple ways of sorting the estimates. See?spec_curvefor details.
spec_summary(mv,var="MasFem") %>% spec_curve(spec_matrix_spacing=4)+ labs(colour="Significant at 0.05")
Jung, Kiju, Sharon Shavitt, Madhu Viswanathan, and Joseph M. Hilbe.2014. “Female Hurricanes Are Deadlier Than Male Hurricanes” 111 (24):8782–87.
Sarma, Abhraneel, Alex Kale, Michael Moon, Nathan Taback, FannyChevalier, Jessica Hullman, and Matthew Kay. 2021. “Multiverse:Multiplexing Alternative Data Analyses in R Notebooks (Version 0.5.0).”https://github.com/MUCollective/multiverse.
Simonsohn, Uri, Joseph P. Simmons, and Leif D. Nelson. 2020.“Specification Curve Analysis” 4 (July): 1208–14.
Steegen, Sara, Francis Tuerlinckx, Andrew Gelman, and Wolf Vanpaemel.2016. “Increasing Transparency Through a Multiverse Analysis” 11 (5):702–12.
About
R package for multiverse analysis. Extends R package multiverse with student and analyst friendly interfaces.
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Contributors4
Uh oh!
There was an error while loading.Please reload this page.

