Linear Design

Tom Kincaid

2019-08-29

Preliminaries

This document presents example GRTS survey designs for a linear resource. The linear resource used in the designs is streams that comprise the Luckiamute watershed in Oregon. Four survey designs will be presented: (1) an unstratified, equal probability design; (2) a stratified, equal probability design with an oversample; (3) a stratified, unequal probability design with an oversample; and (4) a stratified, unequal probability design with an oversample and a panel structure for survey over time. The sampling frame used for the survey designs is contained in either an ESRI shapefile, an sf object, or an sp package object. The frame contains the coordinates for a set of line segments that define the linear resource in addition to attribute data associated with the line segments. The coordinate system for the set of points in the sampling frame is an equal area projection rather than latitude and longitude. An equal area projection is used so that calculation of distance between points is valid.

The initial step is to use the library function to load the spsurvey package. After the package is loaded, a message is printed to the R console indicating that the spsurvey package was loaded successfully.

Load the spsurvey package:

library(spsurvey)

Read the sf object

For creating a survey design using the spsurvey package, the standard form of input regarding the resource is a simple features (sf) object. An sf data set for creating the survey designs in this vignette is included in the data directory of the package. The data function is used to load the data set stored in the data directory into an object named Luck_Ash_streams. Note that sf objects loaded from the data sets in the data directory are stored in a format that is defined in the sf package. See documentation for the sf package for additional information regarding format of those objects.

Load the sf object in the data directory:

data(Luck_Ash_streams)

Attribute data

Two attributes, stream type and Strahler stream order, will be used to define, respectively, stratum codes and unequal selection probability (multidensity) categories for the survey designs. Stream type is contained in a variable named “Per_Int”, and Strahler stream order is contained in a variable named “Strah_Cat”. For stream type, streams are classified as either perennial or intermittent. For Strahler stream order, streams are classified as either first order (“1st”), second order (“2nd”), or third order and higher (“3rd+”). The table and addmargin functions are used to produce a table displaying number of stream segments for each combination of values for the strata and multidensity category variables.

Finally, frame stream length is summarized for the strata and multidensity category attributes. Note that stream length measured in kilometers is contained in the variable named “Length_km”. The tapply function is used to calculate total stream length for each combination of stream type and Strahler stream order. The addmargins function is applied to the output from tapply to calculate stream length for each category of stream type and Strahler stream order, and the round function is used to round value to two decimal places. Finally, the resulting cross-tabulation of sum of stream length in kilometers for Strahler stream order and stream type is displayed.

Display the initial six features in the sf object:

head(Luck_Ash_streams)
#> Simple feature collection with 6 features and 3 fields
#> geometry type:  LINESTRING
#> dimension:      XY
#> bbox:           xmin: -2148980 ymin: 2722288 xmax: -2126694 ymax: 2746966
#> epsg (SRID):    5070
#> proj4string:    +proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
#>        Per_Int Strah_Cat Length_km                       geometry
#> 1    Perennial       2nd 2.3261097 LINESTRING (-2128642 272228...
#> 2 Intermittent       1st 0.5785829 LINESTRING (-2137334 274498...
#> 3 Intermittent       1st 0.7796058 LINESTRING (-2129644 274406...
#> 4    Perennial       1st 1.8757176 LINESTRING (-2148980 274686...
#> 5 Intermittent       1st 1.0012245 LINESTRING (-2134217 274357...
#> 6    Perennial       1st 1.6464196 LINESTRING (-2136771 274488...

Display number of stream segments cross-classified by the strata and multidensity category variables:

with(Luck_Ash_streams, addmargins(table("Stream Type"=Per_Int, "Strahler Order"=Strah_Cat)))
#>               Strahler Order
#> Stream Type    1st 2nd 3rd+ Sum
#>   Intermittent 137  20    2 159
#>   Perennial    104  78   88 270
#>   Sum          241  98   90 429

Summarize frame stream length by stratum and multidensity category:

