Density and random generation of a sum of i.i.d. random variables, where each random variable is from the following mixture distribution: With probability p_i, it is of type i. In that case, it is lognormally distributed with log-mean mu_i and log-standard deviation sigma_i.

1 2 | ```
d.sum.of.mixtures.LNLN(y, n, p.vector, mu.vector, sigma.vector, logdens = T)
r.sum.of.mixtures.LNLN(k, n, p.vector, mu.vector, sigma.vector)
``` |

`y` |
the argument at which the density is evaluated |

`k` |
number of i.i.d. random variables returned by this function (in the considered application: number of tissue samples) |

`n` |
the number of random variables entering each sum (in the considered application: number of cells per tissue sample) |

`p.vector` |
vector (p1,p2,..,pT) containing the probabilities for each type of cell. Its elements have to sum up to one |

`mu.vector` |
vector (mu1,mu2,...,muT) containing the log-means for each type |

`sigma.vector` |
vector (sigma1,...,sigmaT) containing the log-standard deviations sigma for each type |

`logdens` |
if TRUE, the log of the density is returned |

The lengths of p.vector, mu.vector and sigma.vector have to be identical. Their lengths automatically determine the number of different types.

'd.sum.of.mixtures.LNLN' gives the density, and 'r.sum.of.mixtures.LNLN' generates random variables.

Christiane Fuchs

"Parameterizing cell-to-cell regulatory heterogeneities via stochastic transcriptional profiles" by Sameer S Bajikar*, Christiane Fuchs*, Andreas Roller, Fabian J Theis^ and Kevin A Janes^: PNAS 2014, 111(5), E626-635 (* joint first authors, ^ joint last authors)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 | ```
# generate random variables
p <- c(0.25,0.75)
mu <- c(2,-1)
sigma <- c(0.3,0.1)
stochprofML:::set.model.functions("LN-LN")
r <- r.sum.of.mixtures.LNLN(10^4,10,p,mu,sigma)
hist(r,xlab="Sum of mixtures of lognormals",freq=FALSE,breaks=100,ylim=c(0,0.2))
# plot according theoretical density function
x <- seq(round(min(r)),round(max(r)),(round(max(r))-round(min(r)))/500)
y <- d.sum.of.mixtures.LNLN(x,10,p,mu,sigma,logdens=FALSE)
lines(x,y,col="blue",lwd=3)
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.