[math/distributions] calculating p-value?

Hi,
Having a test which values are chi^2-distributed, I tried to calculate a
p-value and utterly failed.
My code, so far:
#include

-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Christian Meesters Sent: Friday, April 09, 2010 11:21 AM To: boost-users@lists.boost.org Subject: [Boost-users] [math/distributions] calculating p-value?
Hi,
Having a test which values are chi^2-distributed, I tried to calculate a p-value and utterly failed.
My code, so far:
#include
using boost::math::chi_squared; <snip> chi_squared dist(N - 1); p = cdf(complement(dist, (std::fabs(beta)))) ; Here, N is the sample size and beta my beta-estimate.
Reading Numerical Recipies my approach might be a bit naive, yet is there any short hand using boost? (Or am I making a stupid mistake here?
Nothing obvious jumps out at me. It appears you have seem the example at boost_1_42_0\libs\math\example\chi_square_std_dev_test.cpp and test_chi_squared.cpp has this very similar code BOOST_CHECK_CLOSE( cdf(complement(dist, cs)), Q, tol); and you have also seen the section in math.pdf on non-member properties, like cdf and when to use complements and why. Have you used a try'n'catch block around your call? without this, if things go wrong it will end silently (no error messages!), and unhappily for you ;-) See page 63 of math.pdf for some discussion and examples. HTH Paul --- Paul A. Bristow Prizet Farmhouse Kendal, UK LA8 8AB +44 1539 561830, mobile +44 7714330204 pbristow@hetp.u-net.com

Thanks Paul. Actually I didn't read the testing sources. However, are the links to the math.pdf broken? (Perhaps it's just me, who cannot download this pdf right now. Or I just have a bad day ...) The solution: I did indeed make a most stupid mistake: When you miscalculate N, the distribution you compare against is wrong and in the extreme, you get only zeros back (which happend to me). Arrgh! *headbang* ;-) Thanks, Christian On Fri, 2010-04-09 at 12:14 +0100, Paul A. Bristow wrote:
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Christian Meesters Sent: Friday, April 09, 2010 11:21 AM To: boost-users@lists.boost.org Subject: [Boost-users] [math/distributions] calculating p-value?
Hi,
Having a test which values are chi^2-distributed, I tried to calculate a p-value and utterly failed.
My code, so far:
#include
using boost::math::chi_squared; <snip> chi_squared dist(N - 1); p = cdf(complement(dist, (std::fabs(beta)))) ; Here, N is the sample size and beta my beta-estimate.
Reading Numerical Recipies my approach might be a bit naive, yet is there any short hand using boost? (Or am I making a stupid mistake here?
Nothing obvious jumps out at me.
It appears you have seem the example at
boost_1_42_0\libs\math\example\chi_square_std_dev_test.cpp
and test_chi_squared.cpp has this very similar code
BOOST_CHECK_CLOSE( cdf(complement(dist, cs)), Q, tol);
and you have also seen the section in math.pdf on non-member properties, like cdf and when to use complements and why.
Have you used a try'n'catch block around your call?
without this, if things go wrong it will end silently (no error messages!), and unhappily for you ;-)
See page 63 of math.pdf for some discussion and examples.
HTH
Paul
--- Paul A. Bristow Prizet Farmhouse Kendal, UK LA8 8AB +44 1539 561830, mobile +44 7714330204 pbristow@hetp.u-net.com
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Christian Meesters Sent: Friday, April 09, 2010 3:16 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [math/distributions] calculating p-value?
Actually I didn't read the testing sources. However, are the links to the math.pdf broken? (Perhaps it's just me, who cannot download this pdf right now.
I think you need to download all the Boost pdf's separately from Sourceforge. http://www.boost.org/doc/libs/1_42_0/libs/math/doc/sf_and_dist/html/index.ht... is of course the html version which is identical.
The solution: I did indeed make a most stupid mistake: When you miscalculate N, the distribution you compare against is wrong and in the extreme, you get only zeros back (which happend to me). Arrgh! *headbang* ;-)
With all Boost.Math using try'n'catch is *ALWAYS* a good idea - to get the helpful error messages. Paul

-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Paul A. Bristow Sent: Friday, April 09, 2010 4:10 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [math/distributions] calculating p-value?
With all Boost.Math using try'n'catch is *ALWAYS* a good idea - to get the helpful error messages.
I forgot to mention if you don't like getting an exception and error message when you pass a 'duff' argument value, (It doesn't only happen from simple 'head banging' causes! ;-) John Maddock has carefully provided the policies mechanism to allow you to alter the behaviour of the package. See the section of policies for some examples - it's not as complicated as it looks. Paul PS A PDF build of the documentation for Boost-1.41 (for those libraries that support it) is now available from the usual sourceforge download site: https://sourceforge.net/projects/boost/files/ in the boost-docs/1.41.0 folder. Direct URL's are: https://sourceforge.net/projects/boost/files/boost-docs/1.41.0/boost_pdf_1_4... (23Mb) https://sourceforge.net/projects/boost/files/boost-docs/1.41.0/boost_pdf_1_4... (22.5Mb) https://sourceforge.net/projects/boost/files/boost-docs/1.41.0/boost_pdf_1_4... (22.2Mb) https://sourceforge.net/projects/boost/files/boost-docs/1.41.0/boost_pdf_1_4... (21Mb) Enjoy! --- Paul A. Bristow Prizet Farmhouse Kendal, UK LA8 8AB +44 1539 561830, mobile +44 7714330204 pbristow@hetp.u-net.com

Actually I didn't read the testing sources. However, are the links to the math.pdf broken? (Perhaps it's just me, who cannot download this pdf right now. Or I just have a bad day ...)
The link from the HTML docs takes you to a download from SVN - it's really slow to open in your browser, but I just tried it and it worked for me - you might be better to right click and select "Save File" etc, or else as Paul says, get the full Boost PDF build from sourceforge.
The solution: I did indeed make a most stupid mistake: When you miscalculate N, the distribution you compare against is wrong and in the extreme, you get only zeros back (which happend to me). Arrgh! *headbang* ;-)
Happens to us all ;-) BTW if you're trying to do something that isn't covered by the existing tutorials, get back to us and hopefully one day something extra can get added! Cheers, John.
participants (3)
-
Christian Meesters
-
John Maddock
-
Paul A. Bristow