svyby                 package:survey                 R Documentation

_S_u_r_v_e_y _s_t_a_t_i_s_t_i_c_s _o_n _s_u_b_s_e_t_s

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

     Compute survey statistics on subsets of a survey defined by
     factors.

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

     svyby(formula, by, design, FUN, ..., deff=FALSE,keep.var = TRUE, keep.names = TRUE)

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

 formula: A formula specifying the variables to pass to 'FUN' (or a
          matrix, data frame, or vector)

      by: A formula specifying factors that define subsets, or a list
          of factors.

  design: A 'svydesign' or 'svrepdesign' object

     FUN: A function taking a formula and survey design object as its
          first two arguments.

     ...: Other arguments to 'FUN'

    deff: Request a design effect from 'FUN'

keep.var: If 'FUN' returns a 'svystat' object, extract standard errors
          from it

keep.names: Define row names based on the subsets

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

     A data frame showing the factors and the results of 'FUN'

_N_o_t_e:

     Asking for a design effect ('deff=TRUE') from a function that does
     not produce one will cause an error or incorrect formatting of the
     output. The same will occur with 'keep.var=TRUE' if the function
     does not compute a standard error.

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

     'svytable' and 'ftable.svystat' for contingency tables,
     'ftable.svyby' for pretty-printing of 'svyby'

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

     data(api)
     dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)

     svyby(~api99, ~stype, dclus1, svymean)
     svyby(~api99, ~stype, dclus1, svyquantile, quantiles=0.5,ci=TRUE)
     ## without ci=TRUE svyquantile does not compute standard errors
     svyby(~api99, ~stype, dclus1, svyquantile, quantiles=0.5, keep.var=FALSE)
     svyby(~api99, list(school.type=apiclus1$stype), dclus1, svymean)
     svyby(~api99+api00, ~stype, dclus1, svymean, deff=TRUE)
     svyby(~api99+api00, ~stype+sch.wide, dclus1, svymean, keep.var=FALSE)

     rclus1<-as.svrepdesign(dclus1)

     svyby(~api99, ~stype, rclus1, svymean)
     svyby(~api99, ~stype, rclus1, svyquantile, quantiles=0.5)
     svyby(~api99, list(school.type=apiclus1$stype), rclus1, svymean)
     svyby(~enroll,~stype, rclus1,svytotal, deff=TRUE)
     svyby(~api99+api00, ~stype+sch.wide, rclus1, svymean, keep.var=FALSE)

