From 801bd503de4d3f0933d98d56e73afd97f5ce5c1a Mon Sep 17 00:00:00 2001 From: Christopher Prener Date: Fri, 22 Mar 2019 21:21:14 -0500 Subject: [PATCH] finish building pkgdown site --- .../areal-weighted-interpolation.html | 523 ++++++++++-------- docs/articles/areal.html | 4 +- docs/articles/data-preparation.html | 4 +- docs/news/index.html | 13 +- vignettes/areal-weighted-interpolation.Rmd | 18 + 5 files changed, 319 insertions(+), 243 deletions(-) diff --git a/docs/articles/areal-weighted-interpolation.html b/docs/articles/areal-weighted-interpolation.html index 025edfd..b007076 100644 --- a/docs/articles/areal-weighted-interpolation.html +++ b/docs/articles/areal-weighted-interpolation.html @@ -30,7 +30,7 @@ areal - 0.1.3 + 0.1.4 @@ -89,7 +89,7 @@

Areal Weighted Interpolation

Christopher Prener, Ph.D.

-

2019-01-18

+

2019-03-22

Source: vignettes/areal-weighted-interpolation.Rmd @@ -324,37 +324,37 @@

The example above is a spatially extensive interpolation because it involves count data. In areal, these estimates are obtained using the aw_interpolate() function:

For spatially extensive interpolations, a list of variable names should be supplied for the argument extensive. This can be a single variable name, such as in the example above, or a vector of variable names:

This ability is a key feature of areal - iteration is built into the package by default, eliminating the need for repeated table joins after interpolations are calculated.

@@ -435,7 +435,7 @@

Intensive Interpolations

-

Spatially intensive operations are used when the data to be interpolated are a ratio. An example of these data can be found in ar_stl_asthma, which contains asthma rates for each census tract in the city. The interpolation process is very similar to the spatially extensive workflow, except with how the areal weight is calculated. Instead of using the source data’s area for reference, the target data is used in the denominator. Let:

+

Spatially intensive operations are used when the data to be interpolated are, for example, a percentage or density value. An example of these data can be found in ar_stl_asthma, which contains asthma rates for each census tract in the city. The interpolation process is very similar to the spatially extensive workflow, except with how the areal weight is calculated. Instead of using the source data’s area for reference, the target data is used in the denominator. Let:

@@ -494,73 +494,101 @@

aw_interpolate(wards, tid = WARD, source = combinedData, sid = GEOID, weight = "sum", output = "tibble", intensive = "ASTHMA", extensive = c("TOTAL_E", "WHITE_E", "BLACK_E")) -#> # A tibble: 28 x 5 -#> WARD TOTAL_E WHITE_E BLACK_E ASTHMA -#> <int> <dbl> <dbl> <dbl> <dbl> -#> 1 1 7992. 153. 7779. 13.4 -#> 2 2 12145. 1323. 10639. 13.2 -#> 3 3 7344. 591. 6635. 14.1 -#> 4 4 8458. 160. 8203. 13.6 -#> 5 5 8783. 1526. 7056. 13.8 -#> 6 6 14050. 5840. 7439. 11.7 -#> 7 7 15840. 8220. 6629. 9.72 -#> 8 8 12188. 7604. 3796. 9.82 -#> 9 9 14217. 6838. 6413. 11.8 -#> 10 10 11239. 8703. 1667. 9.44 +#> # A tibble: 28 x 7 +#> OBJECTID WARD AREA TOTAL_E WHITE_E BLACK_E ASTHMA +#> <dbl> <int> <dbl> <dbl> <dbl> <dbl> <dbl> +#> 1 1 1 46138761. 7992. 153. 7779. 13.4 +#> 2 2 2 267817711. 12145. 1323. 10639. 13.2 +#> 3 3 3 66291644. 7344. 591. 6635. 14.1 +#> 4 4 4 53210707. 8458. 160. 8203. 13.6 +#> 5 5 5 60462396. 8783. 1526. 7056. 13.8 +#> 6 6 6 64337271. 14050. 5840. 7439. 11.7 +#> 7 7 7 101268146. 15840. 8220. 6629. 9.72 +#> 8 8 8 45966410. 12188. 7604. 3796. 9.82 +#> 9 9 9 73993891. 14217. 6838. 6413. 11.8 +#> 10 10 10 62915358. 11239. 8703. 1667. 9.44 #> # … with 18 more rows +

