How to calculate a conditional PDF in mathematica?Calculate probability functionCalculate expected value of custom pdfCalculate expected value of piece-wise pdfIn Mathematica, how to calculate marginal probability of continuous conditional distributions?calculate variance of conditional sum of NormalsConditional probabilityCalculate mean and variance of conditional sum of GammasHow I can define a discrete probability distribution with parameters?Conditional Random Fields in Mathematica?Distribution of Function of Random Sum of Random Variables
Graduate student with abysmal English writing skills, how to help
How would vampires avoid contracting diseases?
How to tell someone I'd like to become friends without letting them think I'm romantically interested in them?
How to convert a file with several spaces into a tab-delimited file?
How do you glue a text to a point?
Cops: The Hidden OEIS Substring
Why do people keep referring to Leia as Princess Leia, even after the destruction of Alderaan?
How to md5 a list of filepaths contained in a file?
C program to parse source code of another language
How to loop for 3 times in bash script when docker push fails?
Using Newton's shell theorem to accelerate a spaceship
Received a dinner invitation through my employer's email, is it ok to attend?
Storming Area 51
Credit score and financing new car
How many hours would it take to watch all of Doctor Who?
How is angular momentum conserved for the orbiting body if the centripetal force disappears?
What was the definition of "set" that resulted in Russell's Paradox
What's the point of having a RAID 1 configuration over incremental backups to a secondary drive?
How do I set up a beta channel for my Steam game?
Why are they 'nude photos'?
definition of "percentile"
Was I subtly told to resign?
Is a 10th-level Transmutation wizard considered a shapechanger for the purpose of effects such as Moonbeam?
Is there any word for "disobedience to God"?
How to calculate a conditional PDF in mathematica?
Calculate probability functionCalculate expected value of custom pdfCalculate expected value of piece-wise pdfIn Mathematica, how to calculate marginal probability of continuous conditional distributions?calculate variance of conditional sum of NormalsConditional probabilityCalculate mean and variance of conditional sum of GammasHow I can define a discrete probability distribution with parameters?Conditional Random Fields in Mathematica?Distribution of Function of Random Sum of Random Variables
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
What is an elegant way of calculating this result (programmatically) in mathematica?
Let $X$ be a random variable with PDF
$$f_X(x) =
begincases
x/4, & textif $1<xleq3$ \
0, & textotherwise
endcases$$
Let $A$ be the event $Xgeq2$
Find $f_X(x)$
Here is the answer done manually for convenience:
$$f_X(x) =
begincases
fracf_X(x)P(A), & textif $2leq xleq3$ \
0, & textotherwise
endcases$$
$$P(A)=P(Xgeq2)=int_2^3f_X(x) dx=5/8$$
$$implies f_X(x) =
begincases
frac2x5, & textif $2leq xleq3$ \
0, & textotherwise
endcases$$
I am looking for a programmatic solution that utilizes [Conditioned] or something else as high-level.
TransformedDistribution and ProbabilityDistribution look like promising avenues, but I am unable to state my problem in terms of them.
I know I could write out the problem explicitly in low level code. But I am looking for an implicit, declarative implementation. Surely mathematica with all its high level abstraction power can do this?
here is a failed attempt
A = X >= 2;
conditionalDist = TransformedDistribution[X [Conditioned] A, X [Distributed]ProbabilityDistribution[x/4, x, 1, 3] ] ;
PDF[conditionalDist, y]
probability-or-statistics
$endgroup$
add a comment |
$begingroup$
What is an elegant way of calculating this result (programmatically) in mathematica?
Let $X$ be a random variable with PDF
$$f_X(x) =
begincases
x/4, & textif $1<xleq3$ \
0, & textotherwise
endcases$$
Let $A$ be the event $Xgeq2$
Find $f_X(x)$
Here is the answer done manually for convenience:
$$f_X(x) =
begincases
fracf_X(x)P(A), & textif $2leq xleq3$ \
0, & textotherwise
endcases$$
$$P(A)=P(Xgeq2)=int_2^3f_X(x) dx=5/8$$
$$implies f_X(x) =
begincases
frac2x5, & textif $2leq xleq3$ \
0, & textotherwise
endcases$$
I am looking for a programmatic solution that utilizes [Conditioned] or something else as high-level.
TransformedDistribution and ProbabilityDistribution look like promising avenues, but I am unable to state my problem in terms of them.
I know I could write out the problem explicitly in low level code. But I am looking for an implicit, declarative implementation. Surely mathematica with all its high level abstraction power can do this?
here is a failed attempt
A = X >= 2;
conditionalDist = TransformedDistribution[X [Conditioned] A, X [Distributed]ProbabilityDistribution[x/4, x, 1, 3] ] ;
PDF[conditionalDist, y]
probability-or-statistics
$endgroup$
add a comment |
$begingroup$
What is an elegant way of calculating this result (programmatically) in mathematica?
Let $X$ be a random variable with PDF
$$f_X(x) =
begincases
x/4, & textif $1<xleq3$ \
0, & textotherwise
endcases$$
Let $A$ be the event $Xgeq2$
Find $f_X(x)$
Here is the answer done manually for convenience:
$$f_X(x) =
begincases
fracf_X(x)P(A), & textif $2leq xleq3$ \
0, & textotherwise
endcases$$
$$P(A)=P(Xgeq2)=int_2^3f_X(x) dx=5/8$$
$$implies f_X(x) =
begincases
frac2x5, & textif $2leq xleq3$ \
0, & textotherwise
endcases$$
I am looking for a programmatic solution that utilizes [Conditioned] or something else as high-level.
TransformedDistribution and ProbabilityDistribution look like promising avenues, but I am unable to state my problem in terms of them.
I know I could write out the problem explicitly in low level code. But I am looking for an implicit, declarative implementation. Surely mathematica with all its high level abstraction power can do this?
here is a failed attempt
A = X >= 2;
conditionalDist = TransformedDistribution[X [Conditioned] A, X [Distributed]ProbabilityDistribution[x/4, x, 1, 3] ] ;
PDF[conditionalDist, y]
probability-or-statistics
$endgroup$
What is an elegant way of calculating this result (programmatically) in mathematica?
Let $X$ be a random variable with PDF
$$f_X(x) =
begincases
x/4, & textif $1<xleq3$ \
0, & textotherwise
endcases$$
Let $A$ be the event $Xgeq2$
Find $f_X(x)$
Here is the answer done manually for convenience:
$$f_X(x) =
begincases
fracf_X(x)P(A), & textif $2leq xleq3$ \
0, & textotherwise
endcases$$
$$P(A)=P(Xgeq2)=int_2^3f_X(x) dx=5/8$$
$$implies f_X(x) =
begincases
frac2x5, & textif $2leq xleq3$ \
0, & textotherwise
endcases$$
I am looking for a programmatic solution that utilizes [Conditioned] or something else as high-level.
TransformedDistribution and ProbabilityDistribution look like promising avenues, but I am unable to state my problem in terms of them.
I know I could write out the problem explicitly in low level code. But I am looking for an implicit, declarative implementation. Surely mathematica with all its high level abstraction power can do this?
here is a failed attempt
A = X >= 2;
conditionalDist = TransformedDistribution[X [Conditioned] A, X [Distributed]ProbabilityDistribution[x/4, x, 1, 3] ] ;
PDF[conditionalDist, y]
probability-or-statistics
probability-or-statistics
edited Jul 2 at 14:41
Conor Cosnett
asked Jul 2 at 13:29
Conor CosnettConor Cosnett
3,42410 silver badges31 bronze badges
3,42410 silver badges31 bronze badges
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
$begingroup$
You can use combination of ProbabilityDistribution and TruncatedDistribution as follows:
f[x_] := x/4
dist = ProbabilityDistribution[f[x], x, 1, 3];
td = TruncatedDistribution[2, Infinity, dist];
PDF[td, x]
$begincases
frac2 x5 & 2<x<3 \
0 & textTrue
endcases$
Probability[Conditioned[x <= t, x > 2], Distributed[x, dist]] // TeXForm
$begincases
1 & tgeq 3 \
frac15 left(t^2-4right) & 2<t<3
endcases$
$endgroup$
add a comment |
$begingroup$
Here's another method that uses the CDF to directly define the desired distribution and which might be a bit more intuitive/self-evident:
f[x_] := x/4
dist = ProbabilityDistribution[f[x], x, 1, 3];
ProbabilityDistribution[
"CDF",
Probability[x < y [Conditioned] x > 2, x [Distributed] dist]
,
y, -[Infinity], [Infinity]
];
ProbabilityDistribution[Piecewise[(2*[FormalX])/5, 2 < [FormalX] < 3, 0], [FormalX], -Infinity, Infinity]
In other words: we just compute the CDF with Probability and then plonk it into ProbabilityDistribution while telling it that it's a CDF rather than a PDF. This is a useful trick to keep in mind, since the CDF is sometimes easier to work with since it's a proper probability.
$endgroup$
$begingroup$
nice! (I felt that there must be a more direct way out there!)
$endgroup$
– Conor Cosnett
Jul 2 at 14:16
add a comment |
$begingroup$
Sometimes "compact" can be considered elegant:
(x/4)/Integrate[x/4, x, 2, 3]
(* (2 x)/5 *)
If you need it in terms of Mathematica's ProbabilityDistribution:
d = ProbabilityDistribution[(x/4)/Integrate[x/4, x, 2, 3], x, 2, 3]
PDF[d, x]

