Mean and variance of probability density with multidimensional indicator function I encountered the following question while studying machine learning:
We are asked to calculate mean and covariance of a given probability density function 
$$p(x) = \frac{1}{16} \cdot 1_{0 \leq x_1 \leq 4} \cdot 1_{-1 \leq x_2 \leq 3}  $$
where $x \in \mathbb{R}^2$ and $1$ is an indicator function.
I know the mean in a one-dimensional setting can be computed like so:
$$\mu = \int p(x) x dx $$
What confuses me here are two things:


*

*How to compute the mean in a two-dimensional setting? 

*If it involves integration: How to integrate the indicator functions?

 A: For the two dimensional random vector $(X_1,X_2)$ with pdf $f(x_1,x_2)$, you have two ways to get the expectations involved one random variables, for $g(X_1)$. 1) you get the marginal pdf of $X_1$ first, then following the way that you get thge expectation for one random variables. 2) $\int \int g(x_1)f(x_1,x_2)dx_1 dx_2$. For the expectation involved two random variables, $g(x_1,x_2)$, for example, $E(X_1X_2)$, you must go through  $\int \int g(x_1,x_2)f(x_1,x_2)dx_1 dx_2$.
For question 2. Here is example: to show $\int\int p(x_1,x_2) d_x1 dx_2 =1$, so that it meet one of the requirements to be pdf. For the area that pdf = 0, the integral is zero on the, so you just to consider the area that pdf not zero. In you case, the area is $0 \leq x_1 \leq 4$ and $-1 \leq x_2 \leq 3$.
$$\int_{-1}^{3}\int_{0}^{4} p(x_1,x_2) dx_1 dx_2 = \int_{-1}^{3}\int_{0}^{4} \frac 1{16} dx_1 dx_2 = \int_{-1}^{3}\frac {x_1}{16}\bigg|_0^4 dx_2 =  \int_{-1}^{3}\frac {1}{4} dx_2 = \frac {x_2}{4}\bigg|_{-1}^3 = \frac 34 - \left(-\frac 14\right) = 1 $$
