# Thread: Finding expected value and variance of pdf

1. ## Finding expected value and variance of pdf

Find $\displaystyle E(X)$ and $\displaystyle Var(X)$ for the random variable $\displaystyle X$ with probability density function proportional to:

$\displaystyle e^{-x^2+x}$

2. First, and very much most importantly, you must specify a DOMAIN. I'm going to guess you mean $\displaystyle [-\infty,\infty]$, but [-5,5] is about the same on this one. Please think about complete definitions. Your life WILL be better.

With that, we can solve the silly "proportional" word. The probability, whatever it is, must sum to unity.

$\displaystyle \int_{-\infty}^{\infty}a\cdot e^{x-x^{2}}\;dx = 1$

Solve for 'a'. I get a = 1.3153602668. You may have to employ some numerical methods.

Can you take it from there? Calculating the first two moments seems a good way to proceed.

3. Originally Posted by TKHunny
First, and very much most importantly, you must specify a DOMAIN. I'm going to guess you mean $\displaystyle [-\infty,\infty]$, but [-5,5] is about the same on this one. Please think about complete definitions. Your life WILL be better.

With that, we can solve the silly "proportional" word. The probability, whatever it is, must sum to unity.

$\displaystyle \int_{-\infty}^{\infty}a\cdot e^{x-x^{2}}\;dx = 1$

Solve for 'a'. I get a = 1.3153602668. You may have to employ some numerical methods.

Can you take it from there? Calculating the first two moments seems a good way to proceed.
Ok, so once we find a, to find the expected value and variance, do I do the following?

$\displaystyle E(X)=1.32\int_{-\infty}^{\infty}xe^{x-x^2}\;dx$

$\displaystyle Var(X)=1.32\int_{-\infty}^{\infty}x^2e^{x-x^2}\;dx-[E(X)]^2$

By the way, what's an easy way of integrating that?

4. you need to use integration by parts for both i think.

Since different people use different notation for integration by parts, here is how i write it:
$\displaystyle \int uv' = \left[uv \right] - \int u'v$

For E(X) use
$\displaystyle v'=xe^{-x^2}$
$\displaystyle v = -0.5e^{-x^2}$

$\displaystyle u=e^{x}$
$\displaystyle u'=e^{x}$

Integration by parts:

$\displaystyle \int_{-\infty}^{\infty} xe^{x-x^2} = \left[uv \right]_{-\infty}^{\infty} - \int_{-\infty}^{\infty} -0.5e^{-x^2}e^{x}$

$\displaystyle \int_{-\infty}^{\infty} xe^{x-x^2} = \left[uv \right]_{-\infty}^{\infty} + 0.5 \int_{-\infty}^{\infty} e^{x-x^2}$

You can recognise the integral on the RHS as the pdf multiplied by a constant $\displaystyle \frac{0.5}{a}$, you know the PDF integrates to 1.

If you take a similar approach to do the $\displaystyle E(x^2)$, I think you will find that the integral "appearing" on the right is equal to E(X) + pdf, multiplied by various constants, but this should be no problem as you just calculated the value of E(X).

Try that, my apologies if it doesn't work. I haven't worked it through myself.

Edit I did the second one to check
Spoiler:

For E(X^2) use
$\displaystyle v'=xe^{-x^2}$
$\displaystyle v = -0.5e^{-x^2}$

$\displaystyle u=xe^{x}$
$\displaystyle u'=xe^{x} + e^x$

$\displaystyle \int_{-\infty}^{\infty} xe^{x-x^2} = \left[uv \right]_{-\infty}^{\infty} - \int_{-\infty}^{\infty} -0.5e^{-x^2}\left(xe^{x} + e^x \right)$

$\displaystyle \int_{-\infty}^{\infty} xe^{x-x^2} = \left[uv \right]_{-\infty}^{\infty} - \left( \int_{-\infty}^{\infty} -0.5e^{-x^2}xe^{x} + \int_{-\infty}^{\infty} -0.5e^{-x^2}e^{x} \right)$

$\displaystyle \int_{-\infty}^{\infty} xe^{x-x^2} = \left[uv \right]_{-\infty}^{\infty} - \left( \int_{-\infty}^{\infty} -0.5xe^{x-x^2} + \int_{-\infty}^{\infty} -0.5e^{x-x^2} \right)$

You can recognise the integrals on the RHS as the PDF and E(X), muyltipled by constants. the PDF integrates to 1 (again), and you just calculated E(X)

5. Originally Posted by acevipa
By the way, what's an easy way of integrating that?
Well, that's why I mentioned the numerical methods. Really, it's not evil to have only 15 decimal places rather than an exact solution. If you were trying to find Mars, I think that much accuracy would get you there. For well-behaved functions, as strictly continuous probability densities often are, simpler methods, such as Simpson's rule, are likely to be quite sufficient. Throw in Rhomberg Extrapolation and a very large percentage of such integrals easily are solved. Maybe Gaussian Quadrature if your feeling a little adventurous.

Just a quick reference for you.

6. worth checking if credit will be given for an approximate solution before doing that. The purpose of these exercises is often to learn to manipulate integrals in that way.

7. In a statistics class?! I cannot agree with that. It should have been in your calculus prerequisites.

My views. I welcome others'.

8. Originally Posted by acevipa
Find $\displaystyle E(X)$ and $\displaystyle Var(X)$ for the random variable $\displaystyle X$ with probability density function proportional to:

$\displaystyle e^{-x^2+x}$
You should be able to re-write this as $\displaystyle e^{-\left(x - \frac{1}{2}\right)^2} e^{-1/4}$ and then normalise $\displaystyle e^{-\left(x - \frac{1}{2}\right)^2}$ by recognising it as being proportional to the pdf of a normal distribution with mean ..... and sd ......

Then use the well known results for mean and variance of a normal distribution to answer your question.

9. You mean those well-known and inexact probabilities in published references and in software algorithms?

Good call. Much simpler not to reinvent the wheel.