Created
December 3, 2016 22:09
-
-
Save cmgiven/84f9920e49ded0cca75637b843b6078b to your computer and use it in GitHub Desktop.
Behavioral Health Event Co-Occurence
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
library("dplyr") | |
library("tidyr") | |
library("cooccur") | |
options(stringsAsFactors=FALSE) | |
bhs <- read.csv("Behavioral Health Services - higher grouping.csv") %>% | |
mutate( | |
SVC_START_DT = as.Date(SVC_START_DT, "%m/%d/%Y"), | |
SVC_END_DT = as.Date(SVC_END_DT, "%m/%d/%Y"), | |
SUBMT_DT = as.Date(SUBMT_DT, "%m/%d/%Y"), | |
SERVICE_CAT_HIGHER = ifelse(SERVICE_CAT_HIGHER == "#N/A", NA, trimws(SERVICE_CAT_HIGHER)) | |
) | |
cooccur_data <- bhs %>% | |
select(MCI_UNIQ_ID, SERVICE_CAT_HIGHER) %>% | |
filter(SERVICE_CAT_HIGHER != "") %>% | |
count(MCI_UNIQ_ID, SERVICE_CAT_HIGHER) %>% | |
mutate(n = ifelse(n > 0, 1, 0)) %>% | |
spread(SERVICE_CAT_HIGHER, n, fill = 0) %>% | |
select(-MCI_UNIQ_ID) %>% | |
as.matrix() %>% | |
t() | |
cooccur_result <- cooccur(cooccur_data, spp_names = TRUE) | |
plot(cooccur_result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment