# Is an implementation of a density function for a logit-normal distribution available in R?

Is an implementation of a density function for a logit-normal distribution available in R?

I have not found one in a package or in the CRAN task view of probability distributions.

This is for a MLE fitting of a function to data.

-

Bare-bones scaled logit-normal distribution code, use at your own risk:

logit <- function(x, a = 0, b = 1)
{
stopifnot(a < b)
x <- (x - a)/(b - a)
log(x) - log(1 - x)
}

invlogit <- function(x, a = 0, b = 1)
{
stopifnot(a < b)
((b - a)/(1 + exp(-x))) + a
}

dlogitnorm <- function(x, ..., a = 0, b = 1, log = FALSE)
{
out <- dnorm(x = logit(x, a, b), ..., log = TRUE) + log(b - a) - log(x - a) - log(b - x)
out[x == a | x == b] <- -Inf
if(log) out else exp(out)
}

plogitnorm <- function(q, ..., a = 0, b = 1, lower.tail = TRUE, log.p = FALSE)
pnorm(logit(q, a, b)), ..., lower.tail = lower.tail, log.p = log.p)

qlogitnorm <- function(p, ..., a = 0, b = 1, lower.tail = TRUE, log.p = FALSE)
invlogit(qnorm(p, ..., lower.tail = lower.tail, log.p = log.p), a, b)

rlogitnorm <- function(n, ..., a = 0, b = 1) invlogit(rnorm(n, ....), a, b)

-
note that logit and invlogit are availabe in base R as plogis, qlogis ... –  Ben Bolker Apr 1 '12 at 17:48
@Cyan, I understand this is provided as is, but just to note that the results from the function you provide are not the same as those provide by the package logitnorm. Any suggestions as to the reason? –  Etienne Low-Décarie Apr 3 '12 at 19:19
@EtienneLow-Décarie, I can't seem to get my hands on the logitnorm package code. The R-Forge download page doesn't have download links. What am I doing wrong? –  Cyan Apr 4 '12 at 2:29