Thu Feb 25 19:24:00 MST 1999 aquarius% maple |\^/| Maple V Release 5.1 (WMI Campus Wide License) ._|\| |/|_. Copyright (c) 1981-1998 by Waterloo Maple Inc. All rights \ MAPLE / reserved. Maple and Maple V are registered trademarks of <____ ____> Waterloo Maple Inc. | Type ? for help. # ----------[ M a p l e ]---------- #interface(echo = 3); # ---------- Initialization ---------- > readlib(showtime): > on; # ---------- Statistics ---------- O1 := with(stats): time = 0.08, bytes = 166254 # Compute the mean of a list of numbers => 9 O2 := describe[mean]([3, 7, 11, 5, 19]); 9 time = 0.06, bytes = 73142 # Compute the median of a list of numbers => 7 O3 := describe[median]([3, 7, 11, 5, 19]); 7 time = 0.02, bytes = 21594 # Compute the first quartile (25% quantile) of a list of numbers => 2 or 5/2 O4 := xx:= [1, 2, 3, 4, 5, 6, 7, 8]: time = 0.02, bytes = 10038 O5 := describe[quartile[1]](xx); 2 time = 0.01, bytes = 17982 O6 := describe[quantile[1/4]](xx); 2 time = 0.02, bytes = 13298 O7 := xx:= 'xx': time = 0.00, bytes = 4274 # Compute the mode (the most frequent item) of a list of numbers => 7 O8 := describe[mode]([3, 7, 11, 7, 3, 5, 7]); 7 time = 0.02, bytes = 19010 # Compute the unbiased sample standard deviation of a list of numbers # => sqrt(5/2) O9 := describe[standarddeviation[1]]([1, 2, 3, 4, 5]); 1/2 1/2 10 time = 0.05, bytes = 40118 # Discrete distributions---what is the probability of finding exactly 12 # switches that work from a group of 15 where the probability of a single one # working is 75%? (Need to use the probability density function [PDF] of the # binomial distribution.) => 0.22520 O10 := statevalf[pf, binomiald[15, .75]](12); .2251990652 time = 0.04, bytes = 66494 # Replace `exactly' by `up through' in the above. (Need to use the cumulative # probability density function [CDF] of the binomial distribution.) => 0.76391 O11 := statevalf[dcdf, binomiald[15, .75]](12); .7639121888 time = 0.03, bytes = 38246 # Continuous distributions---if a radiation emission can be modeled by a # normal distribution with a mean of 4.35 mrem and a standard deviation of # 0.59 mrem, what is the probability of being exposed to anywhere from 4 to 5 # mrem? => .5867 O12 := statevalf[cdf, normald[4.35, 0.59]](5) O12 := - statevalf[cdf, normald[4.35, 0.59]](4); .5881859844 time = 0.07, bytes = 68442 # Hypothesis testing---how good of a guess is 5 for the mean of xx? O13 := xx:= [1, -2, 3, -4, 5, -6, 7, -8, 9, 10]: time = 0.01, bytes = 9762 # Using Student's T distribution (preferred) => 0.057567 O14 := statevalf[cdf, studentst[nops(xx) - 1]]((describe[mean](xx) - 5)/ O14 := (describe[standarddeviation[1]](xx) / sqrt(nops(xx)))); .0575666011 time = 0.07, bytes = 64010 # Using the normal distribution (as an alternative) => 0.040583 O15 := statevalf[cdf, normald]((describe[mean](xx) - 5)/ O15 := (describe[standarddeviation[1]](xx) / sqrt(nops(xx)))); .04058346175 time = 0.06, bytes = 53010 O16 := xx:= 'xx': time = 0.00, bytes = 3494 # Chi-square test---what is the expectation that row characteristics are # independent of column characteristics for a two dimensional array of data? # => 0.469859 (chi2 = 1153/252) O17 := x:= matrix([[41, 27, 22], [79, 53, 78]]): time = 0.01, bytes = 26078 O18 := m:= linalg[rowdim](x): time = 0.02, bytes = 40434 O19 := n:= linalg[coldim](x): time = 0.01, bytes = 7126 O20 := rowSum:= [sum(x[i, j], j = 1..n) $ i = 1..m]: time = 0.02, bytes = 21502 O21 := colSum:= [sum(x[i, j], i = 1..m) $ j = 1..n]: time = 0.01, bytes = 7342 O22 := matSum:= sum(rowSum[i], i = 1..m): time = 0.01, bytes = 6202 O23 := e:= matrix(m, n, (i, j) -> rowSum[i]*colSum[j]/matSum): time = 0.01, bytes = 7810 O24 := chi2:= sum(sum((x[i, j] - e[i, j])^2/e[i, j], i = 1..m), j = 1..n); bytes used=1000024, alloc=851812, time=0.83 1153 ---- 252 time = 0.09, bytes = 9594 O25 := 1 - statevalf[cdf, chisquare[m*n - 1]](chi2); .4698594143 time = 0.07, bytes = 76994 O26 := chi2:= 'chi2': time = 0.01, bytes = 3830 O27 := colSum:= 'colSum': time = 0.00, bytes = 3934 O28 := matSum:= 'matSum': time = 0.00, bytes = 3950 O29 := rowSum:= 'rowSum': time = 0.01, bytes = 4034 O30 := e:= 'e': time = 0.00, bytes = 3982 O31 := m:= 'm': time = 0.01, bytes = 3774 O32 := n:= 'n': time = 0.00, bytes = 4062 O33 := x:= 'x': time = 0.00, bytes = 3942 # Linear regression (age as a function of developmental score). See Lambert # H. Koopmans, _Introduction to Contemporary Statistical Methods_, Second # Edition, Duxbury Press, 1987, p. 459 => y' = 0.7365 x + 6.964 O34 := [[3.33, 3.25, 3.92, 3.50, 4.33, 4.92, 6.08, 7.42, 8.33, 8.00, 9.25, O34 := 10.75], O34 := [8.61, 9.40, 9.86, 9.91, 10.53, 10.61, 10.59, 13.28, 12.76, 13.44, 14.27, O34 := 14.13]]: time = 0.04, bytes = 31974 O35 := fit[leastsquare[[x, y], y = a + b*x, {a, b}]](%); y = 6.964118392 + .7364611289 x time = 0.39, bytes = 722514 # Multiple linear regression (income as a function of age and years of # college) => y = -16278.7 + 960.925 x1 + 2975.66 x2 O36 := [[37, 45, 38, 42, 31], [4, 0, 5, 2, 4], [31200, 26800, 35000, 30300, 25400]]: time = 0.02, bytes = 12786 O37 := fit[leastsquare[[x1, x2, y], y = a + b*x1 + c*x2, {a, b, c}]](%); bytes used=2000352, alloc=1244956, time=1.67 58782300 3469900 10745100 y = --------- + ------- x1 + -------- x2 3611 3611 3611 time = 0.28, bytes = 107234 O38 := evalf(%); y = -16278.67627 + 960.9249515 x1 + 2975.657713 x2 time = 0.01, bytes = 4554 # Multiple linear regression using the L1 or Least Absolute Deviations # technique rather than the Least Squares technique (minimizing the sum of the # absolute values of the residuals rather than the sum of the squares of the # residuals). Here, the Stack-loss Data is used (percentage of ammonia lost # times 10 from the operation of a plant over 21 days as a function of air # flow to the plant, cooling water inlet temperature and acid concentration). # See W. N. Venables and B. D. Ripley, _Modern Applied Statistics with # S-plus_, Springer, 1994, p. 218. # => y = 0.83188 x1 + 0.57391 x2 - 0.06086 x3 - 39.68984 O39 := [[80, 80, 75, 62, 62, 62, 62, 62, 58, 58, 58, 58, 58, 58, 50, 50, 50, 50, 50, O39 := 56, 70], O39 := [27, 27, 25, 24, 22, 23, 24, 24, 23, 18, 18, 17, 18, 19, 18, 18, 19, 19, 20, O39 := 20, 20], O39 := [89, 88, 90, 87, 87, 87, 93, 93, 87, 80, 89, 88, 82, 93, 89, 86, 72, 79, 80, O39 := 82, 91], O39 := [42, 37, 37, 28, 18, 18, 19, 20, 15, 14, 14, 13, 11, 12, 8, 7, 8, 8, 9, O39 := 15, 15]]: time = 0.11, bytes = 76106 O40 := fit[leastsquare[[x1, x2, x3, y], y = a + b*x1 + c*x2 + d*x3, {a, b, c, d}]](%); 47136342623 845013447 191180951 44905797 y = ------------ + ---------- x1 + --------- x2 - --------- x3 1180779736 1180779736 147597467 295194934 time = 0.25, bytes = 216962 O41 := evalf(%); y = -39.91967442 + .7156402005 x1 + 1.295286124 x2 - .1521225191 x3 time = 0.01, bytes = 4398 # Nonlinear regression (Weight Loss Data from an Obese Patient consisting of # the time in days and the weight in kilograms of a patient undergoing a # weight rehabilitation program). Fit this using least squares to weight = # b0 + b1 2^(- days/th), starting at (b0, b1, th) = (90, 95, 120) [Venables # and Ripley, p. 225] => weight = 81.37375 + 102.6842 2^(- days/141.9105) O42 := [[ 0, 4, 7, 7, 11, 18, 24, 30, 32, 43, 46, 60, 64, 70, 71, O42 := 71, 73, 74, 84, 88, 95, 102, 106, 109, 115, 122, 133, 137, 140, 143, O42 := 147, 148, 149, 150, 153, 156, 161, 164, 165, 165, 170, 176, 179, 198, 214, O42 := 218, 221, 225, 233, 238, 241, 246], O42 := [184.35, 182.51, 180.45, 179.91, 177.91, 175.81, 173.11, 170.06, 169.31, O42 := 165.10, 163.11, 158.30, 155.80, 154.31, 153.86, 154.20, 152.20, 152.80, O42 := 150.30, 147.80, 146.10, 145.60, 142.50, 142.30, 139.40, 137.90, 133.70, O42 := 133.70, 133.30, 131.20, 133.00, 132.20, 130.80, 131.30, 129.00, 127.90, O42 := 126.90, 127.70, 129.50, 128.40, 125.40, 124.90, 124.90, 118.20, 118.20, O42 := 115.30, 115.70, 116.00, 115.50, 112.60, 114.00, 112.60]]: time = 0.08, bytes = 82150 # ---------- Quit ---------- O43 := quit bytes used=2410140, alloc=1376004, time=2.15 real 2.98 user 2.23 sys 0.63