HP49-50G Statistics: Variance (Pop/Sample) & Mean, with frequencies - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: HP49-50G Statistics: Variance (Pop/Sample) & Mean, with frequencies (/thread-18177.html) |
HP49-50G Statistics: Variance (Pop/Sample) & Mean, with frequencies - Gil - 03-24-2022 04:28 PM Here is a very basic, elementary small prog to calculate the pop-variance, sample-variance and mean when dealing with frequencies. Suppose you want to calculate the variances and mean of the four values 5,6,7 and 10. Write the Matrix [[5] [6] [7] [10]] and launch —>Var Suppose now that you have 10 times the value 5, 20 times the value 6, 30 times 7 and 1 time the value 10. Write then the following Matrix, adding a column for the frequencies: [[10 5] [20 6] [30 7] [ 1 10]] and launch again —>Var Note: For a single argument like here with the Matrix in stack level 1, the program will then always suppose, automatically, that the frequencies are in the first column (and the corresponding values in the second column). Suppose now it is not the case. Let's say that you have the following Matrix in the stack: [[36 10 5] [26 20 6] [89 30 7] [ 45 1 10]] As the previous frequencies appear now in column 2 and the values in column 3, you will have to "tell that piece of information" to the program, adding the following instruction in stack level 1 {2 3} Now launch (with the matrix in stack level 2) —>Var Note that inside the {} you must have two numbers: the first one being for the frequencies col#, the second one standing for the col# of the corresponding x-values. The code is the following: \<< "1 Arg or 2 Arg If 1 Arg \[]Matrix [nx2] 1st col: freq 2nd col: val OR \[]Matrix [nx1] col: val (all freq=1) If 2 Arg \[]Matrix [n x k] \[]{k1 k2} k1 col: freq k2 col: val " DROP DUP TYPE 5 == IF THEN DUP OBJ\-> DROP 4 PICK UNROT ELSE DUP 1 2 END ROT DUP SIZE OBJ\-> DROP 0 0 0 \-> cf cx M i j \GSf \GSX \GSX2 \<< j 1 == IF THEN M { i 1 } 1 CON 1 COL+ 'M' STO END 1 i FOR i M { i cf } GET \-> f \<< f '\GSf' STO+ M { i cx } GET DUP f * '\GSX' STO+ SQ f * '\GSX2' STO+ \>> NEXT \GSf "N" \->TAG \GSX "\GSX" \->TAG \GSX \GSf / \->NUM "Mean" \->TAG DUP \GSX2 DUP \->NUM "\GSX2" \->TAG UNROT \GSf / SWAP SQ - \->NUM "Vpop" \->TAG DUP \GSf * \GSf 1 - / \->NUM "Vsam" \->TAG \>> \>> The output will be: [[36 10 5 ] [ 26 20 6 ] [ 89 30 7 ] [45 1 10 ]] {2 3} :N: 61 :SumX: 390 :Mean: 6.39344262295 :SumX2: 2540. :Vpop: .7632356893 :Vsam: .775956284122 Regards RE: HP49-50G Statistics: Variance (Pop/Sample) with frequencies - Gil - 04-07-2022 04:25 PM A good idea is to have that small variance program available, wherever you are in a directory. Create a directory TOOL where you will save the variance program —>Var. Then assign the V-key (61.1) to that program as follows: \<< PATH \-> p \<< HOME TOOLS \->Var p EVAL \>> \>> Then write: 61.1 ASN ENTER RE: HP49-50G Statistics: Variance (Pop/Sample) & Mean, with frequencies - Gil - 01-12-2023 01:42 PM Version 1 with .hp ending. |