Expected cases
- indirected standardization
- strata: 2 races X 2 genders = 2X2 = 4
library(SpatialEpi)
n.strata = 4
dohio <- dohio%>%
arrange(county,year,gender,race)
E <- expected(population = dohio$n,
cases = dohio$y,
n.strata = n.strata)
nyears <- length(unique(dohio$year))
countiesE <- rep(unique(dohio$NAME),
each = nyears)
ncounties <- length(unique(dohio$NAME))
yearsE <- rep(unique(dohio$year),
times = ncounties)
dE <- data.frame(county = countiesE, year = yearsE, E = E)
head(dE)
## county year E
## 1 Adams 1968 8.278660
## 2 Adams 1969 8.501767
## 3 Adams 1970 8.779313
## 4 Adams 1971 9.175276
## 5 Adams 1972 9.548736
## 6 Adams 1973 10.099777
d <- merge(d, dE, by = c("county", "year"))
head(d)
## county year Y E
## 1 Adams 1968 6 8.278660
## 2 Adams 1969 5 8.501767
## 3 Adams 1970 9 8.779313
## 4 Adams 1971 6 9.175276
## 5 Adams 1972 10 9.548736
## 6 Adams 1973 7 10.099777