[R] Can R compute the expected value of a random variable?

Paul Smith phhs80 at gmail.com
Sun Aug 27 18:52:15 CEST 2006


On 8/26/06, Mike Nielsen <mr.blacksheep at gmail.com> wrote:
> Yes.
>
> > Can R compute the expected value of a random variable?

Mike: thank you very much indeed for your so insightful and complete
answer. I have  meanwhile deepened my research and, as a consequence,
I have found the following solution, which seems to work fine:

> integrand <- function(x){x*dlnorm(x,meanlog=2,sdlog=3)}
> integrate(integrand,-Inf, Inf)
665.146 with absolute error < 0.046
>

There is also a package apt to calculate expected values: it is called
distrEx. (Thanks, Matthias.)

Paul



More information about the R-help mailing list