How to use ksone to test with Expondist?


emilpohl
09-16-2009, 08:31 PM
Hello all,

could someone give me an example on how to use ksone() test with Expondist? I`m having problems to give "a user-supplied function of a single variable func...". Do I have to initiate the Expondist first using it's constructor eg. myExpondist Expondist(4.8). If so, how to make the arg2 (Doub func(const Doub)) be the Expondist.cdf() function?

thanks in advance.

davekw7x
09-16-2009, 11:28 PM
...how to use ksone() test with Expondist?...

Well, instead of using an Expondist object, you could just implement the exponential cdf directly by the formula

f(x) = 1 - e^{-\lambda x}

(Lambda might be a global variable to which you assign a value before you call ksone, or its value might be hard-coded in the function, depending on your requirements and/or sense of style.)

But I think it's not unreasonable to want to use Expondist::cdf() for this. After all, that seems to be what it is built for, right? See Footnote.

So...

The second argument of ksone() will be the name of a function that has a Doub argument and returns a Doub value.

Since Expondist::cdf() is a function that takes a Doub argument and returns a Doub value, you might think you could use it as an argument for ksone by doing something like


Expondist expondist(lambda);
VecDoub data(whatever);
Doub d, prob;
//
// code to fill up the data vector
//
.
.
.
ksone(data, expondist.cdf, d, prob);
.
.
.


The reason that this doesn't work is that a non-static class member function has an extra (implicit) parameter that makes its signature incompatible with a "regular" function that has the same explicit parameter and return data type.

One way to get around the problem is to make a wrapper function:


//
// A global variable that is the parameter of the
// desired exponential distribution
//
Doub lambda;

//
// A "regular" function with a Doub argument that returns a Doub value
//
// This is what you need for the second argument of ksone
//
Doub f(Doub x)
{
static Expondist expondist(lambda);
return expondist.cdf(x);
}

.
.
.
int main()
{
lambda = 4.8; // or whatever
Doub d, prob;
VecDoub data(1000);
.
.
.
// code to fill up the data vector
.
.
.
ksone(data, f, d, prob);
cout << "d = " << d <<", prob = " << prob << endl;
.
.
.



Regards,

Dave

"A ship in a harbor is safe, but that is not what a ship is built for."
---Rear Admiral Grace Murray Hopper, 1906--1992