forum.alglib.net
http://forum.alglib.net/

Student's distribution in VBA
http://forum.alglib.net/viewtopic.php?f=2&t=10
Page 1 of 2

Author:  silvester [ Mon May 24, 2010 8:06 pm ]
Post subject:  Student's distribution in VBA

Hi,

I am trying to use the the InvStudentTDistribution subroutine in VBA and it often returns zeros.

Can anyone please tell me what could be the problem and what are be the units that I should import in order for this to work properly?

Thanks

Author:  Sergey.Bochkanov [ Tue May 25, 2010 7:10 am ]
Post subject:  Re: Student's distribution in VBA

If it runs without error messages, then you have all units you need. But may be you specify incorrect parameters. Could you give several (k,p) pairs which lead to zero results?

Author:  silvester [ Tue May 25, 2010 9:26 am ]
Post subject:  Re: Student's distribution in VBA

Hi,

For k(degrees of freedom)= 11.08, it returns zeros for probabilities:
0.1526
0.042948
0.243311
0.791464
0.76342
0.797013
0.773646
0.219469
0.76937
0.038192
0.087257
0.85231
0.072724
0.963605
(and other probabilities levels, no pattern/cyclicity in the zeros)
This is the part of the code where I am using InvStudentDistribution
For i = 1 To nr_rolling
For j = 1 To nr_replic
For k = 2 To 5
y(k, i, j) = Rnd()
If y(k, i, j) = 0 Then
z(k, i, j) = -10
Else
z(k, i, j) = Sqr((Df(i) - 2) / Df(i)) * InvStudentTDistribution(Df(i), y(k, i, j))
End If
Next k
Next j
Next i

(What I am actually need to simulate is a standardized student-t (variance =1), hence the multiplication by Sqr((Df(i) - 2) / Df(i)))
Many thanks,
Silvia

Author:  Sergey.Bochkanov [ Tue May 25, 2010 12:42 pm ]
Post subject:  Re: Student's distribution in VBA

I've tried with Excel 2003 (the only version of Excel I have) - it works. Two things are possible: a) we have subtle bug somewhere in the ALGLIB, b) you have unwanted rounding somewhere in your code.

Can you debug InvStudentTDistribution() sub? I think it is the only way to understand what's going on.

Just "Step Over" its 30 lines of code and tell me:
* sequence of line which were executed
* value returned by InvIncompleteBeta() sub
* value of Result variable (when changed)

You shouldn't step into InvIncompleteBeta() sub because it will take too long to debug. I think that InvStudentTDistribution() will be enough.

Author:  silvester [ Tue May 25, 2010 2:01 pm ]
Post subject:  Re: Student's distribution in VBA

Hi again,

I just tried running the code in EXcel 2003 and it seems to work fine now - I used Excel 2007 before when I used to get the zeros.

Thanks a lot for the very prompt replies!

Author:  Sergey.Bochkanov [ Tue May 25, 2010 2:48 pm ]
Post subject:  Re: Student's distribution in VBA

I'll try to find machine with Excel 2007 to test it.

P.S. I thought it should be backward compatible :(

Author:  Doug Jenkins [ Tue May 25, 2010 11:36 pm ]
Post subject:  Re: Student's distribution in VBA

I entered =InvStudentTDistribution(11,x) in Excel 2007, where x was from the list posted above, and got the following results:

x Result
0.1526 -1.075441211
0.042948 -1.886450812
0.243311 -0.719865522
0.791464 0.843205913
0.76342 0.742813645
0.797013 0.864113965
0.773646 0.778478128
0.219469 -0.803077789
0.76937 0.763442736
0.038192 -1.955609831
0.087257 -1.451656865
0.85231 1.098663902
0.072724 -1.566844603
0.963605 1.983838661


Is that the same as XL 2003?

By the way, K is a long, so 11.08 will give the same results as 11.

Author:  Sergey.Bochkanov [ Wed May 26, 2010 5:24 am ]
Post subject:  Re: Student's distribution in VBA

Yes, same as in XL 2003.

Maybe actual bug (unexpected rounding) is somewhere in the silvester's code?

Author:  silvester [ Wed May 26, 2010 1:13 pm ]
Post subject:  Re: Student's distribution in VBA

I got different results with XLS 2003 and 2007 - I only got the zeros with XLS 2007, while with XLS 2003 InvStudenttDistribution worked perfectly. It has to be something I am doing wrong in XLS 2007, but can't quite figure it now...

thanks a lot, once again.

Author:  Sergey.Bochkanov [ Wed May 26, 2010 2:57 pm ]
Post subject:  Re: Student's distribution in VBA

Can you debug InvStudentTDistribution() as I told in post #4?

Without accessing XL 2007 on your machine I think it is the best way to understand what's going on...

Page 1 of 2 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/