Dataset
load("Ozone Data with Region.RData")
pop <- read_excel("Population/Population County.xlsx")
pop12<-pop%>%filter(Year==2012) #Subset Population in Year 2012
Scenario A
## A1
A<-df4%>%
filter(Year==2012,between(Max.Ozone,75,75+0.905)) #subset Ozone in interval 75 to 75.905
unique(A$GEOID)%>%length() #Count number of county affected by Scenario A1
## [1] 349
unique(A$Date..Local.)%>%length() #Count number of Day of event A1
## [1] 160
A<-left_join(A,pop12,by=c("GEOID"="fips")) #Merge Pop in 2012 with Scenario A1
A.pop<-A%>%
distinct(GEOID,MonitorID,.keep_all = T)%>%
group_by(GEOID,MonitorID,Max.Ozone)%>%
summarise(pop=value) # ALL OZONE LEVEL IS 75, So i think it have same kind of drought
## `summarise()` has grouped output by 'GEOID', 'MonitorID'. You can override
## using the `.groups` argument.
# Calculate toatal Population affect by scenario A1
A.pop<-A.pop%>%
group_by(GEOID)%>%
summarise(Pop=mean(pop))%>%
mutate(Sumpop=sum(Pop,na.rm = T)*1000)
A.pop%>%head(3)
## # A tibble: 3 × 3
## GEOID Pop Sumpop
## <chr> <dbl> <dbl>
## 1 01049 70.9 132814089
## 2 01073 658. 132814089
## 3 01089 343. 132814089
### Scenario A2
A2<-df4%>%
filter(Year==2012,between(Max.Ozone,70,70+0.905)) #subset Ozone in interval 70 to 70.905
unique(A2$GEOID)%>%length() #Count number of county affected by Scenario A2
## [1] 517
unique(A2$Date..Local.)%>%length() #Count number of county affected by Scenario A2
## [1] 196
A2<-left_join(A2,pop12,by=c("GEOID"="fips")) #Merge Pop in 2012 with Scenario A2
A2.pop<-A2%>%
distinct(GEOID,MonitorID,.keep_all = T)%>%
group_by(GEOID,MonitorID,Max.Ozone)%>%
summarise(pop=value) # ALL OZONE LEVEL IS 70
## `summarise()` has grouped output by 'GEOID', 'MonitorID'. You can override
## using the `.groups` argument.
#Calculate toatal Population affect by scenario A2
A2.pop<-A2.pop%>%
group_by(GEOID)%>%
summarise(Pop=mean(pop))%>%
mutate(Sumpop=sum(Pop,na.rm = T)*1000)
A2.pop%>%head(3)
## # A tibble: 3 × 3
## GEOID Pop Sumpop
## <chr> <dbl> <dbl>
## 1 01033 54.6 178745925
## 2 01051 80.2 178745925
## 3 01073 658. 178745925
###A3
A3<-df4%>%
filter(Year==2012,between(Max.Ozone,51,51+0.905)) #subset Ozone in interval 51 to 51.905
unique(A3$GEOID)%>%length() #Count number of county affected by Scenario A3
## [1] 772
unique(A3$Date..Local.)%>%length() #Count number of Day of event A3
## [1] 320
A3<-left_join(A3,pop12,by=c("GEOID"="fips")) #Merge Pop in 2012 with Scenario A3
A3.pop<-A3%>%
distinct(GEOID,MonitorID,.keep_all = T)%>%
group_by(GEOID,MonitorID,Max.Ozone)%>%
summarise(pop=value) # ALL OZONE LEVEL IS 51
## `summarise()` has grouped output by 'GEOID', 'MonitorID'. You can override
## using the `.groups` argument.
#Calculate toatal Population affect by scenario A3
A3.pop<-A3.pop%>%
group_by(GEOID)%>%
summarise(Pop=mean(pop))%>%
mutate(Sumpop=sum(Pop,na.rm = T)*1000)
A3.pop%>%head(3)
## # A tibble: 3 × 3
## GEOID Pop Sumpop
## <chr> <dbl> <dbl>
## 1 01003 190. 225735053
## 2 01033 54.6 225735053
## 3 01049 70.9 225735053
Scenario B
## Scenario B1
#subset Ozone in 75<Ozone<75.905 or 75<Ozone<76.693
B<-df4%>%
filter(Year==2012,between(Max.Ozone,75,75+0.905)|between(Max.Ozone,75,75+1.693))
#Count number of county affected by Scenario B1
unique(B$GEOID)%>%length()
## [1] 442
#Count number of Day of event B1
unique(B$Date..Local.)%>%length()
## [1] 172
#Merge Pop in 2012 with Scenario B1
B<-left_join(B,pop12,by=c("GEOID"="fips"))
B.pop<-B%>%
distinct(GEOID,MonitorID,.keep_all = T)%>%
group_by(GEOID,MonitorID,Max.Ozone)%>%
summarise(pop=value) # ALL OZONE LEVEL IS 75, So i think it have same kind of drought
## `summarise()` has grouped output by 'GEOID', 'MonitorID'. You can override
## using the `.groups` argument.
#Calculate toatal Population affect by scenario b1
B.pop<-B.pop%>%
group_by(GEOID)%>%
summarise(Pop=mean(pop))%>%
mutate(Sumpop=sum(Pop,na.rm = T)*1000)
B.pop%>%head(3)
## # A tibble: 3 × 3
## GEOID Pop Sumpop
## <chr> <dbl> <dbl>
## 1 01049 70.9 158680441
## 2 01073 658. 158680441
## 3 01089 343. 158680441
### B2
#subset Ozone in 70<Ozone<70.905 or 70<Ozone<71.693
B2<-df4%>%
filter(Year==2012,between(Max.Ozone,70,70+0.905)|between(Max.Ozone,70,70+1.693))
#Count number of county affected by Scenario B2
unique(B2$GEOID)%>%length()
## [1] 606
#Count number of Day of event B2
unique(B2$Date..Local.)%>%length()
## [1] 204
#Merge Pop in 2012 with Scenario B2
B2<-left_join(B2,pop12,by=c("GEOID"="fips"))
B2.pop<-B2%>%
distinct(GEOID,MonitorID,.keep_all = T)%>%
group_by(GEOID,MonitorID,Max.Ozone)%>%
summarise(pop=value)
## `summarise()` has grouped output by 'GEOID', 'MonitorID'. You can override
## using the `.groups` argument.
#Calculate toatal Population affect by scenario B2
B2.pop<-B2.pop%>%
group_by(GEOID)%>%
summarise(Pop=mean(pop))%>%
mutate(Sumpop=sum(Pop,na.rm = T)*1000)
B2.pop%>%head(3)
## # A tibble: 3 × 3
## GEOID Pop Sumpop
## <chr> <dbl> <dbl>
## 1 01033 54.6 198796234
## 2 01049 70.9 198796234
## 3 01051 80.2 198796234
###B3
#subset Ozone in 51<Ozone<51.905 or 51<Ozone<52.693
B3<-df4%>%
filter(Year==2012,between(Max.Ozone,51,51+0.905)|between(Max.Ozone,51,51+1.693))
#Count number of county affected by Scenario B3
unique(B3$GEOID)%>%length()
## [1] 775
#Count number of Day of event B3
unique(B3$Date..Local.)%>%length()
## [1] 337
#Merge Pop in 2012 with Scenario B3
B3<-left_join(B3,pop12,by=c("GEOID"="fips"))
B3.pop<-B3%>%
distinct(GEOID,MonitorID,.keep_all = T)%>%
group_by(GEOID,MonitorID,Max.Ozone)%>%
summarise(pop=value)
## `summarise()` has grouped output by 'GEOID', 'MonitorID'. You can override
## using the `.groups` argument.
#Calculate toatal Population affect by scenario B3
B3.pop<-B3.pop%>%
group_by(GEOID)%>%
summarise(Pop=mean(pop))%>%
mutate(Sumpop=sum(Pop,na.rm = T)*1000)
B3.pop%>%head(3)
## # A tibble: 3 × 3
## GEOID Pop Sumpop
## <chr> <dbl> <dbl>
## 1 01003 190. 225894339
## 2 01033 54.6 225894339
## 3 01049 70.9 225894339
Scenario C
### Scenario C
#subset Ozone in 75<Ozone<77.598 or 75<Ozone<76.693
C<-df4%>%
filter(Year==2012,between(Max.Ozone,75,75+2.598)|between(Max.Ozone,75,75+1.693))
#Count number of county affected by Scenario C1
unique(C$GEOID)%>%length()
## [1] 488
#Count number of Day of event C1
unique(C$Date..Local.)%>%length()
## [1] 179
#Merge Pop in 2012 with Scenario C1
C<-left_join(C,pop12,by=c("GEOID"="fips"))
C.pop<-C%>%
distinct(GEOID,MonitorID,.keep_all = T)%>%
group_by(GEOID,MonitorID,Max.Ozone)%>%
summarise(pop=value) # ALL OZONE LEVEL IS 75, So i think it have same kind of drought
## `summarise()` has grouped output by 'GEOID', 'MonitorID'. You can override
## using the `.groups` argument.
#Calculate toatal Population affect by scenario C1
C.pop<-C.pop%>%
group_by(GEOID)%>%
summarise(Pop=mean(pop))%>%
mutate(Sumpop=sum(Pop,na.rm = T)*1000)
C.pop%>%head(3)
## # A tibble: 3 × 3
## GEOID Pop Sumpop
## <chr> <dbl> <dbl>
## 1 01049 70.9 172255515
## 2 01073 658. 172255515
## 3 01089 343. 172255515
### C2
#subset Ozone in 70<Ozone<72.598 or 70<Ozone<71.693
C2<-df4%>%
filter(Year==2012,between(Max.Ozone,70,70+2.598)|between(Max.Ozone,70,70+1.693))
#Count number of county affected by Scenario C2
unique(C2$GEOID)%>%length()
## [1] 637
#Count number of Day of event C2
unique(C2$Date..Local.)%>%length()
## [1] 205
#Merge Pop in 2012 with Scenario C2
C2<-left_join(C2,pop12,by=c("GEOID"="fips"))
C2.pop<-C2%>%
distinct(GEOID,MonitorID,.keep_all = T)%>%
group_by(GEOID,MonitorID,Max.Ozone)%>%
summarise(pop=value)
## `summarise()` has grouped output by 'GEOID', 'MonitorID'. You can override
## using the `.groups` argument.
#Calculate toatal Population affect by scenario C2
C2.pop<-C2.pop%>%
group_by(GEOID)%>%
summarise(Pop=mean(pop))%>%
mutate(Sumpop=sum(Pop,na.rm = T)*1000)
C2.pop%>%head(3)
## # A tibble: 3 × 3
## GEOID Pop Sumpop
## <chr> <dbl> <dbl>
## 1 01003 190. 202848364
## 2 01033 54.6 202848364
## 3 01049 70.9 202848364
###C3
#subset Ozone in 51<Ozone<53.905 or 51<Ozone<52.693
C3<-df4%>%
filter(Year==2012,between(Max.Ozone,51,51+2.598)|between(Max.Ozone,51,51+1.693))
#Count number of county affected by Scenario C3
unique(C3$GEOID)%>%length()
## [1] 776
#Count number of Day of event C3
unique(C3$Date..Local.)%>%length()
## [1] 340
#Merge Pop in 2012 with Scenario C3
C3<-left_join(C3,pop12,by=c("GEOID"="fips"))
C3.pop<-C3%>%
distinct(GEOID,MonitorID,.keep_all = T)%>%
group_by(GEOID,MonitorID,Max.Ozone)%>%
summarise(pop=value)
## `summarise()` has grouped output by 'GEOID', 'MonitorID'. You can override
## using the `.groups` argument.
#Calculate toatal Population affect by scenario C3
C3.pop<-C3.pop%>%
group_by(GEOID)%>%
summarise(Pop=mean(pop))%>%
mutate(Sumpop=sum(Pop,na.rm = T)*1000)
C3.pop %>% head(3)
## # A tibble: 3 × 3
## GEOID Pop Sumpop
## <chr> <dbl> <dbl>
## 1 01003 190. 226634039
## 2 01033 54.6 226634039
## 3 01049 70.9 226634039