Users should take care to consider the implications of interpolating multiple values, such as total population and the number of African American residents (both extensive), and then calculating a spatially intensive variable from them such as percent African American. Doing so in multiple steps, and thereby treating extensive and intensive values as independent, may result in estimates that differ from a single step process where the percent of African American residents is interpoltated directly.

+ +

Note that there are a number of points of departure between the data interpolated as intensive values (WHITE_PCT, BLACK_PCT) and those that were interpolated as count data (i.e. extensive values) and then converted to intensive variables (WHITE_PCT_2 and BLACK_PCT_2).

Output Options

All of the above examples have created a tibble for output, but areal also supports the creation of sf objects as well:

- +

Other Features of aw_interpolate

The sf option will include all of the variables that were included in the original target data. The aw_interpolate() function is pipe-able, allowing for existing tidyverse workflows to be integrated into the interpolation process. For example, if we wanted to remove the OBJECTID and AREA columns because they are not needed, this can be accomplished easily with areal and dplyr:

- -

All of the areal functions that are exported support non-standard evaluation, meaning that inputs can be either unquoted as they are above or quoted:

+

All of the areal functions that are exported support non-standard evaluation, meaning that inputs can be either unquoted as they are above or quoted:

+

This functionality is not available for the intensive and extensive arguments at this time.

@@ -583,181 +630,181 @@

Manual Workflow

areal purposely exports the sub-functions that are called by aw_interpolate() so that the interpolation process is not a “black box” but rather can be recreated manually. This is envisioned as a diagnostic toolkit, with the final interpolations estimated using the simpler aw_interpolate() function once any issues have been identified and ameliorated

First, we’ll prepare the data but retaining only the columns we are interested in from the source data using the select() function from dplyr:

- +

We want to be careful to retain both a column with a value to be interpolated (total population in this case, TOTAL_E) and a column with a unique identification number (GEOID in this case).

Intersect Data

As we noted above, the interpolation process begins with calculating the intersection between the source and target data. We use the function aw_intersect() to accomplish this:

- +

Note that aw_intersect() automatically calculates the area of the intersected feature.

Calculate Total Area

Next, we want to apply the total area of our source features to our data using aw_total(). This will implement the correct areal weighting approach based on the type and weight arguments. We’ll use the "sum" approach to areal weights here:

- -

Changing type to "intensive" would be necessary for spatially intensive interpolations. Likewise, changing weight to "total" is necessary if areas that lack overlap should not be allocated into the target features.

-
-
-

-Calculate Areal Weight

-

With the total weight in hand, we are ready to calculate the areal weight itself using aw_weight().

intersect %>%
-  aw_weight(areaVar = "area", totalVar = "totalArea", 
-            areaWeight = "areaWeight") -> intersect
+  aw_total(source = race, id = GEOID, areaVar = "area", totalVar = "totalArea",
+             type = "extensive", weight = "sum") -> intersect
 
 intersect
-#> Simple feature collection with 287 features and 6 fields
-#> geometry type:  MULTIPOLYGON
+#> Simple feature collection with 287 features and 5 fields
+#> geometry type:  GEOMETRY
 #> dimension:      XY
 #> bbox:           xmin: 733361.8 ymin: 4268411 xmax: 746155.7 ymax: 4295504
 #> epsg (SRID):    26915
 #> proj4string:    +proj=utm +zone=15 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
 #> First 10 features:
