Fake migration dataset used to demonstrate the functionality of the hhm function in the hhmR package. It contains the information on the number of people who have moved between a series of fictional geographies. The geographies themselves have a hierarchical structure, with each county existing within a smaller subset of regions.
data(example_migration)
A data frame with 324 rows and 5 variables.
The county (lower-level geography) that each migrant began in.
The county (lower-level geography) that each migrant ended up in.
The region (higher-level geography) that each migrant began in.
The region (higher-level geography) that each migrant ended up in.
The number of migrants that moved from each origin county to each destination county.
library(dplyr)
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
# Code to create dataset
# Define names of fake counties
fake_counties = c("Greenridge","Windermoor","Bramblewood","Silverlake",
"Thornbury","Maplewood","Hawthorne","Pinehurst",
"Riverton","Meadowbrook","Fairhaven","Oakdale","Stonebridge",
"Brookfield","Ashford","Glenville","Sunnyvale","Westfield")
# Create region county lookup tables
rc_lkp = data.frame(region = c(rep("North",3),rep("Midlands",5),
rep("South West",4),rep("South East",6)),
county = fake_counties)
og_lkp = rc_lkp %>% setNames(c("Origin Region" ,"Origin County" ))
dn_lkp = rc_lkp %>% setNames(c("Destination Region","Destination County"))
# Create dataframe of fake migration data
set.seed(1234)
example_migration = expand.grid(fake_counties,fake_counties) %>%
setNames(paste(c("Origin","Destination"),"County",sep=" ")) %>%
full_join(og_lkp) %>% full_join(dn_lkp) %>%
mutate(Migration = (1/rgamma(18*18, shape = 17, rate = 0.5)) %>%
{. * 1000} %>% round())
#> Joining with `by = join_by(`Origin County`)`
#> Joining with `by = join_by(`Destination County`)`
example_migration[example_migration$`Origin County` ==
example_migration$`Destination County`,"Migration"] =
example_migration[example_migration$`Origin County` ==
example_migration$`Destination County`,"Migration"] * 10