Skip to content

Instantly share code, notes, and snippets.

View ericpgreen's full-sized avatar

Eric Green ericpgreen

View GitHub Profile
{
"next": null,
"previous": null,
"results": [
{
"id": 1234,
"uuid": "esn4dk",
"flow": {
"uuid": "whsj5ei",
"name": "weeklyratings"
---
title: "Classify"
output:
flexdashboard::flex_dashboard:
orientation: columns
#logo: # add the relative path/file.png
#favicon: # add the relative path/file.png
theme: bootstrap
#css: custom.css # add the relative path/file.css
vertical_layout: fill
library(tidyverse)
library(ggrepel)
dat <- structure(list(quarter = 1:48,
year = c(2001L, 2001L, 2001L, 2001L, 2002L, 2002L, 2002L,
2002L, 2003L, 2003L, 2003L, 2003L, 2004L, 2004L,
2004L, 2004L, 2005L, 2005L, 2005L, 2005L, 2006L,
2006L, 2006L, 2006L, 2007L, 2007L, 2007L, 2007L,
2008L, 2008L, 2008L, 2008L, 2009L, 2009L, 2009L,
2009L, 2010L, 2010L, 2010L, 2010L, 2011L, 2011L,
# Plot code for https://medium.com/@ericpgreen/my-wife-couldnt-sleep-550e206cd80a
# Eric Green, @ericpgreen
library(tidyverse)
library(ggrepel)
library(lubridate)
# Puljic et al. (2015). The risk of infant and fetal death by each additional week of expectant management in intrahepatic cholestasis of pregnancy by gestational age. American Journal of Obstetrics and Gynecology, 212(5), 667-e1.
# create dataframe from published table
puljic <- data.frame(ga=c(rep(seq(from=34, to=40, by=1), 2)),
# convert back to wide for alluvial
datW <-
datL %>%
# long to wide
select(ID, w1group, time, depress, dep16) %>%
gather(key = variable, value = value, -ID, -w1group, -time) %>%
unite(variableT, variable, time, sep=".") %>%
spread(variableT, value) %>%
# alluvial prep
filter(complete.cases(.)) %>%
# plot individual lines
ggplot() +
# plot N-2 as a base layer
geom_line(data = datL[datL$highlight>2,],
aes(time, depress, color=factor(highlight), group=ID), size=0.5) +
# highlight two individuals and plot them second to appear on top
geom_line(data = datL[datL$highlight<3,],
aes(time, depress, color=factor(highlight), group=ID), size=1) +
scale_color_manual(values=c("#ff0000", "#0000ff", "#D3D3D3")) +
scale_size_manual(values=c(1, 1, 0.5)) +
# load packages
library(tidyverse)
library(RCurl)
library(magrittr)
# get the data
csv <- getURL("https://raw.githubusercontent.com/ericpgreen/JCPP2018/master/data%20and%20replication%20files/input/dat.csv")
dat <- read.csv(text = csv)
# data wrangling
@ericpgreen
ericpgreen / rfeEx2.csv
Created June 29, 2017 08:31
rfe example 2
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 84 columns, instead of 46 in line 1.
"","class","v1","v2","v3","v4","v5","v6","v7","v8","v9","v10","v11","v12","v13","v14","v15","v16","v17","v18","v19","v20","v21","v22","v23","v24","v25","v26","v27","v28","v29","v30","v31","v32","v33","v34","v35","v36","v37","v38","v39","v40","v41","v42","v43","v44","v45","v46","v47","v48","v49","v50","v51","v52","v53","v54","v55","v56","v57","v58","v59","v60","v61","v62","v63","v64","v65","v66","v67","v68","v69","v70","v71","v72","v73","v74","v75","v76","v77","v78","v79","v80","v81","v82"
"1","1",0.666666666666667,0.888888888888889,0.888888888888889,1,1,0.888888888888889,1,1,0.777777777777778,1,1,1,0.888888888888889,1,0.777777777777778,0.777777777777778,0.888888888888889,0,1,1,0.888888888888889,1,0.777777777777778,0.888888888888889,1,0.888888888888889,0.888888888888889,0.777777777777778,0.888888888888889,0.777777777777778,0.777777777777778,1,1,0.777777777777778,1,0.888888888888889,0.777777777777778,0.666666666666667,0.888888888888889,0.666666666666667,0.555555555555556,0.888888888888889,0.777777777777778,0.77
@ericpgreen
ericpgreen / rfe-example.csv
Created June 27, 2017 09:08
rfe example csv
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 76 columns, instead of 38 in line 1.
"","class","v1","v2","v3","v4","v5","v6","v7","v8","v9","v10","v11","v12","v13","v14","v15","v16","v17","v18","v19","v20","v21","v22","v23","v24","v25","v26","v27","v28","v29","v30","v31","v32","v33","v34","v35","v36","v37","v38","v39","v40","v41","v42","v43","v44","v45","v46","v47","v48","v49","v50","v51","v52","v53","v54","v55","v56","v57","v58","v59","v60","v61","v62","v63","v64","v65","v66","v67","v68","v69","v70","v71","v72","v73","v74"
"1",1,0.777777777777778,0.777777777777778,0.666666666666667,0.888888888888889,1,0.888888888888889,1,0.888888888888889,0.666666666666667,0.777777777777778,0.555555555555556,0.777777777777778,0.777777777777778,1,0.888888888888889,0.888888888888889,0.777777777777778,0.333333333333333,0.555555555555556,0.777777777777778,0.444444444444444,0.777777777777778,0.888888888888889,0.888888888888889,0.777777777777778,0.888888888888889,0.777777777777778,0.666666666666667,0.777777777777778,1,0.888888888888889,0.777777777777778,0.777777777777778,0.777777777777778,0.444444444444444,0.7777
@ericpgreen
ericpgreen / df.R
Created June 27, 2017 09:04
rfe example data
df <- structure(list(class = c(1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 1, 1), v1 = c(0.777777777777778, 0.888888888888889, 0.888888888888889,
0.777777777777778, 0.111111111111111, 0.444444444444444, 0.444444444444444,
0.888888888888889, 0.222222222222222, 0.777777777777778, 0.444444444444444,
0.444444444444444, 0.555555555555556, 0.444444444444444, 0.333333333333333,
1, 0.444444444444444, 0.777777777777778, 0.888888888888889, 0.777777777777778,
0.888888888888889, 0.777777777777778, 0, 0.888888888888889, 0.888888888888889,
0.777777777777778, 0.888888888888889, 0.888888888888889, 0.777777777777778,
0.888888888888889, 0.777777777777778, 0.777777777777778, 0.888888888888889,