temp <- with(Luck_Ash_streams, tapply(Length_km, list(Per_Int, Strah_Cat), sum))
temp <- round(addmargins(temp), 2)
names(dimnames(temp)) <- list("Stream Type", "Strahler Order")
temp
#>               Strahler Order
#> Stream Type       1st    2nd   3rd+    Sum
#>   Intermittent 305.53  20.51   3.03 329.07
#>   Perennial    200.53 133.10 159.79 493.42
#>   Sum          506.06 153.61 162.82 822.49

Streams in the Luckiamute watershed are displayed in the figure below, classified by stream type and the following figure classified by Strahler order category.

Location of streams in the Luckiamute watershed classified by stream type.

Location of streams in the Luckiamute watershed classified by stream type.

Location of streams in the Luckiamute watershed classified by Strahler order category.

Location of streams in the Luckiamute watershed classified by Strahler order category.

Unstratified, equal probability, GRTS survey design

The first survey design is an unstratified, equal probability design. The set.seed function is called so that, if necessary, the designs can be replicated.

The initial step is to create a list named Equaldsgn that contains information for specifying the survey design. Since the survey design is unstratified, the list contains a single item named “None” that also is a list. The “None” list includes two items: panel, which is used to specify the sample size for each panel, and seltype, which is used to input the type of random selection for the design. For this example, panel is assigned a single value named “PanelOne” that is set equal to 50, and seltype is assigned the value “Equal”, which indicates equal probability selection.

The grts function in the spsurvey package is called to select the survey design. The following arguments are included in the call to grts: (1) design: the named list of stratum design specifications, which is assigned the Equaldsgn list; (2) DesignID: name for the design, which is used to create a site ID for each site and is assigned the value “EQUAL”; (3) type.frame: the type of frame, which is assigned the value “linear” to indicate a linear resource; (4) src.frame: source of the frame, which is assigned the value “sf.object” to indicate an sf object frame; (5) sf.object: the sf object, which is assigned the value Luck_Ash_streams; and (6) shapefile: option to create a shapefile containing the survey design information, which is assigned FALSE.

During execution of the grts function, messages are printed that indicate the initial number of hierarchical levels used for the GRTS grid, the current number of levels, and the final number of levels. The set of messages is printed for each stratum, and is labeled with the stratum name. For this example, the set of messages is labeled “None”, i.e., the name used in the Equaldsgn list. Upon completion of the call to grts, the initial six sites for the survey design and a design summary are printed. The output object created by the grts function is assigned class “SpatialDesign”. The design summary is created using the summary method for that class. In addition to summary, a plot method is available for the SpatialDesign class. For assistance using the summary and plot methods, see documentation for “SpatialDesign-class” on the R help page for spsurvey.

Call the set.seed function so that the design can be replicated:

set.seed(19742003)

Create the design list:

Equaldsgn <- list(None=list(panel=c(PanelOne=100), seltype="Equal"))

Select the sample:

Equalsites <- grts(design=Equaldsgn,
                   DesignID="EQUAL",
                   type.frame="linear",
                   src.frame="sf.object",
                   sf.object=Luck_Ash_streams,
                   shapefile=FALSE)
#> 
#> Stratum: None 
#> Current number of levels: 4 
#> Current number of levels: 5 
#> Final number of levels: 5

Print the initial six lines of the survey design:

head(Equalsites)
#>           coordinates    siteID   xcoord  ycoord mdcaty      wgt stratum
#> 1 (-2120719, 2736598) EQUAL-001 -2120719 2736598  Equal 8224.881    None
#> 2 (-2150233, 2735349) EQUAL-002 -2150233 2735349  Equal 8224.881    None
#> 3 (-2127679, 2727034) EQUAL-003 -2127679 2727034  Equal 8224.881    None
#> 4 (-2129461, 2715834) EQUAL-004 -2129461 2715834  Equal 8224.881    None
#> 5 (-2122074, 2733907) EQUAL-005 -2122074 2733907  Equal 8224.881    None
#> 6 (-2138997, 2730255) EQUAL-006 -2138997 2730255  Equal 8224.881    None
#>      panel EvalStatus EvalReason      Per_Int Strah_Cat Length_km
#> 1 PanelOne    NotEval            Intermittent       1st 5.5893081
#> 2 PanelOne    NotEval               Perennial       2nd 0.8712123
#> 3 PanelOne    NotEval            Intermittent       1st 3.1007885
#> 4 PanelOne    NotEval               Perennial       2nd 1.2532549
#> 5 PanelOne    NotEval            Intermittent       1st 2.9219660
#> 6 PanelOne    NotEval               Perennial      3rd+ 4.6578267

