#Feb. 9, 2015, C6.txt, Normal Distribution, Hypothesis testing #confidence interval Help:=proc(): print(` ID(f,x,k) , Bin(n,k,p). BinF(n,k,p) `): print(`AcceptNH(p,n,k,eps) `): end: #ID(f,x,k): Given the probabity generating function f #in the variable x, for some r.v. under some prob. distibution #outputs the list [av,var, std. moms] ID:=proc(e,x,k) local i,av,M, f: f:=e/subs(x=1,e): av:=subs(x=1,diff(f,x)): M:=[av]: f:=f/x^av: f:=x*diff(f,x): for i from 2 to k do f:=x*diff(f,x): M:=[op(M),subs(x=1,f)]: od: M: [M[1],M[2],seq(M[i]/M[2]^(i/2),i=3..k)]: end: #Bin(n,k,p): the prob. of getting exactly k Heads tossing #a loaded coin with Pr(H)=p, n times Bin:=proc(n,k,p) local x: simplify(factor(subs(x=0,diff((p*x+(1-p))^n,x$k))/k!)): end: #BinF(n,k,p): the prob. of getting exactly k Heads tossing #a loaded coin with Pr(H)=p, n times BinF:=proc(n,k,p) local x: binomial(n,k)*p^k*(1-p)^(n-k): end: #AcceptNH(p,n,k,eps): Should we accept the Null Hypothesis #that Pr(H)=p if we tossed the coin n times and we got #k head with CONFIDENCE level 1-eps (eps=.05, or 0.01) AcceptNH:=proc(p,n,k,eps) local k0,faroff,i: k0:=trunc(n*p): faroff:=abs(k-k0): #I want to compute the prob. that k is between k0-faroff and #k0+faroff evalb(evalf(add(BinF(n,i,p),i=k0-faroff+1..k0+faroff))<1-eps): end: