Statistics, mean, stanard deviation (population/sample), sum and range

  • administrators

    Here is a quick example of how to calculate a few common statistical functions on a list of numbers. You can generate the list any way you like. I have generated the list by drawing a sample of 10 numbers from a uniform distribution. The list is then stored in the variable $m1.

    # Generates a sample of 10 numbers from a uniform distribution on the range 0 to 5
    $m1 = maple("
    randomize(): #initialise random seed
    A:=Statistics[RandomVariable](Uniform(0,5)):  # uniform on a range 0 to 5
    nums:=Statistics[Sample](A,10);  #pull 10 numbers from the sample
    convert(nums,list)  # converts the vector of numbers to a list

    If you want to define your own list of numbers you can define $m1 as something like

    $m1="[1.2, 4.4, 5.0, 2.5, 3.4, 4.6, 8.6, 7.8, 1.7, 0.4]";

    You can then calculate the various quantities on the list stored in $m1. Note: As a check, in the following I have calculated the sample and population standard deviations using built in functions and the explicit formulas.

    #sample s.d.
    s1:=sqrt(add(i, i = map( x-> (x-mu)^2, $m1))/(nops($m1)-1)); #explicit
    #population s.d.
    sigma1:=sqrt(add(i, i = map( x-> (x-mu)^2, $m1))/(nops($m1))); #explicit
    # return values
    #use switch to get the values from the maple call

    The resultant variable in the algorithm section should now be set to something like the following