-#>          GEOID TOTAL_E WARD         area  totalArea   areaWeight
-#> 1  29510106500    2863    1 4.271176e+05  1064776.2 4.011337e-01
-#> 2  29510106700    3168    1 5.946820e+05  1239241.5 4.798758e-01
-#> 3  29510107500    1991    1 6.146361e+05   912325.0 6.737030e-01
-#> 4  29510107600    1958    1 1.071347e+06  1146634.4 9.343406e-01
-#> 5  29510110100    2820    1 5.563665e+01   994606.5 5.593835e-05
-#> 6  29510109600    3050    1 3.586828e+03  3157835.4 1.135850e-03
-#> 7  29510126900    4462    1 8.903340e+05  4334701.5 2.053968e-01
-#> 8  29510127000    1826    1 1.015451e+03 14726832.5 6.895245e-05
-#> 9  29510106400    1986    1 6.866924e+05  1107191.4 6.202111e-01
-#> 10 29510108100    3309    1 1.198667e+02  3216478.2 3.726645e-05
+#>          GEOID TOTAL_E WARD         area  totalArea
+#> 1  29510106500    2863    1 4.271176e+05  1064776.2
+#> 2  29510106700    3168    1 5.946820e+05  1239241.5
+#> 3  29510107500    1991    1 6.146361e+05   912325.0
+#> 4  29510107600    1958    1 1.071347e+06  1146634.4
+#> 5  29510110100    2820    1 5.563665e+01   994606.5
+#> 6  29510109600    3050    1 3.586828e+03  3157835.4
+#> 7  29510126900    4462    1 8.903340e+05  4334701.5
+#> 8  29510127000    1826    1 1.015451e+03 14726832.5
+#> 9  29510106400    1986    1 6.866924e+05  1107191.4
+#> 10 29510108100    3309    1 1.198667e+02  3216478.2
 #>                          geometry
-#> 1  MULTIPOLYGON (((738110.9 42...
-#> 2  MULTIPOLYGON (((738335.2 42...
-#> 3  MULTIPOLYGON (((740111.6 42...
-#> 4  MULTIPOLYGON (((739386.1 42...
-#> 5  MULTIPOLYGON (((739542.5 42...
-#> 6  MULTIPOLYGON (((740899.6 42...
-#> 7  MULTIPOLYGON (((739115.9 42...
+#> 1  POLYGON ((738110.9 4283989,...
+#> 2  POLYGON ((738335.2 4283055,...
+#> 3  POLYGON ((740111.6 4286547,...
+#> 4  POLYGON ((739386.1 4285082,...
+#> 5  POLYGON ((739542.5 4283728,...
+#> 6  POLYGON ((740899.6 4285240,...
+#> 7  POLYGON ((739115.9 4285807,...
 #> 8  MULTIPOLYGON (((740936.1 42...
-#> 9  MULTIPOLYGON (((738500.9 42...
-#> 10 MULTIPOLYGON (((740163.9 42...
+#> 9 POLYGON ((738500.9 4284750,... +#> 10 POLYGON ((740163.9 4286467,...
+

Changing type to "intensive" would be necessary for spatially intensive interpolations. Likewise, changing weight to "total" is necessary if areas that lack overlap should not be allocated into the target features.

-
+

-Calculate Estimated Population

-

We can then multiply the value (TOTAL_E) by the weight (areaWeight) to get a population estimate for each intersected feature using aw_calculate():

+Calculate Areal Weight

+

With the total weight in hand, we are ready to calculate the areal weight itself using aw_weight().

