(************** Content-type: application/mathematica ************** CreatedBy='Mathematica 4.2' Mathematica-Compatible Notebook This notebook can be used with any Mathematica-compatible application, such as Mathematica, MathReader or Publicon. The data for the notebook starts with the line containing stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. *******************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 15154, 402]*) (*NotebookOutlinePosition[ 15855, 426]*) (* CellTagsIndexPosition[ 15811, 422]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell[TextData[StyleBox["Precedence charts", FontColor->RGBColor[0, 0, 1]]], "Title"], Cell["\<\ A program for computing distribution-free precedence charts, in- and \ out-of-control ARL's and run length probabilities.\ \>", "Subtitle"], Cell["\<\ Theory: S. Chakraborti, P. van der Laan and M.A. van de Wiel. Programming: Mark van de Wiel.\ \>", "Subsubtitle"], Cell[CellGroupData[{ Cell["Functions", "Section"], Cell[BoxData[{ \(\(f1[m_, n_, j_, a_, b_, h_, theta_] := \(f1[m, n, j, a, b, h, theta] = \n\t\tIf[ theta == 0, \((\((\(-1\))\)^h/\((j + h)\))\)* Binomial[n - j, h]*\n\t\((t^\((j + h)\) - \ s^\((j + h)\))\), \((\((\(-1\))\)^h/\((j + h)\))\)* Binomial[n - j, h]*\n\t\((t^\((theta*\((j + h)\))\) - \ s^\((theta*\((j + h)\))\))\)]\);\)\), "\n", \(\(f2[m_, n_, j_, a_, b_, theta_] := \(f2[m, n, j, a, b, theta] = \n\t\t\tSum[f1[m, n, j, a, b, h, theta], {h, 0, n - j}]/ Beta[j, n - j + 1]\);\)\), "\n", \(Expect[m_, n_, j_, a_, b_, theta_] := \(Expect[m, n, j, a, b, theta] = \t\n\t\((1 - f2[m, n, j, a, b, theta])\)\ \ /. \ {t -> 1 - t}\)\), "\n", \(Numeralt[m_, n_, j_, a_, b_] := \(Numeralt[m, n, j, a, b] = \((s^\((a - 1)\))\)*\((\((1 - t - s)\)^\((b - a - 1)\))\)* t^\((m - b)\)\ /. \n\t\t\t{t -> r*Sin[x], s -> \((r*Cos[x])\)^\((\((n - j + 1)\)/j)\)}\)\), "\n", \(Expectchalt[m_, n_, j_, a_, b_, theta_] := \n\t\t\t\(Expectchalt[m, n, j, a, b, theta] = \t\n\t Cancel[\((n - j + 1)\)/j* r^\((\((n - j + 1)\)/j)\)*\((Cos[x])\)^\((\((n - j + 1)\)/j - 1)\)*Numeralt[m, n, j, a, b]*1/\((Expand[ Expect[m, n, j, a, b, theta] /. \ {t -> r*Sin[x], s -> \((r*Cos[x])\)^\((\((n - j + 1)\)/ j)\)}])\)]\)\), "\n", \(facm[m_, a_, b_] := N[\(m!\)/\((\(\((a - 1)\)!\) \(\((b - a - 1)\)!\) \(\((m - b)\)!\))\)]\), "\n", \(ARL1b[m_, n_, j_, a_, b_, theta_] := \(ARL1b[m, n, j, a, b, theta] = If[\n\t\ta*\((n - j + 1)\) + j*\((m - b + 1)\) - j*\((n - j + 1)\) > 0, Module[{\n\t\t\tg = Expectchalt[m, n, j, a, b, theta], jbar = Max[n - j + 1, j]}, \n\t\tNIntegrate[ facm[m, a, b]*g, {x, 0, Pi/2}, {r, 0, \((1/2)\)^\((jbar/\((n - j + 1)\))\)/\((Cos[ x]^\((n - j + 1)\) + Sin[x]^\((n - j + 1)\))\)^\((1/\((n - j + 1)\))\)}]]]\)\)}], "Input", InitializationCell->True], Cell[BoxData[ \(<< Statistics`ContinuousDistributions`\)], "Input", InitializationCell->True], Cell[BoxData[{ \(\(f3[m_, n_, j_, a_, b_, h_, theta_, alt_] := \n\t\(f3[m, n, j, a, b, h, theta, alt] = \n\t\tIf[ theta == 0, \((\((\(-1\))\)^h/\((j + h)\))\)*\n\t\ \ Binomial[ n - j, h]*\n\t\((t^\((j + h)\) - \ s^\((j + h)\))\), \((\((\(-1\))\)^ h/\((j + h)\))\)*\n\t\ \ Binomial[n - j, h]*\n\t\((alt[t, theta]^\((j + h)\) - \ alt[s, theta]^\((j + h)\))\)]\);\)\), "\n", \(\(f4[m_, n_, j_, a_, b_, theta_, alt_] := \n\t\t\(f4[m, n, j, a, b, theta, alt] = \n\t\t\tSum[ f3[m, n, j, a, b, h, theta, alt], {h, 0, n - j}]/\n\t\t\tBeta[ j, n - j + 1]\);\)\)}], "Input", InitializationCell->True], Cell[BoxData[ \(\(\(Expect1[m_, n_, j_, a_, b_, theta_, alt_]\)\(:=\)\(\n\)\(\t\t\t\)\(Expect1[m, n, j, a, b, theta, alt] = \((s^\((a - 1)\))\)*\((\((t - s)\)^\((b - a - 1)\))\)*\((\((1 - t)\)^\((m - b)\))\)/\n\t\t\t\t\((1 - f4[m, n, j, a, b, theta, alt])\)\)\(\ \)\)\)], "Input", InitializationCell->True], Cell[BoxData[ \(ARL[m_, n_, j_, a_, b_, theta_, alt_] := If[\n\t\ta*\((n - j + 1)\) + j*\((m - b + 1)\) - j*\((n - j + 1)\) > 0, Module[{f = Expect1[m, n, j, a, b, theta, alt] /. \ {t -> t1, s -> s1}}, \n\t\tSetAccuracy[ NIntegrate[facm[m, a, b]*f, {t1, 0, 1}, {s1, 0, t1}], 8]], Infinity]\)], "Input", InitializationCell->True], Cell[BoxData[ \(Expect2[m_, n_, j_, a_, b_, theta_, alt_, k_] := \n\t\t\t\(Expect2[m, n, j, a, b, theta, alt, k] = \((s^\((a - 1)\))\)*\((\((t - s)\)^\((b - a - 1)\))\)*\((\((1 - t)\)^\((m - b)\))\)*\n\t\t\t\t\((f4[m, n, j, a, b, theta, alt])\)^k\)\)], "Input", InitializationCell->True], Cell[BoxData[ \(Prob[m_, n_, j_, a_, b_, theta_, alt_, k_] := If[\n\t\ta*\((n - j + 1)\) + j*\((m - b + 1)\) - j*\((n - j + 1)\) > 0, 1 - facm[m, a, b]* Module[{f = Expect2[m, n, j, a, b, theta, alt, k] /. \ {t -> t1, s -> s1}}, \n\t\tNIntegrate[ f, {t1, 0, 1}, {s1, 0, t1}]], Infinity]\)], "Input", InitializationCell->True], Cell[BoxData[ \(Off[]\)], "Input", InitializationCell->True], Cell[BoxData[ \(Prob[100, 25, 13, 24, 77, 0, Uni, 300]\)], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["Input for computation of precedence charts", "Section"], Cell["\<\ This section contains the inputparameters for the computation of two-sided \ precedence charts. The reference sample size is m1, the test sample size is \ n1, pnot is the coverage probability and j1 is the quantile \ (median:j1=(n1+1)/2). One may consider more than one chart at one go by \ simply adding more numbers to the lists (e.g. m1={100,200,500}). The number \ of j1's has to be equal to the number of n1's.\ \>", "Text", FontColor->RGBColor[1, 0, 0]], Cell[BoxData[ \(m1 = {1000}; n1 = {25}; pnot = 1 - 1/500; j1 = {13};\)], "Input", InitializationCell->True], Cell[TextData[StyleBox[ "Now compute the charts by running the previous cell and the next \ `Timing[...]' cell.", FontColor->RGBColor[1, 0, 0]]], "Text"] }, Open ]], Cell[CellGroupData[{ Cell["\<\ Computation of two-sided precedence charts and in-control ARL's\ \>", "Section"], Cell[CellGroupData[{ Cell[BoxData[{ \(\(Timing[sol2 = {}; \npnot1 = \((1 - pnot)\)/2; \n For[i = 1, i <= Length[n1], \(i++\), sol1 = {}; \n\t For[k = 1, k <= Length[m1], \(k++\), m = m1[\([k]\)]; n = n1[\([i]\)]; j = j1[\([i]\)]; \n PB1[w_, m_, n_, j_] := \(PB1[w, m, n, j] = N[Binomial[j + w - 1, w]* Binomial[m + n - j - w, m - w]/Binomial[m + n, n], 4]\); \nprob1 = 0; test = 0; sol = {}; temp = 0; \n\t\tFor[a = 1, a <= m && \ test\ == 0, \(a++\), \n\t\tprob1 = prob1 + PB1[a - 1, m, n, j]; If[prob1 > pnot1, test = 1; \n\t temp = prob1 - PB1[a - 1, m, n, j]]]; \n\t\ttest = 0; prob1 = 0; For[b = m, b >= 0\ && \ test\ == 0, \(b--\), \n\t\tprob1 = prob1 + PB1[b, m, n, j]; If[prob1 > pnot1, test = 1; \n\t If[a - 2 == 0 || b == m, sol = {"\"}, sol = {a - 2, N[temp, 3], b + 1, N[prob1 - PB1[b, m, n, j], 3], N[ARL1b[m, n, j, a - 2, b + 1, 0], 4]}]]]; \n\t\tsol1 = Append[sol1, sol];]; sol2 = Append[sol2, Prepend[Prepend[sol1, j], n]]]; sol2 = Prepend[sol2, Prepend[Prepend[m1, "\"], "\"]];];\)\), "\n", \(Print[TableForm[sol2]]\)}], "Input"], Cell[BoxData[ InterpretationBox[GridBox[{ {"\<\"n\"\>", "\<\"j\\\\m\"\>", "1000"}, {"25", "13", GridBox[{ {"217"}, {"0.0009759787057939628`"}, {"784"}, {"0.0009759787057939628`"}, {"591.4142453140449`"} }, RowSpacings->0.25, ColumnSpacings->1, RowAlignments->Baseline, ColumnAlignments->{Left}]} }, RowSpacings->1, ColumnSpacings->3, RowAlignments->Baseline, ColumnAlignments->{Left}], TableForm[ {{"n", "j\\m", 1000}, {25, 13, {217, .00097597870579396284, 784, .00097597870579396284, 591.41424531404493}}}]]], "Print"] }, Open ]] }, Closed]] }, Open ]], Cell[CellGroupData[{ Cell[TextData[StyleBox["Procedure to obtain limits for target ARL (median \ case): first run procedure above with pnot=1-1/ARL to obtain an approximation \ for limits. Then run procedure below, with appr equal to the approximation \ for the lower limit and ARLtarget equal to the target ARL. In general, the \ approximation does not have to be very good.", FontSize->18, FontColor->RGBColor[1, 0, 0]]], "Title"], Cell[BoxData[{ \(ARLtarget = 500; appr = 217;\), "\[IndentingNewLine]", \(m = m1[\([1]\)]; n = n1[\([1]\)]; j = j1[\([1]\)]; ond = 0; bov = m; new = ARL1b[m, n, j, appr, m + 1 - appr, 0]; k = 1; Print[new]; anew = appr;\), "\[IndentingNewLine]", \(If[new > ARLtarget, newmax = new; newmin = 0; ond = appr, newmax = Infinity; newmin = new, bov = appr]; While[bov - ond \[GreaterEqual] 2, If[new > ARLtarget, \ anew = anew + Min[Round[\((bov - ond)\)/2], 5], anew = anew - Min[Round[\((bov - ond)\)/2], 5]]; new = ARL1b[m, n, j, anew, m + 1 - anew, 0]; \[IndentingNewLine]If[ new > ARLtarget && \ new\ \[LessEqual] newmax, \ newmax = new; ond = anew]; If[new < ARLtarget\ && new \[GreaterEqual] newmin, newmin = new; bov = anew]; \[IndentingNewLine]k = k + 1; Print[{ond, bov, newmin, newmax, new, anew}]];\), "\[IndentingNewLine]", \(\(\(Print["\"\ \ , ond\ , "\<, Upper limit1 = \>", m + 1 - ond, \ "\< with ARL_0 = \>", \ newmax]\)\(;\)\(Print["\"\ \ , bov\ , "\<, Upper limit2 = \>", m + 1 - bov, \ "\< with ARL_0 = \>", \ newmin]\)\(\[IndentingNewLine]\)\)\)}], "Input"], Cell[CellGroupData[{ Cell["Out-of-control ARL's and run length probabilities", "Section"], Cell["\<\ ARL[m1,n1,j1,a,b,theta,out-of-control dist.] computes an out-of-control ARL \ for given values of the reference sample size m1, test sample size n1, \ quantile j1, lower control parameter a, upper control parameter b and a given \ the out-of-control distribution with parameter theta. The alternatives are \ listed below. Other alternatives can be used by implementing these similarly. \ Prob[m1,n1,j1,a,b,theta,alternative,k] computes the probability that the run \ lenght of a chart is smaller or equal to k, given the chart parameters and \ the out-of-contol distribution.\ \>", "Text", FontColor->RGBColor[1, 0, 0]], Cell[CellGroupData[{ Cell[BoxData[ \(ARL[100, 5, 3, 20, 81, 2, Lehmann]\)], "Input"], Cell[BoxData[ \(4.73337267207270517`\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(Prob[100, 5, 3, 20, 81, 2, Lehmann, 1]\)], "Input"], Cell[BoxData[ \(0.251885313546868072`\)], "Output"] }, Open ]], Cell[BoxData[ \(StandNormal[t_, theta_] := Module[{nd = NormalDistribution[0, 1]}, CDF[nd, \n\t\t\tQuantile[nd, t] - theta]]\)], "Input", InitializationCell->True], Cell[BoxData[ \(Normal11[t_, theta_] := Module[{nd = NormalDistribution[0, 1.1]}, CDF[nd, Quantile[nd, t] - theta]]\)], "Input", InitializationCell->True], Cell[BoxData[ \(T40[t_, theta_] := Module[{nd = StudentTDistribution[40]}, CDF[\n\t\t\tnd, Quantile[nd, t] - \((Sqrt[40/38]*theta)\)]]\)], "Input", InitializationCell->True], Cell[BoxData[ \(T4[t_, theta_] := Module[{nd = StudentTDistribution[4]}, CDF[\n\t\t\tnd, Quantile[nd, t] - \((Sqrt[4/2]*theta)\)]]\)], "Input",\ InitializationCell->True], Cell[BoxData[ \(Gamma11[t_, theta_] := Module[{nd = ExponentialDistribution[1]}, \n\t\tIf[t <= CDF[nd, theta], 0, CDF[nd, Quantile[nd, t] - theta]]]\)], "Input", InitializationCell->True], Cell[BoxData[ \(Gamma14[t_, theta_] := Module[{nd = GammaDistribution[4, 1]}, \t If[t <= CDF[nd, theta*2], 0, \t CDF[nd, Quantile[nd, t] - 2*theta]]]\)], "Input", InitializationCell->True], Cell[BoxData[ \(Lapl[t_, theta_] := Module[{nd = LaplaceDistribution[0, 1/Sqrt[2]]}, CDF[\n\t\t\tLaplaceDistribution[theta, 1/Sqrt[2]], Quantile[nd, t]]]\)], "Input", InitializationCell->True], Cell[BoxData[ \(Uni[t_, theta_] := Module[{nd = UniformDistribution[\(-Sqrt[3]\), Sqrt[3]]}, CDF[\n\t\t\tUniformDistribution[\(-Sqrt[3]\) + theta, Sqrt[3] + theta], Quantile[nd, t]]]\)], "Input", InitializationCell->True], Cell[BoxData[ \(Lehmann[t_, theta_] := t^theta\)], "Input", InitializationCell->True], Cell[BoxData[ \(PH[t_, theta_] := 1 - \((1 - t)\)^theta\)], "Input", InitializationCell->True], Cell[BoxData[ \(P1[p1_, p2_, n_, j_] := CDF[BetaDistribution[j, n - j + 1], p2] - CDF[BetaDistribution[j, n - j + 1], p1]\)], "Input"] }, Closed]] }, Open ]] }, FrontEndVersion->"4.2 for Microsoft Windows", ScreenRectangle->{{0, 1024}, {0, 695}}, AutoGeneratedPackage->Automatic, WindowSize->{747, 585}, WindowMargins->{{103, Automatic}, {Automatic, 40}}, ShowCellLabel->False ] (******************************************************************* Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. *******************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1776, 53, 86, 1, 115, "Title"], Cell[1865, 56, 149, 4, 122, "Subtitle"], Cell[2017, 62, 124, 3, 71, "Subsubtitle"], Cell[CellGroupData[{ Cell[2166, 69, 28, 0, 59, "Section"], Cell[2197, 71, 2336, 44, 470, "Input", InitializationCell->True], Cell[4536, 117, 99, 2, 30, "Input", InitializationCell->True], Cell[4638, 121, 767, 14, 230, "Input", InitializationCell->True], Cell[5408, 137, 368, 6, 90, "Input", InitializationCell->True], Cell[5779, 145, 405, 8, 90, "Input", InitializationCell->True], Cell[6187, 155, 349, 6, 90, "Input", InitializationCell->True], Cell[6539, 163, 417, 8, 90, "Input", InitializationCell->True], Cell[6959, 173, 66, 2, 30, "Input", InitializationCell->True], Cell[7028, 177, 71, 1, 30, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[7136, 183, 61, 0, 39, "Section"], Cell[7200, 185, 471, 8, 71, "Text"], Cell[7674, 195, 113, 2, 30, "Input", InitializationCell->True], Cell[7790, 199, 155, 3, 33, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[7982, 207, 90, 2, 59, "Section"], Cell[CellGroupData[{ Cell[8097, 213, 1438, 27, 390, "Input"], Cell[9538, 242, 752, 20, 85, "Print"] }, Open ]] }, Closed]] }, Open ]], Cell[CellGroupData[{ Cell[10351, 269, 415, 6, 225, "Title"], Cell[10769, 277, 1254, 21, 270, "Input"], Cell[CellGroupData[{ Cell[12048, 302, 68, 0, 59, "Section"], Cell[12119, 304, 631, 10, 90, "Text"], Cell[CellGroupData[{ Cell[12775, 318, 67, 1, 30, "Input"], Cell[12845, 321, 54, 1, 29, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[12936, 327, 71, 1, 30, "Input"], Cell[13010, 330, 55, 1, 29, "Output"] }, Open ]], Cell[13080, 334, 185, 4, 50, "Input", InitializationCell->True], Cell[13268, 340, 176, 4, 50, "Input", InitializationCell->True], Cell[13447, 346, 206, 5, 50, "Input", InitializationCell->True], Cell[13656, 353, 193, 5, 50, "Input", InitializationCell->True], Cell[13852, 360, 211, 4, 50, "Input", InitializationCell->True], Cell[14066, 366, 219, 5, 50, "Input", InitializationCell->True], Cell[14288, 373, 225, 5, 50, "Input", InitializationCell->True], Cell[14516, 380, 256, 5, 50, "Input", InitializationCell->True], Cell[14775, 387, 91, 2, 30, "Input", InitializationCell->True], Cell[14869, 391, 100, 2, 30, "Input", InitializationCell->True], Cell[14972, 395, 154, 3, 50, "Input"] }, Closed]] }, Open ]] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************)