# forum.alglib.net

ALGLIB forum
 It is currently Fri May 24, 2024 5:09 am

 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.

 Page 1 of 2 [ 11 posts ] Go to page 1, 2  Next
 Print view Previous topic | Next topic
Author Message
 Post subject: Student's distribution in VBAPosted: Mon May 24, 2010 8:06 pm

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

 Post subject: Re: Student's distribution in VBAPosted: Tue May 25, 2010 7:10 am

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

 Post subject: Re: Student's distribution in VBAPosted: Tue May 25, 2010 9:26 am

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

 Post subject: Re: Student's distribution in VBAPosted: Tue May 25, 2010 12:42 pm

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

 Post subject: Re: Student's distribution in VBAPosted: Tue May 25, 2010 2:01 pm

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

 Post subject: Re: Student's distribution in VBAPosted: Tue May 25, 2010 2:48 pm

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

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

Top

 Post subject: Re: Student's distribution in VBAPosted: Tue May 25, 2010 11:36 pm

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

 Post subject: Re: Student's distribution in VBAPosted: Wed May 26, 2010 5:24 am

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

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

Top

 Post subject: Re: Student's distribution in VBAPosted: Wed May 26, 2010 1:13 pm

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

 Post subject: Re: Student's distribution in VBAPosted: Wed May 26, 2010 2:57 pm

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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 2 [ 11 posts ] Go to page 1, 2  Next

 All times are UTC

#### Who is online

Users browsing this forum: No registered users and 2 guests

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

Search for: