#1: " ----------[ D e r i v e ]---------- " User #2: " ---------- Initialization ---------- " User #3: " ---------- Statistics ---------- " User #4: " Compute the mean of a list of numbers => 9 " User #5: AVERAGE([3, 7, 11, 5, 19]) User #6: 9 Simp(#5) #7: " Compute the median of a list of numbers => 7 " User #8: [3, 7, 11, 5, 19] User #9: [3, 7, 11, 5, 19] Simp(#8) User #10: " Compute the first quartile (25% quantile) of a list of numbers => 2 or 5/2 " #11: xx := [1, 2, 3, 4, 5, 6, 7, 8] User #12: "quartile(xx, 1)" User #13: "quantile(xx, 1/4)" User #14: xx := User User #15: " Compute the mode (the most frequent item) of a list of numbers => 7 " #16: [3, 7, 11, 7, 3, 5, 7] User #17: [3, 7, 11, 7, 3, 5, 7] Simp(#16) User #18: " Compute the unbiased sample standard deviation of a list of numbers " #19: " => sqrt(5/2) " User #20: STDEV(1, 2, 3, 4, 5) User SQRT(10) #21: ---------- Simp(#20) 2 User #22: " Discrete distributions---what is the probability of finding exactly 12 " User #23: " switches that work from a group of 15 where the probability of a single one " User #24: " working is 75%? (Need to use the probability density function [PDF] of the " #25: " binomial distribution.) => 0.22520 " User #26: q_ := BINOMIAL_DENSITY(12, 15, 0.75) User #27: Precision := Approximate User #28: APPROX(q_) User #29: 0.225199 Simp(#28) #30: Precision := Exact User User #31: " Replace `exactly' by `up through' in the above. (Need to use the cumulative " User #32: " probability density function [CDF] of the binomial distribution.) => 0.76391 " #33: q_ := BINOMIAL_DISTRIBUTION(12, 15, 0.75) User #34: Precision := Approximate User #35: APPROX(q_) User #36: 0.763912 Simp(#35) #37: Precision := Exact User User #38: " Continuous distributions---if a radiation emission can be modeled by a " User #39: " normal distribution with a mean of 4.35 mrem and a standard deviation of " User #40: " 0.59 mrem, what is the probability of being exposed to anywhere from 4 to 5 " #41: " mrem? => .5867 " User #42: q_ := NORMAL(5, 4.35, 0.59) - NORMAL(4, 4.35, 0.59) User #43: Precision := Approximate User #44: APPROX(q_) User #45: 0.588185 Simp(#44) #46: Precision := Exact User User #47: " Hypothesis testing---how good of a guess is 5 for the mean of xx? " #48: xx := [1, -2, 3, -4, 5, -6, 7, -8, 9, 10] User User #49: " Using Student's T distribution (preferred) => 0.057567 " User / AVERAGE(xx) - 5 \ 1 - STUDENT|-----------------------, DIMENSION(xx) - 1| | STDEV(xx) | #50: | --------------------- | \ SQRT(DIMENSION(xx)) / q_ := --------------------------------------------------------- 2 #51: Precision := Approximate User #52: APPROX(q_) User #53: 0.0575664 Simp(#52) #54: Precision := Exact User User #55: " Using the normal distribution (as an alternative) => 0.040583 " / AVERAGE(xx) - 5 \ q_ := NORMAL|-----------------------, 0, 1| #56: | STDEV(xx) | User | --------------------- | \ SQRT(DIMENSION(xx)) / #57: Precision := Approximate User #58: APPROX(q_) User #59: 0.0405833 Simp(#58) #60: Precision := Exact User #61: xx := User User #62: " Chi-square test---what is the expectation that row characteristics are " User #63: " independent of column characteristics for a two dimensional array of data? " #64: " => 0.469859 (chi2 = 1153/252) " User / 41 27 22 \ #65: x := | | User \ 79 53 78 / #66: m := DIMENSION(x) User n := DIMENSION(x ) #67: 1 User / n \ #68: rowsum := VECTOR|SUM x , i, 1, m| User \j=1 i,j / / m \ #69: colsum := VECTOR|SUM x , j, 1, n| User \i=1 i,j / m #70: matsum := SUM rowsum User i=1 i #71: MATRIX(z, m, n) := VECTOR(VECTOR(z, j, 1, n), i, 1, m) User / rowsum *colsum \ | i j | #72: e := MATRIX|-----------------, m, n| User \ matsum / 2 (x - e ) n m i,j i,j #73: chi2 := SUM SUM ---------------- User j=1 i=1 e i,j #74: chi2 User 1153 #75: ------ Simp(#74) 252 #76: q_ := 1 - CHI_SQUARE(chi2, m*n - 1) User #77: q_ User 1153/504 / -t_ 3/2 4*/ #e *t_ dt_ #78: 0 Simp(#77) 1 - ----------------------------- 3*SQRT(pi) #79: Precision := Approximate User #80: APPROX(q_) User #81: 0.469859 Simp(#80) #82: Precision := Exact User #83: chi2 := User #84: colsum := User #85: matsum := User #86: rowsum := User #87: e := User #88: m := User #89: n := User #90: x := User User #91: " Linear regression (age as a function of developmental score). See Lambert " User #92: " H. Koopmans, _Introduction to Contemporary Statistical Methods_, Second " User #93: " Edition, Duxbury Press, 1987, p. 459 => y' = 0.7365 x + 6.964 " User / 3.33 3.25 3.92 3.5 4.33 4.92 6.08 7.42 8.33 #94: t := | \ 8.61 9.4 9.86 9.91 10.53 10.61 10.59 13.28 12.76 8 9.25 10.75 \ | 13.44 14.27 14.13 / #95: q_ := FIT([x, a*x + b], t`) User #96: q_ User 2747*x 4464 #97: -------- + ------ Simp(#96) 3730 641 #98: Precision := Approximate User #99: APPROX(q_) User #100:0.736461*x + 6.96411 Simp(#99) #101:Precision := Exact User #102:t := User User #103:" Multiple linear regression (income as a function of age and years of " #104:" college) => y = -16278.7 + 960.925 x1 + 2975.66 x2 " User / 37 45 38 42 31 \ | | #105:q1_ := | 4 0 5 2 4 | User | | \ 31200 26800 35000 30300 25400 / #106:q2_ := FIT([x1, x2, a*x1 + b*x2 + c], q1_`) User #107:q2_ User 473736*x1 104148*x2 553475 #108:----------- + ----------- - -------- Simp(#107) 493 35 34 #109:Precision := Approximate User #110:APPROX(q2_) User 4 #111:960.924*x1 + 2975.65*x2 - 1.62786*10 Simp(#110) #112:Precision := Exact User User #113:" Multiple linear regression using the L1 or Least Absolute Deviations " User #114:" technique rather than the Least Squares technique (minimizing the sum of the " User #115:" absolute values of the residuals rather than the sum of the squares of the " User #116:" residuals). Here, the Stack-loss Data is used (percentage of ammonia lost " User #117:" times 10 from the operation of a plant over 21 days as a function of air " User #118:" flow to the plant, cooling water inlet temperature and acid concentration). " User #119:" See W. N. Venables and B. D. Ripley, _Modern Applied Statistics with " #120:" S-plus_, Springer, 1994, p. 218. " User User #121:" => y = 0.83188 x1 + 0.57391 x2 - 0.06086 x3 - 39.68984 " User / 80 80 75 62 62 62 62 62 58 58 58 58 58 58 | | 27 27 25 24 22 23 24 24 23 18 18 17 18 19 #122:q1_ := | | 89 88 90 87 87 87 93 93 87 80 89 88 82 93 | \ 42 37 37 28 18 18 19 20 15 14 14 13 11 12 50 50 50 50 50 56 70 \ | 18 18 19 19 20 20 20 | | 89 86 72 79 80 82 91 | | 8 7 8 8 9 15 15 / #123:q2_ := FIT([x1, x2, x3, a*x1 + b*x2 + c*x3 + d], q1_`) User #124:q2_ User 8680*x1 4369*x2 1351*x3 34291 #125:--------- + --------- - --------- - ------- Simp(#124) 12129 3373 8881 859 #126:Precision := Approximate User #127:APPROX(q2_) User #128:0.715640*x1 + 1.29528*x2 - 0.152122*x3 - 39.9196 Simp(#127) #129:Precision := Exact User User #130:" Nonlinear regression (Weight Loss Data from an Obese Patient consisting of " User #131:" the time in days and the weight in kilograms of a patient undergoing a " User #132:" weight rehabilitation program). Fit this using least squares to weight = " User #133:" b0 + b1 2^(- days/th), starting at (b0, b1, th) = (90, 95, 120) [Venables " User #134:" and Ripley, p. 225] => weight = 81.37375 + 102.6842 2^(- days/141.9105) " User / 0 4 7 7 11 18 24 #135:q1_ := | \ 184.35 182.51 180.45 179.91 177.91 175.81 173.11 30 32 43 46 60 64 70 71 170.06 169.31 165.1 163.11 158.3 155.8 154.31 153.86 71 73 74 84 88 95 102 106 109 154.2 152.2 152.8 150.3 147.8 146.1 145.6 142.5 142.3 115 122 133 137 140 143 147 148 149 139.4 137.9 133.7 133.7 133.3 131.2 133 132.2 130.8 150 153 156 161 164 165 165 170 176 131.3 129 127.9 126.9 127.7 129.5 128.4 125.4 124.9 179 198 214 218 221 225 233 238 241 124.9 118.2 118.2 115.3 115.7 116 115.5 112.6 114 246 \ | 112.6 / #136:" ---------- Quit ---------- " User