smean: Calculate the survey mean

View source: R/survey_calcs.R

smeanR Documentation

Calculate the survey mean

Description

Calculate the survey mean

Usage

smean(x, ...)

## Default S3 method:
smean(
  x,
  na.rm = T,
  var_type = "none",
  ci_method = "mean",
  level = 0.95,
  use_df = T,
  ids,
  sv,
  st,
  ...
)

## S3 method for class 'character'
smean(x, ...)

## S3 method for class 'character'
stotal(x, ...)

Arguments

x

vector. Vector of values to compute a weighted mean over

...

other arguments. Currently unused.

na.rm

logical. Determines whether NAs are excluded from the analysis

var_type

character. Report variability as one or more of: standard error ("se", default) and confidence interval ("ci")

ci_method

character. Determines how the ci (if requested via var_type) should be calculated Options beside "mean" are only relevant for proportion (e.g. logical or values). When the method is 'mean', the results should match survey::svymean while other options match survey::svyciprop

level

numeric. A value in the range of (0, 1) denoting what level of confidence the CI should be

use_df

logical. Should the estimated degrees of freedom by used to calculate CIs? Default is TRUE. FALSE implies df = Inf. confint(survey::svymean()) uses Inf as a default while confint(survey::svyciprop) uses degf(design)

ids

numeric. indices which are being computed. Can be generally omitted and will be added to the call via '[.dtsurvey'

sv

data.table. Data.table of psu, strata, weight and the like to properly do survey statistics.

st

character. type of survey dataset being analyzed. Can be generally omitted and will be added to the call via '[.dtsurvey'

Details

If var_type is "none", a vector is returned. For factors, the names of the vector correspond to the levels. When var_type is not "none" a named list is returned (and then likely converted into a data.table). The list (which should be named) is ordered in the following manner (by slot): result, se, lower, upper, levels.

Value

a vector or a list (the latter likely converted into a data.table) containing the results


dcaseykc/dtsurvey documentation built on March 9, 2024, 1:09 p.m.