mirror of
https://github.com/msberends/AMR.git
synced 2024-12-25 19:26:13 +01:00
rename vector2ratio to ratio
This commit is contained in:
parent
a1acb2f3ac
commit
3d0d21f322
@ -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)
|
||||
|
6
NEWS.md
6
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 Χ<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 `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)`
|
||||
|
12
R/g.test.R
12
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.')
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user