Skip to content

Commit

Permalink
factoring addtotals2
Browse files Browse the repository at this point in the history
  • Loading branch information
vinnief committed Jun 3, 2020
1 parent 01e59b3 commit b0b3a71
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 24 deletions.
19 changes: 3 additions & 16 deletions Graphs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions data/population.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Country Name,Country Code,2018,
Holy See,,801,
Vatican,,801,
Tuvalu,TUV,11508,
Nauru,NRU,12704,
Palau,PLW,17907,
Expand Down
11 changes: 5 additions & 6 deletions definitions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -736,26 +735,26 @@ 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,
confirmed<= mydata$confirmed &
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,
confirmed>= mydata$confirmed &
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)
}


Expand Down
5 changes: 3 additions & 2 deletions loadData.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>%
Expand All @@ -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")

Expand Down
30 changes: 30 additions & 0 deletions wip.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit b0b3a71

Please sign in to comment.