surveysummary             package:survey             R Documentation

_S_u_m_m_a_r_y _s_t_a_t_i_s_t_i_c_s _f_o_r _s_a_m_p_l_e _s_u_r_v_e_y_s

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

     Compute means, variances, ratios and totals for data from complex
     surveys.

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

     svymean(x, design, na.rm=FALSE,deff=FALSE) 
     svrepmean(x, design, na.rm=FALSE, rho=NULL, return.replicates=FALSE, deff=FALSE) 
     svyvar(x, design, na.rm=FALSE) 
     svrepvar(x, design, na.rm=FALSE, rho=NULL, return.replicates=FALSE) 
     svytotal(x, design, na.rm=FALSE,deff=FALSE) 
     svreptotal(x, design, na.rm=FALSE, rho=NULL, return.replicates=FALSE,
     deff=FALSE)
     cv(object,...)
     ## S3 method for class 'svystat':
     coef(object,...)
     ## S3 method for class 'svrepstat':
     coef(object,...)
     ## S3 method for class 'svystat':
     vcov(object,...)
     ## S3 method for class 'svrepstat':
     vcov(object,...)

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

       x: A formula, vector or matrix

  design: 'survey.design' or 'svyrep.design' object

   na.rm: Should cases with missing values be dropped?

     rho: parameter for Fay's variance estimator in a BRR design

return.replicates: Return the replicate means?

    deff: Return the design effect

  object: The result of one of the other survey summary functions

     ...: additional arguments to 'cv' methods,not currently used

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

     These functions perform weighted estimation, with each observation
     being weighted by the inverse of its sampling probability.  Except
     for the table functions, these also give precision estimates that
     incorporate the effects of stratification and clustering.

     Factor variables are converted to sets of indicator variables for
     each category in computing means and totals.

     With 'na.rm=TRUE', all cases with missing data are removed. With
     'na.rm=FALSE' cases with missing data are not removed and so will
     produce missing results.  When using replicate weights and
     'na.rm=FALSE' it may be useful to set
     'options(na.action="na.pass")', otherwise all replicates with any
     missing results will be discarded.

     The 'svytotal' and 'svreptotal' functions estimate a population
     total.  Use 'predict' on 'svyratio', 'svrepratio', 'svyglm',
     'svrepglm' to get ratio or regression estimates of totals.

     The design effect compares the variance of a mean or total to the
     variance of a simple random sample of the same size.  Although
     strictly speaking this should be a simple random sample without
     replacement, we compute as if it were a simple random sample with
     replacement.

     The 'cv' function computes the coefficient of variation of a
     statistic such as ratio, mean or total.

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

     Objects of class '"svystat"' or '"svrepstat"', which are vectors
     with a '"var"' attribute giving the variance and a '"statistic"'
     attribute giving the name of the statistic.

_A_u_t_h_o_r(_s):

     Thomas Lumley

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

     'svydesign', 'as.svrepdesign', 'svrepdesign', 'svyCprod', 'mean',
     'var', 'svyquantile'

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

       data(api)
       ## population
       mean(apipop$api00)
       quantile(apipop$api00,c(.25,.5,.75))
       var(apipop$api00)
       sum(apipop$enroll)
       sum(apipop$api.stu)/sum(apipop$enroll)

       ## one-stage cluster sample
       dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)
       summary(dclus1)
       svymean(~api00, dclus1, deff=TRUE)
       svymean(~factor(stype),dclus1)
       svyquantile(~api00, dclus1, c(.25,.5,.75))
       svyvar(~api00, dclus1)
       svytotal(~enroll, dclus1, deff=TRUE)
       svyratio(~api.stu, ~enroll, dclus1)

       #stratified sample
       dstrat<-svydesign(id=~1, strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
       summary(dstrat)
       svymean(~api00, dstrat)
       svyquantile(~api00, dstrat, c(.25,.5,.75))
       svyvar(~api00, dstrat)
       svytotal(~enroll, dstrat)
       svyratio(~api.stu, ~enroll, dstrat)

       # replicate weights - jackknife (this is slow)
       jkstrat<-as.svrepdesign(dstrat)
       summary(jkstrat)
       svrepmean(~api00, jkstrat)
       svrepmean(~factor(stype),jkstrat)
       svrepvar(~api00,jkstrat)
       svrepquantile(~api00, jkstrat, c(.25,.5,.75))
       svreptotal(~enroll, jkstrat)
       svrepratio(~api.stu, ~enroll, jkstrat)

       # coefficients of variation
       cv(svytotal(~enroll,dstrat))
       cv(svrepratio(~api.stu, ~enroll, jkstrat))

       # extracting statistic and variance
       coef(svytotal(~enroll,dstrat))
       vcov(svrepmean(~api00+api99,jkstrat))

       # BRR method
       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)
       svrepmean(~arrests+alive, design=scdrep)

      