Print the survey design summary:

summary(Equalsites)
#> 
#> 
#> Design Summary: Number of Sites
#> 
#> stratum
#> None  Sum 
#>  100  100

Stratified, equal probability, GRTS survey design with an oversample

The second survey design is a stratified, equal probability design with an oversample. The stream type attribute is used to identify strata. List Stratdsgn is assigned design specifications. Since the survey design is stratified, Stratdsgn includes two lists named “Perennial” and “Intermittent” that contains three items: panel, seltype, and over. Note that the names for the two lists match the levels of the stratum variable. For both lists, the values for panel and seltype are the same as the ones used for the equal probability design. The third item, over, assigns the value 50 for size of the oversample. An oversample provides additional sample sites to replace sites that cannot be used, e.g., to replace sites in the sample that are not accessible.

For this survey design, a shapefile will be used as the sampling frame. The sf package function st_write is used to create the shapefile. The following arguments are included in the call to grts: (1) design: assigned the Stratdsgn list; (2) DesignID: assigned the value “STRATIFIED”; (3) type.frame: assigned the value “linear”; (4) src.frame: assigned the value “shapefile”; (5) in.shape: assigned the value “Luck_Ash_streams.shp”; (6) stratum: name of the column in the attributes data frame that identifies the stratum code for each element in the frame, which is assigned the value “Per_Int”; and (7) shapefile: assigned the value FALSE. Upon completion of the call to grts, the initial six sites for the survey design and a design summary are printed.

Create the shapefile:

st_write(Luck_Ash_streams, "Luck_Ash_streams.shp", quiet = TRUE, delete_dsn = TRUE)
#> Warning in CPL_write_ogr(obj, dsn, layer, driver,
#> as.character(dataset_options), : GDAL Error 1: Luck_Ash_streams.shp does
#> not appear to be a file or directory.

Create the design list:

Stratdsgn <- list(Perennial=list(panel=c(PanelOne=40),
                                 seltype="Equal",
                                 over=10),
                  Intermittent=list(panel=c(PanelOne=40),
                                    seltype="Equal",
                                    over=10))

Select the sample:

Stratsites <- grts(design=Stratdsgn,
                   DesignID="STRATIFIED",
                   type.frame="linear",
                   src.frame="shapefile",
                   in.shape="Luck_Ash_streams.shp",
                   stratum="Per_Int",
                   shapefile=FALSE)
#> 
#> Stratum: Perennial 
#> Current number of levels: 3 
#> Current number of levels: 4 
#> Final number of levels: 4 
#> 
#> Stratum: Intermittent 
#> Current number of levels: 3 
#> Current number of levels: 4 
#> Current number of levels: 5 
#> Final number of levels: 5

Print the initial six lines of the survey design

head(Stratsites)
#>           coordinates         siteID   xcoord  ycoord mdcaty      wgt
#> 1 (-2119093, 2739081) STRATIFIED-001 -2119093 2739081  Equal 12335.55
#> 2 (-2136479, 2739356) STRATIFIED-002 -2136479 2739356  Equal 12335.55
#> 3 (-2119055, 2722844) STRATIFIED-003 -2119055 2722844  Equal 12335.55
#> 4 (-2142532, 2719233) STRATIFIED-004 -2142532 2719233  Equal 12335.55
#> 5 (-2129603, 2735025) STRATIFIED-005 -2129603 2735025  Equal 12335.55
#> 6 (-2138636, 2733686) STRATIFIED-006 -2138636 2733686  Equal 12335.55
#>     stratum    panel EvalStatus EvalReason Strah_Cat Length_km
#> 1 Perennial PanelOne    NotEval                  1st 11.251478
#> 2 Perennial PanelOne    NotEval                  1st  2.487395
#> 3 Perennial PanelOne    NotEval                 3rd+  4.861622
#> 4 Perennial PanelOne    NotEval                 3rd+  3.567628
#> 5 Perennial PanelOne    NotEval                 3rd+  1.338804
#> 6 Perennial PanelOne    NotEval                  2nd  1.390100

