-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initialize statistical functions
for issue #16
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
||
} |