CDF[d, x]

$endgroup$
add a comment |
$begingroup$
I learned from @kglr that Probability can give you a conditional CDF.
One can take the derivative of this to compute the desired conditional PDF.
A = X >= 2;
conditionalCDF = Probability[X <= y [Conditioned] A, X [Distributed] ProbabilityDistribution[x/4, x, 1, 3]];
D[conditionalCDF, y]
$endgroup$
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
);
);
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%2f201372%2fhow-to-calculate-a-conditional-pdf-in-mathematica%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
You can use combination of ProbabilityDistribution and TruncatedDistribution as follows:
f[x_] := x/4
dist = ProbabilityDistribution[f[x], x, 1, 3];
td = TruncatedDistribution[2, Infinity, dist];
PDF[td, x]
$begincases
frac2 x5 & 2<x<3 \
0 & textTrue
endcases$
Probability[Conditioned[x <= t, x > 2], Distributed[x, dist]] // TeXForm
$begincases
1 & tgeq 3 \
frac15 left(t^2-4right) & 2<t<3
endcases$
$endgroup$
add a comment |
$begingroup$
You can use combination of ProbabilityDistribution and TruncatedDistribution as follows:
f[x_] := x/4
dist = ProbabilityDistribution[f[x], x, 1, 3];
td = TruncatedDistribution[2, Infinity, dist];
PDF[td, x]
$begincases
frac2 x5 & 2<x<3 \
0 & textTrue
endcases$
Probability[Conditioned[x <= t, x > 2], Distributed[x, dist]] // TeXForm
$begincases
1 & tgeq 3 \
frac15 left(t^2-4right) & 2<t<3
endcases$
$endgroup$
add a comment |
$begingroup$
You can use combination of ProbabilityDistribution and TruncatedDistribution as follows:
f[x_] := x/4
dist = ProbabilityDistribution[f[x], x, 1, 3];
td = TruncatedDistribution[2, Infinity, dist];
PDF[td, x]
$begincases
frac2 x5 & 2<x<3 \
0 & textTrue
endcases$
Probability[Conditioned[x <= t, x > 2], Distributed[x, dist]] // TeXForm
$begincases
1 & tgeq 3 \
frac15 left(t^2-4right) & 2<t<3
endcases$
$endgroup$
You can use combination of ProbabilityDistribution and TruncatedDistribution as follows:
f[x_] := x/4
dist = ProbabilityDistribution[f[x], x, 1, 3];
td = TruncatedDistribution[2, Infinity, dist];
PDF[td, x]
$begincases
frac2 x5 & 2<x<3 \
0 & textTrue
endcases$
Probability[Conditioned[x <= t, x > 2], Distributed[x, dist]] // TeXForm
$begincases
1 & tgeq 3 \
frac15 left(t^2-4right) & 2<t<3
endcases$
answered Jul 2 at 13:37
kglrkglr
204k10 gold badges233 silver badges463 bronze badges
204k10 gold badges233 silver badges463 bronze badges
add a comment |
add a comment |
$begingroup$
Here's another method that uses the CDF to directly define the desired distribution and which might be a bit more intuitive/self-evident:
f[x_] := x/4
dist = ProbabilityDistribution[f[x], x, 1, 3];
ProbabilityDistribution[
"CDF",
Probability[x < y [Conditioned] x > 2, x [Distributed] dist]
,
y, -[Infinity], [Infinity]
];
ProbabilityDistribution[Piecewise[(2*[FormalX])/5, 2 < [FormalX] < 3, 0], [FormalX], -Infinity, Infinity]
In other words: we just compute the CDF with Probability and then plonk it into ProbabilityDistribution while telling it that it's a CDF rather than a PDF. This is a useful trick to keep in mind, since the CDF is sometimes easier to work with since it's a proper probability.
$endgroup$
$begingroup$
nice! (I felt that there must be a more direct way out there!)
$endgroup$
– Conor Cosnett
Jul 2 at 14:16
add a comment |
$begingroup$
Here's another method that uses the CDF to directly define the desired distribution and which might be a bit more intuitive/self-evident:
f[x_] := x/4
dist = ProbabilityDistribution[f[x], x, 1, 3];
ProbabilityDistribution[
"CDF",
Probability[x < y [Conditioned] x > 2, x [Distributed] dist]
,
y, -[Infinity], [Infinity]
];
ProbabilityDistribution[Piecewise[(2*[FormalX])/5, 2 < [FormalX] < 3, 0], [FormalX], -Infinity, Infinity]
In other words: we just compute the CDF with Probability and then plonk it into ProbabilityDistribution while telling it that it's a CDF rather than a PDF. This is a useful trick to keep in mind, since the CDF is sometimes easier to work with since it's a proper probability.
$endgroup$
$begingroup$
nice! (I felt that there must be a more direct way out there!)
$endgroup$
– Conor Cosnett
Jul 2 at 14:16
add a comment |
$begingroup$
Here's another method that uses the CDF to directly define the desired distribution and which might be a bit more intuitive/self-evident:
f[x_] := x/4
dist = ProbabilityDistribution[f[x], x, 1, 3];
ProbabilityDistribution[
"CDF",
Probability[x < y [Conditioned] x > 2, x [Distributed] dist]
,
y, -[Infinity], [Infinity]
];
ProbabilityDistribution[Piecewise[(2*[FormalX])/5, 2 < [FormalX] < 3, 0], [FormalX], -Infinity, Infinity]
In other words: we just compute the CDF with Probability and then plonk it into ProbabilityDistribution while telling it that it's a CDF rather than a PDF. This is a useful trick to keep in mind, since the CDF is sometimes easier to work with since it's a proper probability.
$endgroup$
Here's another method that uses the CDF to directly define the desired distribution and which might be a bit more intuitive/self-evident:
f[x_] := x/4
dist = ProbabilityDistribution[f[x], x, 1, 3];
ProbabilityDistribution[
"CDF",
Probability[x < y [Conditioned] x > 2, x [Distributed] dist]
,
y, -[Infinity], [Infinity]
];
ProbabilityDistribution[Piecewise[(2*[FormalX])/5, 2 < [FormalX] < 3, 0], [FormalX], -Infinity, Infinity]
In other words: we just compute the CDF with Probability and then plonk it into ProbabilityDistribution while telling it that it's a CDF rather than a PDF. This is a useful trick to keep in mind, since the CDF is sometimes easier to work with since it's a proper probability.
answered Jul 2 at 14:06
Sjoerd SmitSjoerd Smit
5,4908 silver badges19 bronze badges
5,4908 silver badges19 bronze badges
$begingroup$
nice! (I felt that there must be a more direct way out there!)
$endgroup$
– Conor Cosnett
Jul 2 at 14:16
add a comment |
$begingroup$
nice! (I felt that there must be a more direct way out there!)
$endgroup$
– Conor Cosnett
Jul 2 at 14:16
$begingroup$
nice! (I felt that there must be a more direct way out there!)
$endgroup$
– Conor Cosnett
Jul 2 at 14:16
$begingroup$
nice! (I felt that there must be a more direct way out there!)
$endgroup$
– Conor Cosnett
Jul 2 at 14:16
add a comment |
$begingroup$
Sometimes "compact" can be considered elegant:
(x/4)/Integrate[x/4, x, 2, 3]
(* (2 x)/5 *)
If you need it in terms of Mathematica's ProbabilityDistribution:
d = ProbabilityDistribution[(x/4)/Integrate[x/4, x, 2, 3], x, 2, 3]
PDF[d, x]