Print the survey design summary

summary(Stratsites)
#> 
#> 
#> Design Summary: Number of Sites Classified by panel and stratum
#> 
#>           stratum
#> panel      Perennial Intermittent Sum
#>   OverSamp        10           10  20
#>   PanelOne        40           40  80
#>   Sum             50           50 100

Stratified, unequal probability, GRTS survey design with an oversample

The third survey design is a stratified, unequal probability design with an oversample. As for the second survey design, the stream type attribute is used to identify strata. Strahler order categories are used to identify multidensity categories. List Unequaldsgn is assigned design specifications. Unequaldsgn includes the same two lists with three items (panel, seltype, and over) as used for the stratified, equal probability design plus a value for caty.n. For both lists, panel specifies a single panel, and seltype is assigned “Unequal” to indicate unequal probability sampling. Note that the value 0 is assigned to over for the “Intermittent” stratum, i.e., no oversample. The over item could have been omitted from the list for “Intermittent”. The vector assigned to caty.n specifies sample sizes for each of the three multidensity categories. Note that the sum of values provided in caty.n must equal the value in panel.

For this survey design, an sp package object will be used as the sampling frame. The sf package function as_Spatial is used to create an sp object named Luck_Ash_streams_sp. The following arguments are included in the call to grts: (1) design: assigned the Unequaldsgn list; (2) DesignID: assigned the value “UNEQUAL”; (3) type.frame: assigned the value “linear”; (4) src.frame: assigned the value “sp.object” to indicate that the sampling frame is provided by an sp object; (5) sp.object: name of the sp object, which is assigned the shp object; (6) stratum: assigned the value “Per_Int”; (7) mdcaty: name of the column in the attributes data frame that identifies the unequal probability category for each element in the frame, which is assigned the value “Strah_Cat”; and (8) shapefile: assigned the value FALSE. Upon completion of the call to grts, the initial six sites for the survey design and a design summary are printed.

Create the sp object:

Luck_Ash_streams_sp <- as_Spatial(Luck_Ash_streams)

Create the design list:

Unequaldsgn <- list(Perennial=list(panel=c(PanelOne=60),
                                   seltype="Unequal",
                                   caty.n=c("1st"=20, "2nd"=20, "3rd+"=20),
                                   over=10),
                    Intermittent=list(panel=c(PanelOne=30),
                                      seltype="Unequal",
                                      caty.n=c("1st"=20, "2nd"=7, "3rd+"=3),
                                      over=0))

Select the sample:

Unequalsites <- grts(design=Unequaldsgn,
                     DesignID="UNEQUAL",
                     type.frame="linear",
                     src.frame="sp.object",
                     sp.object=Luck_Ash_streams_sp,
                     stratum="Per_Int",
                     mdcaty="Strah_Cat",
                     shapefile=FALSE)
#> 
#> Stratum: Perennial
#> Warning in grts(design = Unequaldsgn, DesignID = "UNEQUAL", type.frame = "linear", : 
#> Oversample size is not proportional to category sample sizes for stratum
#> "Perennial".
#> Current number of levels: 4 
#> Current number of levels: 5 
#> Final number of levels: 5 
#> 
#> Stratum: Intermittent 
#> Current number of levels: 3 
#> Current number of levels: 5 
#> Current number of levels: 6 
#> Final number of levels: 6

Print the initial six lines of the survey design:

