knitr::opts_chunk$set(echo = TRUE)
require(haven)
## Loading required package: haven
library(tidyr)
library(ggstatsplot)
## You can cite this package as:
##      Patil, I. (2021). Visualizations with statistical details: The 'ggstatsplot' approach.
##      Journal of Open Source Software, 6(61), 3167, doi:10.21105/joss.03167
library(ggpubr)
## Loading required package: ggplot2
library(epiDisplay)
## Loading required package: foreign
## Loading required package: survival
## Loading required package: MASS
## Loading required package: nnet
## 
## Attaching package: 'epiDisplay'
## The following object is masked from 'package:ggplot2':
## 
##     alpha
library(writexl)
library(readxl)
library(ggprism)
library(patchwork)
## 
## Attaching package: 'patchwork'
## The following object is masked from 'package:MASS':
## 
##     area
library(magrittr)
## 
## Attaching package: 'magrittr'
## The following object is masked from 'package:tidyr':
## 
##     extract
library(gtsummary)
## 
## Attaching package: 'gtsummary'
## The following object is masked from 'package:MASS':
## 
##     select
library(FSA)
## Registered S3 methods overwritten by 'FSA':
##   method       from
##   confint.boot car 
##   hist.boot    car
## ## FSA v0.9.4. See citation('FSA') if used in publication.
## ## Run fishR() for related website and fishR('IFAR') for related book.
library(RColorBrewer)
library(ggsci)
library(ggsignif)
library(patchwork)
library(magrittr)
library(gtsummary)
library(patchwork)
library(magrittr)
library(gtsummary)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:MASS':
## 
##     select
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyverse)
## ── Attaching packages
## ───────────────────────────────────────
## tidyverse 1.3.2 ──
## ✔ tibble  3.1.8     ✔ stringr 1.5.0
## ✔ readr   2.1.3     ✔ forcats 0.5.2
## ✔ purrr   1.0.1     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ epiDisplay::alpha() masks ggplot2::alpha()
## ✖ magrittr::extract() masks tidyr::extract()
## ✖ dplyr::filter()     masks stats::filter()
## ✖ dplyr::lag()        masks stats::lag()
## ✖ dplyr::select()     masks gtsummary::select(), MASS::select()
## ✖ purrr::set_names()  masks magrittr::set_names()
library(data.table)
## 
## Attaching package: 'data.table'
## 
## The following object is masked from 'package:purrr':
## 
##     transpose
## 
## The following objects are masked from 'package:dplyr':
## 
##     between, first, last
library(ggplot2)
library(epiDisplay)
library(writexl)
library(stringr)
library(SciViews)
library(trend)
library(aod)
## 
## Attaching package: 'aod'
## 
## The following object is masked from 'package:survival':
## 
##     rats
data <- read_excel("/Users/taylorpyle/Library/Group Containers/UBF8T346G9.OneDriveSyncClientSuite/OneDrive - University of North Carolina at Chapel Hill.noindex/OneDrive - University of North Carolina at Chapel Hill/Dr. Roberts/Dysphagia.xlsx")

data <- data %>% 
  mutate(Age=cut(Age_m, breaks=c(-Inf, 12, 24, 36, 48), labels=c("0-12 Months", "13-24 Months","25-36 Months", "26-48 Months")))

data$improvement[data$improvement == "No"] <- "N"
data$improvement[data$improvement == "x"] <- "Y"
data$Sex[data$Sex == "F"] <- "Female"
data$Sex[data$Sex == "M"] <- "Male"
data$improvement[data$improvement == "N"] <- "No Improvement"
data$improvement[data$improvement == "Y"] <- "Improvement"
data$Sex[data$Sex == "F"] <- "Female"
data$Sex[data$Sex == "M"] <- "Male"

tabledata <- data.frame(data$improvement,
                        Sex = data$Sex, 
                        Indication = data$Indication,
                        Volume = data$volume,
                        Age = data$Age,
                        Comorbidities = data$Comorbidities)

tbl_summary(tabledata, by = data.improvement) 
Characteristic Improvement, N = 351 No Improvement, N = 111
Sex
    Female 17 (49%) 6 (55%)
    Male 18 (51%) 5 (45%)
Indication
    Aspiration on thin liquids 15 (43%) 2 (18%)
    Dysphagia 15 (43%) 6 (55%)
    Laryngomalacia 2 (5.7%) 1 (9.1%)
    Vocal cord paralysis 3 (8.6%) 2 (18%)
Volume
    0.1 8 (23%) 4 (36%)
    0.2 14 (40%) 4 (36%)
    0.3 7 (20%) 1 (9.1%)
    0.4 1 (2.9%) 1 (9.1%)
    0.5 5 (14%) 1 (9.1%)
Age
    0-12 Months 14 (40%) 4 (36%)
    13-24 Months 12 (34%) 2 (18%)
    25-36 Months 6 (17%) 5 (45%)
    26-48 Months 3 (8.6%) 0 (0%)
Comorbidities
    Ankyloglossia 4 (11%) 0 (0%)
    Asthma 10 (29%) 7 (64%)
    GERD 14 (40%) 2 (18%)
    Preterm 6 (17%) 0 (0%)
    Trisomy 21 1 (2.9%) 2 (18%)
1 n (%)
library(stargazer)
## 
## Please cite as:
##  Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
##  R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
stargazer(tabledata, type = 'html') 
## 
## <table style="text-align:center"><tr><td colspan="6" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">Statistic</td><td>N</td><td>Mean</td><td>St. Dev.</td><td>Min</td><td>Max</td></tr>
## <tr><td colspan="6" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">Volume</td><td>46</td><td>0.239</td><td>0.129</td><td>0.100</td><td>0.500</td></tr>
## <tr><td colspan="6" style="border-bottom: 1px solid black"></td></tr></table>

#statistics

fisher.test(table(data$improvement, data$Age))
## 
##  Fisher's Exact Test for Count Data
## 
## data:  table(data$improvement, data$Age)
## p-value = 0.2833
## alternative hypothesis: two.sided
fisher.test(table(data$improvement, data$volume))
## 
##  Fisher's Exact Test for Count Data
## 
## data:  table(data$improvement, data$volume)
## p-value = 0.6824
## alternative hypothesis: two.sided
fisher.test(table(data$improvement, data$Sex))
## 
##  Fisher's Exact Test for Count Data
## 
## data:  table(data$improvement, data$Sex)
## p-value = 1
## alternative hypothesis: true odds ratio is not equal to 1
## 95 percent confidence interval:
##  0.158389 3.781413
## sample estimates:
## odds ratio 
##  0.7911508