intersect %>%
-  aw_calculate(value = TOTAL_E, areaWeight = "areaWeight") -> intersect
-
-intersect
-#> Simple feature collection with 287 features and 6 fields
-#> geometry type:  MULTIPOLYGON
-#> dimension:      XY
-#> bbox:           xmin: 733361.8 ymin: 4268411 xmax: 746155.7 ymax: 4295504
-#> epsg (SRID):    26915
-#> proj4string:    +proj=utm +zone=15 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
-#> First 10 features:
-#>          GEOID      TOTAL_E WARD         area  totalArea   areaWeight
-#> 1  29510106500 1148.4457826    1 4.271176e+05  1064776.2 4.011337e-01
-#> 2  29510106700 1520.2464178    1 5.946820e+05  1239241.5 4.798758e-01
-#> 3  29510107500 1341.3426720    1 6.146361e+05   912325.0 6.737030e-01
-#> 4  29510107600 1829.4388297    1 1.071347e+06  1146634.4 9.343406e-01
-#> 5  29510110100    0.1577461    1 5.563665e+01   994606.5 5.593835e-05
-#> 6  29510109600    3.4643427    1 3.586828e+03  3157835.4 1.135850e-03
-#> 7  29510126900  916.4807234    1 8.903340e+05  4334701.5 2.053968e-01
-#> 8  29510127000    0.1259072    1 1.015451e+03 14726832.5 6.895245e-05
-#> 9  29510106400 1231.7392274    1 6.866924e+05  1107191.4 6.202111e-01
-#> 10 29510108100    0.1233147    1 1.198667e+02  3216478.2 3.726645e-05
-#>                          geometry
-#> 1  MULTIPOLYGON (((738110.9 42...
-#> 2  MULTIPOLYGON (((738335.2 42...
-#> 3  MULTIPOLYGON (((740111.6 42...
-#> 4  MULTIPOLYGON (((739386.1 42...
-#> 5  MULTIPOLYGON (((739542.5 42...
-#> 6  MULTIPOLYGON (((740899.6 42...
-#> 7  MULTIPOLYGON (((739115.9 42...
-#> 8  MULTIPOLYGON (((740936.1 42...
-#> 9  MULTIPOLYGON (((738500.9 42...
-#> 10 MULTIPOLYGON (((740163.9 42...
-

There is an optional newVar argument that can be used to store the estimates in a new column rather than in the existing value column.

+ aw_weight(areaVar = "area", totalVar = "totalArea", + areaWeight = "areaWeight") -> intersect + +intersect +#> Simple feature collection with 287 features and 6 fields +#> geometry type: GEOMETRY +#> dimension: XY +#> bbox: xmin: 733361.8 ymin: 4268411 xmax: 746155.7 ymax: 4295504 +#> epsg (SRID): 26915 +#> proj4string: +proj=utm +zone=15 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +#> First 10 features: +#> GEOID TOTAL_E WARD area totalArea areaWeight +#> 1 29510106500 2863 1 4.271176e+05 1064776.2 4.011337e-01 +#> 2 29510106700 3168 1 5.946820e+05 1239241.5 4.798758e-01 +#> 3 29510107500 1991 1 6.146361e+05 912325.0 6.737030e-01 +#> 4 29510107600 1958 1 1.071347e+06 1146634.4 9.343406e-01 +#> 5 29510110100 2820 1 5.563665e+01 994606.5 5.593835e-05 +#> 6 29510109600 3050 1 3.586828e+03 3157835.4 1.135850e-03 +#> 7 29510126900 4462 1 8.903340e+05 4334701.5 2.053968e-01 +#> 8 29510127000 1826 1 1.015451e+03 14726832.5 6.895245e-05 +#> 9 29510106400 1986 1 6.866924e+05 1107191.4 6.202111e-01 +#> 10 29510108100 3309 1 1.198667e+02 3216478.2 3.726645e-05 +#> geometry +#> 1 POLYGON ((738110.9 4283989,... +#> 2 POLYGON ((738335.2 4283055,... +#> 3 POLYGON ((740111.6 4286547,... +#> 4 POLYGON ((739386.1 4285082,... +#> 5 POLYGON ((739542.5 4283728,... +#> 6 POLYGON ((740899.6 4285240,... +#> 7 POLYGON ((739115.9 4285807,... +#> 8 MULTIPOLYGON (((740936.1 42... +#> 9 POLYGON ((738500.9 4284750,... +#> 10 POLYGON ((740163.9 4286467,... -
+

