This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# write some code and sit on it | |
mycode <- quote(1 + 2 +3) | |
# some time later, at your convenience, evaluate the code | |
eval(mycode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# come up with some code elements | |
num1 <- 10 | |
num2 <- 5 | |
operators <- c('+','-') | |
# create a string of the desired code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# calculate the mixing matrix of in igraph graph object 'mygraph', by some vertex attribute 'attrib' | |
# can change the default use.density=FALSE to return a matrix with raw number of edges rather than density | |
mixmat <- function(mygraph, attrib, use.density=TRUE) { | |
require(igraph) | |
# get unique list of characteristics of the attribute | |
attlist <- sort(unique(get.vertex.attribute(mygraph,attrib))) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# calculate the assortativity coefficient for a mixing matrix of a graph | |
# ref: MEJ Newman, 'Mixing patterns in networks', Phys Rev E 67, 026126 (2003) | |
# | |
# define assortativity coefficient as | |
# trace (m) - sum (m^2) | |
# ac = ------------------------- | |
# 1 - sum (m^2) | |
# | |
# where m is the mixing matrix of a graph |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sample calculating mixing matrix and assortativity coefficient with igraph | |
require(igraph) | |
set.seed(12) | |
# create a random graph | |
g <- random.graph.game(1000,0.15) | |
# assign some characteristics | |
V(g)$color <- c('red','white','blue','orange','green') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this script finds ambulatory sensitive conditions (ACSCs) in ICD-9 codes | |
# the data are based on the appendices from | |
# http://www.ahrq.gov/downloads/pub/ahrqqi/pqiguide.pdf (Appendix A) | |
# usage: acsc(list_of_icd9_dx_codes, list_of_drgcodes, list_of_icd9_proc_codes) | |
# returns: TRUE or FALSE | |
# or set getlist = TRUE to get the list of which ACSCs were found | |
# NB. that some of the definitions for these PQIs exclude hospital transfers | |
# paripartum admissions, or certain age groups, etc. | |
# This script ***only*** assess ACSC status by ICD-9 code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Convert ICD 9 to ICD 10 codes based on the CMS General Equivalency Mappings 2016 | |
# https://www.cms.gov/Medicare/Coding/ICD10/2016-ICD-10-CM-and-GEMs.html | |
library(data.table) | |
library(icd) | |
gem <- fread('~/Desktop/SCIP - Study of Critical Illness Pathways/2018-redo/final_code/2016-General-Equivalence-Mappings/2016_I9gem.txt', | |
colClasses = rep('character',3)) | |
setnames(gem, c('icd9', 'icd10', 'flags_composite')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# extract the ICD10 Cardiac procedure codes from PDF | |
# Appendix B of AHRQ PQI v6.0 | |
require(pdftools) | |
download.file(url = 'http://www.qualityindicators.ahrq.gov/Downloads/Modules/PQI/V60/TechSpecs/PQI_Appendix_B.pdf', | |
destfile = 'PQI_Appendix_B.pdf') | |
raw_text_pages <- pdf_text('PQI_Appendix_B.pdf') | |
raw_text <- paste(raw_text_list, collapse = '') | |
tokens <- unlist(strsplit(raw_text, split = "\\s")) | |
tokens_filt <- tokens[ ! tokens %in% c('APPENDIX', '(ACSCARP)')] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# highlight communities and clusters in an igraph plot | |
library(igraph) | |
g <- erdos.renyi.game(50, .02) | |
# plot regular | |
plot(g) |
OlderNewer