CDF[d, x]

$endgroup$
add a comment |
$begingroup$
Sometimes "compact" can be considered elegant:
(x/4)/Integrate[x/4, x, 2, 3]
(* (2 x)/5 *)
If you need it in terms of Mathematica's ProbabilityDistribution:
d = ProbabilityDistribution[(x/4)/Integrate[x/4, x, 2, 3], x, 2, 3]
PDF[d, x]

CDF[d, x]

$endgroup$
add a comment |
$begingroup$
Sometimes "compact" can be considered elegant:
(x/4)/Integrate[x/4, x, 2, 3]
(* (2 x)/5 *)
If you need it in terms of Mathematica's ProbabilityDistribution:
d = ProbabilityDistribution[(x/4)/Integrate[x/4, x, 2, 3], x, 2, 3]
PDF[d, x]

CDF[d, x]

$endgroup$
Sometimes "compact" can be considered elegant:
(x/4)/Integrate[x/4, x, 2, 3]
(* (2 x)/5 *)
If you need it in terms of Mathematica's ProbabilityDistribution:
d = ProbabilityDistribution[(x/4)/Integrate[x/4, x, 2, 3], x, 2, 3]
PDF[d, x]

CDF[d, x]

answered Jul 2 at 15:39
JimBJimB
19.8k1 gold badge28 silver badges65 bronze badges
19.8k1 gold badge28 silver badges65 bronze badges
add a comment |
add a comment |
$begingroup$
I learned from @kglr that Probability can give you a conditional CDF.
One can take the derivative of this to compute the desired conditional PDF.
A = X >= 2;
conditionalCDF = Probability[X <= y [Conditioned] A, X [Distributed] ProbabilityDistribution[x/4, x, 1, 3]];
D[conditionalCDF, y]
$endgroup$
add a comment |
$begingroup$
I learned from @kglr that Probability can give you a conditional CDF.
One can take the derivative of this to compute the desired conditional PDF.
A = X >= 2;
conditionalCDF = Probability[X <= y [Conditioned] A, X [Distributed] ProbabilityDistribution[x/4, x, 1, 3]];
D[conditionalCDF, y]
$endgroup$
add a comment |
$begingroup$
I learned from @kglr that Probability can give you a conditional CDF.
One can take the derivative of this to compute the desired conditional PDF.
A = X >= 2;
conditionalCDF = Probability[X <= y [Conditioned] A, X [Distributed] ProbabilityDistribution[x/4, x, 1, 3]];
D[conditionalCDF, y]
$endgroup$
I learned from @kglr that Probability can give you a conditional CDF.
One can take the derivative of this to compute the desired conditional PDF.
A = X >= 2;
conditionalCDF = Probability[X <= y [Conditioned] A, X [Distributed] ProbabilityDistribution[x/4, x, 1, 3]];
D[conditionalCDF, y]
answered Jul 2 at 13:54
Conor CosnettConor Cosnett
3,42410 silver badges31 bronze badges
3,42410 silver badges31 bronze badges
add a comment |
add a comment |
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%2f201372%2fhow-to-calculate-a-conditional-pdf-in-mathematica%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