Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/TysonStanley/furniture
The furniture R package contains table1 for publication-ready simple and stratified descriptive statistics, tableC for publication-ready correlation matrixes, and other tables #rstats
https://github.com/TysonStanley/furniture
cran descriptive-statistics exploratory-data-analysis health table-one table1 tables tidy tidyverse
Last synced: 3 months ago
JSON representation
The furniture R package contains table1 for publication-ready simple and stratified descriptive statistics, tableC for publication-ready correlation matrixes, and other tables #rstats
- Host: GitHub
- URL: https://github.com/TysonStanley/furniture
- Owner: TysonStanley
- Created: 2016-06-29T02:23:57.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-02-13T18:37:04.000Z (9 months ago)
- Last Synced: 2024-05-21T02:53:50.360Z (6 months ago)
- Topics: cran, descriptive-statistics, exploratory-data-analysis, health, table-one, table1, tables, tidy, tidyverse
- Language: R
- Homepage:
- Size: 4.2 MB
- Stars: 49
- Watchers: 3
- Forks: 6
- Open Issues: 5
-
Metadata Files:
- Readme: README.Rmd
Awesome Lists containing this project
README
---
output: github_document
---```{r, echo = FALSE, message=FALSE, warning=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
devtools::load_all()
```[![CRAN Status Badge](https://www.r-pkg.org/badges/version/furniture)](https://cran.r-project.org/package=furniture)
![Downloads](https://cranlogs.r-pkg.org/badges/grand-total/furniture)
[![R-CMD-check](https://github.com/TysonStanley/furniture/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/TysonStanley/furniture/actions/workflows/R-CMD-check.yaml)# furniture: `v1.10.0`
The furniture R package contains functions to help with data cleaning/tidying (e.g., `washer()`, `rowmeans()`, `rowsums()`), exploratory data analysis and reporting (e.g., `table1()`, `tableC()`, `tableF()`). It currently contains eight main functions:
1. `table1()` : gives a well-formatted table for academic publication of descriptive statistics. Very useful for quick analyses as well. Notably, `table1()` now works with `dplyr::group_by()`.
2. `tableC()` : gives a well-formatted table of correlations.
3. `tableF()` : provides a thorough frequency table for quick checks of the levels of a variable.
4. `washer()` : changes several values in a variable (very useful for changing place holder values to missing).
5. `long()` : is a wrapper of `stats::reshape()`, takes the data from wide to long format (long is often the tidy version of the data), works well with the tidyverse, and can handle unbalanced multilevel data.
6. `wide()` : also a wrapper of `stats::reshape()`, takes the data from long to wide, and like `long()`, works well with the tidyverse and can handle unbalanced multilevel data.
7. `rowmeans()` and `rowmeans.n()` : tidyverse friendly versions of `rowMeans()`, where the `rowmeans.n()` function allows `n` number of missing
8. `rowsums()` and `rowsums.n()` : tidyverse friendly versions of `rowSums()`, where the `rowsums.n()` function allows `n` number of missingIn conjunction with many other tidy tools, the package should be useful for health, behavioral, and social scientists working on quantitative research.
# Installation
The latest stable build of the package can be downloaded from CRAN via:
```{r, eval = FALSE}
install.packages("furniture")
```You can download the developmental version via:
```{r, eval = FALSE}
remotes::install_github("tysonstanley/furniture")
```# Using furniture
The main functions are the `table*()` functions (e.g., `table1()`, `tableC()`, `tableF()`).
```{r}
library(furniture)
``````{r}
data("nhanes_2010")table1(nhanes_2010,
age, marijuana, illicit, rehab,
splitby=~asthma,
na.rm = FALSE)
``````{r}
table1(nhanes_2010,
age, marijuana, illicit, rehab,
splitby=~asthma,
output = "text2",
na.rm = FALSE)
``````{r, warning=FALSE, message=FALSE}
library(tidyverse)
nhanes_2010 %>%
group_by(asthma) %>%
table1(age, marijuana, illicit, rehab,
output = "text2",
na.rm = FALSE)
````table1()` can do bivariate significance tests as well.
```{r, warning=FALSE, message=FALSE}
library(tidyverse)
nhanes_2010 %>%
group_by(asthma) %>%
table1(age, marijuana, illicit, rehab,
output = "text2",
na.rm = FALSE,
test = TRUE)
```By default it does the appropriate parametric tests. However, you can change that by setting `param = FALSE` (new with `v 1.9.1`).
```{r, warning=FALSE, message=FALSE}
library(tidyverse)
nhanes_2010 %>%
group_by(asthma) %>%
table1(age, marijuana, illicit, rehab,
output = "text2",
na.rm = FALSE,
test = TRUE,
param = FALSE,
type = "condense")
```It can also do a total column with the stratified columns (new with `v 1.9.0`) with the `total = TRUE` argument.
```{r, warning=FALSE, message=FALSE}
nhanes_2010 %>%
group_by(asthma) %>%
table1(age, marijuana, illicit, rehab,
output = "text2",
na.rm = FALSE,
test = TRUE,
type = "condense",
total = TRUE)
```It can also report the statistics in addition to the p-values.
```{r, warning=FALSE, message=FALSE}
nhanes_2010 %>%
group_by(asthma) %>%
table1(age, marijuana, illicit, rehab,
output = "text2",
na.rm = FALSE,
test = TRUE,
total = TRUE,
type = "full")
````table1()` can be outputted directly to other formats. All `knitr::kable()` options are available for this and there is an extra option `"latex2"` which provides a publication ready table in Latex documents.
A new function `table1_gt()` integrates the fantastic `gt` package to make beautiful HTML tables for table1.
```{r, results='asis'}
nhanes_2010 %>%
group_by(asthma) %>%
table1(age, marijuana, illicit, rehab, na.rm = FALSE) %>%
table1_gt() %>%
print()
```The `tableC()` function gives a well-formatted correlation table.
```{r}
tableC(nhanes_2010,
age, active, vig_active,
na.rm=TRUE)
```The `tableF()` function gives a table of frequencies.
```{r}
tableF(nhanes_2010, age)
```In addition, the `rowmeans()` and `rowsums()` functions offer a simplified use of `rowMeans()` and `rowSums()`, particularly when using the tidyverse's `mutate()`.
```{r}
nhanes_2010 %>%
select(vig_active, mod_active) %>%
mutate(avg_active = rowmeans(vig_active, mod_active, na.rm=TRUE)) %>%
mutate(sum_active = rowsums(vig_active, mod_active, na.rm=TRUE)) %>%
head()
```The `rowmeans.n()` and `rowsums.n()` allow `n` missing values while still calculating the mean or sum.
```{r}
df <- data.frame(
x = c(NA, 1:5),
y = c(1:5, NA)
)df %>%
mutate(avg = rowmeans.n(x, y, n = 1))
```## Notes
The package is most useful in conjunction with other tidy tools to get data cleaned/tidied and start exploratory data analysis. I recommend using packages such as `library(dplyr)`, `library(tidyr)`, and `library(ggplot2)` with `library(furniture)` to accomplish this.
The original function--`table1()`--is simply built for both exploratory descriptive analysis and communication of findings. See vignettes or [tysonbarrett.com](https://tysonstanley.github.io/) for several examples of its use. Also see our paper in the [R Journal](https://journal.r-project.org/archive/2017/RJ-2017-037/RJ-2017-037.pdf).