svystatR: Estimation of Ratios in Subpopulations

View source: R/e.svystatR.R

svystatRR Documentation

Estimation of Ratios in Subpopulations

Description

Calculates estimates, standard errors and confidence intervals for Ratios between Totals in subpopulations.

Usage

svystatR(design, num, den, by = NULL, cross = FALSE,
         vartype = c("se", "cv", "cvpct", "var"),
         conf.int = FALSE, conf.lev = 0.95, deff = FALSE,
         na.rm = FALSE)

## S3 method for class 'svystatR'
coef(object, ...)
## S3 method for class 'svystatR'
SE(object, ...)
## S3 method for class 'svystatR'
VAR(object, ...)
## S3 method for class 'svystatR'
cv(object, ...)
## S3 method for class 'svystatR'
deff(object, ...)
## S3 method for class 'svystatR'
confint(object, ...)

Arguments

design

Object of class analytic (or inheriting from it) containing survey data and sampling design metadata.

num

Formula defining the numerator variables for the ratios.

den

Formula defining the denominator variables for the ratios.

by

Formula specifying the variables that define the "estimation domains". If NULL (the default option) estimates refer to the whole population.

cross

Should ratios be estimated for all the pairs of variables in 'num' and 'den'? The default is FALSE, meaning that ratios get estimated parallel-wise (see ‘Details’).

vartype

character vector specifying the desired variability estimators. It is possible to choose one or more of: standard error ('se', the default), coefficient of variation ('cv'), percent coefficient of variation ('cvpct'), or variance ('var').

conf.int

Compute confidence intervals for the estimates? The default is FALSE.

conf.lev

Probability specifying the desired confidence level: the default value is 0.95.

deff

Should the design effect be computed? The default is FALSE (see ‘Details’).

na.rm

Should missing values (if any) be removed from the variables of interest? The default is FALSE (see ‘Details’).

object

An object of class svystatR.

...

Additional arguments to coef, ..., confint methods (if any).

Details

This function computes weighted estimates for Ratios between Totals using suitable weights depending on the class of design: calibrated weights for class cal.analytic and direct weights otherwise. Standard errors are calculated using the Taylor linearization technique.

The mandatory argument num (den) identifies the variables whose totals appear as numerators (denominators) in the Ratios: the corresponding formula must be of the type num = ~num.1 + ... + num.k (den = ~den.1 + ... + den.l). The design variables referenced by num (den) must be numeric.

If cross=TRUE, the function computes estimates for all the Ratios between pairs of variables coming from num and den (that is k*l estimates for the formulae above). If, on the contrary, cross=FALSE (the default), Ratios get estimated parallel-wise and R recycling rule is applied whenever k!=l: for the formulae above, this generates r Ratios, where r=max(k,l).

The optional argument by specifies the variables that define the "estimation domains", that is the subpopulations for which the estimates are to be calculated. If by=NULL (the default option), the estimates produced by svystatR refer to the whole population. Estimation domains must be defined by a formula: for example the statement by=~B1:B2 selects as estimation domains the subpopulations determined by crossing the modalities of variables B1 and B2. Notice that a formula like by=~B1+B2 will be automatically translated into the factor-crossing formula by=~B1:B2: if you need to compute estimates for domains B1 and B2 separately, you have to call svystatR twice. The design variables referenced by by (if any) should be of type factor, otherwise they will be coerced.

The conf.int argument allows to request the confidence intervals for the estimates. By default conf.int=FALSE, that is the confidence intervals are not provided.

Whenever confidence intervals are requested (i.e. conf.int=TRUE), the desired confidence level can be specified by means of the conf.lev argument. The conf.lev value must represent a probability (0<=conf.lev<=1) and its default is chosen to be 0.95.

The optional argument deff allows to request the design effect [Kish 1995] for the estimates. By default deff=FALSE, that is the design effect is not provided. The design effect of an estimator is defined as the ratio between the variance of the estimator under the actual sampling design and the variance that would be obtained for an 'equivalent' estimator under a hypothetical simple random sampling without replacement of the same size. To obtain an estimate of the design effect comparing to simple random sampling “with replacement”, one must use deff="replace".
Being Ratios nonlinear estimators, the design effect is estimated on the linearized version of the estimator (that is: for the estimator of the total of the linearized variable, aka "Woodruff transform").
When dealing with domain estimation, the design effects referring to a given subpopulation are currently computed by taking the ratios between the actual variance estimates and those that would have been obtained if a simple random sampling were carried out within that subpopulation. This is the same as the srssubpop option for Stata's function estat.

