Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Urgent!! Need Help with Union in probability

Subject: Urgent!! Need Help with Union in probability

From: Joni Wahyudi

Date: 12 Feb, 2009 05:19:01

Message: 1 of 9

I have problem about how to make union probability in MATLAB,
P(y1 U y2 U y3 U y4) = ??
I have calculated it, but I thought the result is still wrong. Please help me..
=================================================
K=normrnd(0.3,0.1,200,1);
M1=normrnd(300,45,200,1);
uM2=450+0.8*(45/45).*(M1-300);
sM2=45*sqrt(1-(0.8)^2);
M2=normrnd(uM2,sM2);

g1=4.*M1-1500.*K;
g2=4.*M1+2.*M2-1500.*K-1000;
g3=2.*M1+2.*M2-1000;
g4=2.*M1+4.*M2-1500.*K-1000;
y1=(g1<0);
y2=(g2<0);
y3=(g3<0);
y4=(g4<0);
nf=y1+y2+y3+y4;
nF=sum(nf);
pF=nF/200
======================================
At nf=y1+y2+y3+y4 is P(y1 U y2 U y3 U y4) for 1 sample size.
Please recheck it again..

Subject: Urgent!! Need Help with Union in probability

From: Roger Stafford

Date: 12 Feb, 2009 06:14:02

Message: 2 of 9

"Joni Wahyudi" <joni_hikaru@live.com> wrote in message <gn0bg5$8tb$1@fred.mathworks.com>...
> I have problem about how to make union probability in MATLAB,
> P(y1 U y2 U y3 U y4) = ??
> I have calculated it, but I thought the result is still wrong. Please help me..
> =================================================
> K=normrnd(0.3,0.1,200,1);
> M1=normrnd(300,45,200,1);
> uM2=450+0.8*(45/45).*(M1-300);
> sM2=45*sqrt(1-(0.8)^2);
> M2=normrnd(uM2,sM2);
>
> g1=4.*M1-1500.*K;
> g2=4.*M1+2.*M2-1500.*K-1000;
> g3=2.*M1+2.*M2-1000;
> g4=2.*M1+4.*M2-1500.*K-1000;
> y1=(g1<0);
> y2=(g2<0);
> y3=(g3<0);
> y4=(g4<0);
> nf=y1+y2+y3+y4;
> nF=sum(nf);
> pF=nF/200
> ======================================
> At nf=y1+y2+y3+y4 is P(y1 U y2 U y3 U y4) for 1 sample size.
> Please recheck it again..

  From your earlier question P(y1 U y2 U y3 U y4) = ??, you appear to want the probability that at least one of the four, y1, y2, y3, or y4 is true, but that isn't what your pF gives. It is too large. You could get a number larger than one in the some distributions. You ought to have

 pF = sum(y1 | y2| y3 | y4)/size(K,1);

 Note that this is only a sample estimate of the underlying true probability, based on 200 samples. In general you would need many more than that to arrive at a reliable estimate.

Roger Stafford

Subject: Urgent!! Need Help with Union in probability

From: Occa O'Connor

Date: 12 Feb, 2009 06:42:02

Message: 3 of 9

I'm having trouble following what your doing. Can you explain your steps:

- uM2=450+0.8*(45/45).*(M1-300) - can you give me what formula this is?
- sM2=45*sqrt(1-(0.8)^2) - and this one
- and not sure what the rest is doing.

To answer your question though:
Pr(AUB) = Pr(A) + P(B) - P(A)P(B)
For 4 terms it gets a little bigger:
Pr(AUBUCUD) = Pr(A) + P(B) P(C) + P(D)
                       - P(A)P(B) - P(A)P(C) - P(A)P(D) - P(B)P(C) - P(B)P(D) - P(C)P(D)
                       + P(A)P(B)P(C) + P(A)P(B)P(D) + P(A)P(C)P(D) + P(B)P(C)P(D)
                       - P(A)P(B)P(C)P(D)

So... you can just sub in th means of A, B, C, D in this equation to estimate the resulting mean.
The variance is a little more involved and involves using the rules:
when f = AB, (Sigma_f)^2 = f^2 [ ( sigma_A/A)^2 + ( sigma_B/B)^2 ]
also f = A + B , (Sigma_f)^2 = ( sigma_A/A)^2 + ( sigma_B/B)^2

