-
Notifications
You must be signed in to change notification settings - Fork 3
/
dataAnalytics.R
167 lines (139 loc) · 4.25 KB
/
dataAnalytics.R
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
mydata <- read.csv("mydata.csv")
mydata <- sas.get("data.sas7bdat")
mydata <- read_sas("data.sas7bdat")
mydata <- read.dta("c:/mydata.dta")
str_detect(mydata$linename, "Rituximab")
str_subset(mydata$linename, "Rituximab")
str_trim(mydata$linename) # removes whitespace for variable
# Find top 5 most frequent lines ("linename") for each line of therapy ("linenumber")
library("dplyr")
library("tidyr")
mydata %>%
group_by(linenumber,linename) %>%
summarise(n=n()) %>%
top_n(5) %>%
arrange(desc(n))
labresults <- mydata %>%
filter(linenumber<=4) %>%
left_join(
mydata.labs %>%
filter(labcomponent %in% c("Biomarker1", "Biomarker2, "ADA3")) %>%
select(patientid, practicetype, labcomponent, resultdate, testunitscleaned, testresultcleaned)
) %>%
group_by(patientid, labcomponent, linenumber) %>%
filter(resultdate>=startdate & resultdate<=enddate) %>%
filter(resultdate==min(resultdate)) %>%
ungroup()
labresults_wide <- data.frame(
labresults %>%
select(patientid, practicetype, linenumber, labcomponent, testresultcleaned) %>%
group_by(linenumber) %>%
mutate(grouped_id = row_number()) %>%
spread(labcomponent, testresultcleaned) %>%
group_by(patientid, linenumber) %>%
summarise_each(funs(max(., na.rm = TRUE)))
)
library(table1)
# summary table with remaining variables and stratify by practice type
table1( ~. | practicetype, data=labresults_wide %>%
filter(linenumber==1) %>%
select(~c(patientid, grouped_id, linenumber))
)
model(Y ~ X1 + X2, data=data)
library("glm", "glmnet") # linear models
glm()
glmnet()
cv.glmnet()
predict()
library("lme4", "nlme") # mixed-effect models
lmer()
nlme()
predict()
library("survival") # survival models
Survfit()
Surv(Time, Event)
predict()
library(srvminer) # draw survival curves
ggsurvplot()
library(caret) # machine learning
createDataPartition()
train()
predict()
# Regression, Random forest, Gradient boosting, Support vector machine, Naive Bayes, Neural nets, etc.
# data frame of mortality
# patientid\tduration\tevent01\tlinenumber
# model survival by line of therapy
mydata.os.drug <- survfit(Surv(duration, Event) ~ linenumber, data = refractoryPatients)
ggsurvplot(
mydata,
data = refractoryPatients,
risk.table = TRUE,
xlab = "Time in days",
surv.median.line = "v",
break.time.by = 120,
title = "Indication Drug-refractory overall survival by line of therapy"
)
# distribution of indication stage (at initial diagnosis) by patient birth year
mydata3 <- indication.demographics[,c("patientid", "stage", "birthyear")]
# plot birth year on x-axis
ggplot(mydata3, aes(birthyear)) +
# fill color by indication stage
geom_bar(aes(fill=stage)) +
theme_minimal() +
ggtitle("Distribution of indication stage by patient birth year")
library("cowplot")
p1 <- ggplot(mydata3, aes(birthyear)) +
# fill color by indication stage
geom_bar(aes(fill=stage)) +
theme_minimal() +
ggtitle("Distribution of indication stage by patient birth year")
p2 <- ggplot(mydata3, aes(birthyear)) +
# fill color by indication stage
geom_bar(aes(fill=stage)) +
theme_minimal() +
ggtitle("Distribution of indication stage by patient birth year")
p3 <- ggplot(mydata3, aes(birthyear)) +
# fill color by indication stage
geom_bar(aes(fill=stage)) +
theme_minimal() +
ggtitle("Distribution of indication stage by patient birth year")
plot_grid(p1,p2,p3, ncol=1)
# Result presentation with R Markdown and knitr
## Access Data- RocheTeradata, RWDSverse, Hmisc/foreign/haven
## Manipulate, Wrangle Data- dplyr, tidyr, lubridate, stringr, data.table
## Model- glm/glmnet, lme4/nlme, survival, survminer, caret
## Output- knitr, table1, kableExtra, ggplot2, gridExtra, cowplot, plotly
---
title: "Template Report"
author: "Jeffrey Long"
date: "//2019"
output:
html_document:
toc: true
---
This is a report on indication, drug, assay.
```{r package_options, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Libraries
```{r message=FALSE, warning=FALSE, echo=FALSE}
library(tidyverse)
library(dplyr)
library(table1)
```
## Code
### Get data
```{r echo=FALSE, warning=FALSE}
con <- connect_to_data(datalab = "myData",
type = 'TYPE',
uid = "longj25",
pwd = readLines("~/.ssh/.pass"))
```
### Data wrangling
```{r}
# code here
```
### Results
```{r}
# code here
```