From 3abedde1eb2a6ade49ca5074e6c580d29a165030 Mon Sep 17 00:00:00 2001 From: Jimmy Briggs Date: Tue, 4 Jan 2022 20:43:46 -0500 Subject: [PATCH] feat: initialize statistical functions for issue #16 --- R/stat-logit.R | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 R/stat-logit.R diff --git a/R/stat-logit.R b/R/stat-logit.R new file mode 100644 index 0000000..795cab9 --- /dev/null +++ b/R/stat-logit.R @@ -0,0 +1,45 @@ +#' logit +#' +#' The `logit` function in mathematics is the `quantile` associated with the standard +#' [logistic distribution](https://en.wikipedia.org/wiki/Logistic_distribution). +#' +#' The `logit` is used widely as a method of transforming data for modelling purposes. +#' +#' @param p probability, where 0 < *p* < 1. +#' +#' @return Log of p/(1-p) +#' @export +#' +#' @examples +#' logit(.25) +logit <- function(p) { + + stopifnot( + length(p[p < 0]) == 0, + length(p[p > 1]) == 0 + ) + + log(p / (1 - p)) + +} + +#' dnorm_logit +#' +#' Lognormal Density Function +#' +#' @param p probability at which to evaluate the density function +#' @param mean_logit Mean of logarithmic values +#' @param sd_logit Standard Deviation of logarithmic values. +#' +#' @return z-value representing output of a given value of X +#' @export +#' +#' @examples +#' dnorm_logit() +dnorm_logit <- function(p, mean_logit, sd_logit){ + + z <- 1 / (sd_logit * sqrt(2 * pi)) * 1 / (p * (1 - p)) * exp(-(logit(p) - mean_logit)^2 / (2 * sd_logit^2)) + + return(z) + +}