Missing values (NA) in interest variables should be avoided. If na.rm=FALSE (the default) they generate NAs in estimates (or even an error, if design is calibrated). If na.rm=TRUE, observations containing NAs are dropped, and estimates get computed on non missing values only. This implicitly assumes that missing values hit interest variables completely at random: should this not be the case, computed estimates would be biased. Notice that the na.rm=TRUE option is only allowed for a single Ratio, i.e. if num and den reference a single interest variable.

Value

An object inheriting from the data.frame class, whose detailed structure depends on input parameters' values.

Warning

It can happen that, in some subpopulations, the estimate of the Total of some den variables turns out to be zero. In such cases svystatR estimates are either NaN or Inf, and NaN is returned for the corresponding SE estimates.

Author(s)

Diego Zardetto

References

Sarndal, C.E., Swensson, B., Wretman, J. (1992) “Model Assisted Survey Sampling”, Springer Verlag.

Kish, L. (1995). “Methods for design effects”. Journal of Official Statistics, Vol. 11, pp. 55-77.

European Commission, Eurostat, (2013). “Handbook on precision requirements and variance estimation for ESS households surveys: 2013 edition”, Publications Office. doi: 10.2785/13579

See Also

Estimators of Totals and Means svystatTM, Shares svystatS, Ratios between Shares svystatSR, Multiple Regression Coefficients svystatB, Quantiles svystatQ, Complex Analytic Functions of Totals and/or Means svystatL, and all of the above svystat.

Examples

# Creation of a design object:
data(sbs)
des<-e.svydesign(data=sbs,ids=~id,strata=~strata,weights=~weight,
     fpc=~fpc)

# Estimation of the average value added per employee
# at the nation level:
svystatR(des,~va.imp2,~emp.num)

# The same as above by economic activity macro-sector:
svystatR(des,~va.imp2,~emp.num,~nace.macro,vartype="cvpct")


# Another design object:
data(data.examples)
des<-e.svydesign(data=example,ids=~towcod+famcod,strata=~SUPERSTRATUM,
     weights=~weight)

# Estimation of the ratios y1/x1, y1/x2, y2/x1 and y2/x2 by region,
# notice the use of argument cross:
svystatR(des,~y1+y2,~x1+x2,by=~regcod,cross=TRUE)

# ... compare the latter with the default (i.e. cross=FALSE)
svystatR(des,~y1+y2,~x1+x2,by=~regcod)


# Estimation of the ratios z/x1, z/x2 e z/x3
# for the whole population (notice the recycling rule):
svystatR(des,~z,~x1+x2+x3,conf.int=TRUE)

# Estimators of means can be thought as 
# estimators of ratios:
svystatTM(des,~income,estimator="Mean")  
svystatR(des.addvars(des,ones=1),num=~income,den=~ones)


##################################################
# Household-level averages in household surveys. #
##################################################

# For an introduction on this topic, see ?svystatTM examples.

  # Load survey data:
  data(data.examples)

  # Define the survey design (variable famcod identifies households) 
  exdes<-e.svydesign(data=example,ids=~towcod+famcod,strata=~stratum,
         weights=~weight)

  # Collapse strata to eliminate lonely PSUs
  exdes<-collapse.strata(design=exdes,block.vars=~sr:procod)

  # Now add new convenience variables to the design object:
    ## 'ones':       to estimate individuals counts
    ## 'housize':    to classify individuals by household size
    ## 'houdensity': to estimate households counts
  exdes<-des.addvars(exdes,
                     ones=1,
                     housize=factor(ave(famcod,famcod,FUN = length)),
                     houdensity=ave(famcod,famcod,FUN = function(x) 1/length(x))
                    )

  # Estimate the average number of household components by region:
  svystatR(exdes,num=~ones,den=~houdensity,by=~regcod,
           vartype="cvpct",conf.int=TRUE)

  # Estimate the average household income for the whole population:
  svystatR(exdes,num=~income,den=~houdensity,vartype="cvpct",
           conf.int=TRUE)

  # ...for household size categories:
  svystatR(exdes,num=~income,den=~houdensity,by=~housize,
           vartype="cvpct",conf.int=TRUE)

  # ...and for province and household size:
  svystatR(exdes,num=~income,den=~houdensity,by=~housize:procod,
           vartype="cvpct")

DiegoZardetto/ReGenesees documentation built on Dec. 16, 2024, 2:03 p.m.