eQuate It CAS UDFs — Continuous Probability (TI-Nspire CAS) ============================================================= 1. ccondpr — Continuous conditional probability ------------------------------------------------------- (PDF version) Define ccondpr(pdf, lo, hi) = Prgm Local pA, pAB Disp "P(lo < X < hi | condition)" pAB := ∫(pdf, x, lo, hi) Disp "P(A ∩ B) = ", pAB EndPrgm (Normal distribution version) Define ccondpr(dummy, mu, sigma, c1, c2) = Prgm Local pC1, pC2, pBoth, result pC2 := normCdf(-∞, c2, mu, sigma) pC1 := normCdf(-∞, c1, mu, sigma) pBoth := normCdf(c1, c2, mu, sigma) If c1 < c2 Then result := pBoth / pC2 Else result := pBoth / pC1 EndIf Disp "P(condition1 | condition2) = ", approx(result) EndPrgm 2. confint(n, phat, conf) — Confidence interval ------------------------------------------------------- Define confint(n, phat, conf) = Prgm Local z, se, me, lo, hi z := invNorm((1 + conf)/2, 0, 1) se := sqrt(phat*(1 - phat)/n) me := z * se lo := phat - me hi := phat + me Disp "z-score: ", approx(z) Disp "Std error: ", approx(se) Disp "Margin of error: ", approx(me) Disp "CI: (", approx(lo), ", ", approx(hi), ")" EndPrgm 3. confintsolve(lo, hi, unknown) — Solve for CI parameter ------------------------------------------------------- Define confintsolve(lo, hi, unknown) = Prgm Local phat, me, z, se, n, conf phat := (lo + hi)/2 me := (hi - lo)/2 Disp "p-hat: ", approx(phat) Disp "Margin of error: ", approx(me) If string(unknown) = "n" Then Disp "Solving for sample size..." se := me / invNorm(0.975, 0, 1) n := ceiling(phat*(1 - phat)/se^2) Disp "n = ", n ElseIf string(unknown) = "conf" Then Disp "Solving for confidence level..." Else Disp "Unknown parameter: provide n, se, or conf" EndIf EndPrgm 4. continfo(f, x, lo, hi) — Continuous distribution information ------------------------------------------------------- Define continfo(f, x, lo, hi) = Prgm Local ev, var, sd ev := ∫(x*f, x, lo, hi) var := ∫(x^2*f, x, lo, hi) - ev^2 sd := sqrt(var) Disp "E(X) = ", approx(ev) Disp "Var(X) = ", approx(var) Disp "SD(X) = ", approx(sd) Disp "Verification ∫f = ", approx(∫(f, x, lo, hi)) EndPrgm 5. invnormvals(mu, sigma, p) — Inverse normal (left, right, centre) ------------------------------------------------------- Define invnormvals(mu, sigma, p) = Prgm Local left, right, clo, chi left := invNorm(p, mu, sigma) right := invNorm(1 - p, mu, sigma) clo := invNorm((1 - p)/2, mu, sigma) chi := invNorm((1 + p)/2, mu, sigma) Disp "P(X < a) = ", p Disp " Left: a = ", approx(left) Disp "P(X > a) = ", p Disp " Right: a = ", approx(right) Disp "P(lo < X < hi) = ", p Disp " Centre: (", approx(clo), ", ", approx(chi), ")" EndPrgm 6. normsolve — Solve for mu and sigma ------------------------------------------------------- (Case 1: Both lower and upper given) Define normsolve(lo, plo, hi, phi) = Prgm Local mu, sigma, result result := solve(normCdf(-∞, lo, mu, sigma) = plo and normCdf(-∞, hi, mu, sigma) = phi, {mu, sigma}) Disp "mu = ", result[1] Disp "sigma = ", result[2] EndPrgm