diff --git a/Graphs.R b/Graphs.R index 73ea605..2cdbe2c 100644 --- a/Graphs.R +++ b/Graphs.R @@ -8,23 +8,10 @@ verbose=3 #latest numbers JHH[JHH$Date==max(JHH$Date)&JHH$PSCR %in% c('World','New York,US',"Kazakhstan",'Belgium','US','Netherlands','Europe','Germany','Africa','Iran','Russia','Brazil'),c('confirmed','new_confirmed','active_imputed','deaths','PSCR')]%>% mutate(newrate=round(new_confirmed/active_imputed*100,2))%>% arrange(newrate) #overtaking +map(c('Belgium','Netherlands','Sweden','Germany',"United Kingdom",'Europe','Russia','New York,US'),function(x) overtakenInDays(JHH,x)) +map(c('Belgium','Netherlands','Sweden','Germany',"United Kingdom",'Russia','Europe','New York,US'),function(x) overtakingInDays(JHH,x)) -overtakenin(JHH,"Belgium")[1:10] -overtakenin(JHH,"Netherlands")[1:10] -overtakenin(JHH,"United Kingdom")[1:10] -overtakenin(JHH,"Europe")[1:10] -overtakingin(JHH,"North America")[1:10] -overtakingin(JHH,'Brazil') -overtakenin(JHH,'Russia') -overtakenin(JHH,'New York,US') - -overtakingin(JHH,'Germany') -overtakingin(JHH,'Belgium') -overtakingin(JHH,'Sweden') -overtakingin(JHH,'Indonesia') -overtakingin(JHH,'Peru') -overtakingin(JHH,'India') - +map(c("North America",'Brazil','Indonesia','Peru','India','Russia'),function(x) overtakingInDays(JHH,x)) #compare my countries graph3Dard_fia(ECDC,c("Kazakhstan","Belgium","Netherlands","France")) #make all graphs diff --git a/data/population.csv b/data/population.csv index 4003149..228f3bb 100644 --- a/data/population.csv +++ b/data/population.csv @@ -1,5 +1,6 @@ Country Name,Country Code,2018, Holy See,,801, +Vatican,,801, Tuvalu,TUV,11508, Nauru,NRU,12704, Palau,PLW,17907, diff --git a/definitions.R b/definitions.R index 8322c3a..b7c2ebe 100644 --- a/definitions.R +++ b/definitions.R @@ -689,14 +689,13 @@ addTotals3<- function(lpti=ECDC,totregions="", ID='Region'){ filter(! (!!ID %in% totregions)) World<- unique(lpti1[[ID]]) varnames=c("confirmed","recovered", "deaths","population") - #,'recovered_imputed',"active_imputed") # we impute AFTER this function so no need. for (regio in totregions[!is.na(totregions)]) lpti<- rbind(lpti, lpti1%>% total(regio ,ID=ID, varnames= varnames,newrow=regio)) } -addTotals2<- function(lpdf=JHH,ID='PSCR'){ +addTotals2<- function(lpdf=JHH,totregions="",ID='PSCR'){ lpti<- lpdf %>% #just to be sure, that if i do it twice i dont get double counts. #And omit USA as country, as we have the individual states already. @@ -736,7 +735,7 @@ days2overtake<- function(lpti=JHH,countries=c('Belgium','China','Russia','Nether round(mconf/mnew,1) } -overtakenin<- function(lpti,country){ +overtakenInDays<- function(lpti,country,nr=7){ lastdata<- lpti[lpti$Date==max(lpti$Date),c('PSCR','confirmed','new_confirmed')] mydata<- subset(lastdata,PSCR==country) countries<- subset(lastdata, @@ -744,10 +743,10 @@ overtakenin<- function(lpti,country){ new_confirmed>=mydata$new_confirmed, select=PSCR) oc<- days2overtake(lpti,countries$PSCR)[,country] - oc[order(oc,na.last=FALSE)] + head(oc[order(oc,na.last=FALSE)],nr) } -overtakingin<- function(lpti,country){ +overtakingInDays<- function(lpti,country,nr=7){ lastdata<- lpti[lpti$Date==max(lpti$Date),c('PSCR','confirmed','new_confirmed')] mydata<- subset(lastdata,PSCR==country) countries<- subset(lastdata, @@ -755,7 +754,7 @@ overtakingin<- function(lpti,country){ new_confirmed<=mydata$new_confirmed, select=PSCR) oc<- days2overtake(lpti,countries$PSCR)[,country] - oc[order(oc,na.last=FALSE)] + head(oc[order(oc,na.last=FALSE)],nr) } diff --git a/loadData.R b/loadData.R index 0816ac1..3d37d72 100644 --- a/loadData.R +++ b/loadData.R @@ -6,9 +6,10 @@ source("definitions.R")# make sure we have our definitions. JHH<- makeJHH(force=TRUE) #load data JHH0<- JHH -regios<- c(provincializeJHH(),regios) +regios<- c(list(World=c('World', unique(JHH[['PSCR']]))),provincializeJHH(),regios) #regiosP? verbose=2 + JHH <- JHH0 %>% addPopulation() %>% addTotals2 %>% addRegions( Regiolist= regios)%>% imputeRecovered()%>% extravars() %>% addDoublingDaysAllCountries %>% @@ -20,7 +21,7 @@ writewithcounters(JHH,name="Covid19JHH") #no factors! #same with ECDC ECDC0 <- makeECDC() -ECDC <- ECDC0 %>% imputeRecovered()%>% extravars() %>% +ECDC <- ECDC0 %>% addTotals3%>% imputeRecovered()%>% extravars() %>% addDoublingDaysAllCountries %>% addSimVars(minval=100) writewithcounters(ECDC,name= "Covid19ECDC") diff --git a/wip.R b/wip.R index 7e9f03d..1e1b1ee 100644 --- a/wip.R +++ b/wip.R @@ -31,6 +31,36 @@ checkdouble(c('USA','Netherlands'),JHHRegios) isdouble(c('Belgium','Netherlands'),regios) length(JHHRegios) +addCountryTotals<- function(lpdf=JHH){ + varnames=c("confirmed","recovered", "deaths","population") + existingTotals<- c("China","Australia","Canada",'US') + #just to be sure, that if i do it twice i dont get double counts. + #And omit US as country and US states. + lpti<- lpdf %>% + filter(!( PSCR %in% existingTotals )) # + rbind(lpdf, + lpti%>% totals(c("China","Australia", "Canada",'US'), + ID="Country.Region", varnames= varnames)) + +} +addRegionTotals<- function(lpdf=JHH,totRegions=""){ + existingTotals<- c("South America", "Asia", "Africa", "Europe","China","Australia","Canada",'US','North America',"World") + #just to be sure, that if i do it twice i dont get double counts. + #And omit US as country and US states. + lpti<- lpdf %>% + filter(!(Country.Region =="US" | PSCR%in% existingTotals )) #we have US and USA + if (totRegions[1]=="") totRegions<- c(regios) + if (verbose>=3) { + print('world totals include the following countries: ') + print(paste(World,collapse=","))} + varnames=c("confirmed","recovered", "deaths","population") + for(myRegion in totRegions){ + lpdf<- rbind(lpdf, + lpti%>%total(regios[[myRegion]],ID=ID,newrow=myRegion[1], varnames= varnames)) + } +} +tail(JHH0%>% addPopulation()%>% addCountryTotals %>% addRegionTotals%>% filter(Date==max(Date)),10) + #check colors graph3Dard_fia (JHH,regios$continents)