diff --git a/NAMESPACE b/NAMESPACE index 53a541f5..4ee30533 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -46,13 +46,13 @@ export(left_join_microorganisms) export(mo_property) export(n_rsi) export(p.symbol) +export(ratio) export(right_join_microorganisms) export(rsi) export(rsi_df) export(rsi_predict) export(semi_join_microorganisms) export(top_freq) -export(vector2ratio) exportMethods(as.double.mic) exportMethods(as.integer.mic) exportMethods(as.numeric.mic) diff --git a/NEWS.md b/NEWS.md index 094e92e2..c02cab50 100755 --- a/NEWS.md +++ b/NEWS.md @@ -5,12 +5,12 @@ * Possibility to globally set the default for the amount of items to print in frequency tables (`freq` function), with `options(max.print.freq = n)` * Functions `clipboard_import` and `clipboard_export` as helper functions to quickly copy and paste from/to software like Excel and SPSS * Function `g.test` to perform the Χ2 distributed [*G*-test](https://en.wikipedia.org/wiki/G-test) -* Function `p.symbol` to transform p value to their related symbol: `0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1` -* Function `vector2ratio` to transform a vector of values to a preset ratio. For example: +* Function `ratio` to transform a vector of values to a preset ratio (convenient to use with `g.test`). For example: ```r -vector2ratio(c(772, 1611, 737), ratio = "1:2:1") +ratio(c(772, 1611, 737), ratio = "1:2:1") # [1] 780 1560 780 ``` +* Function `p.symbol` to transform p value to their related symbol: `0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1` #### Changed * Frequency tables (function `freq`) now supports quasiquotation: `freq(mydata, mycolumn)`, or `mydata %>% freq(mycolumn)` diff --git a/R/g.test.R b/R/g.test.R index 5932e8c0..914dae47 100644 --- a/R/g.test.R +++ b/R/g.test.R @@ -20,7 +20,7 @@ #' #' A \emph{G}-test can be used to see whether the number of observations in each category fits a theoretical expectation (called a \strong{\emph{G}-test of goodness-of-fit}), or to see whether the proportions of one variable are different for different values of the other variable (called a \strong{\emph{G}-test of independence}). #' @param x numeric vector or matrix -#' @param y expected value of \code{x}. Leave empty to determine automatically. This can also be ratios of \code{x}, e.g. calculated with \code{\link{vector2ratio}}. +#' @param y expected value of \code{x}. Leave empty to determine automatically. This can also be ratios of \code{x}, e.g. calculated with \code{\link{ratio}}. #' @param alpha value to test the p value against #' @param info logical to determine whether the analysis should be printed #' @param minimum the test with fail if any of the observed values is below this value. Use \code{minimum = 30} for microbial epidemiology, to prevent calculating a p value when less than 30 isolates are available. @@ -70,7 +70,7 @@ #' # ratio. #' #' x <- c(772, 1611, 737) -#' x.expected <- vector2ratio(x, ratio = "1:2:1") +#' x.expected <- ratio(x, "1:2:1") #' x.expected #' # 780 1560 780 #' @@ -90,7 +90,7 @@ #' # observed 1752 right-billed and 1895 left-billed crossbills. #' #' x <- c(1752, 1895) -#' x.expected <- vector2ratio(x, ratio = c(1, 1)) +#' x.expected <- ratio(x, ratio = c(1, 1)) #' x.expected #' # 1823.5 1823.5 #' @@ -215,7 +215,7 @@ g.test <- function(x, #' # ratio. #' #' x <- c(772, 1611, 737) -#' x.expected <- vector2ratio(x, ratio = "1:2:1") +#' x.expected <- ratio(x, "1:2:1") #' x.expected #' # 780 1560 780 #' @@ -235,7 +235,7 @@ g.test <- function(x, #' # observed 1752 right-billed and 1895 left-billed crossbills. #' #' x <- c(1752, 1895) -#' x.expected <- vector2ratio(x, ratio = c(1, 1)) +#' x.expected <- ratio(x, ratio = c(1, 1)) #' x.expected #' # 1823.5 1823.5 #' @@ -245,7 +245,7 @@ g.test <- function(x, #' # There is a significant difference from a 1:1 ratio. #' # Meaning: there are significantly more left-billed birds. #' -vector2ratio <- function(x, ratio) { +ratio <- function(x, ratio) { if (!all(is.numeric(x))) { stop('`x` must be a vector of numeric values.') } diff --git a/man/g.test.Rd b/man/g.test.Rd index 7745cb1f..a52d9c8b 100644 --- a/man/g.test.Rd +++ b/man/g.test.Rd @@ -9,7 +9,7 @@ g.test(x, y = NULL, alpha = 0.05, info = TRUE, minimum = 0) \arguments{ \item{x}{numeric vector or matrix} -\item{y}{expected value of \code{x}. Leave empty to determine automatically. This can also be ratios of \code{x}, e.g. calculated with \code{\link{vector2ratio}}.} +\item{y}{expected value of \code{x}. Leave empty to determine automatically. This can also be ratios of \code{x}, e.g. calculated with \code{\link{ratio}}.} \item{alpha}{value to test the p value against} @@ -68,7 +68,7 @@ If there are more than two categories and you want to find out which ones are si # ratio. x <- c(772, 1611, 737) -x.expected <- vector2ratio(x, ratio = "1:2:1") +x.expected <- ratio(x, "1:2:1") x.expected # 780 1560 780 @@ -88,7 +88,7 @@ g.test(x, x.expected) # observed 1752 right-billed and 1895 left-billed crossbills. x <- c(1752, 1895) -x.expected <- vector2ratio(x, ratio = c(1, 1)) +x.expected <- ratio(x, ratio = c(1, 1)) x.expected # 1823.5 1823.5 diff --git a/man/vector2ratio.Rd b/man/ratio.Rd similarity index 92% rename from man/vector2ratio.Rd rename to man/ratio.Rd index 3d8801c5..ac7c18d6 100644 --- a/man/vector2ratio.Rd +++ b/man/ratio.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/g.test.R -\name{vector2ratio} -\alias{vector2ratio} +\name{ratio} +\alias{ratio} \title{Transform vector to ratio} \usage{ -vector2ratio(x, ratio) +ratio(x, ratio) } \arguments{ \item{x}{vector of values} @@ -25,7 +25,7 @@ Transform vector to ratio # ratio. x <- c(772, 1611, 737) -x.expected <- vector2ratio(x, ratio = "1:2:1") +x.expected <- ratio(x, "1:2:1") x.expected # 780 1560 780 @@ -45,7 +45,7 @@ g.test(x, x.expected) # observed 1752 right-billed and 1895 left-billed crossbills. x <- c(1752, 1895) -x.expected <- vector2ratio(x, ratio = c(1, 1)) +x.expected <- ratio(x, ratio = c(1, 1)) x.expected # 1823.5 1823.5 diff --git a/tests/testthat/test-g.test.R b/tests/testthat/test-g.test.R index 5b601452..d04a3553 100644 --- a/tests/testthat/test-g.test.R +++ b/tests/testthat/test-g.test.R @@ -6,14 +6,14 @@ test_that("G-test works", { # example 1: clearfield rice vs. red rice x <- c(772, 1611, 737) - x.expected <- vector2ratio(x, ratio = "1:2:1") + x.expected <- ratio(x, ratio = "1:2:1") expect_equal(g.test(x, x.expected), expected = 0.12574, tolerance = 0.00001) # example 2: red crossbills x <- c(1752, 1895) - x.expected <- vector2ratio(x, ratio = c(1, 1)) + x.expected <- ratio(x, ratio = c(1, 1)) expect_equal(g.test(x, x.expected), expected = 0.01787343, tolerance = 0.00000001)