Skip to content

Instantly share code, notes, and snippets.

View stephenrho's full-sized avatar

Stephen Rhodes stephenrho

  • UH Cleveland Medical Center
  • USA
View GitHub Profile
@stephenrho
stephenrho / query_fda.R
Last active July 16, 2024 18:27
Get NDC and RxCui from openFDA via generic drug name
query_fda <- function(dname, route){
dname <- gsub(" ", "%", dname)
dname <- sprintf('"%s"', dname) # enclose in quotes
if (!missing(route) & !is.null(route)){
dname <- sprintf('%s+AND+route:"%s"', dname, route)
}
url <- sprintf('https://api.fda.gov/drug/ndc.json?search=generic_name:%s&limit=100', dname)
res <- httr::GET(url)$content |>
@stephenrho
stephenrho / load_nis.R
Last active June 12, 2024 18:06
Load NIS data ("Core", "Hospital", or "Severity") into R
# Note: I have only tested this on 2016-2020
# need `fs` and `readr` installed
#' Get NIS file specifications
#'
#' @description
#' Uses stata load files from hcup-us.ahrq.gov to get specs for loading NIS files
#'
#' @param year of interest
#' @param file "Core", "Hospital", or "Severity"
# model from Sheyn et al. https://pubmed.ncbi.nlm.nih.gov/35830590/
# predictions recalibrated by Rhodea et al. [unpublished, will add link when published]
# set recalibrate = FALSE for original model
cms_model = function(Age, PVD=0, Diabetes_complicated=0, COPD=0,
Mesh=0, Abdominal_sacrocolpopexy=0, Sling=0,
Transfusion=0, Bowel_injury=0, Hemiplegia_or_paraplegia=0,
return_lin_pred=FALSE, recalibrate = TRUE, intercept = -2.18, slope = 0.66){
# Age = in years
# PVD = Current peripheral vascular disease
@stephenrho
stephenrho / chr.R
Created September 14, 2022 21:05
code to calculate scores underlying county health rankings
# https://www.countyhealthrankings.org/explore-health-rankings/our-methods/calculating-ranks
library(data.table)
chr = fread("https://www.countyhealthrankings.org/sites/default/files/media/document/analytic_data2022.csv", skip = 1)
# https://www.countyhealthrankings.org/sites/default/files/media/document/2022%20Ranked%20and%20Additional%20Measures%2C%20Data%20Sources%20and%20Years_0.pdf
measures = list(
# note some are reverse coded (see -ve weights)
health_behaviors = list(