17 Sampling a Population with Subgroups (Ch. 17)
Table 17.1 summarizes, for sites in three settings, the total number of sites (N), the number of sites samples (n), their mean areas (\(\bar{X}\)), and the standard error of their mean areas SE). It’s simpler to build that as a table with three columns and four rows than it is to try to recreate the layout of Drennan’s table, so we’ll do that. Since we’ll also find it useful to have the site areas themselves, we’ll also create vectors of those (mixing them in the same dataframe as the summary statistics would just get messy).
RiverBottoms <- c(3.3, 2.7, 2.1, 3.8, 2.7, 3.4, 2.9, 2.8, 2.4, 1.8, 2.4, 3.1)
RemnantLevees <- c(2.9, 1.7, 1.3, 2.1, 1.9, 1.2, 2.5, 2.1, 1.6, 1.7, 2.0, 1.6, 1.0, 1.4,
2.3, 3.2, .8, .4, .7)
Slopes <- c(.7, 1.3, 1.2, .6, .6, 1.2, .2)
SiteAreas <- data.frame(RiverBottoms = c(53, 12, 2.78, .14), RemnantLevees =
c(76, 19, 1.71, .15), Slopes = c(21, 7 , .83, .13),
row.names = c("N", "n", "barX", "SE"))
kable_classic(kable(SiteAreas), full_width = F)| RiverBottoms | RemnantLevees | Slopes | |
|---|---|---|---|
| N | 53.00 | 76.00 | 21.00 |
| n | 12.00 | 19.00 | 7.00 |
| barX | 2.78 | 1.71 | 0.83 |
| SE | 0.14 | 0.15 | 0.13 |
By all means feel free to recalculate the standard errors and confidence intervals yourself (Drennan tells you how he did it on p233).
Of course stem-and-leaf plots are easy to recreate as well.
## 1 | 2: represents 1.2
## leaf unit: 0.1
## n: 12
## 1 | 8
## 2 | 144
## 2 | 7789
## 3 | 134
## 3 | 8
## 1 | 2: represents 1.2
## leaf unit: 0.1
## n: 19
## 0 | 4
## 0 | 78
## 1 | 0234
## 1 | 66779
## 2 | 0113
## 2 | 59
## 3 | 2
## 1 | 2: represents 1.2
## leaf unit: 0.1
## n: 7
## 0 | 2
## 0 | 667
## 1 | 223
The resulting sample of sites, Drennan points out, can be used to think about sites in each environmental setting, including (for instance) estimating the population means for sites located in river bottoms, on remnant levees, and on slopes. It cannot be used (without some intervening steps), however, for thinking about sites in the region in general - because we haven’t sampled from each region equally (33% of sites on slopes have been sampled, 25% of sites on remnant levees have been sampled, and 22.6% of sites in river bottoms were sampled).
You could also think about the relative representation of environmental settings in the population versus in the sample. We have 150 sites total, of which 35% (53) are in river bottoms, 51% (76) are on remnant levees, and 14% (21) are on slopes. Our sample, however, consists of 38 sites, of which 32% (12) are in river bottoms, 50% (19) are on remant levees, and 18% (7) are on slopes.
Each setting, in this case, represents a sampling stratum, which we have considered as its own population and sampled separately (a sensible thing to do if, for instance, we had some intuition that it was a good idea to consider the sites on these settings separately, or that some settings were likely to be more interesting than others).
Drennan notes that since the sampling fractions for each setting are not wildly different (between 22.6% and 33%, to be precise), we can combine the samples to get a rough idea of what the distribution of the whole population of sites looks like. This produces the stem-and-leaf plot of Table 17.2, which is easy enough to build.
## 1 | 2: represents 1.2
## leaf unit: 0.1
## n: 38
## 0 | 24
## 0 | 66778
## 1 | 0222334
## 1 | 667789
## 2 | 0111344
## 2 | 577899
## 3 | 1234
## 3 | 8
That stem-and-leaf plot suggests that the combined population is reasonably single-peaked and symmetrical, so we might decide it was reasonable to estimate the mean site area of the population of all sites in the region. This we would do by pooling the estimates for our three separate sampling strata.
17.1 Pooling Estimates
This process of calculating the pooled estimate of the mean is described by the formula \[\bar{X}_p=\frac{\Sigma(N_h\bar{X}_h)}{N}\] where \(\bar{X}_p\) is the pooled estimate of the mean, \(\bar{X}_h\) is the mean of the elements in stratum h, \(N_h\) is the total number of elements in stratum h, and N is the total number of elements in the population.
Because R is vectorized, this is easy to put into action; R will chew through an entire vector doing whatever calculation you ask. Because this operation will be easier to follow if we can manipulate N, n, \(\bar{X}\), and SE as columns, we’ll transpose our data frame. Because t() returns a matrix, we have to make it into a data frame again. Then we can perform simple operations that cascade through the entire vector.
SiteAreas_t <- data.frame(t(SiteAreas))
SiteAreas_t$N * SiteAreas_t$barX #performs this for each row## [1] 147.34 129.96 17.43
## [1] 294.73
## [1] 1.964867
If you’d rather, you could make a function to calculate the pooled mean, and feed vectors (rather than individual numbers) to the function:
pooledmean <- function (N, barX) {
sum(N * barX) / sum(N)
}
SiteAreas_pooledmean <- pooledmean(N = SiteAreas_t$N, barX = SiteAreas_t$barX); SiteAreas_pooledmean## [1] 1.964867
Pooling of the standard errors is analogous: \[SE_p=\frac{\sqrt{\Sigma{(N_h^2)(SE_h^2)}}}{N}\] where \(SE_p\) is the pooled standard error, \(SE_h\) is the standard error for stratum h, \(N_h\) is the total number of elements in stratum h, and N is the total number of elements in the population. We can use our transposed data frame to calculate this as well.
pooledSE <- function (N, SE) {
sqrt(sum(N^2*SE^2))/sum(N)
}
SiteAreas_pooledSE <- pooledSE(N = SiteAreas_t$N, SE = SiteAreas_t$SE); SiteAreas_pooledSE## [1] 0.09248887
With the pooled mean and pooled standard error at our disposal, we can estimate the mean site area of the entire population of sites in the region at whatever confidence level we like.
## [1] 0.1874003
We can be 95% confident that the mean size of all the sites in the region is 1.96 ± 0.19 hectares.