head(Unequalsites)
#>           coordinates      siteID   xcoord  ycoord mdcaty       wgt
#> 1 (-2152371, 2736339) UNEQUAL-001 -2152371 2736339    1st 10026.548
#> 2 (-2143322, 2730601) UNEQUAL-002 -2143322 2730601    1st 10026.548
#> 3 (-2139260, 2743889) UNEQUAL-003 -2139260 2743889    1st 10026.548
#> 4 (-2127174, 2722999) UNEQUAL-004 -2127174 2722999    2nd  6655.043
#> 5 (-2140379, 2720016) UNEQUAL-005 -2140379 2720016    2nd  6655.043
#> 6 (-2136001, 2720800) UNEQUAL-006 -2136001 2720800    1st 10026.548
#>     stratum    panel EvalStatus EvalReason Length_km
#> 1 Perennial PanelOne    NotEval             3.711475
#> 2 Perennial PanelOne    NotEval             6.383716
#> 3 Perennial PanelOne    NotEval             2.682515
#> 4 Perennial PanelOne    NotEval             2.326110
#> 5 Perennial PanelOne    NotEval             5.062792
#> 6 Perennial PanelOne    NotEval             2.762255

Print the survey design summary:

summary(Unequalsites)
#> Design Summary: Number of Sites Classified by mdcaty (Multidensity Category) 
#> and stratum
#> 
#>       stratum
#> mdcaty Perennial Intermittent Sum
#>   1st         28           21  49
#>   2nd         24            5  29
#>   3rd+        20            4  24
#>   Sum         72           30 102
#> 
#> 
#> Design Summary: Number of Sites Classified by panel and stratum
#> 
#>           stratum
#> panel      Perennial Intermittent Sum
#>   OverSamp        12            0  12
#>   PanelOne        60           30  90
#>   Sum             72           30 102
#> 
#> 
#> Design Summary: Number of Sites Classified by mdcaty (Multidensity Category), 
#> panel, and stratum
#> 
#> , , stratum = Perennial
#> 
#>       panel
#> mdcaty OverSamp PanelOne Sum
#>   1st         5       23  28
#>   2nd         5       19  24
#>   3rd+        2       18  20
#>   Sum        12       60  72
#> 
#> , , stratum = Intermittent
#> 
#>       panel
#> mdcaty OverSamp PanelOne Sum
#>   1st         0       21  21
#>   2nd         0        5   5
#>   3rd+        0        4   4
#>   Sum         0       30  30
#> 
#> , , stratum = Sum
#> 
#>       panel
#> mdcaty OverSamp PanelOne Sum
#>   1st         5       44  49
#>   2nd         5       24  29
#>   3rd+        2       22  24
#>   Sum        12       90 102

Stratified, unequal probability, GRTS survey design with an oversample and a panel structure for survey over time

The fourth survey design is a stratified, unequal probability design with an oversample and a panel structure for survey over time. List Paneldsgn is assigned design specifications. Analogous to the stratified, unequal probability design, Paneldsgn includes two lists named “Perennial” and “Intermittent”. For the “Perennial” stratum, a vector identifying sample sizes for three panels is assigned to panel. For the “Intermittent” stratum, the sample size for a single panel named “Annual” is assigned to panel. The value “Unequal” is assigned to seltype for both lists, which indicates unequal selection probabilities. For both lists, the third item, caty.n, assigns sample sizes for each of the three multidensity categories. Again, note that the sum of sample sizes provided in caty.n must equal the sum of sample sizes in panel. For the “Perennial” stratum, the value 50 is assigned to over, which specifies an oversample of 50 sites. No oversample is specified for the “Intermittent” stratum, and so over is not included in the list. The grts function attempts to distribute the oversample proportionately among sample sizes for the multidensity categories. If the oversample proportion for one or more categories is not a whole number, a warning message is printed and the proportion is rounded to the next higher integer.

For this survey design, an sf object will be used as the sampling frame. The following arguments are included in the call to grts: (1) design: assigned the Paneldsgn list; (2) DesignID: assigned the value “UNEQUAL”; (3) type.frame: assigned the value “linear”; (4) src.frame: assigned the value “sf.object”; (5) sf.object: the sf object, which is assigned the value Luck_Ash_streams; (6) stratum: assigned the value "Per=_Int“; (7) mdcaty: assigned the value”Strah_Cat"; and (8) shapefile: assigned the value FALSE. Upon completion of the call to grts, the initial six sites for the survey design and a design summary are printed.

Create the design list:

