15 stats programs for TI-82. Some are pedagogical, eg. demonstrate the Central Limit Theorem. Others replace statistical tables, do statistical graphing. ----begin documentation---- TI-82 Statistical Programs Michael Lloyd (lloydm@holly.hsu.edu) Mar 1995 This software is freeware. I am in no responsible for any loss of money, data, or anything else from the use of these programs. documentation - table of contents ASCII - more detailed documentation and human-readable code UUE - TI-82 group file Program Description ======= =========== CDF......... Graph an empirical cumulative distribution function CH12.........Area under a chi-squared probability density function CLT..........Demonstrate the Central Limit Theorem CONT.........Illustrate a discrete distribution converging to a continuous distribution CUMU.........Cumulative frequency or distribution FLIP.........Simulate flipping a coin. The relative frequency converges to 1/2. FREQHIST.....Set the window and generate a frequency histogram GAMMA........Gamma function for half-integral values LSCI.........Compute and graph least squares confidence intervals NORMAL.......Find the area under a standard normal probability density TAREA........Area under the t-distribution TMENU........Compute the critical value from a Student's t distribution TSUB.........Subroutine called by TMENU X2CRIT.......Finds the critical value for a chi-squared distribution ZVAL.........z value from normal distribution ----end documentation---- ----begin ASCII---- Empirical Cumulative Distribution Function 1. Put the data in L_1. 2. Put the theoretical cdf in Y_1 if desired. 3. Set the range values. The empirical cumulative distribution function is graphed. I = counter L_1 = data N = number of data \START82\ \COMMENT=Cumulative Distribution Function \NAME=CDF \FILE=cdf.82P 0\->\Ymin:1\->\Ymax ClrDraw:PlotsOff SortA(\L1\) dim \L1\\->\N Line(Xmin,0,\L1\(1),0) For(I,1,N-1,1) Line(\L1\(I),I/N,\L1\(I+1),I/N) End Line(\L1\(N),1,Xmax,1) \STOP82\ ================================================================= Chi^2 Cumulative Distribution Function A = degrees of freedom B = x value G = gamma function evaluated at A/2 prgmGAMMA W = variable of integration Assume the random variable X is has the Chi squared distribution. Given the degrees of freedom r and x>0, then P[X > x] is approximated. Replace "1-Ans" in the program with "Ans" to approximate P[X < x] instead. \START82\ \COMMENT=Area for a chi squared distribution \NAME=CHI2 \FILE=chi2.82P Input "DF?",A Input "X?",B A/2\->\A prgmGAMMA B^Ae^\(-)\(B/2) Ans+fnInt(W^Ae^\(-)\(W/2),W,0,B,1)/2 Ans/GA2^A Disp "AREA X->OO =",1-Ans \STOP82\ ================================================================= Central Limit Theorem The Central Limit Theorem is demonstrated. Ninety-nine sample means from the uniform distribution on (0,1) of size N are stored into the list L_1. A histogram is plotted along with a normal probability density function. J counter for generating sample of means L_1 sample of sample means N sample size (must be less than 100) X counter for computing each sample mean, x-variable for normal pdf \START82\ \COMMENT=Demonstrate the Central Limit Theorem \NAME=CLT \FILE=clt.82P ClrHome FnOff :PlotsOff \(-)\1\->\Xmin:2\->\Xmax .5\->\Xscl:.5\->\Yscl 0\->\Ymin:2\->\Ymax Disp "DEMONSTRATE","CENTRAL LIMIT","THEOREM"," Input "SAMPLE SIZE?",N ClrDraw DrawF (0\Xmin 2.4\->\Xmax 0\->\Ymin:25\->\Ymax .5\->\Xscl:5\->\Yscl For(J,1,99 sum seq(rand,X,1,N,1)/N\->\\L1\(J End \sqrt\12N\->\A (\L1\-.5)A\->\\L1\ Plot1(Histogram,\L1\,1 Text(0,0,"DISTRIBUTION OF Text(0,53,"\x-bar\ Text(0,65,"N= Text(0,75,N 40/\sqrt\2\pi\\->\A Text(7,0,"WITH STANDARD NORMAL DrawF Ae^\(-)\(X\^2\/2 \STOP82\ ====================================================================== Discrete distribution converges to continuous \START82\ \COMMENT=Illustrate discrete dist -> cont distrib \NAME=CONT \FILE=cont.82P "Xe^\(-)\X\->\\Y1\ FnOff 0\->\Xmin:0\->\Xmax 6\->\Xmax:.5\->\Ymax 0\->\Xscl:0\->\Yscl For(I,2,5 2^I\->\N Text(0,5,"N= Text(0,15,N 6/N\->\W:0\->\B For(J,1,N B\->\A:A+W\->\B fnInt(\Y1\,X,A,B)/W\->\H Line(A,0,A,H Line(A,H,B,H Line(B,H,B,0 End Pause :ClrDraw End Text(0,5,"N=OO DrawF \Y1\ \STOP82\ ====================================================================== Cumulative Frequency or Distribution L_6 is both the input and the output. This list is replaced by the corresponding accumulated list. \START82\ \COMMENT=Cumulative frequency or distribution \NAME=CUMU \FILE=cumu.82P For(I,2,dim \L6\,1) \L6\(I-1)+\L6\(I)\->\\L6\(I) End \STOP82\ ====================================================================== Flip a Fair Coin Simulate flipping a fair coin. Two columns are generated; the left column is the number of experiments, and the right column is the relative frequency. This relative frequency approaches P[head] = 1/2. \START82\ \COMMENT=Simulate coin flip, rel. freq.-> 1/2 \NAME=FLIP \FILE=flip.82P Input "SEED?",A A\->\rand:0\->\A:0\->\N Lbl A A+int 2rand\->\A N+1\->\N Pause {N,A/N Goto A \STOP82\ ====================================================================== Frequency Histogram Set the window and generate a frequency histogram A = lower class limit B = upper class limit C = number of classes F = largest frequency G = used to find F L = smallest datum L_5= frequency (optional) L_6= data M = largest datum N = cardinality of range U = unit of measure X = miscellaneous Xmin = smallest class boundary Xmax = largest class boundary Xscl = class width Y = counter Ymin = 0 Ymax Yscl \START82\ \COMMENT=Frequency Histogram \NAME=FREQHIST \FILE=freqhist.82P SortA(\L6\) dim \L6\\->\N N\->\dim \L5\ Disp "FREQ IN \L5\?0=NO" Repeat X\<>\0 getKey\->\X End If X=102 Fill(1,\L5\) \L6\(1)\->\L \L6\(N)\->\M M-L\->\U For(X,2,N) \L6\(X)-\L6\(X-1) If Ans0 Ans\->\U End 0\->\Ymin L-U/2\->\Xmin Menu("CHOOSE ONE","NO OF CLASSES",1,"CLASS WIDTH",2) Lbl 0 Xmin+CXscl\->\Xmax 0\->\F:Xmin\->\A For(X,1,C) A+Xscl\->\B:0\->\G For(Y,1,N) G+(\L6\(Y)>A and \L6\(Y)\G End If G>F G\->\F B\->\A End Disp "MAX FREQ=",F Input "Ymax?",Ymax Input "Yscl?",Yscl FnOff PlotsOff Plot1(Histogram,\L6\,\L5\) PlotsOn 1 DispGraph Stop Lbl 1 Input "NO OF CLASSES?",C (M-L)/CU iPart Ans+(fPart Ans\<>\0) AnsU\->\Xscl Disp "CLASS WIDTH =",Ans Goto 0 Lbl 2 Input "CLASS WIDTH?",Xscl (M-L+U)/Xscl iPart Ans+(fPart Ans>0)\->\C Disp "NO OF CLASSES =",C Goto 0 \STOP82\ ====================================================================== Gamma Function A = half-integral positive number G = the gamma function evaluated at A X = counter \START82\ \COMMENT=Gamma function for half-integral values \NAME=GAMMA \FILE=gamma.82P If fPart A=0 Then (A-1)!\->\G Else \sqrt\\pi\\->\G .5\->\X While X\G X+1\->\X End End \STOP82\ ====================================================================== Confidence Band for Least Squares Line 1. Put the data in two lists. 2. Select the lists for two-variable statistics. 3. SE is the standard error. 4. C is the confidence level. 5. X is the x value for prediction. 6. Set window and graph to see confidence band. C = confidence level D = standard error K = degrees of freedom prgmTSUB X = x value V = SS_x W = SS_y Y_1 = radius of confidence band Y_2 = lower limit of confidence band Y_3 = upper limit of confidence band Y_4 = least squares line \START82\ \COMMENT=Least squares confidence intervals \NAME=LSCI \FILE=lsci.82P LinReg(ax+b) Sx\^2\n\->\V:Sy\^2\n\->\W \sqrt\((W-a\^2\V)/(n-2))\->\D Disp "SE=",D Input "C?",C n-2\->\K prgmTSUB "aX+b"\->\\Y4\ "DT\sqrt\(1+n\^-1\+(X-\x-bar\)\^2\/V)"\->\\Y1\ "\Y4\-\Y1\"\->\\Y2\ "\Y4\+\Y1\"\->\\Y3\ FnOff 1 Lbl 1 Input "X?",X Disp "PREDICTED Y",\Y4\ Disp "C.I.:" Disp \Y2\,"TO",\Y3\ Goto 1 \STOP82\ ====================================================================== Cumulative Normal Distribution Find the area from 0 to z under the standard normal probability density function. I.e., if Z is a standard normally distributed random variable, then P[0 < Z < z] is approximated. \START82\ \COMMENT=Find the area under standard normal 0->z \NAME=NORMAL \FILE=normal.82P Fix 4 Input "Z?",Z fnInt(e^\(-)\(X\^2\/2),X,0,Z Ans/\sqrt\2\pi\ Disp "AREA (0->Z) =",Ans \STOP82\ ====================================================================== Area under a t-distribution Assume that T is a random variable which has the t-distribution. If the degrees of freedom and a real number t are supplied, then P[T > t] is approximated. A = argument for the gamma function, exponent C = constant D = degrees of freedom prgmGAMMA = gamma function T = t value X = variable of integration \START82\ \COMMENT=Area for the t distribution 2\NAME=TAREA7 \FILE=tarea.82P Fix 3 Input "DF?",D Input "T?",T D/2\->\A prgmGAMMA G\->\C:(D+1)/2\->\A prgmGAMMA \(-)\A\->\A fnInt((1+X\^2\/D)^A,X,0,T) .5-AnsG/C\sqrt\D\pi\ Disp "AREA(T->OO)=",Ans \STOP82\ ====================================================================== Student's t Distribution Menu Approximate a critical t-value. A = tail area(s) C = confidence level K = degress of freedom prgmTSUB T = t value \START82\ \COMMENT=Menu for Student's t distribution \NAME=TMENU \FILE=tmenu.82P Fix 3 Menu("STUDENTS DISTR.","1-TAIL TEST",3,"2-TAIL TEST",4,"CONF. INTERVAL"\#\ ,2) Lbl 2 Input "C?",C Goto 5 Lbl 3 Input "A'?",A 1-2A\->\C:Goto 5 Lbl 4 Input "A''?",A 1-A\->\C Lbl 5 Input "DF?",K prgmTSUB Disp "T=",T \STOP82\ ====================================================================== Student's t Distribution Subroutine This program is used as a subroutine. A C = confidence level, miscellaneous I = old integral J = new integral K = degress of freedom L = lower limit of integral prgmGAMMA T = critical t value U = upper limit of integral X = variable of integration \START82\ \COMMENT=Subroutine called by TMENU \NAME=TSUB \FILE=tsub.82P K/2\->\A prgmGAMMA GC\sqrt\K\pi\\->\C (K+1)/2\->\A prgmGAMMA C/2G\->\C "(1+X\^2\/K)^\(-)\A"\->\\Y0\ FnOff 0 0\->\J:0\->\T Repeat J>C T+1\->\T:J\->\I J+fnInt(\Y0\,X,T-1,T)\->\J End T\->\U T-(J-C)/(J-I)\->\T Repeat abs (T-U)<.0001 U\->\L:T\->\U J+fnInt(\Y0\,X,L,U)\->\J U-(J-C)/\Y0\(U)\->\T End \STOP82\ ====================================================================== Critical Value for the Chi^2 Distribution Assume X is a Chi-squared random variable. Given the tail area and the degrees of freedom, the critical value x is found so that P[ X > x ] = the tail area. A = degrees of freedom, miscellaneous C = tail area, miscellaneous G = gamma function at A/2 prgmGAMMA I = old integral J = new integral L = lower limit of integral T = critical chi^2 value U = upper limit of integration X = variable of integration Y_0 = probability density function modulo constant \START82\ \COMMENT=Finds the critical value for a chi^2 dist. \NAME=X2CRIT \FILE=x2crit.82P Fix 3 Input "DF?",A Input "ALPHA?",C A/2\->\A prgmGAMMA (1-C)G2^A\->\C A-1\->\A "X^Ae^\(-)\(X/2)"\->\\Y0\ FnOff 0 0\->\J:0\->\T Repeat J>C T+1\->\T:J\->\I J+fnInt(\Y0\,X,T-1,T)\->\J End T\->\U T-(J-C)/(J-I)\->\T Repeat abs (T-U)<.0001 U\->\L:T\->\U J+fnInt(\Y0\,X,L,U)\->\J U-(J-C)/\Y0\(U)\->\T End Disp "X\^2\ CRIT =",T \STOP82\ ====================================================================== Z Value from Standard Normal Distribution A = tail area(s) C = critical value I = F(u) L = lower limit of integration U = upper limit of integration X = integration variable Z = z value Given the tail area(s) or the confidence level, the program finds the critical z value. \START82\ \COMMENT=z value from normal distribution \NAME=ZVAL \FILE=zval.82P Fix 3 Menu("Z VALUE","AREA 0 -> Z",1,"CONF. INTERVAL",2,"1 TAIL TEST",3,"2 TA\#\ IL TEST",4) Lbl 2 Input "C?",C C/2\->\A Goto 5 Lbl 1 Input "AREA?",A Goto 5 Lbl 3 Input "A'",A .5-A\->\A Goto 5 Lbl 4 Input "A''",A .5-A/2\->\A Lbl 5 If A\<=\.34 2.93A\->\Z If .34\Z If .48\Z 0\->\U:0\->\I A\sqrt\2\pi\\->\A Repeat abs (Z-U)<.0001 U\->\L:Z\->\U I+fnInt(e^\(-)\(X\^2\/2),X,L,U)\->\I U-(I-A)e^(U\^2\/2)\->\Z End Disp Z \STOP82\ ----end ASCII---- ----begin UUE---- begin 664 STATS.82G M*BI423@R*BH:"@!'`%P`,`1C##XQ!&,-/X4^ZC_C70`1 M/[5=``1./YQC"BLP*UT`$#$1*S`1/]-)*S$K3G$Q*S$1/YQ=`!!)$2M)@TXK M70`027`Q$2M)@TX1/]0_G%T`$$X1*S$K8PLK,1$+`%\`!4-(23(`````7P!= M`-PJ1$:O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