Skip to contents

Logit and inverse logit function that work for vectors, matrices, and other types of arrays that consist of numerical entries.

Usage

logit(mu)

inv_logit(eta)

Arguments

mu

An array with numerical entries between 0 and 1.

eta

An array with arbitrary numerical entries.

Value

Returns an array of either the logits of the entries of mu (function logit()) or the inverse logits of the entries of eta (function inv_logit()).

Details

The logit and inverse logit function are defined as $$logit(x)=log(x/(1-x)),$$ $$inv\_logit(y)=exp(y)/(1+exp(y)).$$ In particular, one has \(logit(inv\_logit(y))=y\) and \(inv\_logit(logit(x))=x\).

Both functions are extracted from a stats::family object of family binomial().

Examples

y <- logit(0.1)
inv_logit(y)
#> [1] 0.1
logit(c(0.1, 0.2, 0.3, 0.4, 0.5))
#> [1] -2.1972246 -1.3862944 -0.8472979 -0.4054651  0.0000000
inv_logit(c(-2, -1, 0, 1, 2))
#> [1] 0.1192029 0.2689414 0.5000000 0.7310586 0.8807971