descartes_mobility_data: Get US daily mobility data from Descartes Labs

Description Usage Value License Author(s) Source References See Also Examples

View source: R/descartes_mobility.R

Description

Descartes Labs quantify the level of human mobility in the US at the state level. Their methodology looks at a collection of mobile devices reporting consistently throughout the day. They calculate the maximum distance moved in kilometers (excluding outliers) from the first reported location. Using this value, they calculate the median across all devices in the sample to generate a mobility metric for selected states.

Usage

1

Value

License

Creative Commons Attribution (CC BY 4.0), see https://github.com/descarteslabs/DL-COVID-19

Author(s)

Sean Davis seandavi@gmail.com

Source

References

See Also

Other data-import: jhu_data(), jhu_us_data(), nytimes_county_data(), usa_facts_data()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
library(dplyr)
res = descartes_mobility_data()
colnames(res)
dplyr::glimpse(res)

# plot data for Georgia
library(ggplot2)

# this gets us state-level data
GA = res %>% dplyr::filter(admin1=='Georgia' & admin_level==1)

ggplot(GA, aes(x=date, y=m50_index)) + geom_line() + ggtitle('M50 index over time in Georgia')

#limit to dates of interest around time that GA is reopening

GA = GA %>% dplyr::filter(date>as.Date('2020-01-01') & date < as.Date('2020-06-01'))
ggplot(GA, aes(x=date, y=m50_index)) +
    geom_line() +
    ggtitle('M50 index over time in Georgia')
# Obviously, there are day-specific effects, so use
# R to "regress out" the effects of day of week to better
# observe trend.
GA = GA %>% dplyr::mutate(dow = lubridate::wday(date, label=TRUE))
lmfit = lm(m50_index ~ dow, data = GA)

# We are interested in the residuals, or
# the variation in the data not explained by
# the day of the week.
GA$m50_index_regressed = residuals(lmfit)

ggplot(GA, aes(x=date, y=m50_index_regressed)) +
    geom_smooth() +
    geom_point()

# Compare states
states = c("New York", "California", "Nevada",
           "Texas", "Georgia", "Florida")
ST = res %>%
          dplyr::filter(admin1 %in% states & admin_level==1) %>%
          dplyr::mutate(dow = lubridate::wday(date, label=TRUE))
lmfit = lm(m50_index ~ dow + admin1, data = ST)
ST$m50_index_regressed = residuals(lmfit)

ggplot(ST, aes(x=date, y=m50_index_regressed)) +
    geom_smooth() +
    geom_point() +
    facet_wrap('admin1', nrow=2) +
    ggtitle('Mobility index differences across states')

vjcitn/sars2app documentation built on Jan. 3, 2022, 12:19 a.m.