I am interested in finding a conditional expectation of a multivariate Normal distribution. For example, let $X$ and $Y$ denote two random variables with a joint normal distribution.

Let $X \sim N(\mu_x, \sigma_x)$, $Y\sim N(\mu_y, \sigma_y)$ and $Cov(X,Y) = \sigma^{2}_{x}$

I want to compute for example $E(X|Y)$. While I know how to get this using paper and pencil, I want to learn how one would go about computing the general solution in Mathematica.

To this end I wrote the following code:

  x \[Conditioned] y
  ,{x,y} \[Distributed] MultinormalDistribution[{Subscript[μ, x], Subscript[μ,y]}, {{Subscript[σ,x]^2,Subscript[σ,x]^2 }, {Subscript[σ,x]^2 ,Subscript[σ,x]^2+ Subscript[σ, y]^2}}]

Unfortunately, the only output I get it just what I wrote as the input. There is no solution. How can I compute the conditional expectations I want?

  • $\begingroup$ Welcome to Mma.SE. Start by taking the tour now and learning about asking and what's on-topic. Always edit if improvable, show due diligence, give brief context, include minimal working example of code and data in formatted form. By doing all this you help us to help you and likely you will inspire great answers. The site depends on participation, as you receive give back: vote and answer questions, keep the site useful, be kind, correct mistakes and share what you have learned. $\endgroup$
    – rhermans
    Jul 30, 2018 at 16:15
  • $\begingroup$ On a side note, you should avoid using Subscript while defining symbols (variables). We know they look nice, but Subscript[x, 1] is not a symbol, but a composite expression where Subscript is an operator without built-in meaning. You expect to do $x_1=2$ but you are actually doing Set[Subscript[x, 1], 2] which is to assign a DownValues to the operator Subscript and not an OwnValues to an indexed x as you may intend. Read how to properly define indexed variables here $\endgroup$
    – rhermans
    Jul 30, 2018 at 16:16

1 Answer 1


First, following @rhermans advice about Subscripts's is imperative. Second, while writing $x | y$ is the mathematical way to write a conditioned statement, the function Expectation requires the term on the right of the modulus sign to be a "condition". So putting all of this together we have

Expectation[x \[Conditioned] y == y0, 
{x, y} \[Distributed] MultinormalDistribution[{μx, μy}, {{σx^2, σx^2}, {σx^2, σx^2 + σy^2}}]]

(y0 σx^2 + μx σx^2 - μy σx^2 + μx σy^2)/(σx^2 + σy^2)

Using FullSimplify on the result gives

μx + ((y0 - μy) σx^2)/(σx^2 + σy^2)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.