withReplicates {survey}R Documentation

Compute variances by replicate weighting


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


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


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?


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.


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.

See Also

svrepdesign, as.svrepdesign, svrVar


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

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

[Package survey version 3.18 Index]