weighted_se: Weighted statistics for variables

View source: R/wtd_se.R

survey_medianR Documentation

Weighted statistics for variables

Description

weighted_se() computes weighted standard errors of a variable or for all variables of a data frame. survey_median() computes the median for a variable in a survey-design (see [⁠survey::svydesign()]⁠). weighted_correlation() computes a weighted correlation for a two-sided alternative hypothesis.

Usage

survey_median(x, design)

weighted_correlation(data, ...)

## Default S3 method:
weighted_correlation(data, x, y, weights, ci.lvl = 0.95, ...)

## S3 method for class 'formula'
weighted_correlation(formula, data, ci.lvl = 0.95, ...)

weighted_se(x, weights = NULL)

Arguments

x

(Numeric) vector or a data frame. For survey_median() or weighted_ttest(), the bare (unquoted) variable name, or a character vector with the variable name.

design

An object of class svydesign, providing a specification of the survey design.

data

A data frame.

...

Currently not used.

y

Optional, bare (unquoted) variable name, or a character vector with the variable name.

weights

Bare (unquoted) variable name, or a character vector with the variable name of the numeric vector of weights. If weights = NULL, unweighted statistic is reported.

ci.lvl

Confidence level of the interval.

formula

A formula of the form lhs ~ rhs1 + rhs2 where lhs is a numeric variable giving the data values and rhs1 a factor with two levels giving the corresponding groups and rhs2 a variable with weights.

Value

The weighted (test) statistic.

Examples


data(efc)
weighted_se(efc$c12hour, abs(runif(n = nrow(efc))))

# survey_median ----
# median for variables from weighted survey designs
data(nhanes_sample)

des <- survey::svydesign(
  id = ~SDMVPSU,
  strat = ~SDMVSTRA,
  weights = ~WTINT2YR,
  nest = TRUE,
  data = nhanes_sample
)
survey_median(total, des)
survey_median("total", des)


strengejacke/sjstats documentation built on May 28, 2024, 8:30 p.m.