Martin‽ [🇷 for BE/BA]

posted by Helmut Homepage – Vienna, Austria, 2013-07-28 04:01 (3922 d 10:39 ago) – Posting: # 11081
Views: 46,835

Hi ElMaestro & Martin,

❝ Sorry to embark on archaelogy.


Great. Comes handy for some TSD sim’s I’m currently running!

meang <- function(z) { exp(mean(log(na.omit(z)))) }
mu <- 1
CV <- 0.3
set.seed(20130728)
n  <- 1e7
x  <- rlnorm(n=n, meanlog=log(mu)-0.5*log(1+CV^2), sdlog=sqrt(log(CV^2+1)))
y  <- rlnorm(n=n, meanlog=log(mu), sdlog=sqrt(log(CV^2+1)))
res<- matrix(nrow=2, ncol=6)
colnames(res) <- c("a. mean", "%RE a. mean", "CV", "%RE CV",
                   "g. mean", "%RE g. mean")
rownames(res) <- c("Par. 1 (x)", "Par. 2 (y)")
split.screen(c(2, 1))
  screen(1)
    hist(log(x), freq=F, xlim=c(-1, 1), las=1, breaks="fd",
         col="bisque", border=NA, font.main=1, cex.main=1,
         main=expression(meanlog==log[e](mu)-0.5%*%log[e](1+italic(CV)^2)),
         xlab=expression("log("*italic(x)*")"))
    abline(v=log(meang(x)), lwd=2, col="red")
  screen(2)
    hist(log(y), freq=F, xlim=c(-1, 1), las=1, breaks="fd",
         col="bisque", border=NA, font.main=1, cex.main=1,
         main=expression(meanlog==log[e](mu)),
         xlab=expression("log("*italic(x)*")"))
    abline(v=log(meang(y)), lwd=2, col="green")
close.screen(all=TRUE)
res[1, 1] <- mean(x)
res[1, 2] <- 100*(mean(x)-mu)/mu
res[1, 3] <- sd(x)/mean(x)
res[1, 4] <- 100*(sd(x)/mean(x)-CV)/CV
res[1, 5] <- meang(x)
res[1, 6] <- 100*(meang(x)-mu)/mu
res[2, 1] <- mean(y)
res[2, 2] <- 100*(mean(y)-mu)/mu
res[2, 3] <- sd(y)/mean(y)
res[2, 4] <- 100*(sd(y)/mean(y)-CV)/CV
res[2, 5] <- meang(y)
res[2, 6] <-100*(meang(y)-mu)/mu
round(res, 5)


[image]

           a. mean %RE a. mean      CV   %RE CV g. mean %RE g. mean
Par. 1 (x) 1.00008     0.00773 0.29994 -0.01999 0.95792    -4.20770
Par. 2 (y) 1.04414     4.41438 0.29992 -0.02725 1.00011     0.01147


Or alternatively:
boxplot(log(x), log(y), ylab="log(x, y)",
        names=c("Par. 1", "Par. 2"), las=1)
abline(h=0, lty=3)


[image]

Sometimes [image] drives my nuts. Modified from help(rlnorm):
The log normal distribution has density $$\small{f(x)=\frac{1}{\sqrt{2\pi}\sigma x}\exp (-\frac{(\log_{e}x - \mu)^2}{2 \sigma^2})}$$ where \(\small{\mu}\) and \(\small{\sigma}\) are the mean and standard deviation of the logarithm. The mean is \(\small{E(X) = \exp(\mu + \frac{1}{2}\sigma^2)}\), the median is \(\small{med(X) = \exp(\mu)}\), and the variance \(\small{Var(X) = \exp(2\mu+\sigma^2)\exp(\sigma^2-1)}\) and hence the coefficient of variation is \(\small{\sqrt{\exp(\sigma^2)-1}}\) […].

How I love the word “hence”.

Note that the maximum is located at \(\small{mode(X)=\exp(\mu-\sigma^2)}\).

Dif-tor heh smusma 🖖🏼 Довге життя Україна! [image]
Helmut Schütz
[image]

The quality of responses received is directly proportional to the quality of the question asked. 🚮
Science Quotes

Complete thread:

UA Flag
Activity
 Admin contact
22,990 posts in 4,826 threads, 1,646 registered users;
59 visitors (1 registered, 58 guests [including 8 identified bots]).
Forum time: 14:41 CEST (Europe/Vienna)

If you don’t like something change it;
if you can’t change it, change the way you think about it.    Mary Engelbreit

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5