forum.alglib.net

ALGLIB forum
It is currently Thu Mar 28, 2024 9:15 pm

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Student's distribution in VBA
PostPosted: Mon May 24, 2010 8:06 pm 
Offline

Joined: Mon May 24, 2010 8:03 pm
Posts: 4
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


Top
 Profile  
 
 Post subject: Re: Student's distribution in VBA
PostPosted: Tue May 25, 2010 7:10 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 903
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?


Top
 Profile  
 
 Post subject: Re: Student's distribution in VBA
PostPosted: Tue May 25, 2010 9:26 am 
Offline

Joined: Mon May 24, 2010 8:03 pm
Posts: 4
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


Top
 Profile  
 
 Post subject: Re: Student's distribution in VBA
PostPosted: Tue May 25, 2010 12:42 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 903
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.


Top
 Profile  
 
 Post subject: Re: Student's distribution in VBA
PostPosted: Tue May 25, 2010 2:01 pm 
Offline

Joined: Mon May 24, 2010 8:03 pm
Posts: 4
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!


Top
 Profile  
 
 Post subject: Re: Student's distribution in VBA
PostPosted: Tue May 25, 2010 2:48 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 903
I'll try to find machine with Excel 2007 to test it.

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


Top
 Profile  
 
 Post subject: Re: Student's distribution in VBA
PostPosted: Tue May 25, 2010 11:36 pm 
Offline

Joined: Sun May 16, 2010 11:42 pm
Posts: 63
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.

_________________
Doug Jenkins
http://newtonexcelbach.wordpress.com/


Top
 Profile  
 
 Post subject: Re: Student's distribution in VBA
PostPosted: Wed May 26, 2010 5:24 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 903
Yes, same as in XL 2003.

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


Top
 Profile  
 
 Post subject: Re: Student's distribution in VBA
PostPosted: Wed May 26, 2010 1:13 pm 
Offline

Joined: Mon May 24, 2010 8:03 pm
Posts: 4
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.


Top
 Profile  
 
 Post subject: Re: Student's distribution in VBA
PostPosted: Wed May 26, 2010 2:57 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 903
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...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 55 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group