2
$\begingroup$

Say I have a random variable $X\sim\mathscr{N}\left(0,\sigma^2\right)$ and another random variable $Y=X+\varepsilon$, where $\varepsilon\sim\mathscr{N}\left(0,\eta^2\right)$ is independent of $X$. I can calculate $Cov\left(X,Y\right)=Cov\left(X,X+\varepsilon\right)=Var(X)=\sigma^2$.

Is there a way to get Mathematica to generate a bivariate normal distribution automatically from the given information? Specifically, rather than working out the covariance matrix myself and then inputting to Mathematica, I would like to be able to do something like (implementing the above example):

\[ScriptCapitalX] = NormalDistribution[0, \[Sigma]]
\[CapitalEpsilon] = NormalDistribution[0, \[Eta]]
\[ScriptCapitalY] = TransformedDistribution[X + \[CurlyEpsilon], {X \[Distributed] \[ScriptCapitalX], \[CurlyEpsilon] \[Distributed] \[CapitalEpsilon]}]

\[Mu] = {Mean[\[ScriptCapitalX]], Mean[\[ScriptCapitalY]]}
\[CapitalSigma] = {{Variance[\[ScriptCapitalX]], Covariance[\[ScriptCapitalX], \[ScriptCapitalY]]}, {Covariance[\[ScriptCapitalX], \[ScriptCapitalY]], Variance[\[ScriptCapitalY]]}}

multi = MultinormalDistribution[\[Mu], \[CapitalSigma]]
want = Expectation[X \[Conditioned] Y = y, {Y, X} \[Distributed] multi]

Obviously, the Covariance function doesn't work that way, but at a minimum I would really like to have Mathematica do the covariance calculation. Also, if there's an easy way to get the mean vector and covariance matrix without explicitly calling Mean, Variance, etc. on individual elements to construct them, that would be even better. I am quite new to the Wolfram language.

$\endgroup$
1
  • 1
    $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$
    – bbgodfrey
    Feb 11 at 10:34

1 Answer 1

3
$\begingroup$

You were almost there:

\[ScriptCapitalX] = NormalDistribution[0, σ]
\[CapitalEpsilon] = NormalDistribution[0, η]
multi = TransformedDistribution[{X, X + ε}, 
  {X \[Distributed] \[ScriptCapitalX], ε \[Distributed] \[CapitalEpsilon]}]

Covariance[multi][[1, 2]]
(* σ^2 *)

Expectation[X \[Conditioned] Y == y, {X, Y} \[Distributed] multi]
(* (y σ^2)/(η^2 + σ^2) *)
$\endgroup$

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.