1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-26 08:06:12 +01:00

rename vector2ratio to ratio

This commit is contained in:
dr. M.S. (Matthijs) Berends 2018-07-02 11:14:20 +02:00
parent a1acb2f3ac
commit 3d0d21f322
6 changed files with 20 additions and 20 deletions

View File

@ -46,13 +46,13 @@ export(left_join_microorganisms)
export(mo_property) export(mo_property)
export(n_rsi) export(n_rsi)
export(p.symbol) export(p.symbol)
export(ratio)
export(right_join_microorganisms) export(right_join_microorganisms)
export(rsi) export(rsi)
export(rsi_df) export(rsi_df)
export(rsi_predict) export(rsi_predict)
export(semi_join_microorganisms) export(semi_join_microorganisms)
export(top_freq) export(top_freq)
export(vector2ratio)
exportMethods(as.double.mic) exportMethods(as.double.mic)
exportMethods(as.integer.mic) exportMethods(as.integer.mic)
exportMethods(as.numeric.mic) exportMethods(as.numeric.mic)

View File

@ -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)` * 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 * 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 Χ<sup>2</sup> distributed [*G*-test](https://en.wikipedia.org/wiki/G-test) * Function `g.test` to perform the Χ<sup>2</sup> 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 `ratio` to transform a vector of values to a preset ratio (convenient to use with `g.test`). For example:
* Function `vector2ratio` to transform a vector of values to a preset ratio. For example:
```r ```r
vector2ratio(c(772, 1611, 737), ratio = "1:2:1") ratio(c(772, 1611, 737), ratio = "1:2:1")
# [1] 780 1560 780 # [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 #### Changed
* Frequency tables (function `freq`) now supports quasiquotation: `freq(mydata, mycolumn)`, or `mydata %>% freq(mycolumn)` * Frequency tables (function `freq`) now supports quasiquotation: `freq(mydata, mycolumn)`, or `mydata %>% freq(mycolumn)`

View File

@ -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}). #' 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 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 alpha value to test the p value against
#' @param info logical to determine whether the analysis should be printed #' @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. #' @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. #' # ratio.
#' #'
#' x <- c(772, 1611, 737) #' x <- c(772, 1611, 737)
#' x.expected <- vector2ratio(x, ratio = "1:2:1") #' x.expected <- ratio(x, "1:2:1")
#' x.expected #' x.expected
#' # 780 1560 780 #' # 780 1560 780
#' #'
@ -90,7 +90,7 @@
#' # observed 1752 right-billed and 1895 left-billed crossbills. #' # observed 1752 right-billed and 1895 left-billed crossbills.
#' #'
#' x <- c(1752, 1895) #' x <- c(1752, 1895)
#' x.expected <- vector2ratio(x, ratio = c(1, 1)) #' x.expected <- ratio(x, ratio = c(1, 1))
#' x.expected #' x.expected
#' # 1823.5 1823.5 #' # 1823.5 1823.5
#' #'
@ -215,7 +215,7 @@ g.test <- function(x,
#' # ratio. #' # ratio.
#' #'
#' x <- c(772, 1611, 737) #' x <- c(772, 1611, 737)
#' x.expected <- vector2ratio(x, ratio = "1:2:1") #' x.expected <- ratio(x, "1:2:1")
#' x.expected #' x.expected
#' # 780 1560 780 #' # 780 1560 780
#' #'
@ -235,7 +235,7 @@ g.test <- function(x,
#' # observed 1752 right-billed and 1895 left-billed crossbills. #' # observed 1752 right-billed and 1895 left-billed crossbills.
#' #'
#' x <- c(1752, 1895) #' x <- c(1752, 1895)
#' x.expected <- vector2ratio(x, ratio = c(1, 1)) #' x.expected <- ratio(x, ratio = c(1, 1))
#' x.expected #' x.expected
#' # 1823.5 1823.5 #' # 1823.5 1823.5
#' #'
@ -245,7 +245,7 @@ g.test <- function(x,
#' # There is a significant difference from a 1:1 ratio. #' # There is a significant difference from a 1:1 ratio.
#' # Meaning: there are significantly more left-billed birds. #' # Meaning: there are significantly more left-billed birds.
#' #'
vector2ratio <- function(x, ratio) { ratio <- function(x, ratio) {
if (!all(is.numeric(x))) { if (!all(is.numeric(x))) {
stop('`x` must be a vector of numeric values.') stop('`x` must be a vector of numeric values.')
} }

View File

@ -9,7 +9,7 @@ g.test(x, y = NULL, alpha = 0.05, info = TRUE, minimum = 0)
\arguments{ \arguments{
\item{x}{numeric vector or matrix} \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} \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. # ratio.
x <- c(772, 1611, 737) x <- c(772, 1611, 737)
x.expected <- vector2ratio(x, ratio = "1:2:1") x.expected <- ratio(x, "1:2:1")
x.expected x.expected
# 780 1560 780 # 780 1560 780
@ -88,7 +88,7 @@ g.test(x, x.expected)
# observed 1752 right-billed and 1895 left-billed crossbills. # observed 1752 right-billed and 1895 left-billed crossbills.
x <- c(1752, 1895) x <- c(1752, 1895)
x.expected <- vector2ratio(x, ratio = c(1, 1)) x.expected <- ratio(x, ratio = c(1, 1))
x.expected x.expected
# 1823.5 1823.5 # 1823.5 1823.5

View File

@ -1,10 +1,10 @@
% Generated by roxygen2: do not edit by hand % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/g.test.R % Please edit documentation in R/g.test.R
\name{vector2ratio} \name{ratio}
\alias{vector2ratio} \alias{ratio}
\title{Transform vector to ratio} \title{Transform vector to ratio}
\usage{ \usage{
vector2ratio(x, ratio) ratio(x, ratio)
} }
\arguments{ \arguments{
\item{x}{vector of values} \item{x}{vector of values}
@ -25,7 +25,7 @@ Transform vector to ratio
# ratio. # ratio.
x <- c(772, 1611, 737) x <- c(772, 1611, 737)
x.expected <- vector2ratio(x, ratio = "1:2:1") x.expected <- ratio(x, "1:2:1")
x.expected x.expected
# 780 1560 780 # 780 1560 780
@ -45,7 +45,7 @@ g.test(x, x.expected)
# observed 1752 right-billed and 1895 left-billed crossbills. # observed 1752 right-billed and 1895 left-billed crossbills.
x <- c(1752, 1895) x <- c(1752, 1895)
x.expected <- vector2ratio(x, ratio = c(1, 1)) x.expected <- ratio(x, ratio = c(1, 1))
x.expected x.expected
# 1823.5 1823.5 # 1823.5 1823.5

View File

@ -6,14 +6,14 @@ test_that("G-test works", {
# example 1: clearfield rice vs. red rice # example 1: clearfield rice vs. red rice
x <- c(772, 1611, 737) 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), expect_equal(g.test(x, x.expected),
expected = 0.12574, expected = 0.12574,
tolerance = 0.00001) tolerance = 0.00001)
# example 2: red crossbills # example 2: red crossbills
x <- c(1752, 1895) 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), expect_equal(g.test(x, x.expected),
expected = 0.01787343, expected = 0.01787343,
tolerance = 0.00000001) tolerance = 0.00000001)