election               package:survey               R Documentation

_U_S _2_0_0_4 _p_r_e_s_i_d_e_n_t_i_a_l _e_l_e_c_t_i_o_n _d_a_t_a _a_t _s_t_a_t_e _o_r _c_o_u_n_t_y _l_e_v_e_l

_D_e_s_c_r_i_p_t_i_o_n:

     A 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.

_U_s_a_g_e:

     data(election)

_F_o_r_m_a_t:

     'election' is a data frame with 4600 observations on the following
     8 variables.

     '_C_o_u_n_t_y' A factor specifying the state or country

     '_T_o_t_P_r_e_c_i_n_c_t_s' Number of precincts in the state or county

     '_P_r_e_c_i_n_c_t_s_R_e_p_o_r_t_i_n_g' Number of precincts supplying data

     '_B_u_s_h' Votes for George W. Bush

     '_K_e_r_r_y' Votes for John Kerry

     '_N_a_d_e_r' Votes for Ralph Nader

     '_v_o_t_e_s' Total votes for those three candidates

     '_p' Sampling 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.

_S_o_u_r_c_e:

     .

_E_x_a_m_p_l_e_s:

     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)
     svytotal(~Bush+Kerry+Nader, dpps_yg)
     svytotal(~Bush+Kerry+Nader, dpps_hr)
     svytotal(~Bush+Kerry+Nader, dpps_hryg)
     svytotal(~Bush+Kerry+Nader, dpps_hr1)
     svytotal(~Bush+Kerry+Nader, dpps_br)
     svytotal(~Bush+Kerry+Nader, dpps_ov)
     svytotal(~Bush+Kerry+Nader, dppswr)