So you just work out the variance for all the multiplications then add them up and you have the resulting variance..

Hope that helps. I'm not sure of automatic MATLAB functions in this regard.

Cheers

Occa

Subject: Urgent!! Need Help with Union in probability

From: Joni Wahyudi

Date: 12 Feb, 2009 06:43:01

Message: 4 of 9

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gn0ena$omd$1@fred.mathworks.com>...
> "Joni Wahyudi" <joni_hikaru@live.com> wrote in message <gn0bg5$8tb$1@fred.mathworks.com>...
> > I have problem about how to make union probability in MATLAB,
> > P(y1 U y2 U y3 U y4) = ??
> > I have calculated it, but I thought the result is still wrong. Please help me..
> > =================================================
> > K=normrnd(0.3,0.1,200,1);
> > M1=normrnd(300,45,200,1);
> > uM2=450+0.8*(45/45).*(M1-300);
> > sM2=45*sqrt(1-(0.8)^2);
> > M2=normrnd(uM2,sM2);
> >
> > g1=4.*M1-1500.*K;
> > g2=4.*M1+2.*M2-1500.*K-1000;
> > g3=2.*M1+2.*M2-1000;
> > g4=2.*M1+4.*M2-1500.*K-1000;
> > y1=(g1<0);
> > y2=(g2<0);
> > y3=(g3<0);
> > y4=(g4<0);
> > nf=y1+y2+y3+y4;
> > nF=sum(nf);
> > pF=nF/200
> > ======================================
> > At nf=y1+y2+y3+y4 is P(y1 U y2 U y3 U y4) for 1 sample size.
> > Please recheck it again..
>
> From your earlier question P(y1 U y2 U y3 U y4) = ??, you appear to want the probability that at least one of the four, y1, y2, y3, or y4 is true, but that isn't what your pF gives. It is too large. You could get a number larger than one in the some distributions. You ought to have
>
> pF = sum(y1 | y2| y3 | y4)/size(K,1);
>
> Note that this is only a sample estimate of the underlying true probability, based on 200 samples. In general you would need many more than that to arrive at a reliable estimate.
>
> Roger Stafford

Thank you Mr. Stafford for your help, but I still can not get the true answer for the problem, because for 200 sample sizes pF ~ 0.0148 and for 1000 sample sizes pF ~ 0.0151, and for my program the answer of 200 sample sizes is pF = 0.010 and for 1000 sample sizes is pF = 0.0180.
I didn't know why the answer was different.
But thank you..

Subject: Urgent!! Need Help with Union in probability

From: Joni Wahyudi

Date: 12 Feb, 2009 07:46:04

Message: 5 of 9

"Occa O'Connor" <whereisocca@gmail.com> wrote in message <gn0gbq$f92$1@fred.mathworks.com>...
> I'm having trouble following what your doing. Can you explain your steps:
>
> - uM2=450+0.8*(45/45).*(M1-300) - can you give me what formula this is?
> - sM2=45*sqrt(1-(0.8)^2) - and this one
> - and not sure what the rest is doing.
>
uM2 is conditional probability M2 to M1 for mean value, and sM2 is conditional probablilty M2 to M1 for standard deviation.
Occa, Thank you for your help.

Subject: Urgent!! Need Help with Union in probability

From: Occa O'Connor

Date: 12 Feb, 2009 08:02:03

Message: 6 of 9

"Joni Wahyudi" <joni_hikaru@live.com> wrote in message <gn0k3s$q7a$1@fred.mathworks.com>...
> "Occa O'Connor" <whereisocca@gmail.com> wrote in message <gn0gbq$f92$1@fred.mathworks.com>...
> > I'm having trouble following what your doing. Can you explain your steps:
> >
> > - uM2=450+0.8*(45/45).*(M1-300) - can you give me what formula this is?
> > - sM2=45*sqrt(1-(0.8)^2) - and this one
> > - and not sure what the rest is doing.
> >
> uM2 is conditional probability M2 to M1 for mean value, and sM2 is conditional probablilty M2 to M1 for standard deviation.
> Occa, Thank you for your help.

