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.

survey_median(x, design)

weighted_correlation(data, ...)

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

# S3 method for 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))))
#> [1] 6.811783

# 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)
#> $total
#>      0.5
#> [1,]   6
#> 
#> attr(,"hasci")
#> [1] FALSE
#> attr(,"class")
#> [1] "newsvyquantile"
survey_median("total", des)
#> $total
#>      0.5
#> [1,]   6
#> 
#> attr(,"hasci")
#> [1] FALSE
#> attr(,"class")
#> [1] "newsvyquantile"