Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

svysd

Calculate standard deviations with complex survey data


Description

svysd extends the survey package by calculating standard deviations with syntax similar to the original package, which provides only a svyvar() function.

Usage

svysd(
  formula,
  design,
  na.rm = FALSE,
  digits = getOption("jtools-digits", default = 3),
  ...
)

Arguments

formula

A formula (e.g., ~var1+var2) specifying the term(s) of interest.

design

The survey.design or svyrep.design object.

na.rm

Logical. Should cases with missing values be dropped?

digits

An integer specifying the number of digits past the decimal to report in the output. Default is 3. You can change the default number of digits for all jtools functions with options("jtools-digits" = digits) where digits is the desired number.

...

Additional arguments passed to svyvar().

Details

An alternative is to simply do sqrt(svyvar(~term, design = design)). However, if printing and sharing the output, this may be misleading since the output will say "variance."

Note

This function was designed independent of the survey package and is neither endorsed nor known to its authors.

See Also

Other survey package extensions: svycor()

Other survey tools: pf_sv_test(), svycor(), weights_tests(), wgttest()

Examples

if (requireNamespace("survey")) {
 library(survey)
 data(api)
 # Create survey design object
 dstrat <- svydesign(id = ~1,strata = ~stype, weights = ~pw, data = apistrat,
                     fpc=~fpc)

 # Print the standard deviation of some variables
 svysd(~api00+ell+meals, design = dstrat)
}

jtools

Analysis and Presentation of Social Scientific Data

v2.1.3
MIT + file LICENSE
Authors
Jacob A. Long [aut, cre] (<https://orcid.org/0000-0002-1582-6214>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.