svyquantile

0th

Percentile

Summary statistics for sample surveys

Compute means, variances, quantiles, and cross-tabulations for data from complex surveys.

Keywords
univar, survey
Usage
svyquantile(x, design, quantiles, method = "linear", f = 1)
svymean(x, design, na.rm=FALSE) 
svyvar(x, design, na.rm=FALSE) 
svytable(formula, design, Ntotal = NULL)
Arguments
x
A formula, vector or matrix
design
survey.design object
quantiles
Quantiles to estimate
method
see approxfun
f
see approxfun
na.rm
Should missing values be removed?
formula
A one-sided formula specifying variables to be tabulated
Ntotal
Table will be normalised to this total if not NULL
Details

These functions perform weighted estimation, with each observation being weighted by the inverse of its sampling probability. The svymean and svyvar functions also give precision estimates that incorporate the effects of stratification and clustering. The first three functions are similar to the standard functions whose names do not begin with svy.

The svytable function computes a weighted crosstabulation. If the sampling probabilities supplied to svydesign were actual probabilities (rather than relative probabilities) this estimates a full population crosstabulation. Otherwise it estimates only relative proportions and should be normalised to some convenient total such as 100 or 1.0 by specifying the Ntotal argument.

Value

  • The first three functions return vectors, the last returns an xtabs object.

References

~put references to the literature/web site here ~

See Also

svydesign,mean,var, quantile, xtabs

Aliases
  • svyquantile
  • svytable
  • svymean
  • svyvar
Examples
#population
  df<-data.frame(x=rnorm(1000),z=rep(0:4,200))
  df$y<-with(df, 3+3*x*z)
  #sampling fraction
  df$p<-with(df, exp(x)/(1+exp(x)))
  #sample
  xi<-rbinom(1000,1,df$p)
  sdf<-df[xi==1,]
  
  #survey design object: independent sampling, 
  dxi<-svydesign(~0,~p,data=sdf)
 
  dxi

  mean(df$x)		#right
  mean(sdf$x)		#wrong
  svymean(sdf$x,dxi)	#right

  var(df$x)		#right
  var(sdf$x)		#wrong
  svyvar(sdf$x,dxi)		#right

  quantile(df$x,c(0.025,0.5,0.975))  #right
  quantile(sdf$x,c(0.025,0.5,0.975))  #wrong
  svyquantile(sdf$x,design=dxi,c(0.025,0.5,0.975))  #right

  table(sdf$z)  # sample table
  svytable(~z, dxi) # estimated population table
Documentation reproduced from package survey, version 0.9-1, License: LGPL

Community examples

Looks like there are no examples yet.