hb_shrink | R Documentation |
This is a function that takes a "success" and a "total" variable (often something like "number of devices staying home" and "total number of devices") and shrinks them to the full data set using shrinkage methods for proportions.
hb_shrink(success, total)
success |
A numeric integer variable containing the number of successes. |
total |
A numeric integer variable containing the total sample size. |
This is usually called by group, either with dplyr::group_by
or with the by
argument in a data.table
, so that individual observations can be shrunk to the group level.
## Not run: # The directory distdat is the folder we have downloaded the distancing data to from AWS. # Read and compile all distancing data from May 1 to May 7 distancing <- read_distancing( start = lubridate::ymd('2020-05-01'), end = lubridate::ymd('2020-05-07'), dir = distdat ) # Shrink county to state distancing <- distancing[,.(county_fips = county_fips, unshrunk_stay_home = completely_home_device_count/device_count, shrunk_stay_home = hb_shrink(completely_home_device_count, device_count)), by = .(state_fips, date)] ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.