survey_median | R Documentation |
Weighted statistics for variables
weighted_sd()
, weighted_se()
, weighted_mean()
and weighted_median()
compute weighted standard deviation, standard error, mean or median for a
variable or for all variables of a data frame. survey_median()
computes the
median for a variable in a survey-design (see svydesign
).
weighted_correlation()
computes a weighted correlation for a two-sided alternative
hypothesis.
Weighted tests
weighted_ttest()
computes a weighted t-test, while weighted_mannwhitney()
computes a weighted Mann-Whitney-U test or a Kruskal-Wallis test
(for more than two groups). weighted_chisqtest()
computes a weighted
Chi-squared test for contigency tables.
survey_median(x, design) weighted_chisqtest(data, ...) ## Default S3 method: weighted_chisqtest(data, x, y, weights, ...) ## S3 method for class 'formula' weighted_chisqtest(formula, data, ...) 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_mean(x, weights = NULL) weighted_median(x, weights = NULL) weighted_mannwhitney(data, ...) ## Default S3 method: weighted_mannwhitney(data, x, grp, weights, ...) ## S3 method for class 'formula' weighted_mannwhitney(formula, data, ...) weighted_sd(x, weights = NULL) wtd_sd(x, weights = NULL) weighted_se(x, weights = NULL) weighted_ttest(data, ...) ## Default S3 method: weighted_ttest( data, x, y = NULL, weights, mu = 0, paired = FALSE, ci.lvl = 0.95, alternative = c("two.sided", "less", "greater"), ... ) ## S3 method for class 'formula' weighted_ttest( formula, data, mu = 0, paired = FALSE, ci.lvl = 0.95, alternative = c("two.sided", "less", "greater"), ... )
x |
(Numeric) vector or a data frame. For |
design |
An object of class |
data |
A data frame. |
... |
For |
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 |
formula |
A formula of the form |
ci.lvl |
Confidence level of the interval. |
grp |
Bare (unquoted) name of the cross-classifying variable, where
|
mu |
A number indicating the true value of the mean (or difference in means if you are performing a two sample test). |
paired |
Logical, whether to compute a paired t-test. |
alternative |
A character string specifying the alternative hypothesis,
must be one of |
The weighted (test) statistic.
weighted_chisq()
is a convenient wrapper for crosstable_statistics
.
For a weighted one-way Anova, use means_by_group()
with
weights
-argument.
weighted_ttest()
assumes unequal variance between the two groups.
# weighted sd and se ---- weighted_sd(rnorm(n = 100, mean = 3), runif(n = 100)) data(efc) weighted_sd(efc[, 1:3], runif(n = nrow(efc))) weighted_se(efc[, 1:3], runif(n = nrow(efc))) # survey_median ---- # median for variables from weighted survey designs if (require("survey")) { data(nhanes_sample) des <- svydesign( id = ~SDMVPSU, strat = ~SDMVSTRA, weights = ~WTINT2YR, nest = TRUE, data = nhanes_sample ) survey_median(total, des) survey_median("total", des) } # weighted t-test ---- efc$weight <- abs(rnorm(nrow(efc), 1, .3)) weighted_ttest(efc, e17age, weights = weight) weighted_ttest(efc, e17age, c160age, weights = weight) weighted_ttest(e17age ~ e16sex + weight, efc) # weighted Mann-Whitney-U-test ---- weighted_mannwhitney(c12hour ~ c161sex + weight, efc) # weighted Chi-squared-test ---- weighted_chisqtest(efc, c161sex, e16sex, weights = weight, correct = FALSE) weighted_chisqtest(c172code ~ c161sex + weight, efc) # weighted Chi-squared-test for given probabilities ---- weighted_chisqtest(c172code ~ weight, efc, p = c(.33, .33, .34))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.