I am trying to allocate census data based on the block group level into school attendance zones. In using this code, the weights are based on the area of the block group covered by any attendance zone. However, at the edges of the map, there are places where block groups are partly in one school zone and partly not covered by any school zone. For example, a block group might be 20% in School Zone A, 30% in School Zone B, but 50% not covered by any school zone. The code above does not account for this missing 50% and therefore allocates all the residents of that block group into school zones A and B, rather than only 20% and 30% respectively.
Can anyone help me with adjusting this code such that the denominator for the block group weights reflects the total area of the block group?
schoolzones %>% aw_intersect(censusbgs, areaVar = "area") %>% aw_total(censusbgs, id = FIPS, areaVar = "area", totalVar = "totalArea", type = "extensive", weight = "sum") %>% aw_weight(areaVar = "area", totalVar = "totalArea", areaWeight = "bg_weight")
Created on 2022-09-12 with reprex v2.0.2