HP4950G Statistics: Variance (Pop/Sample) & Mean, with frequencies

03242022, 04:28 PM
(This post was last modified: 01122023 01:40 PM by Gil.)
Post: #1




HP4950G Statistics: Variance (Pop/Sample) & Mean, with frequencies
Here is a very basic, elementary small prog to calculate the popvariance, samplevariance 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 xvalues. 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 

04072022, 04:25 PM
(This post was last modified: 04102022 11:03 AM by Gil.)
Post: #2




RE: HP4950G Statistics: Variance (Pop/Sample) with frequencies
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 Vkey (61.1) to that program as follows: \<< PATH \> p \<< HOME TOOLS \>Var p EVAL \>> \>> Then write: 61.1 ASN ENTER 

01122023, 01:42 PM
Post: #3




RE: HP4950G Statistics: Variance (Pop/Sample) & Mean, with frequencies
Version 1
with .hp ending. 

« Next Oldest  Next Newest »

User(s) browsing this thread: 1 Guest(s)