Paneldsgn <- list(Perennial=list(panel=c(Annual=20, Year1=20, Year2=20),
                                 seltype="Unequal",
                                 caty.n=c("1st"=25, "2nd"=20, "3rd+"=15),
                                 over=15),
                  Intermittent=list(panel=c(Annual=25),
                                    seltype="Unequal",
                                    caty.n=c("1st"=18, "2nd"=5, "3rd+"=2)))

Select the sample:

Panelsites <- grts(design=Paneldsgn,
                   DesignID="UNEQUAL",
                   type.frame="linear",
                   src.frame="sf.object",
                   sf.object=Luck_Ash_streams,
                   stratum="Per_Int",
                   mdcaty="Strah_Cat",
                   shapefile=FALSE)
#> 
#> Stratum: Perennial
#> Warning in grts(design = Paneldsgn, DesignID = "UNEQUAL", type.frame = "linear", : 
#> Oversample size is not proportional to category sample sizes for stratum
#> "Perennial".
#> Current number of levels: 4 
#> Current number of levels: 5 
#> Final number of levels: 5 
#> 
#> Stratum: Intermittent 
#> Current number of levels: 3 
#> Current number of levels: 4 
#> Current number of levels: 5 
#> Current number of levels: 6 
#> Final number of levels: 6

Print the initial six lines of the survey design:

head(Panelsites)
#>           coordinates      siteID   xcoord  ycoord mdcaty       wgt
#> 1 (-2124696, 2743279) UNEQUAL-001 -2124696 2743279    1st  8021.238
#> 2 (-2139956, 2736488) UNEQUAL-002 -2139956 2736488    1st  8021.238
#> 3 (-2149976, 2735214) UNEQUAL-003 -2149976 2735214   3rd+ 10652.682
#> 4 (-2138533, 2737853) UNEQUAL-004 -2138533 2737853    1st  8021.238
#> 5 (-2128068, 2733806) UNEQUAL-005 -2128068 2733806    2nd  6655.043
#> 6 (-2142682, 2729721) UNEQUAL-006 -2142682 2729721    1st  8021.238
#>     stratum  panel EvalStatus EvalReason Length_km
#> 1 Perennial Annual    NotEval            1.7852580
#> 2 Perennial Annual    NotEval            3.0482268
#> 3 Perennial Annual    NotEval            0.6150209
#> 4 Perennial Annual    NotEval            1.8896457
#> 5 Perennial Annual    NotEval            2.8633171
#> 6 Perennial Annual    NotEval            6.3837155

Print the survey design summary:

summary(Panelsites)
#> Design Summary: Number of Sites Classified by mdcaty (Multidensity Category) 
#> and stratum
#> 
#>       stratum
#> mdcaty Perennial Intermittent Sum
#>   1st         36           19  55
#>   2nd         24            3  27
#>   3rd+        16            3  19
#>   Sum         76           25 101
#> 
#> 
#> Design Summary: Number of Sites Classified by panel and stratum
#> 
#>           stratum
#> panel      Perennial Intermittent Sum
#>   Annual          20           25  45
#>   OverSamp        16            0  16
#>   Year1           20            0  20
#>   Year2           20            0  20
#>   Sum             76           25 101
#> 
#> 
#> Design Summary: Number of Sites Classified by mdcaty (Multidensity Category), 
#> panel, and stratum
#> 
#> , , stratum = Perennial
#> 
#>       panel
#> mdcaty Annual OverSamp Year1 Year2 Sum
#>   1st      12        6     7    11  36
#>   2nd       3        8     9     4  24
#>   3rd+      5        2     4     5  16
#>   Sum      20       16    20    20  76
#> 
#> , , stratum = Intermittent
#> 
#>       panel
#> mdcaty Annual OverSamp Year1 Year2 Sum
#>   1st      19        0     0     0  19
#>   2nd       3        0     0     0   3
#>   3rd+      3        0     0     0   3
#>   Sum      25        0     0     0  25
#> 
#> , , stratum = Sum
#> 
#>       panel
#> mdcaty Annual OverSamp Year1 Year2 Sum
#>   1st      31        6     7    11  55
#>   2nd       6        8     9     4  27
#>   3rd+      8        2     4     5  19
#>   Sum      45       16    20    20 101