G'Day Joni, if your talking about conditional probabilities then there is a dependance between the events and that formula I gave you gets a whole more complicated.
Probability of A given B = P(A|B)

Now all of those P(A)P(B) should actually read P(A)*P(B|A) to take into account dependance.

I'm still not following the sequence you've used to solve the problem can you write out the problem, define the variables and give the formulas your using.. Sorry I can't give more than that I just can't follow the maths...

Cheers

Occa

Subject: Urgent!! Need Help with Union in probability

From: Roger Stafford

Date: 12 Feb, 2009 08:43:01

Message: 7 of 9

"Joni Wahyudi" <joni_hikaru@live.com> wrote in message <gn0gdl$iuf$1@fred.mathworks.com>...
> Thank you Mr. Stafford for your help, but I still can not get the true answer for the problem, because for 200 sample sizes pF ~ 0.0148 and for 1000 sample sizes pF ~ 0.0151, and for my program the answer of 200 sample sizes is pF = 0.010 and for 1000 sample sizes is pF = 0.0180.
> I didn't know why the answer was different.
> But thank you..

  Based on your query "P(y1 U y2 U y3 U y4) = ??" you appear to be asking for the probability that one or more of the four variables, g1, g2, g3, or g4 is negative. Each of your y quantities is true whenever the corresponding g is negative, so your question becomes, what fraction of these 200 cases has at least one of the y's true.

  You don't get that by simply adding the y's, because that sum can be greater than 1. For example, a case in which all four g's were negative, (which is quite possible,) would count as four occurrences in your sum, not one. You want something that is 1 just when one or more of the y's are true, and 0 when they are all false. That is a job for the matlab '|' or 'OR' operation, not the 'sum' operator. Your program not correct in this respect.

  You speak of "the true answer for the problem", but how do you know the true answer? What you have generated are samples of four random variables, g1, g2, g3, and g4, which are not mutually independent and which in fact are linearly dependent. As you have defined them, they must satisfy the linear identity

 2*g1-3*g2+g3+g4 = 1000

exactly. Finding the true underlying probability for your question would be a difficult task.

Roger Stafford

Subject: Urgent!! Need Help with Union in probability

From: Joni Wahyudi

Date: 12 Feb, 2009 11:26:01

Message: 8 of 9

> Based on your query "P(y1 U y2 U y3 U y4) = ??" you appear to be asking for the probability that one or more of the four variables, g1, g2, g3, or g4 is negative. Each of your y quantities is true whenever the corresponding g is negative, so your question becomes, what fraction of these 200 cases has at least one of the y's true.
>
> You don't get that by simply adding the y's, because that sum can be greater than 1. For example, a case in which all four g's were negative, (which is quite possible,) would count as four occurrences in your sum, not one. You want something that is 1 just when one or more of the y's are true, and 0 when they are all false. That is a job for the matlab '|' or 'OR' operation, not the 'sum' operator. Your program not correct in this respect.
>
> You speak of "the true answer for the problem", but how do you know the true answer? What you have generated are samples of four random variables, g1, g2, g3, and g4, which are not mutually independent and which in fact are linearly dependent. As you have defined them, they must satisfy the linear identity
>
> 2*g1-3*g2+g3+g4 = 1000
>
> exactly. Finding the true underlying probability for your question would be a difficult task.
>
> Roger Stafford

Yeah, i think you are right that I can't do simply adding the y's. About the answer, that answer is the answer of my advisor. Thank you for your help...all of you..

Subject: Urgent!! Need Help with Union in probability

From: Roger Stafford

Date: 13 Feb, 2009 02:45:03

Message: 9 of 9

"Joni Wahyudi" <joni_hikaru@live.com> wrote in message <gn1109$99o$1@fred.mathworks.com>...
> Yeah, i think you are right that I can't do simply adding the y's. About the answer, that answer is the answer of my advisor. Thank you for your help...all of you.

  My advice to you, Joni, is to not always believe implicitly everything your advisor tells you. He or she just might have made a mistake in their own calculations. After all, advisors are only human. It would be easy to err on this problem. But first make very sure your own Monte Carlo samplings are correctly done and involve sufficiently large samples to be reliable.

Roger Stafford

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us