Solved – If the probability density function of X is f(x)=sin(x) then what is the variance of X

distributionsintegralprobability-calculusself-studyvariance

I am studying a random variable X with probability density function

f(x) = sin(x)

the domain of X is (0,pi/2). I'm trying to determine the variance of X. I know

var(X) = E(X^2) – E(X)^2

how do i determine E(X)? do i calculate x*P(X=x) across a grid of values and sum them? I have similar questions about calculating E(X^2). Is it possible to use a simulation based approach to estimating E(X)? I do not need an exact answer.

Best Answer

Simulating from the density $$f(x)=\sin(x)\mathbb{I}_{(0,\pi/2)}(x)$$ can be done by the inverse cdf method, since the cdf is then $$F(x)=\int_0^x \sin(x)\text{d}x=1-\cos(x)\qquad 0\le x\le\pi/2$$ The inverse cdf method consists in simulating $U\sim\mathcal{U}(0,1)$, a standard Uniform, and then solving $F(x)=u$, which in this case means $$1-\cos(x)=u\quad\text{i.e.}\quad x=\arccos(1-u)$$

The Monte Carlo approximations to mean and variance are then easily coded, for instance in R

>mean(acos(runif(1e5)))
[1] 1.000211

>var(acos(runif(1e5)))
[1] 0.1415383

Note that the expectation coincides with your suggestion to use the identity$$\mathbb{E}[X]=\int_0^{\pi/2} \{1-F(x)\}\,\text{d}x=\int_0^{\pi/2} \cos(x)\,\text{d}x=1$$