diff --git a/R/wtd_se.R b/R/wtd_se.R index dde3850..bf6265b 100644 --- a/R/wtd_se.R +++ b/R/wtd_se.R @@ -1,60 +1,43 @@ #' @title Weighted statistics for tests and variables #' @name weighted_se -#' @description \strong{Weighted statistics for variables} -#' \cr \cr -#' \code{weighted_sd()}, \code{weighted_se()}, \code{weighted_mean()} and \code{weighted_median()} -#' compute weighted standard deviation, standard error, mean or median for a -#' variable or for all variables of a data frame. \code{survey_median()} computes the -#' median for a variable in a survey-design (see \code{\link[survey]{svydesign}}). -#' \code{weighted_correlation()} computes a weighted correlation for a two-sided alternative -#' hypothesis. -#' \cr \cr -#' \strong{Weighted tests} -#' \cr \cr -#' \code{weighted_ttest()} computes a weighted t-test, while \code{weighted_mannwhitney()} -#' computes a weighted Mann-Whitney-U test or a Kruskal-Wallis test -#' (for more than two groups). `weighted_ranktest()` is an alias for `weighted_mannwhitney()`. -#' \code{weighted_chisqtest()} computes a weighted Chi-squared test for contingency tables. +#' @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. #' -#' @param x (Numeric) vector or a data frame. For \code{survey_median()}, \code{weighted_ttest()}, -#' \code{weighted_mannwhitney()} and \code{weighted_chisqtest()} the bare (unquoted) variable -#' name, or a character vector with the variable name. +#' @param 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. #' @param weights Bare (unquoted) variable name, or a character vector with -#' the variable name of the numeric vector of weights. If \code{weights = NULL}, -#' unweighted statistic is reported. +#' the variable name of the numeric vector of weights. If `weights = NULL`, +#' unweighted statistic is reported. #' @param data A data frame. -#' @param formula A formula of the form \code{lhs ~ rhs1 + rhs2} where \code{lhs} is a -#' numeric variable giving the data values and \code{rhs1} a factor with two -#' levels giving the corresponding groups and \code{rhs2} a variable with weights. +#' @param 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. #' @param y Optional, bare (unquoted) variable name, or a character vector with -#' the variable name. +#' the variable name. #' @param mu A number indicating the true value of the mean (or difference in -#' means if you are performing a two sample test). +#' means if you are performing a two sample test). #' @param ci.lvl Confidence level of the interval. #' @param alternative A character string specifying the alternative hypothesis, -#' must be one of \code{"two.sided"} (default), \code{"greater"} or -#' \code{"less"}. You can specify just the initial letter. +#' must be one of `"two.sided"` (default), `"greater"` or `"less"`. You can +#' specify just the initial letter. #' @param paired Logical, whether to compute a paired t-test. -#' @param ... For \code{weighted_ttest()} and \code{weighted_mannwhitney()}, currently not used. -#' For \code{weighted_chisqtest()}, further arguments passed down to -#' \code{\link[stats]{chisq.test}}. +#' @param ... Currently not used. #' #' @inheritParams svyglm.nb #' #' @return The weighted (test) statistic. #' -#' @note \code{weighted_chisq()} is a convenient wrapper for \code{\link{crosstable_statistics}}. -#' For a weighted one-way Anova, use \code{means_by_group()} with -#' \code{weights}-argument. +#' @note `weighted_chisq()` is a convenient wrapper for `\link{crosstable_statistics`}. +#' For a weighted one-way Anova, use `means_by_group()` with +#' `weights`-argument. #' \cr \cr -#' \code{weighted_ttest()} assumes unequal variance between the two groups. +#' `weighted_ttest()` assumes unequal variance between the two groups. #' #' @examples -#' # 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 ---- diff --git a/man/weighted_se.Rd b/man/weighted_se.Rd index 22c2ee6..806da87 100644 --- a/man/weighted_se.Rd +++ b/man/weighted_se.Rd @@ -47,18 +47,15 @@ weighted_ttest(data, ...) ) } \arguments{ -\item{x}{(Numeric) vector or a data frame. For \code{survey_median()}, \code{weighted_ttest()}, -\code{weighted_mannwhitney()} and \code{weighted_chisqtest()} the bare (unquoted) variable -name, or a character vector with the variable name.} +\item{x}{(Numeric) vector or a data frame. For \code{survey_median()} or \code{weighted_ttest()}, +the bare (unquoted) variable name, or a character vector with the variable name.} \item{design}{An object of class \code{\link[survey]{svydesign}}, providing a specification of the survey design.} \item{data}{A data frame.} -\item{...}{For \code{weighted_ttest()} and \code{weighted_mannwhitney()}, currently not used. -For \code{weighted_chisqtest()}, further arguments passed down to -\code{\link[stats]{chisq.test}}.} +\item{...}{Currently not used.} \item{y}{Optional, bare (unquoted) variable name, or a character vector with the variable name.} @@ -79,42 +76,23 @@ means if you are performing a two sample test).} \item{paired}{Logical, whether to compute a paired t-test.} \item{alternative}{A character string specifying the alternative hypothesis, -must be one of \code{"two.sided"} (default), \code{"greater"} or -\code{"less"}. You can specify just the initial letter.} +must be one of \code{"two.sided"} (default), \code{"greater"} or \code{"less"}. You can +specify just the initial letter.} } \value{ The weighted (test) statistic. } \description{ -\strong{Weighted statistics for variables} -\cr \cr -\code{weighted_sd()}, \code{weighted_se()}, \code{weighted_mean()} and \code{weighted_median()} -compute weighted standard deviation, standard error, mean or median for a -variable or for all variables of a data frame. \code{survey_median()} computes the -median for a variable in a survey-design (see \code{\link[survey]{svydesign}}). -\code{weighted_correlation()} computes a weighted correlation for a two-sided alternative -hypothesis. -\cr \cr -\strong{Weighted tests} -\cr \cr -\code{weighted_ttest()} computes a weighted t-test, while \code{weighted_mannwhitney()} -computes a weighted Mann-Whitney-U test or a Kruskal-Wallis test -(for more than two groups). \code{weighted_ranktest()} is an alias for \code{weighted_mannwhitney()}. -\code{weighted_chisqtest()} computes a weighted Chi-squared test for contingency tables. +\code{weighted_se()} computes weighted standard errors of a variable or for +all variables of a data frame. \code{survey_median()} computes the median for +a variable in a survey-design (see [\verb{survey::svydesign()]}). +\code{weighted_correlation()} computes a weighted correlation for a two-sided +alternative hypothesis. } \note{ -\code{weighted_chisq()} is a convenient wrapper for \code{\link{crosstable_statistics}}. -For a weighted one-way Anova, use \code{means_by_group()} with -\code{weights}-argument. -\cr \cr -\code{weighted_ttest()} assumes unequal variance between the two groups. +\code{weighted_chisq()} is a convenient wrapper for \verb{\link{crosstable_statistics`}. For a weighted one-way Anova, use }means_by_group()\code{with}weights\verb{-argument. \\cr \\cr }weighted_ttest()` assumes unequal variance between the two groups. } \examples{ -# 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 ----