election.RdA sample of voting data from US states or counties (depending on data availability), sampled with probability proportional to number of votes. The sample was drawn using Tille's splitting method, implemented in the "sampling" package.
data(election)election is a data frame with 4600 observations on the following 8 variables.
CountyA factor specifying the state or country
TotPrecinctsNumber of precincts in the state or county
PrecinctsReportingNumber of precincts supplying data
BushVotes for George W. Bush
KerryVotes for John Kerry
NaderVotes for Ralph Nader
votesTotal votes for those three candidates
pSampling probability, proportional to votes
election_pps is a sample of 40 counties or states taken with
probability proportional to the number of votes. It includes the
additional column wt with the sampling weights.
election_insample indicates which rows of election were sampled.
election_jointprob are the pairwise sampling probabilities and
election_jointHR are approximate pairwise sampling probabilities using
the Hartley-Rao approximation.
.
data(election)
## high positive correlation between totals
plot(Bush~Kerry,data=election,log="xy")
## high negative correlation between proportions
plot(I(Bush/votes)~I(Kerry/votes), data=election)
## Variances without replacement
## Horvitz-Thompson type
dpps_br<- svydesign(id=~1, fpc=~p, data=election_pps, pps="brewer")
dpps_ov<- svydesign(id=~1, fpc=~p, data=election_pps, pps="overton")
dpps_hr<- svydesign(id=~1, fpc=~p, data=election_pps, pps=HR(sum(election$p^2)/40))
dpps_hr1<- svydesign(id=~1, fpc=~p, data=election_pps, pps=HR())
dpps_ht<- svydesign(id=~1, fpc=~p, data=election_pps, pps=ppsmat(election_jointprob))
## Yates-Grundy type
dpps_yg<- svydesign(id=~1, fpc=~p, data=election_pps, pps=ppsmat(election_jointprob),variance="YG")
dpps_hryg<- svydesign(id=~1, fpc=~p, data=election_pps, pps=HR(sum(election$p^2)/40),variance="YG")
## The with-replacement approximation
dppswr <-svydesign(id=~1, probs=~p, data=election_pps)
svytotal(~Bush+Kerry+Nader, dpps_ht)
#> total SE
#> Bush 64518472 2604404
#> Kerry 51202102 2523712
#> Nader 478530 102326
svytotal(~Bush+Kerry+Nader, dpps_yg)
#> total SE
#> Bush 64518472 2406526
#> Kerry 51202102 2408091
#> Nader 478530 101664
svytotal(~Bush+Kerry+Nader, dpps_hr)
#> total SE
#> Bush 64518472 2624662
#> Kerry 51202102 2525222
#> Nader 478530 102793
svytotal(~Bush+Kerry+Nader, dpps_hryg)
#> total SE
#> Bush 64518472 2436738
#> Kerry 51202102 2439845
#> Nader 478530 102016
svytotal(~Bush+Kerry+Nader, dpps_hr1)
#> total SE
#> Bush 64518472 2472753
#> Kerry 51202102 2426842
#> Nader 478530 102595
svytotal(~Bush+Kerry+Nader, dpps_br)
#> total SE
#> Bush 64518472 2447629
#> Kerry 51202102 2450787
#> Nader 478530 102420
svytotal(~Bush+Kerry+Nader, dpps_ov)
#> total SE
#> Bush 64518472 2939608
#> Kerry 51202102 1964632
#> Nader 478530 104373
svytotal(~Bush+Kerry+Nader, dppswr)
#> total SE
#> Bush 64518472 2671455
#> Kerry 51202102 2679433
#> Nader 478530 105303