var.est: Calculates variance estimates from samples.

View source: R/var.est.r

var.estR Documentation

Calculates variance estimates from samples.

Description

This function calculates variance estimates of population mean, total or proportion from an object of class 'sample' or 'samples.population'.

Usage

  var.est(dat,type="ybar",cond=NULL,by.stratum=FALSE)

Arguments

dat

Object of class 'sample' or 'samples.population'.

type

Type of variance estimate. Valid types are

  • "ybar":sample mean

  • "ybar.tot":sample total

  • "ybar.ppn":sample proportion

  • "strat.mean":stratified sample mean

  • "strat.tot":stratified sample total

  • "strat.ppn":stratified sample proportion

  • "ratio.mean":ratio estimate of mean

  • "ratio.tot":ratio estimate of total

  • "ratio.ppn":ratio estimate of proportion

  • "strat.ratio":stratified ratio estimate of mean

  • "strat.ratio.tot":stratified ratio estimate of total

  • "strat.ratio.ppn":stratified ratio estimate of proportion

  • "regr.mean":regression estimate of mean

  • "regr.tot":regression estimate of total

  • "regr.ppn":regression estimate of proportion

  • "strat.regr":stratified regression estimate of mean

  • "strat.regr.tot":stratified regression estimate of total

  • "strat.regr.ppn":stratified regression estimate of proportion

  • "diffr.mean":difference estimate of mean

  • "diffr.tot":difference estimate of total

  • "diffr.ppn":difference estimate of proportion

  • "strat.diffr":stratified difference estimate of mean

  • "strat.diffr.tot":stratified difference estimate of total

  • "strat.diffr.ppn":stratified difference estimate of proportion

  • "clust.mean":cluster estimate of mean from mean of cluster totals

  • "clust.tot":cluster estimate of mean from total of cluster totals

  • "clust.ppn":cluster estimate of proportion from mean of cluster totals

  • "clust.r.mean":cluster ratio estimate of mean

  • "clust.r.tot":cluster ratio estimate of total

  • "clust.r.ppn":cluster ratio estimate of proportion

cond

Condition to use when calculation proportions. Character of form "<logical operator><value>", where <value> is a valid value for the response variable (y) and <logical operator> is one of the following:

  • "<"if you want the proportion of response values less than <value>

  • ">"if you want the proportion of response values greater than <value>

  • "<="if you want the proportion of response values less than or equal to <value>

  • ">="if you want the proportion of response values greater than or equal to <value>

  • "=="if you want the proportion of response values equal to <value>

  • "!="if you want the proportion of response values not equal to <value>

by.stratum

If TRUE, returns point estimates by stratum as well as over all strata. If the object is of class 'samples.population' (containing the set of all possible samples), the argument 'by.stratum' is set to FALSE irrespective of what value was passed to the function. Estimates by stratum can therefore only be obtained for a single sample.

Details

Returns variance estimates of the appropriate type.

Value

If 'by.stratum' is FALSE, the function returns a scalar, being the point estimate from the sample. If 'by.stratum' is TRUE, the function returns a list with the following components:

  • "est"the point estimate from the sample,

  • "est.by.stratum"a vector containing the point estimates from each stratum,

  • "N"a vector containing the number of primary units in each stratum,

  • "n"a vector containing the number of primary units sampled in each stratum.

See Also

add.var.est, point.est, add.point.est, ci.est, add.ci.est

Examples

  data(barnett) # get barnett data
  
  # total weight of class from srs:
  samp<-take.sample(barnett,y.name="weight",n=6)
  # estimate total
  var.est(samp,type="ybar.tot")
  
  # proportion of class with weight more than 15, from srs:
  samp<-take.sample(barnett,y.name="weight",n=6)
  # estimate total
  var.est(samp,type="ybar.ppn",cond=">15")
  
  # Stratified mean
  # Define 4 strata based on weight, with 10 lb interval widths:
  
    strat.barnett<-define.subunit(barnett,aux.name="weight",breaks=c(0,10,20,30,40),
                                    type="strat")
  # take stratified sample
  samp<-take.sample(strat.barnett,y.name="height",type="strat",n=c(2,5,4,2))
  # estimate mean height using stratified estimator
  var.est(samp,type="strat.mean")
  # now estimate by stratum too:
  var.est(samp,type="strat.mean",by.stratum=TRUE)
  
  # Cluster mean
  # Define 4 clusters based on weight, with 10 lb interval widths:
  
    clust.barnett<-define.subunit(barnett,aux.name="weight",breaks=c(0,10,20,30,40),
                                    type="clust")
  # take cluster sample of size 2
  samp<-take.sample(clust.barnett,y.name="height",type="clust",m=2)
  # estimate mean height using cluster estimator
  var.est(samp,type="clust.mean")
  
  # Ratio estimator
  # take srs of size 6, with weight as auxiliary variable:
  
    samp<-take.sample(clust.barnett,y.name="height",aux.name="weight",type="srs",n=6
    )
  # estimate mean height using cluster estimator
  var.est(samp,type="ratio.mean")
  
  

david-borchers/sampling documentation built on Sept. 17, 2022, 7:54 a.m.