rake                 package:survey                 R Documentation

_R_a_k_i_n_g _o_f _s_u_r_v_e_y _d_e_s_i_g_n

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

     Raking uses iterative post-stratification to match marginal
     distributions of a survey sample to known population margins.

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

     rake(design, sample.margins, population.margins, control = list(maxit =
     10, epsilon = 1, verbose=FALSE))

_A_r_g_u_m_e_n_t_s:

  design: A survey design with replicate weights 

sample.margins: list of formulas or data frames describing sample
          margins

population.margins: list of tables or data frames describing
          corresponding population margins 

 control: 'maxit' controls the number of iterations. Convergence is
          declared if the maximum change in a table entry is less than 
          'epsilon'. If 'epsilon<1' it is taken to be a fraction of the
          total sampling weight. 

_D_e_t_a_i_l_s:

     The 'sample.margins' should be in a format suitable for
     'postStratify'.

     Raking is known to converge for any table without zeros, and for
     any table with zeros for which there is a joint distribution with
     the given margins and the same pattern of zeros.   The `margins'
     need not be one-dimensional.

     The algorithm works by repeated calls to 'postStratify', perhaps
     the least efficient possible implementation.

_V_a_l_u_e:

     A raked survey design.

_S_e_e _A_l_s_o:

     'as.svrepdesign', 'svrepdesign', 'postStratify'

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

     data(api)
     dclus1 <- svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)
     rclus1 <- as.svrepdesign(dclus1)

     svrepmean(~api00, rclus1)
     svreptotal(~enroll, rclus1)

     ## population marginal totals for each stratum
     pop.types <- data.frame(stype=c("E","H","M"), Freq=c(4421,755,1018))
     pop.schwide <- data.frame(sch.wide=c("No","Yes"), Freq=c(1072,5122))

     rclus1r <- rake(rclus1, list(~stype,~sch.wide), list(pop.types, pop.schwide))

     svrepmean(~api00, rclus1r)
     svreptotal(~enroll, rclus1r)

     ## marginal totals correspond to population
     xtabs(~stype, apipop)
     svreptable(~stype, rclus1r, round=TRUE)
     xtabs(~sch.wide, apipop)
     svreptable(~sch.wide, rclus1r, round=TRUE)

     ## joint totals don't correspond 
     xtabs(~stype+sch.wide, apipop)
     svreptable(~stype+sch.wide, rclus1r, round=TRUE)

     ## compare to joint post-stratification
     ## (only possible if joint population table is known)
     ##
     pop.table <- xtabs(~stype+sch.wide,apipop)
     rclus1ps <- postStratify(rclus1, ~stype+sch.wide, pop.table)
     svreptable(~stype+sch.wide, rclus1ps, round=TRUE)

     svrepmean(~api00, rclus1ps)
     svreptotal(~enroll, rclus1ps)

