Hi, I am finding that I get quite different results when I interchange the following "equivalent" lines for sampling from a beta distribution in my r script. The rbeta line is correct judging by the summary statistics of the simulated values, while the qbeta line consistently leads to a higher mean simulated value. simulation <- rbeta(1, alpha, beta) simulation <- qbeta(runif(1), alpha, beta) Are there any implementation reasons for this? Thanks Mark Pinkerton Risk Management Solutions Peninsular House 30 Monument Street London EC3R 8HB UK www.RMS.com <http://www.rms.com/> Tel: +44 20 7444 7783 Fax: +44 20 7444 7601 This message and any attachments contain information that may be RMS Inc. confidential and/or privileged. If you are not the intended recipient (or authorized to receive for the intended recipient), and have received this message in error, any use, disclosure or distribution is strictly prohibited. If you have received this message in error, please notify the sender immediately by replying to the e-mail and permanently deleting the message from your computer and/or storage system. [[alternative HTML version deleted]]
On 9/14/2006 1:42 PM, Mark Pinkerton wrote:> Hi, > I am finding that I get quite different results when I interchange the > following "equivalent" lines for sampling from a beta distribution in my > r script. The rbeta line is correct judging by the summary statistics of > the simulated values, while the qbeta line consistently leads to a > higher mean simulated value. > > simulation <- rbeta(1, alpha, beta) > simulation <- qbeta(runif(1), alpha, beta) > > Are there any implementation reasons for this?You need to be more specific about the R version, the parameter values you're using, and the size of the differences you're seeing. I just tried > x <- rbeta(100000, 1, 6) > y <- qbeta(runif(100000), 1, 6) > summary(x); summary(y) Min. 1st Qu. Median Mean 3rd Qu. Max. 4.076e-07 4.681e-02 1.085e-01 1.423e-01 2.055e-01 8.773e-01 Min. 1st Qu. Median Mean 3rd Qu. Max. 2.803e-06 4.583e-02 1.078e-01 1.419e-01 2.047e-01 8.861e-01 and I think those results look reasonable (and the qbeta method has a smaller mean, this run). Duncan Murdoch> > Thanks > > Mark Pinkerton > Risk Management Solutions > Peninsular House > 30 Monument Street > London EC3R 8HB > UK > > www.RMS.com <http://www.rms.com/> > Tel: +44 20 7444 7783 > Fax: +44 20 7444 7601 > > > > This message and any attachments contain information that may be RMS Inc. > confidential and/or privileged. If you are not the intended recipient > (or authorized to receive for the intended recipient), and have received > this message in error, any use, disclosure or distribution is strictly > prohibited. If you have received this message in error, please notify > the sender immediately by replying to the e-mail and permanently deleting > the message from your computer and/or storage system. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
On 9/14/2006 5:26 PM, Mark Pinkerton wrote:> Hi Duncan, > I had also validated the logic with a simple test which is why I was surprised by the differences I was seeing from tthe more complex simulation. I am running R on a Windows 2000 - I'll have to check which version at my desk tomorrow but it's pretty up to date, maybe 6 monthes old. Attached is a code snippet from my simulation program which is used to estimate multi-event annual losses for US hurricanes. The event set being sampled from is quite large (~14000) with each event and account combination having a unique beta loss distribution. Simply swapping lines 23 and 24 has the effect on results that I mentioned in the previous email. The simulation is large enough that the MC error in the estimated means are negligible.The code you sent isn't usable, because it's missing your data. Could you please do the following? - verify that the behaviour still happens in the current alpha test version - try to simplify the example code so someone else can run it? It could be that certain values of alpha and beta trigger a bug but the ones I tried were fine. Duncan Murdoch
On 9/15/2006 6:43 AM, Mark Pinkerton wrote:> Hi Duncan, > Thanks for having a look at this. Find attached a zip with all the > relevant files to run the simulation. I am running this on Windows XP, R > version 2.3.1.Does the error still occur in a recent alpha build? It's downloadable from CRAN, in cran.r-project.org/bin/windows/base/rtest.html (though I notice the version there is a week old; I'd better kick the build script). Duncan Murdoch '> > The correct result for the average annual loss, calculated using a > battle tested FFT engine, is 1,609,361 The summary stats from my last > run are below: > >> # Summary stats >> summary(totals.losses1) > Min. 1st Qu. Median Mean 3rd Qu. Max. > 0 0 1142 1620000 698000 132500000 >> mean(totals.losses1) > [1] 1619891 >> sd(totals.losses1)/sqrt(length(totals.losses1)) > [1] 77949.25 >> summary(totals.losses2) > Min. 1st Qu. Median Mean 3rd Qu. Max. > 0 0 2352 2341000 749700 141700000 >> mean(totals.losses2) > [1] 2341237 >> sd(totals.losses2)/sqrt(length(totals.losses2)) > [1] 129695.9 > > Thanks, > Mark > > Mark Pinkerton > Risk Management Solutions > Peninsular House > 30 Monument Street > London EC3R 8HB > UK > > www.RMS.com > Tel: +44 20 7444 7783 > Fax: +44 20 7444 7601 > > -----Original Message----- > From: Duncan Murdoch [mailto:murdoch at stats.uwo.ca] > Sent: 15 September 2006 00:45 > To: Mark Pinkerton > Cc: r-help at stat.math.ethz.ch > Subject: Re: [R] Beta stochastic simulation > > On 9/14/2006 5:26 PM, Mark Pinkerton wrote: >> Hi Duncan, >> I had also validated the logic with a simple test which is why I was > surprised by the differences I was seeing from tthe more complex > simulation. I am running R on a Windows 2000 - I'll have to check which > version at my desk tomorrow but it's pretty up to date, maybe 6 monthes > old. Attached is a code snippet from my simulation program which is > used to estimate multi-event annual losses for US hurricanes. The event > set being sampled from is quite large (~14000) with each event and > account combination having a unique beta loss distribution. Simply > swapping lines 23 and 24 has the effect on results that I mentioned in > the previous email. The simulation is large enough that the MC error in > the estimated means are negligible. > > The code you sent isn't usable, because it's missing your data. Could > you please do the following? > > - verify that the behaviour still happens in the current alpha test > version > > - try to simplify the example code so someone else can run it? It > could be that certain values of alpha and beta trigger a bug but the > ones I tried were fine. > > Duncan Murdoch > > > This message and any attachments contain information that may be RMS Inc. > confidential and/or privileged. If you are not the intended recipient > (or authorized to receive for the intended recipient), and have received > this message in error, any use, disclosure or distribution is strictly > prohibited. If you have received this message in error, please notify > the sender immediately by replying to the e-mail and permanently deleting > the message from your computer and/or storage system.
I have just installed 2.4.0 alpha and the problem persists. Here is the output of the run:> # Summary stats > summary(totals.losses1)Min. 1st Qu. Median Mean 3rd Qu. Max. 0 0 1284 1617000 685100 219200000> mean(totals.losses1)[1] 1617219> sd(totals.losses1)/sqrt(length(totals.losses1))[1] 78863.17> > summary(totals.losses2)Min. 1st Qu. Median Mean 3rd Qu. Max. 0 0 1422 2417000 819200 118200000> mean(totals.losses2)[1] 2417471> sd(totals.losses2)/sqrt(length(totals.losses2))[1] 134866.0 Thanks, Mark Mark Pinkerton Risk Management Solutions Peninsular House 30 Monument Street London EC3R 8HB UK www.RMS.com Tel: +44 20 7444 7783 Fax: +44 20 7444 7601 -----Original Message----- From: Duncan Murdoch [mailto:murdoch at stats.uwo.ca] Sent: 15 September 2006 12:15 To: Mark Pinkerton Cc: r-help at stat.math.ethz.ch Subject: Re: [R] Beta stochastic simulation On 9/15/2006 6:43 AM, Mark Pinkerton wrote:> Hi Duncan, > Thanks for having a look at this. Find attached a zip with all the > relevant files to run the simulation. I am running this on Windows XP,> R version 2.3.1.Does the error still occur in a recent alpha build? It's downloadable from CRAN, in cran.r-project.org/bin/windows/base/rtest.html (though I notice the version there is a week old; I'd better kick the build script). Duncan Murdoch '> > The correct result for the average annual loss, calculated using a > battle tested FFT engine, is 1,609,361 The summary stats from my last > run are below: > >> # Summary stats >> summary(totals.losses1) > Min. 1st Qu. Median Mean 3rd Qu. Max. > 0 0 1142 1620000 698000 132500000 >> mean(totals.losses1) > [1] 1619891 >> sd(totals.losses1)/sqrt(length(totals.losses1)) > [1] 77949.25 >> summary(totals.losses2) > Min. 1st Qu. Median Mean 3rd Qu. Max. > 0 0 2352 2341000 749700 141700000 >> mean(totals.losses2) > [1] 2341237 >> sd(totals.losses2)/sqrt(length(totals.losses2)) > [1] 129695.9 > > Thanks, > Mark > > Mark Pinkerton > Risk Management Solutions > Peninsular House > 30 Monument Street > London EC3R 8HB > UK > > www.RMS.com > Tel: +44 20 7444 7783 > Fax: +44 20 7444 7601 > > -----Original Message----- > From: Duncan Murdoch [mailto:murdoch at stats.uwo.ca] > Sent: 15 September 2006 00:45 > To: Mark Pinkerton > Cc: r-help at stat.math.ethz.ch > Subject: Re: [R] Beta stochastic simulation > > On 9/14/2006 5:26 PM, Mark Pinkerton wrote: >> Hi Duncan, >> I had also validated the logic with a simple test which is why I was > surprised by the differences I was seeing from tthe more complex > simulation. I am running R on a Windows 2000 - I'll have to check > which version at my desk tomorrow but it's pretty up to date, maybe 6 > monthes old. Attached is a code snippet from my simulation program > which is used to estimate multi-event annual losses for US hurricanes.> The event set being sampled from is quite large (~14000) with each > event and account combination having a unique beta loss distribution. > Simply swapping lines 23 and 24 has the effect on results that I > mentioned in the previous email. The simulation is large enough that > the MC error in the estimated means are negligible. > > The code you sent isn't usable, because it's missing your data. Could> you please do the following? > > - verify that the behaviour still happens in the current alpha test > version > > - try to simplify the example code so someone else can run it? It > could be that certain values of alpha and beta trigger a bug but the > ones I tried were fine. > > Duncan Murdoch > > > This message and any attachments contain information that may be RMSInc.> confidential and/or privileged. If you are not the intended recipient> (or authorized to receive for the intended recipient), and have > received this message in error, any use, disclosure or distribution isstrictly> prohibited. If you have received this message in error, pleasenotify> the sender immediately by replying to the e-mail and permanently > deleting the message from your computer and/or storage system.This message and any attachments contain information that may be RMS Inc. confidential and/or privileged. If you are not the intended recipient (or authorized to receive for the intended recipient), and have received this message in error, any use, disclosure or distribution is strictly prohibited. If you have received this message in error, please notify the sender immediately by replying to the e-mail and permanently deleting the message from your computer and/or storage system.
Yes, indeed I do. Is there any way I can dig into these a bit more? I have also just tried using the OO inverse beta from the distr package and this seems to work. Mark Pinkerton Risk Management Solutions Peninsular House 30 Monument Street London EC3R 8HB UK www.RMS.com Tel: +44 20 7444 7783 Fax: +44 20 7444 7601 -----Original Message----- From: Duncan Murdoch [mailto:murdoch at stats.uwo.ca] Sent: 15 September 2006 12:15 To: Mark Pinkerton Cc: r-help at stat.math.ethz.ch Subject: Re: [R] Beta stochastic simulation On 9/15/2006 6:43 AM, Mark Pinkerton wrote:> Hi Duncan, > Thanks for having a look at this. Find attached a zip with all the > relevant files to run the simulation. I am running this on Windows XP,> R version 2.3.1.Does the error still occur in a recent alpha build? It's downloadable from CRAN, in cran.r-project.org/bin/windows/base/rtest.html (though I notice the version there is a week old; I'd better kick the build script). Duncan Murdoch '> > The correct result for the average annual loss, calculated using a > battle tested FFT engine, is 1,609,361 The summary stats from my last > run are below: > >> # Summary stats >> summary(totals.losses1) > Min. 1st Qu. Median Mean 3rd Qu. Max. > 0 0 1142 1620000 698000 132500000 >> mean(totals.losses1) > [1] 1619891 >> sd(totals.losses1)/sqrt(length(totals.losses1)) > [1] 77949.25 >> summary(totals.losses2) > Min. 1st Qu. Median Mean 3rd Qu. Max. > 0 0 2352 2341000 749700 141700000 >> mean(totals.losses2) > [1] 2341237 >> sd(totals.losses2)/sqrt(length(totals.losses2)) > [1] 129695.9 > > Thanks, > Mark > > Mark Pinkerton > Risk Management Solutions > Peninsular House > 30 Monument Street > London EC3R 8HB > UK > > www.RMS.com > Tel: +44 20 7444 7783 > Fax: +44 20 7444 7601 > > -----Original Message----- > From: Duncan Murdoch [mailto:murdoch at stats.uwo.ca] > Sent: 15 September 2006 00:45 > To: Mark Pinkerton > Cc: r-help at stat.math.ethz.ch > Subject: Re: [R] Beta stochastic simulation > > On 9/14/2006 5:26 PM, Mark Pinkerton wrote: >> Hi Duncan, >> I had also validated the logic with a simple test which is why I was > surprised by the differences I was seeing from tthe more complex > simulation. I am running R on a Windows 2000 - I'll have to check > which version at my desk tomorrow but it's pretty up to date, maybe 6 > monthes old. Attached is a code snippet from my simulation program > which is used to estimate multi-event annual losses for US hurricanes.> The event set being sampled from is quite large (~14000) with each > event and account combination having a unique beta loss distribution. > Simply swapping lines 23 and 24 has the effect on results that I > mentioned in the previous email. The simulation is large enough that > the MC error in the estimated means are negligible. > > The code you sent isn't usable, because it's missing your data. Could> you please do the following? > > - verify that the behaviour still happens in the current alpha test > version > > - try to simplify the example code so someone else can run it? It > could be that certain values of alpha and beta trigger a bug but the > ones I tried were fine. > > Duncan Murdoch > > > This message and any attachments contain information that may be RMSInc.> confidential and/or privileged. If you are not the intended recipient> (or authorized to receive for the intended recipient), and have > received this message in error, any use, disclosure or distribution isstrictly> prohibited. If you have received this message in error, pleasenotify> the sender immediately by replying to the e-mail and permanently > deleting the message from your computer and/or storage system.This message and any attachments contain information that may be RMS Inc. confidential and/or privileged. If you are not the intended recipient (or authorized to receive for the intended recipient), and have received this message in error, any use, disclosure or distribution is strictly prohibited. If you have received this message in error, please notify the sender immediately by replying to the e-mail and permanently deleting the message from your computer and/or storage system.