-
Notifications
You must be signed in to change notification settings - Fork 0
/
NAMCS08-Analysis.Rmd
139 lines (107 loc) · 3.32 KB
/
NAMCS08-Analysis.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
---
title: "NAMCS-2008 Analysis with Shiny"
author: "shramesh"
#date: "8/21/2021"
output:
html_document:
toc: TRUE
toc_float: TRUE
runtime: shiny
---
```{r include=FALSE}
library(tidyverse)
library(shiny)
library(rlang) # to use !!parse_expr()
load('Data/namcs08.RData') #National Ambulatory Medical Care Survey (NAMCS) data
```
### Introduction
###### This shiny document is created using NAMCS 2008 dataset and I have used shiny widgets to create some plots and tables to understand some of the information in the dataset.
### Mean Systolic Blood Pressure (SBP)
```{r echo=FALSE}
selectInput('diagnosis', label = 'Which diagnosis would you like to explore?',
choices = c('Diabetes'='diabetes',
'Congestive Heart Failure' ='chf',
'Hypertension'= 'htn'))
selectInput('age_filter', label = 'For everyone?',
choices = c('Yes'='TRUE',
'Age greater than 65'= 'age > 65'))
renderTable({
left_join(patients,pmh) %>%
filter(!!parse_expr(input$age_filter)) %>%
group_by(!!parse_expr(input$diagnosis)) %>%
summarize(meanSBP = mean(sbp, na.rm = TRUE))
})
```
### Top reasons for visit
```{r echo=FALSE}
# sliderInput -> we don't have to parse_expr()
sliderInput('rows_to_show',
label = 'How many rows to show?',
min = 1,
max = 10,
step = 1,
value = 5)
renderTable({
patients %>%
group_by(Sex = sex,
`Visit Reason` = visitreason) %>%
summarize(count=n()) %>%
arrange(desc(count)) %>%
group_by(Sex) %>%
slice(1:input$rows_to_show)
})
```
### Insurance used by patients
```{r echo=FALSE }
patients %>%
ggplot(aes(x=fct_infreq(paytype))) +
geom_bar()+
labs(x="Insurance Type", y="Frequency") +
coord_flip()
```
### Relation between age and height/weight
```{r echo=FALSE}
selectInput('yvar', label = 'Which variable on y axis?',
choices = c('height','weight'))
sliderInput('age_range',
label = 'What is the age range?',
min = 0, max = 100,
value = c(0,100),
step = 10)
checkboxInput('smoothed_line',
label = 'Should we show the smoothed line?',
value = FALSE)
renderPlot({
age_plot = patients %>%
ggplot(aes(x=age,y=!!parse_expr(input$yvar))) +
geom_point() +
coord_cartesian(xlim = c(input$age_range[1], input$age_range[2]))
if(input$smoothed_line) { #if_else will not work with ggplot
age_plot + geom_smooth()
} else {
age_plot
}
})
```
### Relation between depression and diabetes
```{r echo=FALSE}
selectInput('x_mapping',
label = 'What is on the x axis?',
choices = c('Diabetes'='diabetes',
'Depression'='depression'))
selectInput('fill_mapping',
label = 'What is being filled?',
choices = c('Depression'='depression'
,'Diabetes'='diabetes'))
renderPlot({
pmh %>%
mutate(diabetes = if_else(diabetes == 1, 'Diabetes','No diabetes')) %>%
mutate(depression = if_else(depression == 1, 'Depression','No depression')) %>%
ggplot(aes(x=!!parse_expr(input$x_mapping),
fill=!!parse_expr(input$fill_mapping))) +
geom_bar(position='fill') +
theme_minimal()+
scale_fill_manual(values=c("darkcyan","darksalmon")) +
labs(y="Proportion")
})
```