View source: R/sample_size_adjust.R
sample_size_adjust | R Documentation |
This function uses 2016 American Community Survey data to adjust SafeGraph counts for the portion of the population that is sampled. This function will return a data.table
with columns for a geographic ID and the variable adjust_factor
, which you can merge into your data and then multiply whatever count variables you like by adjust_factor
to adjust them for sampling differences.
sample_size_adjust( data, from_id = "census_block_group", sample_id = "number_devices_residing", from_level = "cbg", to_level = "county", by = NULL, pop_data = NULL )
data |
A |
from_id |
A character vector either giving the variable name of the census block group ID, or both the state FIPS and county FIPS variables (which must be numeric, and in state, then county order). Census block group must be specified if |
sample_id |
A character variable giving the variable name of the variable in |
from_level |
Either |
to_level |
Either |
by |
The data returned will be on the |
pop_data |
If a populatinon data file other than |
## Not run: # The current working directory has many home_panel_summary files # Do some futzing with the census_block_group variable to # Get it in the same format as how it is in cbg_pop home_panel <- read_many_csvs(colClasses= c(census_block_group='character')) home_panel[,census_block_group := as.character(as.numeric(census_block_group))] # Create the data set with the adjust_factor variable # This will adjust CBG populations to county ones, by default adj_factor <- sample_size_adjust(home_panel, by = 'date_range_start') # Now take some distancing data I have # (where census_block_group is stored as origin_census_block_group) data.table::setnames(adj_factor, census_block_group, origin_census_block_group) # and merge in the adjustment factor distancing <- merge(distancing, adj_factor, all.x = TRUE, by = 'origin_census_block_group') # And use that adjustment factor to adjust! distancing[,adj_device_count := device_count*adj_factor] ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.