withReplicates            package:survey            R Documentation

_C_o_m_p_u_t_e _v_a_r_i_a_n_c_e_s _b_y _r_e_p_l_i_c_a_t_e _w_e_i_g_h_t_i_n_g

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

     Given a function or expression computing a statistic based on
     sampling weights, 'withReplicates' evaluates the statistic and
     produces a replicate-based estimate of variance.

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

     withReplicates(design, theta, rho = NULL, ..., scale.weights=FALSE, return.replicates=FALSE)

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

  design: A survey design with replicate weights (eg from
          'svrepdesign')

   theta: A function or expression: see Details below

     rho: If 'design' uses BRR weights, 'rho' optionally specifies the
          parameter for Fay's variance estimator.

     ...: Other arguments to 'theta'

scale.weights: Divide the probability weights by their sum (can help
          with overflow problems)

return.replicates: Return the replicate estimates as well as the
          variance?

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

     If 'theta' is a function its first argument will be a vector of
     weights and the second argument will be a data frame containing
     the variables from the design object. 

     If it is an expression, the sampling weights will be available as
     the variable '.weights'.  Variables in the design object will also
     be in scope.  It is possible to use global variables in the
     expression, but unwise, as they may be masked by local variables
     inside 'withReplicates'.

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

     If 'return.replicates=FALSE',  the weighted statistic, with the
     variance matrix as the '"var"' attribute. If
     'return.replicates=TRUE', a list with elements 'theta' for the
     usual return value and 'replicates' for the replicates.

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

     'svrepdesign', 'as.svrepdesign', 'svrVar'

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

     data(scd)
     repweights<-2*cbind(c(1,0,1,0,1,0), c(1,0,0,1,0,1), c(0,1,1,0,0,1),
     c(0,1,0,1,1,0))
     scdrep<-svrepdesign(data=scd, type="BRR", repweights=repweights)

     a<-svyratio(~alive, ~arrests, design=scdrep)
     print(a$ratio)
     print(a$var)
     withReplicates(scdrep, quote(sum(.weights*alive)/sum(.weights*arrests)))
     withReplicates(scdrep, function(w,data) sum(w*data$alive)/sum(w*data$arrests))

