-
Notifications
You must be signed in to change notification settings - Fork 0
/
NFIP_claims_processing.R
50 lines (41 loc) · 2.08 KB
/
NFIP_claims_processing.R
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
49
50
## Connor P. Jackson second year paper
## Exploratory code: FEMA National Flood Insurance Program
library(data.table)
library(sf)
## ---- import-nfip-claims ----
assemble_claims <-function(path="../data_buyouts/FimaNfipClaims.csv", state=NULL) {
claims <- fread(path, stringsAsFactors = TRUE)
state_filter <- state
validclaims <-
claims[occupancyType == 1 & totalBuildingInsuranceCoverage > 0 &
totalBuildingInsuranceCoverage <= 250000 & amountPaidOnBuildingClaim > 0 &
amountPaidOnBuildingClaim <= 250000 &
amountPaidOnBuildingClaim <= totalBuildingInsuranceCoverage]
if (is.null(state_filter)) {
return(validclaims)
} else {
return(validclaims[state == state_filter])
}
}
# Need to handle negative claim amounts and corresponding duplicate claim payments
claims <- assemble_claims(state="NC")
claims[abs(elevationDifference) == 999, elevationDifference := NA]
claims[, floodZone := as.character(floodZone)]
claims[, sfha := grepl("A|V", floodZone)]
claims[censusTract < 37000000000, censusTract := NA]
claims <- claims[!is.na(censusTract)]
# todo: attempt to recreate missing census tracts from zipcodes/latLongs
## ---- import-nfip-policies ----
policies <- fread("../data_buyouts/policies.csv")
policies[censusTract < 37000000000 | censusTract >= 38000000000, censusTract := NA]
policies <- policies[!is.na(censusTract) & occupancyType == 1 &
totalBuildingInsuranceCoverage > 0 & totalBuildingInsuranceCoverage <= 250000]
policies[, originalConstructionDate := year(originalConstructionDate)]
policies[originalConstructionDate > year(Sys.time()), originalConstructionDate := NA]
policies <- policies[!is.na(originalConstructionDate)]
policies[, policyyear := year(policyEffectiveDate)]
policies <- policies[policyyear < year(Sys.time())] # drop the handful of 2021 policies
policies[elevationDifference < -100 | elevationDifference > 200, elevationDifference := NA]
policies[, sfha := grepl("A|V", floodZone)]
# dates: policyEffectiveDate, originalNBDate, policyTerminationDate, (cancellationDateOfFloodPolicy)