Title: | Pull North Carolina Covid-19 Outbreak Information |
---|---|
Description: | This package allows users to easily retrieve data that have been pulled from the North Carolina Department of Health and Human Services Covid-19 Dashboard. |
Authors: | Michael DeWitt [aut, cre] , Jennifer Wenner [aut], Cone Health [aut, cph] |
Maintainer: | Michael DeWitt <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.21 |
Built: | 2024-11-21 03:04:30 UTC |
Source: | https://github.com/conedatascience/nccovid |
Estimate the aerosol concentration given environment parameters
aerosol_concentration( room_area = 60, room_height = 3, emission_breathing = 0.06, emission_speaking = 0.6, speaking_ratio = 0.1, resp_rate = 10 )
aerosol_concentration( room_area = 60, room_height = 3, emission_breathing = 0.06, emission_speaking = 0.6, speaking_ratio = 0.1, resp_rate = 10 )
room_area |
a double, meters squared |
room_height |
a double, meters |
emission_breathing |
a double, emission while breathing cm^3 |
emission_speaking |
a double, emission while speaking cm^3 |
speaking_ratio |
a double, between 0 and 1 for ratio between speaking and breathing |
resp_rate |
a double, the respiratory rate in liters per minute |
Estimate the aerosol emission rate per hours
aerosol_emission( emission_breathing = 0.06, emission_speaking = 0.6, speaking_ratio = 0.1, resp_rate = 10 )
aerosol_emission( emission_breathing = 0.06, emission_speaking = 0.6, speaking_ratio = 0.1, resp_rate = 10 )
emission_breathing |
a double, emission while breathing cm^3 |
emission_speaking |
a double, emission while speaking cm^3 |
speaking_ratio |
a double, between 0 and 1 for ratio between speaking and breathing |
resp_rate |
a double, the respiratory rate in liters per minute |
Uses a Taylor approximation for repeated Binomial trials Classically associated with the "Birthday Problem"
calc_risk(I, n, pop)
calc_risk(I, n, pop)
I |
integer, the number of persons infected |
n |
integer, the number of contacts per day |
pop |
integer, the total population |
P(A) = 1- P(A)'
Considering Proportion of the Vaccinated and Those Who Were Infected
calculate_community_immunity(prop_infected, prop_vaccinated)
calculate_community_immunity(prop_infected, prop_vaccinated)
prop_infected |
a numeric representing the proportion of the population with natural infection |
prop_vaccinated |
a numeric representing the proportion of the population that is vaccinated. |
Lopman, B. A. et al. A framework for monitoring population immunity to SARS-CoV-2. Annals of Epidemiology S1047279721002635 (2021) doi:10.1016/j.annepidem.2021.08.013.
{ calculate_community_immunity(.3,.5) plot(seq(.4,.7,.1), calculate_community_immunity(prop_infected = seq(.4,.7,.1), prop_vaccinated = .5), ylab = "Community Immunity", xlab = "Proportion Infected", main = "Community Immunity Given 50% Vaccinated", adj =0) }
{ calculate_community_immunity(.3,.5) plot(seq(.4,.7,.1), calculate_community_immunity(prop_infected = seq(.4,.7,.1), prop_vaccinated = .5), ylab = "Community Immunity", xlab = "Proportion Infected", main = "Community Immunity Given 50% Vaccinated", adj =0) }
Calculate Shannon Index for a Series
calculate_shannon(incidence)
calculate_shannon(incidence)
incidence |
numeric, the case incidence |
double, the intensity of epidemic calculated via Shannon index
dat <- nccovid::get_covid_state(c("Guilford", "Forsyth", "Mecklenburg", "Wake")) library(dplyr) library(ggplot2) counties <- unique(dat$county) entropy_values = dat %>% group_by(county) %>% dplyr::group_split() %>% lapply( function(x) calculate_shannon(incidence = x$cases_daily) ) %>% unlist() entropy_values = data.frame(county = counties, intensity = entropy_values) entropy_values %>% filter(county %in% nccovid::triad_counties) %>% ggplot(aes(reorder(county,intensity), intensity))+ geom_point()+ coord_flip()+ labs( title = "Epidemic Intensity" )
dat <- nccovid::get_covid_state(c("Guilford", "Forsyth", "Mecklenburg", "Wake")) library(dplyr) library(ggplot2) counties <- unique(dat$county) entropy_values = dat %>% group_by(county) %>% dplyr::group_split() %>% lapply( function(x) calculate_shannon(incidence = x$cases_daily) ) %>% unlist() entropy_values = data.frame(county = counties, intensity = entropy_values) entropy_values %>% filter(county %in% nccovid::triad_counties) %>% ggplot(aes(reorder(county,intensity), intensity))+ geom_point()+ coord_flip()+ labs( title = "Epidemic Intensity" )
Calculating the Transmission Increase from Factors
calculate_transmission_increase(R_w, rho, D = 4.7, omega = 0)
calculate_transmission_increase(R_w, rho, D = 4.7, omega = 0)
R_w |
a numeric, the baseline effective reproduction number |
rho |
a numeric, the estimated transmission advantage |
D |
a numeric, the generation time (average) |
omega |
a numeric with default of NULL indicating proportion of the population that has immunity against earlier variants |
c(4,6) * calculate_transmission_increase(R_w = .8, .43, D = 5.2, omega = NULL) c(4,6) * calculate_transmission_increase(R_w = .8, .43, D = 5.2, omega = .25)
c(4,6) * calculate_transmission_increase(R_w = .8, .43, D = 5.2, omega = NULL) c(4,6) * calculate_transmission_increase(R_w = .8, .43, D = 5.2, omega = .25)
Regions in Cone Region of Service
cone_region
cone_region
a vector
Mortality Estimates from Verity Et Al for Covid
covid_mortality_data
covid_mortality_data
data frame
Decreased previous observed cases back to scale
decrease_cases(calculated_cases, pos_rate, m = 10.83, k = 0.5)
decrease_cases(calculated_cases, pos_rate, m = 10.83, k = 0.5)
calculated_cases |
numeric, the calculated cases |
pos_rate |
numeric, the observed positivity rate |
m |
scaling factor |
k |
scaling factor with default of 1/2 on range [0,1] |
https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4809590/
Calculates Effective Vaccine Effectiveness as a function of parameters and time since vaccination. Includes heavyside function to accomendate the daily from injection
effective_ve_wane(VE = 0.8, omega = 0.1, t, theta = 0.3, t_2 = 14)
effective_ve_wane(VE = 0.8, omega = 0.1, t, theta = 0.3, t_2 = 14)
VE |
a numeric, the maximum vaccine efficacy |
omega |
a numeric, the rate parameter of wane |
t |
an integer, the day of interest |
theta |
a numeric, the general wane of the vaccine to be calibrated |
t_2 |
an integer, the inflection of the heavyside |
plot(0:30, effective_ve_wane(t = 0:30))
plot(0:30, effective_ve_wane(t = 0:30))
Perform a convolution given a pdf
epi_convolve(cases, pdf, direction = "forward")
epi_convolve(cases, pdf, direction = "forward")
cases |
numeric, the observed cases |
pdf |
numeric vector, the pdf of cases |
direction |
string, one of forward or backwards convolution |
{ true_cases <- rpois(100, 5) out <- data.frame(reported = ceiling(epi_convolve(true_cases, pdf = c(.2,.2,.3,.2,.1))), true_cases, date = 1:100 ) library(ggplot2) ggplot(out, aes(date))+ geom_line(aes(y = true_cases))+ geom_line(aes(y = reported), color = "blue") }
{ true_cases <- rpois(100, 5) out <- data.frame(reported = ceiling(epi_convolve(true_cases, pdf = c(.2,.2,.3,.2,.1))), true_cases, date = 1:100 ) library(ggplot2) ggplot(out, aes(date))+ geom_line(aes(y = true_cases))+ geom_line(aes(y = reported), color = "blue") }
Calculate the final size of an epidemic. Usethe the following logic:
epi_finalsize(r0)
epi_finalsize(r0)
r0 |
a double, the reproduction number (can be basic or Reff) |
1 + 1/R0*W(-R0exp(-R0))
## Not run: epi_finalsize(3.5) plot(seq(1,3,.01), epi_finalsize(seq(1,3,.01)),xlab = "R", ylab = "Percent Infected", type = "l") ## End(Not run)
## Not run: epi_finalsize(3.5) plot(seq(1,3,.01), epi_finalsize(seq(1,3,.01)),xlab = "R", ylab = "Percent Infected", type = "l") ## End(Not run)
Generates a graphic that shows the vaccine coverage by age band as a stacked bar chart in order to show the coverage as well as the raw number of vaccinated versus unvaccinated individuals.
generate_vax_coverage_age(county_use = nccovid::cone_region)
generate_vax_coverage_age(county_use = nccovid::cone_region)
county_use |
a string vector representing the North Carolina counties to be displayed |
Utilizes the CDC's COVID-19 Tracker to General Information About the Spread of Disease.
get_cdc_detail()
get_cdc_detail()
a data.table with details regarding disease spread by county
<https://covid.cdc.gov/covid-data-tracker/#datatracker-home>
Utilizes the CDC's COVID-19 Tracker to Retrieve Vaccination Rates
get_cdc_vax()
get_cdc_vax()
a data.table with vaccination information by county by day
<https://covid.cdc.gov/covid-data-tracker/#datatracker-home>
Retrieve Latest Demographic data from NC DHHS.
get_county_covid_demographics( demographic = "age_group", region = NULL, add_population = TRUE )
get_county_covid_demographics( demographic = "age_group", region = NULL, add_population = TRUE )
demographic |
a string, one of age, k_12, ethnicity, gender, or race |
region |
a string vector, could a string or vector of the counties of interest |
add_population |
a boolean, TRUE to add the population estimates (may not be available for all demographics) |
library(ggplot2) library(data.table) out <- get_county_covid_demographics(region = "Guilford", demographic = "age") out[,per_capita:=cases/(population/100000)] ggplot(out, aes(week_of, per_capita, colour = metric))+ geom_line()+ theme_bw()+ theme(legend.position = "top")+ labs( title = "SARS-CoV-2 Cases per 100k Residents", subtitle = "Guilford County, North Carolina", x = "Cases per 100k", y = NULL )
library(ggplot2) library(data.table) out <- get_county_covid_demographics(region = "Guilford", demographic = "age") out[,per_capita:=cases/(population/100000)] ggplot(out, aes(week_of, per_capita, colour = metric))+ geom_line()+ theme_bw()+ theme(legend.position = "top")+ labs( title = "SARS-CoV-2 Cases per 100k Residents", subtitle = "Guilford County, North Carolina", x = "Cases per 100k", y = NULL )
Pulling information on tests and percent positive at the county level. Notes that these data are updated manually.
get_county_tests(county_select = NULL)
get_county_tests(county_select = NULL)
county_select |
a string, the county of counties of interest |
Combined NCDHHS Case and Death Counts with CDC Details
get_covid_county_plus(county = NULL, adjusted = TRUE)
get_covid_county_plus(county = NULL, adjusted = TRUE)
county |
a string vector, representing the counties of interest. If left NULL then all counties in North Carolina will be returned |
adjusted |
a logical, should the adjusted cases be used (to account for
reporting gaps on weekends and holidays from NCDHHS). Defaults to |
a data.table with combined values for all counties or specified counties
These data originate from the North Carolina DHHS Covid-19 Dashboard
get_covid_demographics()
get_covid_demographics()
This functions hits the Johns Hopkins Covid Data Repository and filters down to North Carolina Data. Alternatively, it can retrieve any state.
get_covid_state( state = "North Carolina", select_county = NULL, data_source = c("cone", "hopkins"), reporting_adj = FALSE )
get_covid_state( state = "North Carolina", select_county = NULL, data_source = c("cone", "hopkins"), reporting_adj = FALSE )
state |
with a default of North Carolina |
select_county |
the county, if desired |
data_source |
which data source you would like to use one of "cone" or "hopkins" |
reporting_adj |
a boolean, default of |
## Not run: # To get all counties get_covid_state() # To get a single county get_covid_state(select_county = "Guilford") ## End(Not run)
## Not run: # To get all counties get_covid_state() # To get a single county get_covid_state(select_county = "Guilford") ## End(Not run)
This function will pull down NC Covid Information by Zip Code
get_covid_zip()
get_covid_zip()
This is a helper function to automatically access Google's Mobility data for North Carolina Counties
get_google_mobility(counties = NULL)
get_google_mobility(counties = NULL)
counties |
a string vector of the desired counties deafult of |
<https://www.gstatic.com/covid19/mobility/Global_Mobility_Report.csv>
## Not run: # Return All NC Counties get_google_mobility() # Return a Specific County get_google_mobility("Alamance County") ## End(Not run)
## Not run: # Return All NC Counties get_google_mobility() # Return a Specific County get_google_mobility("Alamance County") ## End(Not run)
Get Google Mobility (Version 2) This is a helper function to automatically access Google's Mobility data for North Carolina Counties. It's a bit faster than 'get_google_mobility' which downloads the entire csv for the world
get_google_mobility2(counties = NULL, state_in = "North Carolina")
get_google_mobility2(counties = NULL, state_in = "North Carolina")
counties |
a string vector of the desired counties default of |
state_in |
a string vector representing state or states of interest |
Retrieve Latest Hospitalisation data from NC DHHS. This is not an automatic Scrap so there could be some delay.
get_hospitalizations()
get_hospitalizations()
Pulled from <conedatascience/covid-data>
get_vaccinations(county_list = NULL, add_population = TRUE)
get_vaccinations(county_list = NULL, add_population = TRUE)
county_list |
a string, the county to pull. default is all counties |
add_population |
a boolean, default of TRUE to add a population |
{ get_vaccinations(county_list = "Guilford") }
{ get_vaccinations(county_list = "Guilford") }
Pulled from <conedatascience/covid-data>. The column vax_n returns vaccination counts. Population references are available for the user to calculate distribution and/or per capita rates.
get_vaccinations_demo(county_list = NULL, demographic = NULL, status = NULL)
get_vaccinations_demo(county_list = NULL, demographic = NULL, status = NULL)
county_list |
a string, the county to pull. default is all counties. |
demographic |
a string, the demographic requested. one or more of "race", "age", "ethnicity", "sex". default is all demographics |
status |
string, either 'partial' or 'full' for number of people with partially or fully vaccinated. Default of NULL returns both. |
{ get_vaccinations_demo(county_list = "Guilford", demographic = 'race', status = 'partial') }
{ get_vaccinations_demo(county_list = "Guilford", demographic = 'race', status = 'partial') }
Calculates Basic Herd Immunity Threshold Based on the Basic Reproduction Number
hit(R0)
hit(R0)
R0 |
a positive double, the basic reproduction number |
# Calculate the Herd Immunity Threshold for R0 Between 1 and 9 o <- vapply(seq(1,9, .1), hit, FUN.VALUE = numeric(1)) plot(seq(1,9, .1), o, main = "HIT", type = "l", ylab = "Prop with Immunity", xlab = expression(R[0]))
# Calculate the Herd Immunity Threshold for R0 Between 1 and 9 o <- vapply(seq(1,9, .1), hit, FUN.VALUE = numeric(1)) plot(seq(1,9, .1), o, main = "HIT", type = "l", ylab = "Prop with Immunity", xlab = expression(R[0]))
Increase case count in the presence of high testing positivity
increase_cases(observed_cases, pos_rate, m = 10.83, k = 0.5)
increase_cases(observed_cases, pos_rate, m = 10.83, k = 0.5)
observed_cases |
numberic, the reported cases |
pos_rate |
numberic, the observed positivity rate |
m |
scaling factor |
k |
scaling factor with default of 1/2 on range [0,1] |
https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4809590/
Calculate Infection probability given D50 1-10^(log10(.5)/D50)
infection_probability(D50 = 316)
infection_probability(D50 = 316)
D50 |
a double, #RNA for 50 percent infection probability (D50) |
Computes the Lambert W function, giving efficient solutions to the equation x*exp(x)==x lambertW(z, b = 0, maxiter = 10, eps = .Machine$double.eps, min.imag = 1e-09)
lambertW(z, b = 0, maxiter = 10, eps = .Machine$double.eps, min.imag = 1e-09)
lambertW(z, b = 0, maxiter = 10, eps = .Machine$double.eps, min.imag = 1e-09)
z |
(complex) vector of values for which to compute the function |
b |
integer, defaults to 0. vector of branches: b=0 specifies the principal branch, 0 and -1 are the ones that can take non-complex values |
maxiter |
maximum numbers of iterations for convergence |
eps |
convergence tolerance |
min.imag |
maximum magnitude of imaginary part to chop when returning solutions |
Compute the Lambert W function of z. This function satisfies W(z)*exp(W(z)) = z, and can thus be used to express solutions of transcendental equations involving exponentials or logarithms. The Lambert W function is also available in Mathematica (as the ProductLog function), and in Maple and Wolfram.
Nici Schraudolph <schraudo at inf.ethz.ch> (original version (c) 1998), Ben Bolker (R translation) See <https://stat.ethz.ch/pipermail/r-help/2003-November/042793.html>
Corless, Gonnet, Hare, Jeffrey, and Knuth (1996), "On the Lambert W Function", Advances in Computational Mathematics 5(4):329-359
NC Biological Sex Information by County
nc_county_demos
nc_county_demos
a data.frame, with NC DHHS county level demographic metrics
American Community Survey (2020 Vintage)
NC Fips by County
nc_county_fips
nc_county_fips
a data.frame
https://www.lib.ncsu.edu/gis/countyfips
Reported testing and reporting delays were fit using the EpiNow2 boostrapped gamma fit. The reported delays were manually collected from the NCDHHS website.
nc_delay
nc_delay
a list, with parameters for a gamma distribution fit to delays
https://covid19.ncdhhs.gov/dashboard/testing
Key North Carolina Events
nc_events
nc_events
a data.frame
various and https://www.nc.gov/covid-19/staying-ahead-curve
Mortality and Hospitalization Estimates
nc_fatality_estimates
nc_fatality_estimates
data.frame
NC Hospital Preparedness Coalitions
nc_hc_coalitions
nc_hc_coalitions
a data.frame, with NC county name and associated coalition
https://easternhpc.com/state-coalition-map/
North Carolina Population by County by Age
nc_pop_age
nc_pop_age
a data.frame
ACS2020 Metrics
NC Population by NCDHHS Age Band
nc_pop_dhhs
nc_pop_dhhs
a data.frame
2020 ACS Survey
North Carolina Population by County
nc_population
nc_population
a data.frame
Source: North Carolina OSBM, Standard Population Estimates, Vintage 2018 and Population Projections, Vintage 2019 <https://www.osbm.nc.gov/demog/county-estimates>
CDC Social Vulnerability for North Carolina by County
nc_svi_county
nc_svi_county
a data.frame
[U.S. Centers for Disease Prevention and Control (CDC) Social Vulnerability Index (SVI)](https://svi.cdc.gov/)
This pulls the most up to date summary data from the state.
pull_covid_summary()
pull_covid_summary()
a data.table with information for North Carolina
All estimates for North Carolina and some select regions have been precalculated and available for download. These estimates are utilising the EpiNow2 package
pull_estimates(region = NULL, variable = "R")
pull_estimates(region = NULL, variable = "R")
region |
a string or string vector, the region or county of interest |
variable |
a string or string vector, the measure of interest |
A Helper Function That Pull Hospitalizations by Demographics as Posted by NCDHHS
pull_hospitalization_demos()
pull_hospitalization_demos()
a data.table
o <- pull_hospitalization_demos() age_only <-o[demographic=="Age"&covid_status=="Confirmed"] age_only <- age_only[date<Sys.Date()-90] plot(NULL, xlim=range(age_only$date), ylim=range(age_only$value), ylab="Admissions", xlab="Date", main = "Admissions by Age") buckets <- unique(age_only$category) my_cols <- c("#00A2B2", "#F1BD51", "#00205C", "#c9c9c9", "#7750A9", "#B7D866", "#5C5859", "#DB2B27", "#63CCFF", "#000000", "#123453") names(my_cols) <- buckets for(i in buckets){ lines(age_only[category==i]$date, age_only[category==i]$value, col = my_cols[[i]]) }
o <- pull_hospitalization_demos() age_only <-o[demographic=="Age"&covid_status=="Confirmed"] age_only <- age_only[date<Sys.Date()-90] plot(NULL, xlim=range(age_only$date), ylim=range(age_only$value), ylab="Admissions", xlab="Date", main = "Admissions by Age") buckets <- unique(age_only$category) my_cols <- c("#00A2B2", "#F1BD51", "#00205C", "#c9c9c9", "#7750A9", "#B7D866", "#5C5859", "#DB2B27", "#63CCFF", "#000000", "#123453") names(my_cols) <- buckets for(i in buckets){ lines(age_only[category==i]$date, age_only[category==i]$value, col = my_cols[[i]]) }
The purpose of this function is to pull data provided by NCDHHS on vaccination rates by census tract. Additionally, information on SVI and other demographics is provided
pull_vaccine_census(county_pull = NULL)
pull_vaccine_census(county_pull = NULL)
county_pull |
a vector, the counties to select for the query |
a data.table with vaccination rates at the census tract level
A helper function to pull SARS-CoV-2 Copies Detected in Wastewater
pull_wastewater(county_in = NULL)
pull_wastewater(county_in = NULL)
county_in |
a string vector indicating the counties served
with a default of |
raw_dat <- pull_wastewater(county_in = "Guilford") raw_dat <- raw_dat[!is.na(sars_cov2_raw_copiesL)][,copies_log10 := log10(sars_cov2_normalized)] par(mar = c(5, 4, 4, 4) + 0.3) plot(copies_log10~date_new, data = raw_dat, type ="b", xlab = "Date", ylab = "SARS-CoV-2 RNA Copies (Log10)") par(new = TRUE) plot(log10(cases_new_cens_per10k)~date_new, data = raw_dat, type = "l", axes = FALSE, bty = "n", xlab = "", ylab = "", col = "orange") axis(side=4, at = pretty(range(log10(raw_dat$cases_new_cens_per10k)))) mtext("Log10(New Cases per 100k)", side=4, line=3) title("Guilford SARS-CoV-2 Detected in Wastewater vs New Cases per 100k")
raw_dat <- pull_wastewater(county_in = "Guilford") raw_dat <- raw_dat[!is.na(sars_cov2_raw_copiesL)][,copies_log10 := log10(sars_cov2_normalized)] par(mar = c(5, 4, 4, 4) + 0.3) plot(copies_log10~date_new, data = raw_dat, type ="b", xlab = "Date", ylab = "SARS-CoV-2 RNA Copies (Log10)") par(new = TRUE) plot(log10(cases_new_cens_per10k)~date_new, data = raw_dat, type = "l", axes = FALSE, bty = "n", xlab = "", ylab = "", col = "orange") axis(side=4, at = pretty(range(log10(raw_dat$cases_new_cens_per10k)))) mtext("Log10(New Cases per 100k)", side=4, line=3) title("Guilford SARS-CoV-2 Detected in Wastewater vs New Cases per 100k")
Convenience function to convert a growth rate (little r) to a reproduction number (R) given a particular generation time.
r2R(r, mu_gamma = 4.7, sd_gamma = 2.9)
r2R(r, mu_gamma = 4.7, sd_gamma = 2.9)
r |
a double representing the growth rate |
mu_gamma |
a double representing mean of the gamma function characterizing the generation time. |
sd_gamma |
a double representing standard deviation of the gamma function characterizing the generation time. |
https://royalsocietypublishing.org/doi/10.1098/rsif.2020.0144
cases <- rpois(10,2.5) t <- 1:10 fit <- glm(cases ~ t, family = "poisson") r2R(coef(fit)[2])
cases <- rpois(10,2.5) t <- 1:10 fit <- glm(cases ~ t, family = "poisson") r2R(coef(fit)[2])
Estimate the RNA Content in an Aerosol
rna_content(resp_fluid = 5e+08, wet_aerosol_diameter = 5)
rna_content(resp_fluid = 5e+08, wet_aerosol_diameter = 5)
resp_fluid |
a double, respiratory fluid RNA conc [/cm^3] |
wet_aerosol_diameter |
a double, mean wet aerosol diameter [um] |
List of Triad Counties
triad_counties
triad_counties
a vector