-Aggregate Estimated Population by Target ID

-

Finally, we aggregate the estimated values by target features using aw_aggregate():

+Calculate Estimated Population +

We can then multiply the value (TOTAL_E) by the weight (areaWeight) to get a population estimate for each intersected feature using aw_calculate():

+#> GEOID TOTAL_E WARD area totalArea areaWeight +#> 1 29510106500 1148.4457826 1 4.271176e+05 1064776.2 4.011337e-01 +#> 2 29510106700 1520.2464178 1 5.946820e+05 1239241.5 4.798758e-01 +#> 3 29510107500 1341.3426720 1 6.146361e+05 912325.0 6.737030e-01 +#> 4 29510107600 1829.4388297 1 1.071347e+06 1146634.4 9.343406e-01 +#> 5 29510110100 0.1577461 1 5.563665e+01 994606.5 5.593835e-05 +#> 6 29510109600 3.4643427 1 3.586828e+03 3157835.4 1.135850e-03 +#> 7 29510126900 916.4807234 1 8.903340e+05 4334701.5 2.053968e-01 +#> 8 29510127000 0.1259072 1 1.015451e+03 14726832.5 6.895245e-05 +#> 9 29510106400 1231.7392274 1 6.866924e+05 1107191.4 6.202111e-01 +#> 10 29510108100 0.1233147 1 1.198667e+02 3216478.2 3.726645e-05 +#> geometry +#> 1 POLYGON ((738110.9 4283989,... +#> 2 POLYGON ((738335.2 4283055,... +#> 3 POLYGON ((740111.6 4286547,... +#> 4 POLYGON ((739386.1 4285082,... +#> 5 POLYGON ((739542.5 4283728,... +#> 6 POLYGON ((740899.6 4285240,... +#> 7 POLYGON ((739115.9 4285807,... +#> 8 MULTIPOLYGON (((740936.1 42... +#> 9 POLYGON ((738500.9 4284750,... +#> 10 POLYGON ((740163.9 4286467,...
+

There is an optional newVar argument that can be used to store the estimates in a new column rather than in the existing value column.

+
+
+

+Aggregate Estimated Population by Target ID

+

Finally, we aggregate the estimated values by target features using aw_aggregate():

+
diff --git a/docs/articles/areal.html b/docs/articles/areal.html index 780ad66..7e0b65e 100644 --- a/docs/articles/areal.html +++ b/docs/articles/areal.html @@ -30,7 +30,7 @@ areal - 0.1.3 + 0.1.4 @@ -90,7 +90,7 @@

Areal Interpolation in R

Christopher Prener, Ph.D.

-

2019-01-18

+

2019-03-22

Source: vignettes/areal.Rmd diff --git a/docs/articles/data-preparation.html b/docs/articles/data-preparation.html index 69034df..a876677 100644 --- a/docs/articles/data-preparation.html +++ b/docs/articles/data-preparation.html @@ -30,7 +30,7 @@ areal - 0.1.3 + 0.1.4 @@ -89,7 +89,7 @@

Preparing Data for Interpolation

Christopher Prener, Ph.D.

-

2019-01-18

+

2019-03-22

Source: vignettes/data-preparation.Rmd diff --git a/docs/news/index.html b/docs/news/index.html index 7c24eec..03fcb6a 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -60,7 +60,7 @@ areal - 0.1.3 + 0.1.4 @@ -121,6 +121,16 @@

Changelog

Source: NEWS.md +
+

+areal 0.1.4 Unreleased +

+ +

areal 0.1.3 Unreleased @@ -174,6 +184,7 @@

Contents