Quick Snowy …
Source:
https://ourworldindata.org/coronavirus
‘R is below one in the community’ - Patrick Valence 16th April 2020.
Data from:
Total and daily confirmed COVI-19 cases: total-and-daily-cases-covid-19,csv
Merge these two by column: daily-deaths-covid-19.csv total-covid-deaths-region.csv
buildDf <- function(df)
{
#
# Build data frame for an entity
#
df$cases <- as.numeric(trim(df$cases))
df$deaths <- as.numeric(trim(df$deaths))
df['date.int'] <- rep(NA,nrow(df))
df$date.int <- to.date.int( df$date, 2 )
#
# This is day number with 1 for first (by date)
# entry for this entity.
#
df <- arrange(df,date.int)
df['day.number'] <- rep(NA,nrow(df))
df$day.number <- c(1:nrow(df))
# Deaths
df['deaths.ma'] <- rep(NA,nrow(df))
df$deaths.ma <- ma(df$deaths,3)
df['deaths.na.to.zero'] <- rep(0,nrow(df))
df$deaths.na.to.zero <- df$deaths
df['deaths.ma.na.to.zero'] <- rep(0,nrow(df))
df$deaths.ma.na.to.zero <- df$deaths.ma
# Cases
df['cases.ma'] <- rep(NA,nrow(df))
df$cases.ma <- ma(df$cases,3)
# Estimate of R
df['r.est'] <- rep(NA,nrow(df))
df$r.est <- r.vec(df$cases.ma)
df['r.est.ma'] <- rep(NA,nrow(df))
df$r.est.ma <- ma(df$r.est,3)
# Time to double
# Derive time-to-double on ma cases
df['time.to.double'] <- rep(NA,nrow(df))
df$time.to.double <- time.to.double(df$cases.ma)
# Now do ma on time to double
df['time.to.double.ma'] <- rep(NA,nrow(df))
df$time.to.double.ma <- ma(df$time.to.double,5)
df['time.to.double.from.r'] <- rep(NA,nrow(df))
df$time.to.double.from.r <- time.to.double.from.r(df$r.est.ma)
# Up/down marker
df['decreased.cases'] <- rep(NA,nrow(df))
df$decreased.cases <- upDown(df$cases)
df['decreased.cases.ma'] <- rep(NA,nrow(df))
df$decreased.cases.ma <- upDown(df$cases.ma)
return(df)
}
#df <- buildDf(df)
# Assign day numbers by country by doing something like:
prt <- TRUE
buildForEntity <- function(a1,a2){
if ( prt ) {
print('class of a1:')
print(class(a1));
print('class of a2:')
print(class(a2));
print('names of a1:')
print(names(a1));
print('names of a2:')
print(names(a2));
print(a2$entity[1])
prt <<- FALSE
}
#
# This will work but it will set day number arbitrarily.
#
return(buildDf(a1))
}
df.new <- df.new %>% group_by(entity) %>% group_modify(buildForEntity)
## [1] "class of a1:"
## [1] "tbl_df" "tbl" "data.frame"
## [1] "class of a2:"
## [1] "tbl_df" "tbl" "data.frame"
## [1] "names of a1:"
## [1] "code" "date" "cum.cases" "cases" "cum.deaths"
## [6] "deaths"
## [1] "names of a2:"
## [1] "entity"
## [1] Afghanistan
## 206 Levels: Afghanistan Albania Algeria Andorra Angola ... Zimbabwe
\[ cases_i = raw \ case \ count\ for \ day \ i, i = 1 \ for \ 01/03/2020 \]
Red dot shows increase in daily cases, green dot is a decrease.
Daily cases based on a moving average.
Time to double can be checked against:
Serial interval distribution estimate taken from :
https://wwwnc.cdc.gov/eid/article/26/6/20-0357_article
(mean 3.96, SD 4.75)
Raw (unsmoothed) case data used.
## Warning: package 'EpiEstim' was built under R version 3.6.3
## Default config will estimate R on weekly sliding windows.
## To change this change the t_start and t_end arguments.
## TableGrob (3 x 1) "arrange": 3 grobs
## z cells name grob
## incid 1 (1-1,1-1) arrange gtable[layout]
## R 2 (2-2,1-1) arrange gtable[layout]
## SI 3 (3-3,1-1) arrange gtable[layout]
df.from.march <- filter(df.new, date >= '2020-03-01')
ggplot(
filter(df.from.march,
(entity=='France')|
(entity=='Italy')|
(entity=='Germany')|
(entity=='Spain')|
(entity=='United Kingdom')),
aes(x=date,y=cum.cases,color=entity)
) +
geom_line() +
geom_point() +
theme_minimal()
Also see:
https://community.rstudio.com/t/rstudio-v1-1-456-rpubs-upload-error-no-login-prompt/19393/9
Copyright © 2020 George McGill / RSquaredLab.net.