BW2stagePPS | R Documentation |

Compute components of relvariance for a sample design where primary sampling units (PSUs) are selected with probability proportional to size (*pps*) and elements are selected via simple random sampling (*srs*). The input is an entire sampling frame.

```
BW2stagePPS(X, pp, psuID, lonely.SSU = "mean")
```

`X` |
data vector; length is the number of elements in the population. |

`pp` |
vector of one-draw probabilities for the PSUs; length is number of PSUs in population. |

`psuID` |
vector of PSU identification numbers. This vector must be as long as |

`lonely.SSU` |
indicator for how singleton SSUs should be handled when computing the within PSU unit relvariance. Allowable values are |

`BW2stagePPS`

computes the between and within population relvariance components
appropriate for a two-stage sample in which PSUs are selected with varying probabilities
and with replacement. Elements within PSUs are selected by simple random sampling.
The components are appropriate for approximating the relvariance of the probability-with-replacement (*pwr*)-estimator of a total when the same number of elements are selected within each sample PSU.
The function requires that an entire frame of PSUs and elements be input.

If a PSU contains multiple SSUs, some of which have missing data, or contains only one SSU, a value is imputed. If `lonely.SSU = "mean"`

, the mean of the non-missing PSU contributions is imputed. If `lonely.SSU = "zero"`

, a 0 is imputed. The former would be appropriate if a PSU contains multiple SSUs but one or more of them has missing data in which case R will normally calculate
an NA. The latter would be appropriate if the PSU contains only one SSU which would be selected with certainty in any sample.

If any PSUs have one-draw probabilities of 1 (pp=1), they will be excluded from all computations.

(Use `BW2stagePPSe`

if only a sample of PSUs and elements is available.)

List object with values:

`B2` |
between PSU unit relvariance |

`W2` |
within PSU unit relvariance |

`unit relvar` |
unit relvariance for population |

`B2+W2` |
sum of between and within relvariance estimates |

`k` |
ratio of |

`delta` |
measure of homogeneity with PSUs estimated as |

Richard Valliant, Jill A. Dever, Frauke Kreuter

Cochran, W.G. (1977, pp.308-310). *Sampling Techniques*. New York: John Wiley & Sons.

Saerndal, C.E., Swensson, B., and Wretman, J. (1992). *Model Assisted Survey Sampling*. New York: Springer.

Valliant, R., Dever, J., Kreuter, F. (2018, sect. 9.2.3). *Practical Tools for Designing and Weighting Survey Samples, 2nd edition*. New York: Springer.

`BW2stagePPSe`

, `BW2stageSRS`

, `BW3stagePPS`

, `BW3stagePPSe`

```
data(MDarea.pop)
MDsub <- MDarea.pop[1:100000,]
# Use PSU and SSU variables to define psu's
pp.PSU <- table(MDsub$PSU) / nrow(MDsub)
pp.SSU <- table(MDsub$SSU) / nrow(MDsub)
# components with psu's defined by the PSU variable
BW2stagePPS(MDsub$y1, pp=pp.PSU, psuID=MDsub$PSU, lonely.SSU="mean")
# components with psu's defined by the SSU variable
BW2stagePPS(MDsub$y1, pp=pp.SSU, psuID=MDsub$SSU, lonely.SSU="mean")
# Use census tracts and block groups to define psu's
trtBG <- 10*MDsub$TRACT + MDsub$BLKGROUP
pp.trt <- table(MDsub$TRACT) / nrow(MDsub)
pp.BG <- table(trtBG) / nrow(MDsub)
# components with psu's defined by tracts
BW2stagePPS(MDsub$ins.cov, pp=pp.trt, psuID=MDsub$TRACT, lonely.SSU="mean")
# components with psu's defined by block groups
BW2stagePPS(MDsub$ins.cov, pp=pp.BG, psuID=trtBG, lonely.SSU="mean")
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.