1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-08 09:51:48 +02:00

edited g.test

This commit is contained in:
2019-01-12 11:06:58 +01:00
parent 641d866db2
commit 5aad26035c
62 changed files with 703 additions and 845 deletions

0
R/ab_property.R Normal file → Executable file
View File

0
R/abname.R Normal file → Executable file
View File

15
R/age.R Normal file → Executable file
View File

@ -21,11 +21,11 @@
#' Age in years of individuals
#'
#' Calculates age in years based on a reference date, which is the sytem time at default.
#' Calculates age in years based on a reference date, which is the sytem date at default.
#' @param x date(s), will be coerced with \code{\link{as.POSIXlt}}
#' @param reference reference date(s) (defaults to today), will be coerced with \code{\link{as.POSIXlt}}
#' @param reference reference date(s) (defaults to today), will be coerced with \code{\link{as.POSIXlt}} and cannot be lower than \code{x}
#' @return Integer (no decimals)
#' @seealso \code{\link{age_groups}} to splits age into groups
#' @seealso \code{\link{age_groups}} to split age into age groups
#' @importFrom dplyr if_else
#' @inheritSection AMR Read more on our website!
#' @export
@ -45,8 +45,8 @@ age <- function(x, reference = Sys.Date()) {
years_gap <- reference$year - x$year
# from https://stackoverflow.com/a/25450756/4575331
ages <- if_else(reference$mon < x$mon | (reference$mon == x$mon & reference$mday < x$mday),
as.integer(years_gap - 1),
as.integer(years_gap))
as.integer(years_gap - 1),
as.integer(years_gap))
if (any(ages > 120)) {
warning("Some ages are > 120.")
}
@ -60,7 +60,7 @@ age <- function(x, reference = Sys.Date()) {
#' @param split_at values to split \code{x} at, defaults to age groups 0-11, 12-24, 26-54, 55-74 and 75+. See Details.
#' @details To split ages, the input can be:
#' \itemize{
#' \item{A numeric vector. A vector of \code{c(10, 20)} will split on 0-9, 10-19 and 20+. A value of only \code{50} will split on 0-49 and 50+.
#' \item{A numeric vector. A vector of e.g. \code{c(10, 20)} will split on 0-9, 10-19 and 20+. A value of only \code{50} will split on 0-49 and 50+.
#' The default is to split on young children (0-11), youth (12-24), young adults (26-54), middle-aged adults (55-74) and elderly (75+).}
#' \item{A character:}
#' \itemize{
@ -139,8 +139,7 @@ age_groups <- function(x, split_at = c(12, 25, 55, 75)) {
for (i in 1:length(split_at)) {
y[x >= split_at[i]] <- i
# create labels
# when age group consists of only one age
labs[i - 1] <- paste0(unique(c(split_at[i - 1], split_at[i] - 1)), collapse = "-")
labs[i - 1] <- paste0(unique(c(split_at[i - 1], split_at[i] - 1)), collapse = "-")
}
# last category

0
R/count.R Normal file → Executable file
View File

0
R/deprecated.R Normal file → Executable file
View File

15
R/g.test.R Normal file → Executable file
View File

@ -44,7 +44,7 @@
#'
#' It is also possible to do a \emph{G}-test of independence with more than two nominal variables. For example, Jackson et al. (2013) also had data for children under 3, so you could do an analysis of old vs. young, thigh vs. arm, and reaction vs. no reaction, all analyzed together.
#'
#' Fisher's exact test (\code{\link{fisher.test}}) is more accurate than the \emph{G}-test of independence when the expected numbers are small, so it is recommend to only use the \emph{G}-test if your total sample size is greater than 1000.
#' Fisher's exact test (\code{\link{fisher.test}}) is an \strong{exact} test, where the \emph{G}-test is still only an \strong{approximation}. For any 2x2 table, Fisher's Exact test may be slower but will still run in seconds, even if the sum of your observations is multiple millions.
#'
#' The \emph{G}-test of independence is an alternative to the chi-square test of independence (\code{\link{chisq.test}}), and they will give approximately the same results.
#' @section How the test works:
@ -155,6 +155,9 @@ g.test <- function(x,
nc <- as.integer(ncol(x))
if (is.na(nr) || is.na(nc) || is.na(nr * nc))
stop("invalid nrow(x) or ncol(x)", domain = NA)
# add fisher.test suggestion
if (nr == 2 && nc == 2)
warning("`fisher.test()` is always more reliable for 2x2 tables and although must slower, often only takes seconds.")
sr <- rowSums(x)
sc <- colSums(x)
E <- outer(sr, sc, "*")/n
@ -221,15 +224,9 @@ g.test <- function(x,
}
names(STATISTIC) <- "X-squared"
names(PARAMETER) <- "df"
# if (any(E < 5) && is.finite(PARAMETER))
# warning("G-statistic approximation may be incorrect")
if (any(E < 5) && is.finite(PARAMETER))
warning("G-statistic approximation may be incorrect due to E < 5")
# suggest fisher.test when total is < 1000 (John McDonald, Handbook of Biological Statistics, 2014)
if (sum(x, na.rm = TRUE) < 1000 && is.finite(PARAMETER)) {
warning("G-statistic approximation may be incorrect, consider Fisher's Exact test")
} else if (any(E < 5) && is.finite(PARAMETER)) {
warning("G-statistic approximation may be incorrect, consider Fisher's Exact test")
}
structure(list(statistic = STATISTIC, parameter = PARAMETER,
p.value = PVAL, method = METHOD, data.name = DNAME,
observed = x, expected = E, residuals = (x - E)/sqrt(E),

0
R/get_locale.R Normal file → Executable file
View File

0
R/ggplot_rsi.R Normal file → Executable file
View File

0
R/guess_ab_col.R Normal file → Executable file
View File

2
R/itis.R Normal file → Executable file
View File

@ -26,7 +26,7 @@
#' \if{html}{\figure{itis_logo.jpg}{options: height=60px style=margin-bottom:5px} \cr}
#' This package contains the \strong{complete microbial taxonomic data} (with all nine taxonomic ranks - from kingdom to subspecies) from the publicly available Integrated Taxonomic Information System (ITIS, \url{https://www.itis.gov}).
#'
#' All (sub)species from \strong{the taxonomic kingdoms Bacteria, Fungi and Protozoa are included in this package}, as well as all previously accepted names known to ITIS. Furthermore, the responsible authors and year of publication are available. This allows users to use authoritative taxonomic information for their data analysis on any microorganism, not only human pathogens. It also helps to quickly determine the Gram stain of bacteria, since all bacteria are classified into subkingdom Negibacteria or Posibacteria.
#' All ~20,000 (sub)species from \strong{the taxonomic kingdoms Bacteria, Fungi and Protozoa are included in this package}, as well as all ~2,500 previously accepted names known to ITIS. Furthermore, the responsible authors and year of publication are available. This allows users to use authoritative taxonomic information for their data analysis on any microorganism, not only human pathogens. It also helps to quickly determine the Gram stain of bacteria, since all bacteria are classified into subkingdom Negibacteria or Posibacteria.
#'
#' ITIS is a partnership of U.S., Canadian, and Mexican agencies and taxonomic specialists [3].
#' @inheritSection AMR Read more on our website!

0
R/key_antibiotics.R Normal file → Executable file
View File

0
R/kurtosis.R Normal file → Executable file
View File

0
R/like.R Normal file → Executable file
View File

0
R/mo.R Normal file → Executable file
View File

0
R/mo_property.R Normal file → Executable file
View File

0
R/p.symbol.R Normal file → Executable file
View File

0
R/read.4d.R Normal file → Executable file
View File

0
R/resistance_predict.R Normal file → Executable file
View File

0
R/rsi.R Normal file → Executable file
View File

0
R/rsi_calc.R Normal file → Executable file
View File

0
R/skewness.R Normal file → Executable file
View File