#C5.txt, Feb. 5, 2015 #more on random variables and prob. distribution Help:=proc() print(` MomN(P,L,k) , Alpha(P,L,k), MomNs(e,x,k) `): end: #####################stuff from Class 4 #Groundhog day, C4n.txt #introducing proba. distribution Help4:=proc() print(` ClassStat,AveS, Expec(P,L)`): print(`PGF(P,L,X) ,MomS(P,L,k), Mom(P,L,k) , sd(P,L) `): end: #gathering statistics about the class #[Name,Gender,Age,Height,EyeColor] ClassStat:=proc() local A: A:= [ [Mingjia,F,25,164,Br], [Anthony,M,21,173,Br], [Aniket,M,21,173,Br], [Abigail,F,22,173,Br], [Nathan,M,24,172,Br], [Sowmya,F,23,155,Br], [Ha,F,27,162,Br], [Kafung,F,27,165,Br], [Matthew,M,21,176,Bl], [Marc,M,25,172,G], [Melissa,F,26,172,Bl], [Collin,M,30,183,Bl], [John,M,26,173,Br], [Elliot,M,18,179,Bl], [Michael,M,44,172,Br], [Alex,M,32,189,Bl], [Doron,M,64, 178,Br] ]: end: #AveS(L): the simple average of a list L AveS:=proc(L) evalf(convert(L,`+`)/nops(L)): end: #Expec(P,L): Expec:=proc(P,L) local i: add(P[i]*L[i],i=1..nops(L)): end: #PGF(P,L,x): the probability generating function of #the random variable L defined on {1, ..., nops(L)} #with prob. dist. P PGF:=proc(P,L,x) local i: add(P[i]*x^(L[i]),i=1..nops(L)): end: #MomS(P,L,k):the k-th straight moment of the r.v. L defined on #prob. space given P MomS:=proc(P,L,k) local i: add(P[i]*L[i]^k,i=1..nops(L)): end: #Mom(P,L,k):the k-th moment about the mean of the r.v. L defined on #prob. space given P Mom:=proc(P,L,k) local i,av: av:=Expec(P,L): add(P[i]*(L[i]-av)^k,i=1..nops(L)): end: #standard deviation of r.v. L with prob. dist. P sd:=proc(P,L) evalf(sqrt(Mom(P,L,2))): end: #####end of stuff from Class 4 #MomN(P,L,k): A nicer way to compute the moments about the mean #we output the LIST [Exp,Var,3rd-moment, 4th-moment, ...,k-the #moment (the Exp is NOT the expect. about the mean, alias 0) #the k-th moment about the mean of the r.v. L defined on #prob. space given P MomN:=proc(P,L,k) local i,av,x,f,M: f:=PGF(P,L,x): 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: end: #the list [av,variance, standardized-k-th moment] Alpha:=proc(P,L,k) local M,sd1: M:=MomN(P,L,k): sd1:=sqrt(M[2]): [M[1],M[2],seq(M[i]/sd1^i , i=3..k)]: end: #MomNs(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, moms] #[Note: previous version claimed that it outputs the standardized moments, that was erroenous] MomNs:=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: end: