(10-26-2015 08:39 PM)Thomas Klemm Wrote: Here's a program for the Student's t-distribution:
Code:
T001 LBL T ; Student's t
T002 INPUT K ; degrees of freedom
T003 1
T004 -
T005 2
T006 /
T007 ! ; Γ((k+1)/2) = (k-1)/2 !
T008 RCL K
T009 2
T010 /
T011 1
T012 -
T013 ! ; Γ(k/2) = (k/2 - 1)!
T014 /
T015 PI
T016 RCL* K
T017 SQRT
T018 /
T019 STO G
T020 RTN
I001 LBL I ; inverse CDF ( CDF -- X )
I002 INPUT A ; area
I003 0.5
I004 -
I005 RCL/ G
I006 STO X ; initial guess
I007 XEQ C003 ; calulate cdf(X)
I008 RCL- A ; we want this difference to become 0
I009 RCL X
I010 STO T
I011 R↓
I012 XEQ D001 ; derivative at X = pdf(X)
I013 /
I014 STO- X ; improved guess
I015 ABS
I016 RCL E ; small like 1e-6
I017 x<y? ; close enough?
I018 GTO I006 ; not yet
I019 RCL X
I020 RTN
C001 LBL C ; CDF
C002 INPUT X
C003 0 ; lower limit
C004 RCL X ; upper limit
C005 FN= D ; the distribution
C006 ∫FN d T ; integrate pdf
C007 0.5 ; we add 0.5 since
C008 + ; the lower limit was 0
C009 RTN
P001 LBL P ; PDF
P002 INPUT X
P003 STO T
D001 LBL D ; Distribution: ( T -- PDF )
D002 RCL T
D003 x^2
D004 RCL/ K
D005 1
D006 + ; 1 + t^2/k
D007 LASTx
D008 RCL+ K
D009 2
D010 / ; (1 + k)/2
D011 y^x
D012 RCL G
D013 x<>y
D014 /
D015 RTN
You have to initialize the program with the degrees of freedom:
XEQ T ENTER
K?
7
R/S
To calculate the PDF use the program P:
XEQ P ENTER
X?
1.6
R/S
0.110665
PDF[StudentTDistribution[7],1.6]
To calculate the CDF use the program C:
XEQ C ENTER
X?
1.5
R/S
0.911351
CDF[StudentTDistribution[7],1.5]
For the next program set the accuracy to a reasonable value:
1E-6
STO E
To calculate the Inverse CDF use the program I:
XEQ I ENTER
X?
0.99
R/S
2.997951
HTH
Thomas
Thomas, two questions. What is the sequence of keys to enter STEP C006. To run the label I, the question is A ?, rather X?, right?