Symbolic integration of logmultinormal distributionhow to simplify symbolic integrationSymbolic Definite IntegrationMultidimensional integral to compute the end-to-end distribution of a FENE ideal chainSymbolic integration conditional bug?Symbolic vs numerical integrationSymbolic Integration of definite integralUnable to integrate function using IntegrateFaster symbolic integrationContour integration with MathematicaHow to study the behavior of this series in Mathematica?
Does 5e follow the Primary Source rule?
Who would use the word "manky"?
I have found a mistake on someone's code published online: what is the protocol?
Why teach C using scanf without talking about command line arguments?
Three Subway Escalators
"This used to be my phone number"
When designing an adventure, how can I ensure a continuous player experience in a setting that's likely to favor TPKs?
BritRail England Passes compared to return ticket for travel in England
Null expletive objects in Latin? "Cariotae cum ficis certandum habent" (Plin. Ep. 1,8)
Which GPUs to get for Mathematical Optimization (if any)?
What could make large expeditions ineffective for exploring territory full of dangers and valuable resources?
What is the name for the average of the largest and the smallest values in a given data set?
Do medium format lenses have a crop factor?
We get more abuse than anyone else
Why aren't there any women super GMs?
Last-minute canceled work-trip mean I'll lose thousands of dollars on planned vacation
Making a Dataset that emulates `ls -tlra`?
How did J. J. Thomson establish the particle nature of the electron?
How long were the Apollo astronauts allowed to breathe 100% oxygen at 1 atmosphere continuously?
Improving an O(N^2) function (all entities iterating over all other entities)
Do pedestrians imitate auto traffic?
Why do jet engines sound louder on the ground than inside the aircraft?
Locked-up DOS computer beeped on keypress. What mechanism caused that?
Is encryption still applied if you ignore the SSL certificate warning for self-signed certs?
Symbolic integration of logmultinormal distribution
how to simplify symbolic integrationSymbolic Definite IntegrationMultidimensional integral to compute the end-to-end distribution of a FENE ideal chainSymbolic integration conditional bug?Symbolic vs numerical integrationSymbolic Integration of definite integralUnable to integrate function using IntegrateFaster symbolic integrationContour integration with MathematicaHow to study the behavior of this series in Mathematica?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
I have been trying to integrate and compute moments of LogMultinormalDistribution
in Mathematica, but the integrals don't seem to evaluate. Say for the first moment, $langle x rangle $
Integrate[
PDF[LogMultinormalDistribution[
Subscript[μ, 1], Subscript[μ, 2],
Subscript[σ, 1]^2, Subscript[σ, 1] Subscript[σ, 2] ρ,
Subscript[σ, 1] Subscript[σ, 2] ρ, Subscript[σ, 2]^2
]
, x, y
]*x
, x, 0, Infinity
, y, 0, Infinity
]
I also tried typing out the PDF,
Integrate[(2*Pi*σx*σy Sqrt[1 - ρ^2])^-1*
Exp[-1/2*(1/(
1 - ρ^2)) (((Log[x] - μx)/σx)^2 -
2*ρ*((Log[x] - μx)/σx)*((
Log[y] - μy)/σy) + ((
Log[y] - μy)/σy)^2)]*x, x, 0, Infinity, y, 0, Infinity]
But no luck.
The integrals don't seem to evaluate and either I end up aborting them or the program seems to crash.
In general, I would like compute $langle x^n y^m rangle$ for bivariate log normal distribution in mathematica.
Is there a way to speed up the integrals/evaluate them at all.
I am running Mathematica 11.3 on Mac OS Mojave if that helps.
calculus-and-analysis
New contributor
$endgroup$
add a comment |
$begingroup$
I have been trying to integrate and compute moments of LogMultinormalDistribution
in Mathematica, but the integrals don't seem to evaluate. Say for the first moment, $langle x rangle $
Integrate[
PDF[LogMultinormalDistribution[
Subscript[μ, 1], Subscript[μ, 2],
Subscript[σ, 1]^2, Subscript[σ, 1] Subscript[σ, 2] ρ,
Subscript[σ, 1] Subscript[σ, 2] ρ, Subscript[σ, 2]^2
]
, x, y
]*x
, x, 0, Infinity
, y, 0, Infinity
]
I also tried typing out the PDF,
Integrate[(2*Pi*σx*σy Sqrt[1 - ρ^2])^-1*
Exp[-1/2*(1/(
1 - ρ^2)) (((Log[x] - μx)/σx)^2 -
2*ρ*((Log[x] - μx)/σx)*((
Log[y] - μy)/σy) + ((
Log[y] - μy)/σy)^2)]*x, x, 0, Infinity, y, 0, Infinity]
But no luck.
The integrals don't seem to evaluate and either I end up aborting them or the program seems to crash.
In general, I would like compute $langle x^n y^m rangle$ for bivariate log normal distribution in mathematica.
Is there a way to speed up the integrals/evaluate them at all.
I am running Mathematica 11.3 on Mac OS Mojave if that helps.
calculus-and-analysis
New contributor
$endgroup$
$begingroup$
This may not be the problem, but in general you should avoid usingSubscript
while defining symbols (variables).Subscript[x, 1]
is not a symbol, but a composite expression whereSubscript
is an operator without built-in meaning. You expect to do $x_1=2$ but you are actually doingSet[Subscript[x, 1], 2]
which is to assign aDownValues
to the operatorSubscript
and not anOwnValues
to an indexedx
as you may intend. Read how to properly define indexed variables here
$endgroup$
– rhermans
9 hours ago
$begingroup$
BTW, 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
9 hours ago
$begingroup$
Thanks for the link to defining indexed variables. I will keep that in mind. removing the subscripts however, doesn't help either to be honest.
$endgroup$
– jcp
9 hours ago
1
$begingroup$
There is nothing wrong with using subscript notation with integration in Mma, provided you don't mix using $x$ and subscript $x$ (say $x_1$) in the same expression.
$endgroup$
– wolfies
8 hours ago
$begingroup$
@wolfies, I know you think that, you made your point in the Q&A I link, but many people disagree with that, including me. For a new user I think my advice is beneficial, there is nothing to gain and much to loose by usingSubscript
for anything other than display.
$endgroup$
– rhermans
8 hours ago
add a comment |
$begingroup$
I have been trying to integrate and compute moments of LogMultinormalDistribution
in Mathematica, but the integrals don't seem to evaluate. Say for the first moment, $langle x rangle $
Integrate[
PDF[LogMultinormalDistribution[
Subscript[μ, 1], Subscript[μ, 2],
Subscript[σ, 1]^2, Subscript[σ, 1] Subscript[σ, 2] ρ,
Subscript[σ, 1] Subscript[σ, 2] ρ, Subscript[σ, 2]^2
]
, x, y
]*x
, x, 0, Infinity
, y, 0, Infinity
]
I also tried typing out the PDF,
Integrate[(2*Pi*σx*σy Sqrt[1 - ρ^2])^-1*
Exp[-1/2*(1/(
1 - ρ^2)) (((Log[x] - μx)/σx)^2 -
2*ρ*((Log[x] - μx)/σx)*((
Log[y] - μy)/σy) + ((
Log[y] - μy)/σy)^2)]*x, x, 0, Infinity, y, 0, Infinity]
But no luck.
The integrals don't seem to evaluate and either I end up aborting them or the program seems to crash.
In general, I would like compute $langle x^n y^m rangle$ for bivariate log normal distribution in mathematica.
Is there a way to speed up the integrals/evaluate them at all.
I am running Mathematica 11.3 on Mac OS Mojave if that helps.
calculus-and-analysis
New contributor
$endgroup$
I have been trying to integrate and compute moments of LogMultinormalDistribution
in Mathematica, but the integrals don't seem to evaluate. Say for the first moment, $langle x rangle $
Integrate[
PDF[LogMultinormalDistribution[
Subscript[μ, 1], Subscript[μ, 2],
Subscript[σ, 1]^2, Subscript[σ, 1] Subscript[σ, 2] ρ,
Subscript[σ, 1] Subscript[σ, 2] ρ, Subscript[σ, 2]^2
]
, x, y
]*x
, x, 0, Infinity
, y, 0, Infinity
]
I also tried typing out the PDF,
Integrate[(2*Pi*σx*σy Sqrt[1 - ρ^2])^-1*
Exp[-1/2*(1/(
1 - ρ^2)) (((Log[x] - μx)/σx)^2 -
2*ρ*((Log[x] - μx)/σx)*((
Log[y] - μy)/σy) + ((
Log[y] - μy)/σy)^2)]*x, x, 0, Infinity, y, 0, Infinity]
But no luck.
The integrals don't seem to evaluate and either I end up aborting them or the program seems to crash.
In general, I would like compute $langle x^n y^m rangle$ for bivariate log normal distribution in mathematica.
Is there a way to speed up the integrals/evaluate them at all.
I am running Mathematica 11.3 on Mac OS Mojave if that helps.
calculus-and-analysis
calculus-and-analysis
New contributor
New contributor
edited 8 hours ago
rhermans
23.3k4 gold badges42 silver badges107 bronze badges
23.3k4 gold badges42 silver badges107 bronze badges
New contributor
asked 9 hours ago
jcpjcp
111 bronze badge
111 bronze badge
New contributor
New contributor
$begingroup$
This may not be the problem, but in general you should avoid usingSubscript
while defining symbols (variables).Subscript[x, 1]
is not a symbol, but a composite expression whereSubscript
is an operator without built-in meaning. You expect to do $x_1=2$ but you are actually doingSet[Subscript[x, 1], 2]
which is to assign aDownValues
to the operatorSubscript
and not anOwnValues
to an indexedx
as you may intend. Read how to properly define indexed variables here
$endgroup$
– rhermans
9 hours ago
$begingroup$
BTW, 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
9 hours ago
$begingroup$
Thanks for the link to defining indexed variables. I will keep that in mind. removing the subscripts however, doesn't help either to be honest.
$endgroup$
– jcp
9 hours ago
1
$begingroup$
There is nothing wrong with using subscript notation with integration in Mma, provided you don't mix using $x$ and subscript $x$ (say $x_1$) in the same expression.
$endgroup$
– wolfies
8 hours ago
$begingroup$
@wolfies, I know you think that, you made your point in the Q&A I link, but many people disagree with that, including me. For a new user I think my advice is beneficial, there is nothing to gain and much to loose by usingSubscript
for anything other than display.
$endgroup$
– rhermans
8 hours ago
add a comment |
$begingroup$
This may not be the problem, but in general you should avoid usingSubscript
while defining symbols (variables).Subscript[x, 1]
is not a symbol, but a composite expression whereSubscript
is an operator without built-in meaning. You expect to do $x_1=2$ but you are actually doingSet[Subscript[x, 1], 2]
which is to assign aDownValues
to the operatorSubscript
and not anOwnValues
to an indexedx
as you may intend. Read how to properly define indexed variables here
$endgroup$
– rhermans
9 hours ago
$begingroup$
BTW, 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
9 hours ago
$begingroup$
Thanks for the link to defining indexed variables. I will keep that in mind. removing the subscripts however, doesn't help either to be honest.
$endgroup$
– jcp
9 hours ago
1
$begingroup$
There is nothing wrong with using subscript notation with integration in Mma, provided you don't mix using $x$ and subscript $x$ (say $x_1$) in the same expression.
$endgroup$
– wolfies
8 hours ago
$begingroup$
@wolfies, I know you think that, you made your point in the Q&A I link, but many people disagree with that, including me. For a new user I think my advice is beneficial, there is nothing to gain and much to loose by usingSubscript
for anything other than display.
$endgroup$
– rhermans
8 hours ago
$begingroup$
This may not be the problem, but in general you should avoid using
Subscript
while defining symbols (variables). 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
9 hours ago
$begingroup$
This may not be the problem, but in general you should avoid using
Subscript
while defining symbols (variables). 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
9 hours ago
$begingroup$
BTW, 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
9 hours ago
$begingroup$
BTW, 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
9 hours ago
$begingroup$
Thanks for the link to defining indexed variables. I will keep that in mind. removing the subscripts however, doesn't help either to be honest.
$endgroup$
– jcp
9 hours ago
$begingroup$
Thanks for the link to defining indexed variables. I will keep that in mind. removing the subscripts however, doesn't help either to be honest.
$endgroup$
– jcp
9 hours ago
1
1
$begingroup$
There is nothing wrong with using subscript notation with integration in Mma, provided you don't mix using $x$ and subscript $x$ (say $x_1$) in the same expression.
$endgroup$
– wolfies
8 hours ago
$begingroup$
There is nothing wrong with using subscript notation with integration in Mma, provided you don't mix using $x$ and subscript $x$ (say $x_1$) in the same expression.
$endgroup$
– wolfies
8 hours ago
$begingroup$
@wolfies, I know you think that, you made your point in the Q&A I link, but many people disagree with that, including me. For a new user I think my advice is beneficial, there is nothing to gain and much to loose by using
Subscript
for anything other than display.$endgroup$
– rhermans
8 hours ago
$begingroup$
@wolfies, I know you think that, you made your point in the Q&A I link, but many people disagree with that, including me. For a new user I think my advice is beneficial, there is nothing to gain and much to loose by using
Subscript
for anything other than display.$endgroup$
– rhermans
8 hours ago
add a comment |
3 Answers
3
active
oldest
votes
$begingroup$
Life is easier when one can go straight to the answer without going through the integration.
Given a mean vector and covariance matrix
μ = μ1, μ2;
Σ = σ1^2, σ1 σ2 ρ, σ1 σ2 ρ, σ2^2;
the moment generating function for a bivariate normal is
mgf[t1_, t2_] := Exp[t1, t2.μ + t1, t2.Σ.t1, t2/2]
Because the definition of the moment generating function is $E[e^t_1 X_1+t_2 X_2]=E[Y_1^t_1 Y_2^t_2]$, then mgf[t1_, t2_]
is the function that gives the expectation of $Y_1^t_1 Y_2^t_2$.
mgf[m, n]
(* E^(m μ1 + n μ2 + 1/2 (m (m σ1^2 + n ρ σ1 σ2) + n (m ρ σ1 σ2 + n σ2^2))) *)
You can see that this easily generalizes to more than two dimensions. Here is a reference with the steps of integration: The Lognormal Random Multivariate
$endgroup$
$begingroup$
There can be no better answer than this.
$endgroup$
– wolfies
7 hours ago
$begingroup$
@wolfies. I agree. But I wish I would have immediately thought of it. Good thing Google is around.
$endgroup$
– JimB
6 hours ago
$begingroup$
Ah this makes a lot of sense. Can't believe I did not think of doing this earlier.
$endgroup$
– jcp
5 hours ago
add a comment |
$begingroup$
For Mathematica the integral can be very complicated if all general cases are considered for each parameter. One option to speed and simplify things is to analyze more specific cases using Assuming
.
You would need to decide if these assumptions are valid, and define your own if not, but these seem quite reasonable to me.
pdf = Assuming[
And[x > 0, y > 0, ρ^2 < 1, σ1, σ2, μ1, μ2 ∈ Reals, σ2 > 0],
Simplify@PDF[
LogMultinormalDistribution[
μ1, μ2,
σ1^2, ρ σ1 σ2,
ρ σ1 σ2, σ2^2
]
, x, y]
]
Notice I have avoided the use of Subscript
and used Simplify
and indentation to make the code more readable.
Assuming[
And[x > 0, y > 0, ρ^2 < 1, σ1, σ2, μ1, μ2 ∈ Reals, σ2 > 0],
Integrate[
pdf
, x, 0, Infinity
, y, 0, Infinity
]
]
(* 1 *)
So the integral is $1$, as expected for a PDF
.
Assuming[
And[x > 0, y > 0, ρ^2 < 1, σ1, σ2, μ1, μ2 ∈ Reals, σ2 > 0],
Integrate[
pdf x
, x, 0, Infinity
, y, 0, Infinity
]
]
E^(μ1 + σ1^2/2)
Using AbsoluteTiming
the solution took 123 seconds in my computer (Mathematica 12 i7-4770 3.4GHz)
$endgroup$
$begingroup$
Hi. thanks this definitely helps. Running absolute timing on my computer however yields 165.78 and 203.667 s for the first and second computation respectively. Is there anyway to speed this up further? I need to repeat this computation several times.
$endgroup$
– jcp
8 hours ago
$begingroup$
@jcp see the answer by JimB
$endgroup$
– rhermans
8 hours ago
add a comment |
$begingroup$
Format[μ[n_]] := Subscript[μ, n];
Format[σ[n_]] := Subscript[σ, n]
dist = LogMultinormalDistribution[μ[1], μ[2],
σ[1]^2, ρ σ[1] σ[2], ρ σ[1] σ[2], σ[2]^2];
The Moment
s are built-in for this distribution
Moment[dist, m, n]
$endgroup$
$begingroup$
I guess there is a better answer.
$endgroup$
– JimB
31 mins ago
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
jcp is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f202395%2fsymbolic-integration-of-logmultinormal-distribution%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Life is easier when one can go straight to the answer without going through the integration.
Given a mean vector and covariance matrix
μ = μ1, μ2;
Σ = σ1^2, σ1 σ2 ρ, σ1 σ2 ρ, σ2^2;
the moment generating function for a bivariate normal is
mgf[t1_, t2_] := Exp[t1, t2.μ + t1, t2.Σ.t1, t2/2]
Because the definition of the moment generating function is $E[e^t_1 X_1+t_2 X_2]=E[Y_1^t_1 Y_2^t_2]$, then mgf[t1_, t2_]
is the function that gives the expectation of $Y_1^t_1 Y_2^t_2$.
mgf[m, n]
(* E^(m μ1 + n μ2 + 1/2 (m (m σ1^2 + n ρ σ1 σ2) + n (m ρ σ1 σ2 + n σ2^2))) *)
You can see that this easily generalizes to more than two dimensions. Here is a reference with the steps of integration: The Lognormal Random Multivariate
$endgroup$
$begingroup$
There can be no better answer than this.
$endgroup$
– wolfies
7 hours ago
$begingroup$
@wolfies. I agree. But I wish I would have immediately thought of it. Good thing Google is around.
$endgroup$
– JimB
6 hours ago
$begingroup$
Ah this makes a lot of sense. Can't believe I did not think of doing this earlier.
$endgroup$
– jcp
5 hours ago
add a comment |
$begingroup$
Life is easier when one can go straight to the answer without going through the integration.
Given a mean vector and covariance matrix
μ = μ1, μ2;
Σ = σ1^2, σ1 σ2 ρ, σ1 σ2 ρ, σ2^2;
the moment generating function for a bivariate normal is
mgf[t1_, t2_] := Exp[t1, t2.μ + t1, t2.Σ.t1, t2/2]
Because the definition of the moment generating function is $E[e^t_1 X_1+t_2 X_2]=E[Y_1^t_1 Y_2^t_2]$, then mgf[t1_, t2_]
is the function that gives the expectation of $Y_1^t_1 Y_2^t_2$.
mgf[m, n]
(* E^(m μ1 + n μ2 + 1/2 (m (m σ1^2 + n ρ σ1 σ2) + n (m ρ σ1 σ2 + n σ2^2))) *)
You can see that this easily generalizes to more than two dimensions. Here is a reference with the steps of integration: The Lognormal Random Multivariate
$endgroup$
$begingroup$
There can be no better answer than this.
$endgroup$
– wolfies
7 hours ago
$begingroup$
@wolfies. I agree. But I wish I would have immediately thought of it. Good thing Google is around.
$endgroup$
– JimB
6 hours ago
$begingroup$
Ah this makes a lot of sense. Can't believe I did not think of doing this earlier.
$endgroup$
– jcp
5 hours ago
add a comment |
$begingroup$
Life is easier when one can go straight to the answer without going through the integration.
Given a mean vector and covariance matrix
μ = μ1, μ2;
Σ = σ1^2, σ1 σ2 ρ, σ1 σ2 ρ, σ2^2;
the moment generating function for a bivariate normal is
mgf[t1_, t2_] := Exp[t1, t2.μ + t1, t2.Σ.t1, t2/2]
Because the definition of the moment generating function is $E[e^t_1 X_1+t_2 X_2]=E[Y_1^t_1 Y_2^t_2]$, then mgf[t1_, t2_]
is the function that gives the expectation of $Y_1^t_1 Y_2^t_2$.
mgf[m, n]
(* E^(m μ1 + n μ2 + 1/2 (m (m σ1^2 + n ρ σ1 σ2) + n (m ρ σ1 σ2 + n σ2^2))) *)
You can see that this easily generalizes to more than two dimensions. Here is a reference with the steps of integration: The Lognormal Random Multivariate
$endgroup$
Life is easier when one can go straight to the answer without going through the integration.
Given a mean vector and covariance matrix
μ = μ1, μ2;
Σ = σ1^2, σ1 σ2 ρ, σ1 σ2 ρ, σ2^2;
the moment generating function for a bivariate normal is
mgf[t1_, t2_] := Exp[t1, t2.μ + t1, t2.Σ.t1, t2/2]
Because the definition of the moment generating function is $E[e^t_1 X_1+t_2 X_2]=E[Y_1^t_1 Y_2^t_2]$, then mgf[t1_, t2_]
is the function that gives the expectation of $Y_1^t_1 Y_2^t_2$.
mgf[m, n]
(* E^(m μ1 + n μ2 + 1/2 (m (m σ1^2 + n ρ σ1 σ2) + n (m ρ σ1 σ2 + n σ2^2))) *)
You can see that this easily generalizes to more than two dimensions. Here is a reference with the steps of integration: The Lognormal Random Multivariate
answered 8 hours ago
JimBJimB
19.9k1 gold badge28 silver badges65 bronze badges
19.9k1 gold badge28 silver badges65 bronze badges
$begingroup$
There can be no better answer than this.
$endgroup$
– wolfies
7 hours ago
$begingroup$
@wolfies. I agree. But I wish I would have immediately thought of it. Good thing Google is around.
$endgroup$
– JimB
6 hours ago
$begingroup$
Ah this makes a lot of sense. Can't believe I did not think of doing this earlier.
$endgroup$
– jcp
5 hours ago
add a comment |
$begingroup$
There can be no better answer than this.
$endgroup$
– wolfies
7 hours ago
$begingroup$
@wolfies. I agree. But I wish I would have immediately thought of it. Good thing Google is around.
$endgroup$
– JimB
6 hours ago
$begingroup$
Ah this makes a lot of sense. Can't believe I did not think of doing this earlier.
$endgroup$
– jcp
5 hours ago
$begingroup$
There can be no better answer than this.
$endgroup$
– wolfies
7 hours ago
$begingroup$
There can be no better answer than this.
$endgroup$
– wolfies
7 hours ago
$begingroup$
@wolfies. I agree. But I wish I would have immediately thought of it. Good thing Google is around.
$endgroup$
– JimB
6 hours ago
$begingroup$
@wolfies. I agree. But I wish I would have immediately thought of it. Good thing Google is around.
$endgroup$
– JimB
6 hours ago
$begingroup$
Ah this makes a lot of sense. Can't believe I did not think of doing this earlier.
$endgroup$
– jcp
5 hours ago
$begingroup$
Ah this makes a lot of sense. Can't believe I did not think of doing this earlier.
$endgroup$
– jcp
5 hours ago
add a comment |
$begingroup$
For Mathematica the integral can be very complicated if all general cases are considered for each parameter. One option to speed and simplify things is to analyze more specific cases using Assuming
.
You would need to decide if these assumptions are valid, and define your own if not, but these seem quite reasonable to me.
pdf = Assuming[
And[x > 0, y > 0, ρ^2 < 1, σ1, σ2, μ1, μ2 ∈ Reals, σ2 > 0],
Simplify@PDF[
LogMultinormalDistribution[
μ1, μ2,
σ1^2, ρ σ1 σ2,
ρ σ1 σ2, σ2^2
]
, x, y]
]
Notice I have avoided the use of Subscript
and used Simplify
and indentation to make the code more readable.
Assuming[
And[x > 0, y > 0, ρ^2 < 1, σ1, σ2, μ1, μ2 ∈ Reals, σ2 > 0],
Integrate[
pdf
, x, 0, Infinity
, y, 0, Infinity
]
]
(* 1 *)
So the integral is $1$, as expected for a PDF
.
Assuming[
And[x > 0, y > 0, ρ^2 < 1, σ1, σ2, μ1, μ2 ∈ Reals, σ2 > 0],
Integrate[
pdf x
, x, 0, Infinity
, y, 0, Infinity
]
]
E^(μ1 + σ1^2/2)
Using AbsoluteTiming
the solution took 123 seconds in my computer (Mathematica 12 i7-4770 3.4GHz)
$endgroup$
$begingroup$
Hi. thanks this definitely helps. Running absolute timing on my computer however yields 165.78 and 203.667 s for the first and second computation respectively. Is there anyway to speed this up further? I need to repeat this computation several times.
$endgroup$
– jcp
8 hours ago
$begingroup$
@jcp see the answer by JimB
$endgroup$
– rhermans
8 hours ago
add a comment |
$begingroup$
For Mathematica the integral can be very complicated if all general cases are considered for each parameter. One option to speed and simplify things is to analyze more specific cases using Assuming
.
You would need to decide if these assumptions are valid, and define your own if not, but these seem quite reasonable to me.
pdf = Assuming[
And[x > 0, y > 0, ρ^2 < 1, σ1, σ2, μ1, μ2 ∈ Reals, σ2 > 0],
Simplify@PDF[
LogMultinormalDistribution[
μ1, μ2,
σ1^2, ρ σ1 σ2,
ρ σ1 σ2, σ2^2
]
, x, y]
]
Notice I have avoided the use of Subscript
and used Simplify
and indentation to make the code more readable.
Assuming[
And[x > 0, y > 0, ρ^2 < 1, σ1, σ2, μ1, μ2 ∈ Reals, σ2 > 0],
Integrate[
pdf
, x, 0, Infinity
, y, 0, Infinity
]
]
(* 1 *)
So the integral is $1$, as expected for a PDF
.
Assuming[
And[x > 0, y > 0, ρ^2 < 1, σ1, σ2, μ1, μ2 ∈ Reals, σ2 > 0],
Integrate[
pdf x
, x, 0, Infinity
, y, 0, Infinity
]
]
E^(μ1 + σ1^2/2)
Using AbsoluteTiming
the solution took 123 seconds in my computer (Mathematica 12 i7-4770 3.4GHz)
$endgroup$
$begingroup$
Hi. thanks this definitely helps. Running absolute timing on my computer however yields 165.78 and 203.667 s for the first and second computation respectively. Is there anyway to speed this up further? I need to repeat this computation several times.
$endgroup$
– jcp
8 hours ago
$begingroup$
@jcp see the answer by JimB
$endgroup$
– rhermans
8 hours ago
add a comment |
$begingroup$
For Mathematica the integral can be very complicated if all general cases are considered for each parameter. One option to speed and simplify things is to analyze more specific cases using Assuming
.
You would need to decide if these assumptions are valid, and define your own if not, but these seem quite reasonable to me.
pdf = Assuming[
And[x > 0, y > 0, ρ^2 < 1, σ1, σ2, μ1, μ2 ∈ Reals, σ2 > 0],
Simplify@PDF[
LogMultinormalDistribution[
μ1, μ2,
σ1^2, ρ σ1 σ2,
ρ σ1 σ2, σ2^2
]
, x, y]
]
Notice I have avoided the use of Subscript
and used Simplify
and indentation to make the code more readable.
Assuming[
And[x > 0, y > 0, ρ^2 < 1, σ1, σ2, μ1, μ2 ∈ Reals, σ2 > 0],
Integrate[
pdf
, x, 0, Infinity
, y, 0, Infinity
]
]
(* 1 *)
So the integral is $1$, as expected for a PDF
.
Assuming[
And[x > 0, y > 0, ρ^2 < 1, σ1, σ2, μ1, μ2 ∈ Reals, σ2 > 0],
Integrate[
pdf x
, x, 0, Infinity
, y, 0, Infinity
]
]
E^(μ1 + σ1^2/2)
Using AbsoluteTiming
the solution took 123 seconds in my computer (Mathematica 12 i7-4770 3.4GHz)
$endgroup$
For Mathematica the integral can be very complicated if all general cases are considered for each parameter. One option to speed and simplify things is to analyze more specific cases using Assuming
.
You would need to decide if these assumptions are valid, and define your own if not, but these seem quite reasonable to me.
pdf = Assuming[
And[x > 0, y > 0, ρ^2 < 1, σ1, σ2, μ1, μ2 ∈ Reals, σ2 > 0],
Simplify@PDF[
LogMultinormalDistribution[
μ1, μ2,
σ1^2, ρ σ1 σ2,
ρ σ1 σ2, σ2^2
]
, x, y]
]
Notice I have avoided the use of Subscript
and used Simplify
and indentation to make the code more readable.
Assuming[
And[x > 0, y > 0, ρ^2 < 1, σ1, σ2, μ1, μ2 ∈ Reals, σ2 > 0],
Integrate[
pdf
, x, 0, Infinity
, y, 0, Infinity
]
]
(* 1 *)
So the integral is $1$, as expected for a PDF
.
Assuming[
And[x > 0, y > 0, ρ^2 < 1, σ1, σ2, μ1, μ2 ∈ Reals, σ2 > 0],
Integrate[
pdf x
, x, 0, Infinity
, y, 0, Infinity
]
]
E^(μ1 + σ1^2/2)
Using AbsoluteTiming
the solution took 123 seconds in my computer (Mathematica 12 i7-4770 3.4GHz)
edited 8 hours ago
answered 8 hours ago
rhermansrhermans
23.3k4 gold badges42 silver badges107 bronze badges
23.3k4 gold badges42 silver badges107 bronze badges
$begingroup$
Hi. thanks this definitely helps. Running absolute timing on my computer however yields 165.78 and 203.667 s for the first and second computation respectively. Is there anyway to speed this up further? I need to repeat this computation several times.
$endgroup$
– jcp
8 hours ago
$begingroup$
@jcp see the answer by JimB
$endgroup$
– rhermans
8 hours ago
add a comment |
$begingroup$
Hi. thanks this definitely helps. Running absolute timing on my computer however yields 165.78 and 203.667 s for the first and second computation respectively. Is there anyway to speed this up further? I need to repeat this computation several times.
$endgroup$
– jcp
8 hours ago
$begingroup$
@jcp see the answer by JimB
$endgroup$
– rhermans
8 hours ago
$begingroup$
Hi. thanks this definitely helps. Running absolute timing on my computer however yields 165.78 and 203.667 s for the first and second computation respectively. Is there anyway to speed this up further? I need to repeat this computation several times.
$endgroup$
– jcp
8 hours ago
$begingroup$
Hi. thanks this definitely helps. Running absolute timing on my computer however yields 165.78 and 203.667 s for the first and second computation respectively. Is there anyway to speed this up further? I need to repeat this computation several times.
$endgroup$
– jcp
8 hours ago
$begingroup$
@jcp see the answer by JimB
$endgroup$
– rhermans
8 hours ago
$begingroup$
@jcp see the answer by JimB
$endgroup$
– rhermans
8 hours ago
add a comment |
$begingroup$
Format[μ[n_]] := Subscript[μ, n];
Format[σ[n_]] := Subscript[σ, n]
dist = LogMultinormalDistribution[μ[1], μ[2],
σ[1]^2, ρ σ[1] σ[2], ρ σ[1] σ[2], σ[2]^2];
The Moment
s are built-in for this distribution
Moment[dist, m, n]
$endgroup$
$begingroup$
I guess there is a better answer.
$endgroup$
– JimB
31 mins ago
add a comment |
$begingroup$
Format[μ[n_]] := Subscript[μ, n];
Format[σ[n_]] := Subscript[σ, n]
dist = LogMultinormalDistribution[μ[1], μ[2],
σ[1]^2, ρ σ[1] σ[2], ρ σ[1] σ[2], σ[2]^2];
The Moment
s are built-in for this distribution
Moment[dist, m, n]
$endgroup$
$begingroup$
I guess there is a better answer.
$endgroup$
– JimB
31 mins ago
add a comment |
$begingroup$
Format[μ[n_]] := Subscript[μ, n];
Format[σ[n_]] := Subscript[σ, n]
dist = LogMultinormalDistribution[μ[1], μ[2],
σ[1]^2, ρ σ[1] σ[2], ρ σ[1] σ[2], σ[2]^2];
The Moment
s are built-in for this distribution
Moment[dist, m, n]
$endgroup$
Format[μ[n_]] := Subscript[μ, n];
Format[σ[n_]] := Subscript[σ, n]
dist = LogMultinormalDistribution[μ[1], μ[2],
σ[1]^2, ρ σ[1] σ[2], ρ σ[1] σ[2], σ[2]^2];
The Moment
s are built-in for this distribution
Moment[dist, m, n]
answered 1 hour ago
Bob HanlonBob Hanlon
63.7k3 gold badges36 silver badges99 bronze badges
63.7k3 gold badges36 silver badges99 bronze badges
$begingroup$
I guess there is a better answer.
$endgroup$
– JimB
31 mins ago
add a comment |
$begingroup$
I guess there is a better answer.
$endgroup$
– JimB
31 mins ago
$begingroup$
I guess there is a better answer.
$endgroup$
– JimB
31 mins ago
$begingroup$
I guess there is a better answer.
$endgroup$
– JimB
31 mins ago
add a comment |
jcp is a new contributor. Be nice, and check out our Code of Conduct.
jcp is a new contributor. Be nice, and check out our Code of Conduct.
jcp is a new contributor. Be nice, and check out our Code of Conduct.
jcp is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f202395%2fsymbolic-integration-of-logmultinormal-distribution%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
This may not be the problem, but in general you should avoid using
Subscript
while defining symbols (variables).Subscript[x, 1]
is not a symbol, but a composite expression whereSubscript
is an operator without built-in meaning. You expect to do $x_1=2$ but you are actually doingSet[Subscript[x, 1], 2]
which is to assign aDownValues
to the operatorSubscript
and not anOwnValues
to an indexedx
as you may intend. Read how to properly define indexed variables here$endgroup$
– rhermans
9 hours ago
$begingroup$
BTW, 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
9 hours ago
$begingroup$
Thanks for the link to defining indexed variables. I will keep that in mind. removing the subscripts however, doesn't help either to be honest.
$endgroup$
– jcp
9 hours ago
1
$begingroup$
There is nothing wrong with using subscript notation with integration in Mma, provided you don't mix using $x$ and subscript $x$ (say $x_1$) in the same expression.
$endgroup$
– wolfies
8 hours ago
$begingroup$
@wolfies, I know you think that, you made your point in the Q&A I link, but many people disagree with that, including me. For a new user I think my advice is beneficial, there is nothing to gain and much to loose by using
Subscript
for anything other than display.$endgroup$
– rhermans
8 hours ago