maxima book chapter 10

Upload: prakushprakush

Post on 04-Jun-2018

222 views

Category:

Documents


2 download

TRANSCRIPT

  • 8/13/2019 Maxima Book Chapter 10

    1/80

    Probability distributions in MaximaIn this Chapter we describe the functions available todescribe probability distributions using Maxima.Probability functions in Maxima are available byloading the distribpackage using: load(distrib).

    efore showing applications of the distrib package we include so!e definitions related toprobability distributions.

    Definitions

    "ando! variable : # function that assigns a nu!erical value to the outco!e of ane$peri!ent or observation. "ando! variables can be discrete or continuous.

    Notation: %se upper&case letters to refer to the na!e of the rando! variable' e.g.'X, Y, etc. %se lower&case letters to refer to a specific value taken by the rando!variable' e.g.'x, y, etc.

    iscrete rando! variable : # rando! variable that can only take a finite or infinitenu!ber of point values (typically integers). # discrete rando! variable ischaracteried by itsprobability function (orprobability mass function, abbreviated

    pmf) defined as:f(x) = P(X=x)

    P(*+$) is interpreted as the probability that the rando! variableXtakes the valuex.

    Properties of thepmf:

    (,)f(x) 0

    (2) all x fx=1

    Continuous rando! variable : # rando! variable that can' in principle' attain anyvalue in a given interval. # continuous rando! variable is characteried by its

    probability density function (abbreviatedpdf)'f(x). -hepdf is used to calculateprobabilities according to the following definition:

    PaXb =a

    b

    fxdx

    /-0: 1or continuous rando! variables' PX=a =a

    a

    fxdx=0 ' thus' for

    continuous rando! variables the following state!ents are e2uivalent:

    P(a X b) P(a < X b) P(a X < b) P(a < X < b) = PaXb=a

    b

    fxdx

    10-1 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    2/80

    Properties of the pdf:

    (,)f(x) 0

    (3)

    fx dx=1

    -he distribution function or' (cumulative distribution function' abbreviated C!)' for

    both' discrete and continuous rando! variables' is defined by

    !(x) = P(Xx)

    1or a discrete rando! variable: Fx =PXx=kx

    fk

    1or a continuous rando! variable: Fx =PXx=

    x

    f d ' fx =dF

    dx' and

    PaXb=FbFa .

    1or both' discrete and continuous' rando! variables' use the probability of aco!ple!ent as follows: PXx =1PXx =1Fx ' andPXx =1PXx .

    4athe!atical e$pectation. Fora discrete rando! variable withpmf f(x) or for acontinuous rando! function withpdf f(x)' the !athe!atical e$pectation ofX(expected "alue, mean "alue) is given by:

    iscrete: X=EX=kx

    kfk

    Continuous: X=EX=

    xf x dx

    Expectation of a function of X. If#(X) is a function of the rando! variableX' then thee$pected value of#(X) is defined as:

    iscrete: E[gX]=kx

    gkf k

    Continuous: E[gX]=

    gx fxdx

    5ariance . 1or both discrete and continuous rando! variables' the variance ofX is

    defined by X2=VarX=E[XX

    2]=E[X

    2]EX

    2=E[X

    2]X

    2

    1or a discrete variable: VarX=kx

    x2fx

    1or a continuous variable: VarX=

    x2fxdx

    10-2 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    3/80

    6tandard deviation . -he standard deviation' *' is the s2uare root of the variance.

    6kewness and kurtosis. Para!eters related to the shape of thepmf orpdf.

    6kewness is defined as: 3= 1

    X3E[XX

    3]

    1or discrete rando! variables: 3=1

    X3

    kx

    kX3f k

    1or continuous rando! variables: 3= 1

    X3

    xX3fxdx

    If $%0' the distribution is skewed to the right

    If $&0' the distribution is skewed to the left

    If $=0' the distribution is sy!!etric

    7urtosis is defined as: = 1X

    E[XX

    ]

    1or discrete rando! variables: 3=1

    X3

    kx

    kX3f k

    1or continuous rando! variables' 3= 1

    X3

    xX3fxdx

    -he kurtosis of the nor!al distribution (see chapter 8) is 8 + 9. -his is used asreference to co!pare the peakedness of other distributions:

    If 8 9' the distribution is !ore peaked than the corresponding nor!al

    If 8; 9' the distribution is less peaked than the corresponding nor!al

    Summations and integrals for probability distributionsxample Probability !ass functions for discrete rando! variables can be defined by atable. 1or e$a!ple:

    -his table can be used to calculate the !easures of the rando! variable' na!ely' !ean'variance' standard deviation' skewness' and kurtosis' as illustrated below.

    10-3 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    4/8010-4 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    5/80

    xample # probability !ass function (p!f) can be defined in ter!s of a constant' e.g.'

    fx =cln x1 ' for x=0!1!...,"

    -o deter!ine the value of the constant c' we use the following property of apmf:

    %sing 4a$i!a:

    e$t' we calculate the !easures of this distribution:

    all x

    fx=1

    10-5 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    6/80

    xample -he following e$a!ple uses a for! of the probability density function (pdf) forthe exponential distribution' na!ely:

    fx =ex

    , x0 .

    -he !easures of this distribution can be calculated as follows:

    10-6 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    7/80

    xample< # probability density functionf(x)!ay depend on the value of an unknownconstant' e.g.'

    fx =c1x2 ' for 0x10 .

    -he constant is found by using the property:

    f x dx=1 . %sing Maxima:

    -he !easures of this distribution can be calculated as shown below:

    10-7 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    8/80

  • 8/13/2019 Maxima Book Chapter 10

    9/80

    =ist of function prefi$es and probability distributions in the package distrib-he following is the list of function prefi$es in the distrib package:

    -he following is the list of the probability distributions available in the distribpackage:

    e$t' we>ll show e$a!ples of applications of the functions resulting fro! co!bining thefunction prefi$es with the probability distributions available in the distribpackage. In thee$a!ples that follow' a brief description of each distribution presented will be given as thee$a!ples are presented. -he following pages were generated in -xMaxima.

    10-9 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    10/80

    ProbabilityDistributionsExamplesDISCRETE.wxmx 1 / 17

    - - > l oad("di s t r i b" ) $

    CALCULATI ONS WI TH DI SCRETE DI STRI BUTI ONS========================================

    The basi s of many a di scr et e di st r i but i on i s t he Ber noul l i di st r i but i on, out ofwhi ch one can devel op t he Bi nomi al , Poi sson, Geomet r i c, and Negat i ve Bi nomi al

    di s t r i but i ons .

    The Bernoul l i Di st r i but i on- - - - - - - - - - - - - - - - - - - - - - - - - -

    The Ber noul l i di st r i but i on i s used t o model a pr ocess i n whi ch t her e ar e onl yt wo out comes: success ( X=1) wi t h pr obabi l i t y p, and f ai l ur e ( X=0) wi t hpr obabi l i t y 1- p. I n t hi s case we say t hat t he r andom var i abl e X f ol l owst he Ber noul l i di st r i but i on wi t h success pr obabi l i t y p, or X ~ Ber noul l i ( p) .The probabi l i t y mass f unct i on f ( x) f or t he Bernoul l i di st r i but i on i s f ound byusi ng t he f unct i on "pdf _ber noul l i ". An at t empt t o use "pdf _ber noul l i ( x, p) " showsi t t o be the same as t he Bi nomi al pmf f or n = 1:

    - - > pdf _ber noul l i ( x, p) ;

    ( %o2) pdf _bi nomi al( )x, 1, p

    Usi ng t he pr obabi l i t y of success p = 0. 3, we f i nd t he Ber noul l i pmf f orX = 1 and X = 0:

    - - > pdf _ber noul l i ( 1, 0. 3) ;

    ( %o3) 0. 3

    - - > pdf _ber noul l i ( 0, 0. 3) ;

    ( %o4) 0. 7

    Next, we at t empt t o cal cul at e t he measur es of t he Ber noul l i di st r i but i on f or aparameter p, j ust t o get back t he Bi nomi al measures f or n = 1:

    - - > [ mean_ber noul l i ( p) , var _ber noul l i ( p) , std_ber noul l i ( p) ] ;

    ( %o5) [ mean_bi nomi al( )1, p , var _bi nomi al( )1, p , st d_bi nomi al( )1, p ]

    Act ual cal cul at i ons of t he di st r i but i on measur es wi t h p = 0. 3 are shown bel ow:

    - - > [ mean_ber noul l i ( 0. 3) , var _ber noul l i ( 0. 3) , std_ber noul l i ( 0. 3) ] ;

    ( %o6) [ 0. 3 , 0. 21 , 0. 45825756949558]

    - - > [ skewness_ber noul l i ( 0. 3) , kur t osi s_ber noul l i ( 0. 3) ] ;

    ( %o7) [ 0. 87287156094397 , { 1. 238095238095237]

    The f ol l owi ng command gener ates 10 r andom i nst ances of a Ber noul l i var i abl e wi t hp = 0. 3. We expect t hree 1' s and seven 0' s:

    - - > r andom_ber noul l i ( 0. 3, 10) ;

    ( %o8) [ 1 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0]

    10-10 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    11/80

    ProbabilityDistributionsExamplesDISCRETE.wxmx 2 / 17

    The bi nomi al coef f i ci ent- - - - - - - - - - - - - - - - - - - - - - - -

    Maxi ma i ncl udes f unct i on "bi nomi al " t o cal cul at e t he bi nomi al coef f i ci ent :

    n! bi nomi al ( n, r ) = - - - - - - - - - - r ! ( n- r ) !

    - - > bi nomi al ( n, r ) ;

    ( %o9)n

    r

    - - > bi nomi al ( 8, 3) ;

    ( %o10) 56

    The bi nomi al di st r i but i on- - - - - - - - - - - - - - - - - - - - - - - - -

    I f a Ber noul l i pr ocess wi t h success pr obabi l i t y p i s r epeated n t i mes and we l etX r epr esent t he number of successes i n those n repet i t i ons, t hen we say t hat Xf ol l ows t he Bi nomi al di st r i but i on wi t h par amet er s n and p, i . e. , X~Bi n( n, p) .

    The probabi l i t y mass f unct i on of t he Bi nomi al var i abl e X~Bi n( n, p) i s gi ven by t hef ol l owi ng expr essi on, f or x = 0, 1, 2. . . . , n:

    - - > f ( x)=bi nomi al ( n, x) *p x*( 1- p) ( n- x) ;

    ( %o11) f( )x =n

    x( )1{p n { xpx

    The mean and var i ance of t he Bi nomi al var i abl e X ~ Bi n(n, p) are:

    - - > [ %mu = n*p, %si gma 2=n*p*( 1- p) ] ;

    ( %o12) [ = n p , 2= n ( )1{p p ]

    Cal cul at i ons wi t h t he Bi nomi al di st r i but i on - X ~ Bi n( n, p) wi t h n = 5, p = 0. 2."pdf _bi nomi al ( 2, 5, 0. 2) " cal cul at es P(X=2) = f ( 2) wi t h X ~ Bi n( 5, 0. 2) :

    - - > pdf _bi nomi al ( 2, 5, 0. 2) ;

    ( %o13) 0. 2048

    "cdf _bi nomi al ( 2, 5, 0. 2) " cal cul ates P( X cdf _bi nomi al ( 2, 5, 0. 2) ;

    ( %o14) 0. 94208

    The f ol l owi ng are measur es of t he bi nomi al di st r i but i on X ~ Bi n( 5, 0. 2) :

    10-11 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    12/80

    ProbabilityDistributionsExamplesDISCRETE.wxmx 3 / 17

    - - > [ mean_bi nomi al ( 5, 0. 2) , var _bi nomi al ( 5, 0. 2) , st d_bi nomi al ( 5, 0. 2) ] ;

    ( %o15) [ 1. 0 , 0. 8 , 0. 89442719099992]

    - - > [ skewness_bi nomi al ( 5, 0. 2) , kur t osi s_bi nomi al ( 5, 0. 2) ] ;

    ( %o16) [ 0. 67082039324994 , 0. 05]

    Quant i l es- - - - - - - - -The f ol l owi ng exerci se ser ves t o i l l ust r at e t he i dea of a quant i l e.The command "cdf _bi nomi al ( 2, 5, 0. 2) " r epresent s P( X [ cdf _bi nomi al ( 2, 5, 0. 2) , quant i l e_bi nomi al ( 0. 94, 5, 0. 2) ] ;

    ( %o17) [ 0. 94208 , 2]

    Noti ce t hat i f we use pr ob = 0. 95 i n "quant i l e_bi nomi al ( pr ob, n, p) ", t hen t her esul t i s now 3:

    - - > quant i l e_bi nomi al ( 0. 95, 5, 0. 2) ;

    ( %o18) 3

    Funct i on " r andom_bi nomi al ( 5, 0. 2, 10) " produces 10 r andom numbers t hat f ol l owt he bi nomi al di st r i but i on wi t h n = 5 and p = 0. 2:

    - - > r andom_bi nomi al ( 5, 0. 2, 10) ;

    ( %o19) [ 1 , 3 , 1 , 1 , 0 , 1 , 2 , 3 , 2 , 0]

    The Poi sson di st r i but i on- - - - - - - - - - - - - - - - - - - - - - - -

    When a Bi nomi al var i abl e i s such t hat n i s ver y l ar ge, t hen t he Bi nomi al var i abl ecan be approxi mat ed by t he Poi sson di st r i but i on wi t h par ameter " l ambda" = np. Wesay t hat t he r andomvar i abl e X f ol l ows t he Poi sson di st r i but i on wi t h paramet er" l ambda", or X ~ Poi sson( l ambda) . The Poi sson di st r i but i on can be used t o appr oxi mat et he Bi nomi al di st r i but i on i f "np>5" or "n(1- p) >5".

    The Poi sson di st r i but i on i s used t o model a di scr et e r andom var i abl e r epresent i ng t heoccur r ence of a phenomenon per uni t t i me, or uni t l engt h, or uni t area, or uni t vol umeet c. The pr obabi l i t y mass f unct i on ( pmf ) f or X ~ Poi sson( l ambda) , f or x = 0, 1, 2, . .i nf i ni t y, i s:

    - - > f ( x) =exp( - %l ambda) *%l ambda x/ x! ;

    ( %o20) f( )x =x %e{

    x!

    The mean val ue and var i ance of a Poi sson di st r i but i on are:

    - - > [ %mu = %l ambda, %si gma 2 = %l ambda] ;

    ( %o21) [ = , 2= ]

    10-12 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    13/80

    ProbabilityDistributionsExamplesDISCRETE.wxmx 4 / 17

    The f ol l owi ng exampl es show cal cul at i ons of t he pr obabi l i t y mass f unct i on and cumul at idi st r i but i on f unct i on f or a Poi sson di st r i but i on wi t h par amet er %l ambda = 5. Her e,"pdf _poi sson( 2, 5) " cal cul at es f ( 2) = P( X=2) f or X ~ Poi sson( 5) , whi l e "cdf _poi sson( 2, 5cal cul ates F( 2) = P(X [ pdf _poi sson( 2, 5) , cdf _poi sson( 2, 5) ] ;

    ( %o22) [

    25 %e{ 5

    2 , gamma_i ncompl et e_r egul ar i zed( )3, 5 ]

    - - > f l oat ( %) ;

    ( %o23) [ 0. 084224337488568, 0. 12465201948308]

    The cal cul at i on of t he measures f or X ~ Poi sson(3) are shown next :

    - - > [ mean_poi sson( 3) , var _poi sson( 3) , st d_poi sson( 3) ] ;

    ( %o24) [ 3 , 3 ,p

    3]

    - - > [ skewness_poi sson( 3) , kur t osi s_poi sson( 3) ] ;

    ( %o25) [1p3

    ,1

    3]

    The f ol l owi ng exampl es show quant i l es of X ~ Poi sson(3) :

    - - > [ quant i l e_poi sson( 0. 25, 3) , quant i l e_poi sson( 0. 75, 3) ] ;

    ( %o26) [ 2 , 4]

    The f ol l owi ng pr oduce 10 r andom val ues t hat f ol l ow X ~ Poi sson( 3) :

    - - > r andom_poi sson(3, 10) ;

    ( %o27) [ 3 , 4 , 4 , 4 , 0 , 2 , 6 , 2 , 4 , 4]

    The medi an and quar t i l es- - - - - - - - - - - - - - - - - - - - - - - -I n an exampl e shown above, f or t he Poi sson di st r i but i on, we cal cul ated t he quant i l escorr espondi ng t o cumul at i ve pr obabi l i t i es of 0. 25 ( 25%) and 0. 75 ( 75%) . Thesequant i l es ar e r ef err ed t o as the FI RST QUARTI LE and t he THI RD QUARTI LE, r espect i vel y,as t hey cor r espond t o cumul at i ve pr obabi l i t i es t hat spl i t t he di st r i but i on i n quar t er sThe SECOND QUARTI LE, cor r espondi ng t o a cumul at i ve probabi l i t y of 0. 5 ( 50%) , i s al soknown as the MEDI AN of t he di st r i but i on. Thus, f or t he Poi sson di st r i but i on, wi t hparamet er " l ambda" = 3, we f i nd the f i r st quart i l e (Q1) , t he medi an ( medi an, Q2) , andt hi r d quar t i l e ( Q3) t o be:

    - - > Q1 : quant i l e_poi sson( 0. 25, 3) ;

    ( %o28) 2

    - - > Q2: quant i l e_poi sson( 0. 50, 3) ;

    ( %o29) 3

    - - > Q3 : quant i l e_poi sson( 0. 75, 3) ;

    ( %o30) 4

    10-13 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    14/80

    ProbabilityDistributionsExamplesDISCRETE.wxmx 5 / 17

    The i nt er quar t i l e r ange- - - - - - - - - - - - - - - - - - - - - - -The i nt er quar t i l e r ange ( I QR) i s t he di f f erence between t he t hi r d and t he f i r stquar t i l es, i . e. ,

    I QR = Q3 - Q1

    For exampl e, f or t he Poi sson di st r i but i on wi t h paramet er " l ambda" = 3, t he i nt er -quar t i l e r ange i s:

    - - > I QR : Q3- Q1;

    ( %o31) 2

    The geomet r i c di st r i but i on- - - - - - - - - - - - - - - - - - - - - - - - - -

    Suppose t hat we observe a ser i es of i ndependent Bernoul l i event s wi t h successpr obabi l i t y p, and l et X be the number of i nst ances unt i l , but not i ncl udi ng,t he f i r st successf ul out come. Then X f ol l ows one f or m of t he geomet r i cdi st r i but i on, or X ~ geom( p) . For t hi s case, t he pr obabi l i t y mass f unct i on i sgi ven by

    f ( x) = P( X=x) = p*( 1- p) x, f or x = 0, 1, 2, . . . , i nf i ni t y

    The mean val ue and var i ance ar e:

    - - > [ %mu = ( 1- p) / p, %si gma 2 = ( 1- p) / p 2] ;

    ( %o32) [ =1{p

    p, 2=

    1{p

    p2]

    Cal cul at i ons of pr obabi l i t y mass f unct i on and cumul at i ve di st r i but i on f unct i onf or t he geomet r i c di st r i but i on ar e shown next . "pdf _geomet r i c( 2, 0. 2) " cal cul at esf ( 2) = P(X=2) f or X ~ geom( p) , whi l e " cdf _geomet r i c( 2, 0. 2) " cal cul ates F(2) =P( X pdf _geomet r i c( 2, 0. 2) ;

    ( %o33) 0. 128

    - - > cdf _geomet r i c( 3, 0. 2) ;

    ( %o34) 0. 5904

    Measur es of X ~ geom( 0. 2) ar e shown next :

    - - > [ mean_geomet r i c( 0. 2) , var _geomet r i c( 0. 2) , st d_geomet r i c( 0. 2) ] ;

    ( %o35) [4. 0

    ,20. 0

    ,4. 472135954999579

    ]

    - - > [ skewness_geomet r i c( 0. 2) , kur t osi s_geomet r i c( 0. 2) ] ;

    ( %o36) [ 2. 012461179749811, 6. 05]

    Exampl es of a quant i l es f or t he geomet r i c di st r i but i on wi t h p = 0. 2 i s shownnext :

    - - > [ quant i l e_geomet r i c(0. 3, 0. 2) , quant i l e_geomet r i c(0. 7, 0. 2) ] ;

    ( %o37) [ 1 , 5]

    10-14 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    15/80

    ProbabilityDistributionsExamplesDISCRETE.wxmx 6 / 17

    A l i st of r andom number s x such t hat X ~ geom( 0. 2) :

    - - > r andom_geometr i c( 0. 2, 10) ;

    ( %o38) [ 4 , 9 , 6 , 1 , 3 , 2 , 8 , 3 , 8 , 7]

    Al t er nat i ve def i ni t i on of t he geomet r i c di st r i but i on- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    The def i ni t i on of t he geomet r i c di st r i but i on used by package "di st r i b, " asi ndi cated above, uses a r andom var i abl e X r epr esent i ng the number of i nst ances,i n a ser i es of Ber noul l i t r i al s , unt i l , but not i nc l udi ng, t he f i rs t successf ulout come. An al t er nat i ve def i ni t i on of t he r andomvar i abl e X woul d have i tr epr esent "t he number of i nst ances, i n a ser i es of Ber noul l i t r i al s, unt i l andi ncl udi ng, t he f i r st successf ul out come. " Wi t h t hi s al t er nat i ve def i ni t i on,t he pr obabi l i t y mass f unct i on of t he geomet r i c di st r i but i on, X ~ geom( p) , woul dbe: f ( x) = P( X=x) = p*( 1- p) ( x- 1) , f or x = 1, 2, 3, . . . , i nf i ni t y

    Compare t hi s pmf wi t h t hat of t he geomet r i c di st r i but i on i n "di st r i b", namel y:

    f ( x) = P( X=x) = p*( 1- p) x , f or x = 0, 1, 2, . . . , i nf i ni t y

    Thus, use of t he al t er nat i ve def i ni t i on woul d produce di f f erent val ues ofpr obabi l i t i es. Al so, t he domai n of t he al t er nat i ve def i ni t i on pmf excl udes theval ue x = 0.

    I f you pr ef er t o use t hi s al t er nat i ve def i ni t i on of t he geomet r i c di st r i but i on,you can def i ne your own pmf ( or pdf ) and cdf f unct i ons as ( A = al t er nat i ve) :

    - - > pdf _geomet r i c_A( x, p) : =pdf _geomet r i c( x- 1, p) ;

    ( %o39) pdf _geomet r i c_A( )x, p : =pdf _geomet r i c( )x{ 1, p

    - - > cdf _geomet r i c_A( x, p) : =cdf _geomet r i c( x- 1, p) ;

    ( %o40) cdf _geomet r i c_A( )x, p : =cdf _geomet r i c( )x{ 1, p

    Exampl es compar i ng t he "di st r i b" def i ni t i on of t he geomet r i c di st r i but i on andt he al t er nat i ve def i ni t i on are shown bel ow:

    - - > [ pdf _geomet r i c_A( 5, 0. 2) , pdf _geomet r i c( 4, 0. 2) ] ;

    ( %o41) [ 0. 08192 , 0. 08192]

    - - > [ pdf _geomet r i c_A( 5, 0. 2) , pdf _geomet r i c( 5, 0. 2) ] ;

    ( %o42) [ 0. 08192 , 0. 065536]

    - - > [ cdf _geomet r i c_A( 5, 0. 2) , cdf _geomet r i c( 4, 0. 2) ] ;

    ( %o43) [ 0. 67232 , 0. 67232]

    - - > [ cdf _geomet r i c_A( 5, 0. 2) , cdf _geomet r i c( 5, 0. 2) ] ;

    ( %o44) [ 0. 67232 , 0. 737856]

    - - > [ pdf _geomet r i c_A( 1, 0. 2) , pdf _geomet r i c( 0, 0. 2) ] ;

    ( %o45) [ 0. 2 , 0. 2]

    10-15 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    16/80

    ProbabilityDistributionsExamplesDISCRETE.wxmx 7 / 17

    The f ol l owi ng r esul t s compare t he mean and var i ance of t he geometr i c di st r i but i onusi ng t he def i ni t i on i n package "di st r i b" and t he al t er nat i ve def i ni t i on shownabove: package "di str i b" al t er nat i ve def i ni t i on

    mean: ( 1- p) / p 1/ pvar i ance: ( 1- p) / p 2 ( 1- p) / p 2

    Thus, t he mean t urns out t o be di f f erent between t he t wo def i ni t i ons, but t hevar i ance i s t he same.

    The negat i ve bi nomi al di st r i but i on- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Suppose t hat i nst ead of watchi ng f or t he f i r st occur r ence of a succesf ul out come i na ser i es of i ndependent Ber noul l i t r i al s, as we di d f or t he geomet r i c di st r i but i on,we f ocus on t he number of t r i al s X unt i l , but not i ncl udi ng, t he r - t h succesf ul out comI n t hi s case we say t hat X f ol l ows t he negat i ve bi nomi al di st r i but i on wi t h paramet er sr and p ( p i s t he success pr obabi l i t y of t he Ber noul l i t r i al s) , or X ~ NB( r , p) .

    The probabi l i t y mass f unct i on of t he negat i ve bi nomi al X ~ NB( r , p) , f or x = r , r +1, . . . ,i s gi ven by:

    - - > f ( x) =bi nom( r +x- 1, r - 1) *p r *( 1- p) x;

    ( %o46) f( )x =( )1{p xpr x+ r{ 1

    r{ 1

    Cal cul at i ons of pr obabi l i t y mass f unct i on and cumul at i ve di st r i but i on f unct i onf or t he negati ve bi nomi al di st r i but i on ar e shown next:"pdf _negat i ve_bi nomi al ( 5, 3, 0. 2) " cal cul at es f ( 5) = P( X=5) f or X ~ NB( 3, 0. 2)"cdf _negat i ve_bi nomi al ( 5, 3, 0. 2) " cal cul at es F( 5) = P( X pdf _negat i ve_bi nomi al ( 5, 3, 0. 2) ;

    ( %o47) 0. 05505024

    - - > cdf _negat i ve_bi nomi al ( 5, 3, 0. 2) ;

    ( %o48) 0. 20308224

    The mean and var i ance of t he negat i ve bi nomi al di st r i but i on are gi ven by:

    - - > [ %mu = r *( 1- p) / p, %si gma 2 = r *( 1- p) / p 2] ;

    ( %o49) [ =( )1{p r

    p, 2=

    ( )1{p r

    p2]

    The f ol l owi ng cal cul ati ons show t he measur es of t he negat i ve bi nomi al di st r i but i onf or X ~ NB( 3, 0. 2) :

    - - > [ mean_negat i ve_bi nomi al ( 3, 0. 2) ] ;

    ( %o50) [ 12. 0]

    - - > [ var _negat i ve_bi nomi al ( 3, 0. 2) , st d_negat i ve_bi nomi al ( 3, 0. 2) ] ;

    ( %o51) [ 60. 0 , 7. 745966692414834]

    10-16 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    17/80

    ProbabilityDistributionsExamplesDISCRETE.wxmx 8 / 17

    - - > [ skewness_negat i ve_bi nomi al ( 3, 0. 2) , kur t osi s_negat i ve_bi nomi al ( 3, 0. 2) ] ;

    ( %o52) [ 1. 161895003862225, 2. 016666666666666]

    Funct i on "quant i l e_negat i ve_bi nomi al ( pr ob, r , p) " cal cul at es quant i l es of t henegat i ve bi nomi al di st r i but i on. The f ol l owi ng exampl es show t he cal cul at i onsof t he f i r st and t hi r d quar t i l es ( Q1, Q3) , t he medi an, and t he i nt er quar t i l er ange f or X ~ NB( 3, 0. 2) :

    - - > Q1 : quant i l e_negat i ve_bi nomi al ( 0. 25, 3, 0. 2) ;

    ( %o53) 6

    - - > Q2 : quant i l e_negat i ve_bi nomi al ( 0. 50, 3, 0. 2) ;

    ( %o54) 11

    - - > Q3 : quant i l e_negat i ve_bi nomi al ( 0. 75, 3, 0. 2) ;

    ( %o55) 15

    - - > I QR : Q3 - Q1;

    ( %o56) 9

    The f ol l owi ng command generat es 10 r andom number s X ~ NB( 3, 0. 2) :

    - - > r andom_negat i ve_bi nomi al ( 3, 0. 2, 10) ;

    ( %o57) [ 17, 40, 4 , 11, 15, 7 , 5 , 5 , 13, 5]

    Al t er nat i ve def i ni t i on of t he negat i ve bi nomi al di st r i but i on- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    An al t er nat i ve def i ni t i on of t he negat i ve bi nomi al di st r i but i on f ol l ows i f wel et X be t he number of t r i al s up t o, and i ncl udi ng, t he r - t h successf ul out comei n a ser i es of i ndependent Ber noul l i t r i al s wi t h success pr obabi l i t y p. For t hi sdef i ni t i on, t he random var i abl e X ~ NB( r , p) woul d have the f ol l owi ng pr obabi l i t ymass f uncti on f or x = r +1, r +2, . . . , i nf i ni t y:

    - - > f ( x) =bi nom( x- 1, r - 1) *p r *( 1- p) ( x- r ) ;

    ( %o58) f( )x =( )1{p x{ rpr x{ 1

    r{ 1

    Compare wi t h the pmf used i n the negat i ve bi nomi al avai l abl e i n package "di st " f orx = r , r+1, . . . , i nf i ni t y:

    - - > f ( x) =bi nom( r +x- 1, r - 1) *p r *( 1- p) x;

    ( %o59) f( )x =( )1{p xpr x+ r{ 1

    r{ 1

    I f you pr ef er t o use t he al t er nat i ve def i ni t i on of t he geomet r i c di st r i but i on,you can def i ne your own pmf ( or pdf ) and cdf f unct i ons as ( A = al t er nat i ve) :

    - - > pdf _negat i ve_bi nomi al _A( x, r , p) : =pdf _negat i ve_bi nomi al ( x- r , r , p) ;

    ( %o60) pdf _negat i ve_bi nomi al _A( )x, r, p : =pdf _negat i ve_bi nomi al( )x{ r, r, p

    10-17 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    18/80

    ProbabilityDistributionsExamplesDISCRETE.wxmx 9 / 17

    - - > cdf _negat i ve_bi nomi al _A( x, r , p) : =cdf _negat i ve_bi nomi al ( x- r , r , p) ;

    ( %o61) cdf _negat i ve_bi nomi al _A( )x, r, p : =cdf _negat i ve_bi nomi al( )x{ r, r, p

    Exampl es compar i ng t he "di st r i b" def i ni t i on of t he geomet r i c di st r i but i on andt he al t er nat i ve def i ni t i on are shown bel ow:

    - - > [ pdf _negat i ve_bi nomi al _A( 5, 3, 0. 2) , pdf _negat i ve_bi nomi al ( 2, 3, 0. 2) ] ;( %o62) [ 0. 03072 , 0. 03072]

    - - > [ cdf _negat i ve_bi nomi al _A( 5, 3, 0. 2) , cdf _negat i ve_bi nomi al ( 2, 3, 0. 2) ] ;

    ( %o63) [ 0. 05792 , 0. 05792]

    - - > [ pdf _negat i ve_bi nomi al _A( 5, 3, 0. 2) , pdf _negat i ve_bi nomi al ( 5, 3, 0. 2) ] ;

    ( %o64) [ 0. 03072 , 0. 05505024]

    The f ol l owi ng r esul t s compare t he mean and var i ance of t he negat i ve bi nomi aldi st r i but i on usi ng t he def i ni t i on i n package "di st r i b" and t he al t er nat i vedef i ni t i on shown above:

    package "di str i b" al t er nat i ve def i ni t i on

    mean: r *( 1- p) / p r / pvar i ance: r *( 1- p) / p 2 r *( 1- p) / p 2

    Agai n, t he mean t ur ns out t o be di f f er ent between t he t wo def i ni t i ons, but t hevar i ance i s t he same.

    The hyper geomet r i c di st r i but i on- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    Consi der a f i ni t e popul at i on made of n1 el ement s t hat are consi der ed f ai l ur esand n2 el ement s t hat ar e consi der ed successes, so that t he t otal popul at i on si zei s N = n1+n2. Next , t ake a sampl e of n el ement s f r om t hat popul at i on, and l etX r epr esent t he number of successes i n t he sampl e of si ze n. Then, we say t hatX f ol l ows t he hyper geomet r i c di st r i but i on wi t h par amet er s n1, n2, and n, i . e. ,X ~ H( n1, n2, n) . The pr obabi l i t y mass f unct i on f or t he hyper geomet r i cdi st r i but i on X ~ H( N, R, n) , i n t he domai n max( 0, n- n2)

  • 8/13/2019 Maxima Book Chapter 10

    19/80

    ProbabilityDistributionsExamplesDISCRETE.wxmx 10 / 17

    - - > pdf _hyper geomet r i c( 3, 5, 15, 10) ; f l oat( %) ;

    ( %o66)225

    646( %o67) 0. 34829721362229

    - - > cdf _hyper geomet r i c( 3, 5, 15, 10) ; f l oat ( %) ;

    ( %o68) 274323

    ( %o69) 0. 84829721362229

    The mean val ue and var i ance of t he hypergeometr i c di st r i but i on are gi ven by:

    - - > [ %mu=( n*n1) / ( n1+n2) , %si gma 2=n*( n1/ ( n1+n2) ) *( n2/ ( n1+n2) ) *( ( n1+n2- n) / ( n1+n2- 1) ) ] ;

    ( %o70) [ = n n1

    n2 + n1, 2=

    n n1 n2 ( )n2 + n1 { n

    ( )n2 + n1 { 1 ( )n2 + n1 2]

    Cal cul at i ons of t he measur es of t he hyper geomet r i c di st r i but i on, gi ven byX ~ H( 5, 15, 10) are shown bel ow:

    - - > [ mean_hyper geomet r i c( 5, 15, 10) ] ; f l oat ( %) ;

    ( %o71) [5

    2]

    ( %o72) [ 2. 5]

    - - > [ var _hyper geomet r i c( 5, 15, 10) , st d_hyper geomet r i c( 5, 15, 10) ] ; f l oat ( %) ;

    ( %o73) [75

    76,

    5p

    3

    2 p19]

    ( %o74) [ 0. 98684210526316 , 0. 99339926779878]

    - - > [ skewness_hyper geomet r i c( 5, 15, 10) , kur t osi s_hyper geomet r i c( 5, 15, 10) ] ; f l oat ( %) ;

    ( %o75) [ 0 , {62

    255]

    ( %o76) [ 0. 0 , { 0. 24313725490196]

    The quar t i l es of t hi s hyper geomet r i c di st r i but i on, namel y, X ~ H( 5, 15, 10) ,are gi ven by:

    - - > Q1 : quant i l e_hyper geomet r i c( 0. 25, 5, 15, 10) ;

    ( %o77) 2

    - - > Q2 : quant i l e_hyper geomet r i c( 0. 50, 5, 15, 10) ;

    ( %o78) 2

    - - > Q3 : quant i l e_hyper geomet r i c( 0. 75, 5, 15, 10) ;

    ( %o79) 3

    A ser i es of 20 r andom val ues of X ~ H( 5, 15, 10) can be generat ed by usi ng:

    10-19 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    20/80

    ProbabilityDistributionsExamplesDISCRETE.wxmx 11 / 17

    - - > r andom_hypergeomet r i c( 5, 15, 10, 20) ;

    ( %o80) [ 3 , 4 , 4 , 3 , 4 , 3 , 2 , 4 , 3 , 2 , 2 , 2 , 3 , 4 , 4 , 2 , 2 , 4 , 3 , 3]

    Al t er nat i ve def i ni t i on of t he hyper geomet r i c di st r i but i on- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    Consi der a f i ni t e popul at i on of N el ement s, out of whi ch t her e are R el ement sl abel ed as " success" ( R

  • 8/13/2019 Maxima Book Chapter 10

    21/80

    ProbabilityDistributionsExamplesDISCRETE.wxmx 12 / 17

    - - > [ pdf _di scr et e_uni f or m( 2, 5) , pdf _di scret e_uni f or m( 4, 5) ] ;

    ( %o86) [1

    5,

    1

    5]

    - - > [ cdf _di scr et e_uni f or m( 0, 5) , cdf _di scret e_uni f or m( 6, 5) ] ;

    ( %o87) [ 0 , 1]

    - - > [ cdf _di scr et e_uni f or m( 2, 5) , cdf _di scret e_uni f or m( 4, 5) ] ;

    ( %o88) [2

    5,

    4

    5]

    The mean and var i ance of t he di scret e uni f or m di st r i but i onX ~ DU( n=5) ar e:

    - - > [ %mu = ( n+1) / 2, %si gma 2 =( n 2- 1) / 12] ;

    ( %o89) [ =n + 1

    2, 2=

    n2{ 1

    12]

    Measures of t he di scr et e uni f orm di st r i but i on X ~ DU( n=5) are:

    - - > [ mean_di scr et e_uni f orm( 5) ] ;

    ( %o90) [ 3]

    - - > [ var _di scr et e_uni f or m( 5) , st d_di scr et e_uni f or m( 5) ] ;

    ( %o91) [ 2 ,p

    2]

    - - > [ skewness_di scret e_uni f or m( 5) , kur t osi s_di scret e_uni f or m( 5) ] ;

    ( %o92) [ 0 , { 1310

    ]

    Quar t i l es of t he di scret e uni f or m di st r i but i on X ~ DU( n=5) :

    - - > Q1 : quant i l e_di scret e_uni f or m( 0. 25, 5) ;

    ( %o93) 2

    - - > Q2 : quant i l e_di scret e_uni f or m( 0. 50, 5) ;

    ( %o94) 3

    - - > Q3 : quant i l e_di scret e_uni f or m( 0. 75, 5) ;

    ( %o95) 4

    The f ol l owi ng command generat es 20 r andom numbers X ~ DU( n=5) :

    - - > r andom_di scr et e_uni f orm( 5, 20) ;

    ( %o96) [ 3 , 3 , 4 , 4 , 1 , 1 , 3 , 3 , 2 , 3 , 1 , 4 , 1 , 2 , 4 , 1 , 2 , 1 , 2 , 4]

    10-21 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    22/80

  • 8/13/2019 Maxima Book Chapter 10

    23/80

    ProbabilityDistributionsExamplesDISCRETE.wxmx 14 / 17

    Al l of t he pr obabi l i t y di st r i but i ons cont ai ned i n t he "di st r i b" package cor r espond t odomai ns of X t hat i ncr ease one- by- one. For such cases, t he f ol l owi ng equat i ons appl yi n t he cal cul at i on of pr obabi l i t y di str i but i ons:

    ( 1) Def i ni t i on of t he pmf ( or pdf ) : P( X=x) = f ( x) , pdf _ i n Maxi ma( 2) Def i ni t i on of t he cdf : P(X

  • 8/13/2019 Maxima Book Chapter 10

    24/80

    ProbabilityDistributionsExamplesDISCRETE.wxmx 15 / 17

    Let ' s cal cul at e, f or exampl e, t he pr obabi l i t y: P( XB cdf _bi nomi al ( 10, 200, 0. 05) ;

    ( %o111) 0. 58306718208111

    The cor r espondi ng appr oxi mat i on usi ng t he Poi sson di st r i but i on i s:

    - - > l ambda :n*p; f l oat ( cdf _poi sson( 10, l ambda) ) ;

    ( %o112) 10. 0( %o113) 0. 58303975019299

    Not i ce t hat t he di f f er ence bet ween t he t wo pr obabi l i t i es i s i n t he 5- t hdeci mal . Ot her exampl es:( 1) P( XB>10) = 1 - P( XB [ 1 - cdf _bi nomi al ( 10, n, p) , f l oat ( 1 - cdf _poi sson( 10, l ambda) ) ] ;

    ( %o114) [ 0. 41693281791889 , 0. 41696024980701]

    ( 2) P(10 x : makel i st ( k, k, 0, 20) ;( %o116) [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]

    10-24 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    25/80

    ProbabilityDistributionsExamplesDISCRETE.wxmx 16 / 17

    - - > f : makel i st( pdf _bi nomi al ( x[ k] , 20, 0. 5) , k, 1, 21) ;

    ( %o117) [ 9. 5367431640625 10- 7, 1. 9073486328125 10- 5, 1. 811981201171875 10- 4,0. 0010871887207031, 0. 0046205520629883 , 0. 014785766601563,0. 036964416503906, 0. 073928833007813, 0. 1201343536377 , 0. 16017913818359,0. 17619705200195 , 0. 16017913818359 , 0. 1201343536377 , 0. 073928833007813,

    0. 036964416503906, 0. 014785766601563, 0. 0046205520629883,

    0. 0010871887207031, 1. 811981201171875 10- 4, 1. 9073486328125 10- 5,

    9. 5367431640625 10- 7]

    - - > F : makel i st ( cdf _bi nomi al ( x[ k] , 20, 0. 5) , k, 1, 21) ;

    ( %o118) [ 9. 5367431640625614 10- 7, 2. 0027160644531552 10- 5, 2. 0122528076171956

    10- 4, 0. 0012884140014649, 0. 0059089660644531, 0. 020694732666016,0. 057659149169922, 0. 13158798217774 , 0. 25172233581543, 0. 41190147399903,0. 58809852600097 , 0. 74827766418457 , 0. 86841201782226, 0. 94234085083008,0. 97930526733398 , 0. 99409103393555 , 0. 99871158599854, 0. 99979877471924,0. 99997997283936 , 0. 99999904632568 , 1]

    - - > wxpl ot 2d( [ di scret e, x, f ] , [ s tyl e, [ poi nt s , 3, 2, 2] ] ) ;

    ( %t 119)

    ( %o119)

    10-25 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    26/80

    ProbabilityDistributionsExamplesDISCRETE.wxmx 17 / 17

    - - > wxpl ot 2d( [ di scret e, x, F] , [ s tyl e, [ poi nt s , 3, 2, 2] ] ) ;

    ( %t 122)

    ( %o122)

    10-26 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    27/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 1 / 41

    ( %i 7) l oad("di s t r i b" ) $

    CALCULATI ONS WI TH CONTI NUOUS DI STRI BUTI ONS==========================================

    Cont i nuous di st r i but i ons come i n many f l avors. Basi cal l y al l what you need i s acont i nuous f unct i on f ( x) >0, known as t he pr obabi l i t y densi t y f unct i on ( pdf ) , t hat

    sat i sf i es t he condi t i on t hat :

    - - > i nt egr at e( f ( x) , x, mi nf , i nf ) =1;

    ( %o637)

    Z{1

    1

    f( )xdx= 1

    The nor mal di st r i but i on- - - - - - - - - - - - - - - - - - - - - - -

    The nor mal di st r i but i on t akes that name because i t s pdf i s used t o model t he

    behavi or of many physi cal ( and other ) phenomena that behave "normal l y. " I t i sal so cal l ed t he Gaussi an di st r i but i on or bel l cur ve ( due t o t he char act er i st i cbel l - shaped cur ve of i t s pdf ) . [ I n Spani sh i t i s known as "l a campana de Gauss( Gauss' bel l ) " . ]

    The pdf of t he normal di st r i but i on i s def i ned i n t er ms of t wo paramet er s: %muand %si gma, whi ch act ual l y r epr esent t he mean and st andar d devi at i on of acont i nuous r andom var i abl e X. We say t hat X f ol l ows t he nor mal di st r i but i onwi t h par amet er s %mu and %si gma, or X ~ N( %mu, %si gma) . The cor r espondi ng pdf ,val i d f or al l r eal number s, i s gi ven by:

    - - > f ( x) = 1/ ( %si gma*sqr t ( 2*%pi ) ) *exp( - ( x- %mu) 2/ ( 2*%si gma) ) ;

    ( %o638) f( )x =%e{

    ( )x{ 2

    2 p2p

    A pl ot of t he nor mal pdf f or %mu = 1200, %si gma = 300 i s shown bel ow:

    10-27 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    28/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 2 / 41

    - - > wxpl ot 2d( pdf _nor mal ( x, 1200, 300) , [ x, 0, 2400] ) ;

    ( %t 639)

    ( %o639)

    For a cont i nuous di st r i but i on t he cumul at i ve di st r i but i on f unct i on ( cdf )F( x) i s def i ned, i n t er ms of t he pdf f ( x) , by:

    - - > F(x)=i nt egr at e( f ( %xi ) , %xi , mi nf , x) ;

    ( %o640) F( )x =

    Z{1

    x

    f( ) d

    A pl ot f or t he nor mal cdf wi t h %mu = 1200 and %si gma = 300 i s shown bel ow:

    - - > wxpl ot 2d( cdf _nor mal ( x, 1200, 300) , [ x, 0, 2400] ) ;

    ( %t 641)

    ( %o641)

    Measures of t he normal di st r i but i on X ~ N( 1200, 300) ar e cal cul at ed next :

    10-28 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    29/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 3 / 41

    - - > [ mean_normal ( 1200, 300) , var _normal ( 1200, 300) , st d_normal ( 1200, 300) ] ;

    ( %o642) [ 1200 , 90000 , 300]

    - - > [ skewness_normal ( 1200, 300) , kur t osi s_nor mal ( 1200, 300) ] ;

    ( %o643) [ 0 , 0]

    Pr obabi l i t i es f or cont i nuous di st r i but i ons ar e cal cul at ed f or i nt er val sof t he r andomvar i abl e X usi ng t he cumul at i ve di st r i but i on f unct i on ( CDF)accor di ng t o t he f ol l owi ng:

    ( 1) P( Xx) = 1 - P( X

  • 8/13/2019 Maxima Book Chapter 10

    30/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 4 / 41

    - - > Q1: f l oat ( quant i l e_normal ( 0. 25, 1200, 300) ) ;

    ( %o650) 997. 6530749411754

    To pr oduce, say, 5 val ues of X ~ N( 1200, 300) use the f ol l owi ng command:

    - - > r andom_nor mal ( 1200, 300, 5) ;

    ( %o651) [ 1461. 969267753788, 1490. 428719983386, 835. 5971211746528,751. 065724173536, 1385. 822704318661]

    The er r or f unct i on- - - - - - - - - - - - - - - - - -

    Not i ce t hat t he nor mal pr oabi l i t i es cal cul at ed above ar e f i r st gi ven i nsymbol i c f or m i n t er ms of t he er r or f unct i on ( er f ) , whi ch i s def i ned by2

    - - > er f ( x) = 2/ sqr t ( %pi ) *' i nt egr at e( exp( - t 2) , t , 0, x) ;

    ( %o652) er f( )x =2Z

    0

    x

    %e

    {t2

    dt

    p

    A pl ot of t he er r or f unct i on i s shown bel ow:

    - - > wxpl ot 2d( er f ( x) , [ x, - 3, 3] ) ;

    ( %t 653)

    ( %o653)

    Associ at ed wi t h the er r or f unct i on i s t he "compl ement ar y er r or f unct i on,er f c(x) ", def i ned as er f c(x) = 1 - er f ( x) .

    The st andar d normal di st r i but i on- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    10-30 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    31/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 5 / 41

    A "st andar di zed" var i abl e Z i s def i ned i n t er ms of a r andomvar i abl e Xwi t h mean val ue %mu and st andar d devi at i on %si gma as:

    - - > Z = ( X- %mu) / %si gma;

    ( %o654) Z=X{

    You can ver i f y, by appl yi ng t he def i ni t i ons of a mean val ue and st andar ddevi at i on, t hat t he mean and st andard devi at i on of Z are 0 and 1, r espect i vel y.

    I n t erms of normal di st r i but i ons, i f X ~ N( %mu, %si gma) , t hen Z ~ N( 0, 1) .The di st r i but i on of Z i s known as t he "st andar d normal di st r i but i on", andhas appl i cat i ons i n stati st i cal i nf er ence ( e. g. , r el at ed t o cal cul at i ngconf i dence i nt erval s and hypothesi s t est i ngs on means) .

    The pr obabi l i t y densi t y f unct i on of t he st andar d normal var i abl e, Z ~ N( 0, 1) , i s:

    - - > %phi ( z) =1/ sqrt ( 2*%pi ) *exp( - z 2/ 2) ;

    ( %o655) '( )z =%e{

    z2

    2p2p

    Thi s f unct i on i s symmet r i c about z = 0, and shows t he typi cal bel l - shaped cur veof t he nor mal di st r i but i on:

    - - > wxpl ot 2d( pdf _nor mal ( z, 0, 1) , [ z, - 4, 4] ) ;

    ( %t 656)

    ( %o656)

    The pl ot of t he st andar d normal cur ve, shown above, i ndi cat es t hat t heor di nat es of t he cur ve go cl ose to zer o wi t hi n 4 standar d devi at i onsof t he mean. ( Recal l t hat t he mean of Z i s zer o, and i t s st andarddevi at i on i s one. ) Al so, one can cal cul at e t he pr obabi l i t i es cont ai nedi n t he di st r i but i on i n i nt er val s l ocat ed wi t hi n 1, 2, and 3 st andar ddevi at i ons f r om t he mean and f i nd t he f ol l owi ng r esul t s. To start wi t h,we cal cul ate P( - 1 < Z < 1) usi ng:

    10-31 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    32/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 6 / 41

    - - > cdf _nor mal ( 1, 0, 1) - cdf _nor mal ( - 1, 0, 1) ; f l oat ( %) ;

    ( %o657) er f

    1p2

    ( %o658) 0. 68268949213709

    That means t hat 68. 26% of pr obabi l i t y i s cont ai ned wi t hi n one st andard

    devi at i on f r om t he mean. Al so, cal cul at i ng P( - 2 < Z < 2) :

    - - > cdf _nor mal ( 2, 0, 1) - cdf _nor mal ( - 2, 0, 1) ; f l oat ( %) ;

    ( %o659) er f( )p

    2( %o660) 0. 95449973610364

    we f i nd t hat 95. 44% of probabi l i t y i s cont ai ned wi t hi n t wo st andar ddevi at i ons f r om t he mean. Fi nal l y, cal cul at i ng P( - 3 < Z < 3) :

    - - > cdf _nor mal ( 3, 0, 1) - cdf _nor mal ( - 3, 0, 1) ; f l oat ( %) ;

    ( %o661) er f 3p

    2

    ( %o662) 0. 99730020393674

    we f i nd t hat 99. 73% ( al most 100%) of pr obabi l i t y i s cont ai ned wi t hi nt hr ee st andard devi at i ons f r omt he mean.

    The cumul at i ve di st r i but i on f unct i on of t he st andar d normal var i abl edoes not have a cl osed f orm expr essi on because i t i nvol ves an i nt egr alof t he exponent i al of x squared, namel y,

    - - > %Phi ( z) = 1/ sqr t ( 2*%pi ) *' i nt egr at e( exp( - %xi 2/ 2) , %xi , mi nf , z) ;

    ( %o663) ( )z =

    Z{1

    z

    %e{

    2

    2 d

    p2p

    I n year s past , bef ore handhel d cal cul ators and comput ers wer e r eadi l yavai l abl e, nor mal pr obabi l i t y cal cul at i ons wer e per f or med by r ef er r i ng t oa t abl e of t he st andard normal cdf based on t he f ol l owi ng r el at i onshi pbetween a normal var i abl e X ~ N( %mu, %si gma) and t he st andar d nor malvar i abl e Z ~ N( 0, 1) :

    - - > ' P( X

  • 8/13/2019 Maxima Book Chapter 10

    33/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 7 / 41

    Ot her pr obabi l i t y cal cul at i ons f or X ~ N( %mu, %si gma) r el at ed to t hose ofZ ~ N( 0, 1) are t he f ol l owi ng:

    ( a) P( X>x) = 1 - P( X

  • 8/13/2019 Maxima Book Chapter 10

    34/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 8 / 41

    - - > [ n*p, n*( 1- p) ] ;

    ( %o673) [ 8. 0 , 92. 0]

    Try t he exampl e: P( XB7) = 1 - P(XB

  • 8/13/2019 Maxima Book Chapter 10

    35/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 9 / 41

    I n t hi s case t he di f f er ence i n t he pr obabi l i t i es i s f ound i n t he seconddeci mal .

    Ot her exampl es of pr obabi l i t y cal cul at i ons are shown next :( 1) P( XP>7) = 1 - P(X{P

  • 8/13/2019 Maxima Book Chapter 10

    36/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 10 / 41

    - - > wxpl ot 2d( pdf _l ognor mal ( x, 0. 2, 0. 5) , [ x, 0. 0, 5. 0] ) ;

    ( %t 684)

    ( %o684)

    Pr obabi l i t i es can be cal cul at ed wi t h f unct i on "cdf _l ognor mal ( x, %mu[ Y], %si gma[ Y] ) " .For exampl e, gi ven X ~ l ognormal ( 0. 2, 0. 5) , we cal cul at e:

    ( a) P(X cdf _l ognor mal ( 1. 2, 0. 2, 0. 5) ; f l oat ( %) ;

    ( %o685)1

    2{

    er f

    0. 035356886412091p

    2

    2

    ( %o686) 0. 48589758142911

    ( b) P(X>0. 8) = 1 - P(X 1 - cdf _l ognor mal ( 0. 8, 0. 2, 0. 5) ; f l oat ( %) ;

    ( %o687)

    er f

    0. 84628710262842p

    2

    2 +

    1

    2( %o688) 0. 80130369950568

    ( c) P(0. 8

  • 8/13/2019 Maxima Book Chapter 10

    37/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 11 / 41

    - - > [ %mu[ X] = exp( %mu[ Y] +1/ 2*%si gma[ Y] 2) ,%si gma[ X] 2 = exp(2*%mu[ Y] +%si gma[ Y] 2) *( exp(%si gma[ Y] 2) - 1) ] ;

    ( %o691) [ X=%e

    Y2

    2+ Y

    , X2 =

    %eY

    2{1 %eY

    2 + 2Y]

    The measur es of X ~ l ognor mal ( 0. 2, 0. 5) can be f ound as:

    - - > [ mean_l ognor mal ( 0. 2, 0. 5) , var _l ognor mal ( 0. 2, 0. 5) , st d_l ognor mal ( 0. 2, 0. 5) ] ;

    ( %o692) [ 1. 384030645980751, 0. 54406228214305 , 0. 73760577691817]

    - - > [ skewness_l ognor mal ( 0. 2, 0. 5) , kur t osi s_l ognor mal ( 0. 2, 0. 5) ] ;

    ( %o693) [ 1. 750189655069718, 8. 898445673784778]

    Quar t i l es of X ~ l ognor mal ( 0. 2, 0. 5) ar e cal cul at ed as f ol l ows:

    - - > Q1 : f l oat ( quant i l e_l ognor mal ( 0. 25, 0. 2, 0. 5) ) ;

    ( %o694) 0. 87175672847869

    - - > Q2 : f l oat ( quant i l e_l ognor mal ( 0. 50, 0. 2, 0. 5) ) ;

    ( %o695) 1. 22140275816017

    - - > Q1 : f l oat ( quant i l e_l ognor mal ( 0. 75, 0. 2, 0. 5) ) ;

    ( %o696) 1. 711285555827784

    To gener at e, say, 5 val ues of X ~ l ognormal ( 0. 2, 0. 5) use:

    - - > r andom_l ognormal ( 0. 2, 0. 5, 5) ;

    ( %o697) [ 1. 232156558962817, 1. 925711055107971, 2. 080534411554896,0. 66458324247616 , 0. 86889118540493]

    NOTE: I n year s past , t abl es of t he cdf f or t he st andar d normal di st r i but i on,%Phi ( z) , woul d have been used t o cal cul at e pr obabi l i t i es of t he l ognormaldi st r i but i on by usi ng t he f ol l owi ng t r ansf or mat i on:

    P( X

  • 8/13/2019 Maxima Book Chapter 10

    38/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 12 / 41

    - - > F(x) : =i ntegrat e( f ( t ) , t , a, x) ; F( x) ;

    ( %o699) F( )x: =

    Za

    x

    f( )t dt

    ( %o700)x{a

    b{a

    Thus, i f X f ol l ows the cont i nuous uni f or m di st r i but i on i n t he i nt er val [ a, b] ,we can wr i t e X ~ CU( a, b) . The mean and var i ance of t he cont i nuous uni f or mdi str i but i on ar e:

    - - > [ %mu = ( a+b) / 2, %si gma 2 = ( b- a) 2/ 12] ;

    ( %o701) [ =b+a

    2, 2=

    ( )b{a 2

    12]

    Usi ng t he f unct i ons def i ned i n t he "di st r i b" package, we can cal cul at e t hef ol l owi ng f or t he cont i nuous uni f or m di st r i but i on:

    ( 1) pdf : pdf _cont i nuous_uni f or m( x, a, b) - use i t t o pl ot t he pdf( 2) cdf : cdf _cont i nuous_uni f or m( x, a, b) = F(x) = P( X %Gamma( z) =' i nt egr at e( exp( - t ) *t ( z- 1) , t , 0, i nf ) ;

    ( %o702) ( )z =

    Z0

    1

    tz{ 1 %e{tdt

    I f z i s an i nt eger , t he f ol l owi ng r esul t s r el at i ng t he gamma f unct i on t o t he f act or i alof an i nt eger ar e f ound:

    - - > [ %Gamma( n+1) = n! , %Gamma( n) =( n- 1) ! ] ;

    ( %o703) [ ( )101 =933262154439441526816992388562[ 98 di gi t s] 916864000000000000000000000000,

    ( )100 =933262154439441526816992388562[ 96 di gi t s] 109168640000000000000000000000]

    The gamma f unct i on i s not def i ned f or negat i ve i nt eger val ues. The f ol l owi ng i s a pl oof t he gamma f unct i on:

    10-38 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    39/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 13 / 41

    - - > wxpl ot 2d( gamma( x) , [ x, - 4, 4] , [ y, - 10, 10] ) ;

    gamma: gamma( - 4. 0) i s undef i ned.gamma: gamma( 0. 0) i s undef i ned.gamma: gamma( - 3. 0) i s undef i ned.gamma: gamma( - 2. 0) i s undef i ned.gamma: gamma( - 1. 0) i s undef i ned.pl ot2d: expr essi on eval uates to non- numer i c val ue somewhere i n pl ot t i ng r ange.

    pl ot2d: some val ues were cl i pped.

    ( %t 704)

    ( %o704)

    The gamma di st r i but i on- - - - - - - - - - - - - - - - - - - - - -

    The gamma di st r i but i on uses t wo par amet er s: a shape par amet er ( %al pha) and ascal e parameter ( %bet a) . A cont i nuous r andomvar i abl e X t hat f ol l ows t hegamma di st r i but i on wi t h paramet er s %al pha and %bet a, i . e. , X ~ gamma( %al pha, %bet a) ,has t he f ol l owi ng pr obabi l i t y densi t y f unct i on, f or x > 0:

    - - > f ( x) : =( ( x/ %beta) ( %al pha- 1) *exp( - ( x/ %beta) ) ) / ( %beta*gamma(%al pha) ) ;

    ( %o705) f( )x: =

    x

    { 1

    exp

    {x

    ( )

    The graph bel ow shows t he pdf pl ot s f or di f f erent gamma f unct i ons. As you can see

    f r om t hi s gr aph you can adj ust t he par amet er s %al pha and %bet a t o change t he shapeof t he gamma di st r i but i on' s pdf .

    10-39 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    40/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 14 / 41

    - - > wxpl ot2d( [ pdf _gamma(x, 1, 2) , pdf _gamma(x, 3, 1) , pdf _gamma(x, 3, 2) ,pdf _gamma( x, 3, 3) ] , [ x, 0, 20] ) ;

    ( %t 706)

    ( %o706)

    The mean and var i ance of t he gamma di st r i but i on ar e gi ven by:

    - - > [ %mu = %al pha* %bet a, %si gma 2 = %al pha* %bet a 2] ;

    ( %o707) [ = , 2= 2]

    Usi ng t he f unct i ons def i ned i n t he "di st r i b" package, we can cal cul at e t hef ol l owi ng f or t he gamma di st r i but i on:

    ( 1) pdf : pdf _gamma(x, %al pha, %beta) - use i t t o pl ot t he pdf

    ( 2) cdf : cdf _gamma(x, %al pha, %beta) = F( x) = P(X

  • 8/13/2019 Maxima Book Chapter 10

    41/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 15 / 41

    - - > Bet a( al pha, bet a) = ( gamma( al pha) *gamma( bet a) ) / gamma( al pha+bet a) ;

    ( %o709) B( ) , =( ) ( )

    ( )+

    NOTE: t o cal l f unct i on "bet a" i n Maxi ma, use the l ower case ref er ence "bet a"r ather t han t he uppercase "Beta" used i n t he t wo def i ni t i ons i mmedi atel y above.I used t he uppercase "Bet a" r ef er ence i n her e t o mai nt ai n t he t ypi cal r ef erencet o t he Beta f unct i on shown i n mathemat i cal t ext books.

    The gr aph bel ow shows t he pdf pl ots f or di f f er ent bet a f unct i ons. As you can seef r om t hi s gr aph you can adj ust t he par amet er s %al pha and %bet a t o change t he shapeof t he bet a di st r i but i on' s pdf .

    - - > wxpl ot 2d( [ pdf _bet a( x, 2, 5) , pdf _bet a( x, 2, 3) , pdf _bet a( x, 3, 2) ,pdf _bet a( x, 5, 2) ] , [ x, 0, 1] ) ;

    ( %t 710)

    ( %o710)

    Because the bet a di st r i but i on i s def i ned i n t he range 0 < x < 1 onl y, i t i ssui t abl e t o model t he behavi or of cont i nuous r andom var i abl es r epr esent i ng,f or exampl e, a per cent age or a f r act i on.

    The mean and var i ance of t he beta di st r i but i on are gi ven by:

    - - > [ %mu = al pha/ ( al pha+bet a) , %si gma 2 = al pha*bet a/ ( ( al pha+bet a) 2*( al pha+bet a+1) )

    ( %o711) [ = +

    , 2= ( )+ 2 ( )+ + 1

    ]

    10-41 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    42/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 16 / 41

    Usi ng t he f unct i ons def i ned i n t he "di st r i b" package, we can cal cul at e t hef ol l owi ng f or t he bet a di st r i but i on:( 1) pdf : pdf _bet a( x, %al pha, %bet a) - use i t t o pl ot t he pdf( 2) cdf : cdf _bet a( x, %al pha, %bet a) = F( x) = P(X

  • 8/13/2019 Maxima Book Chapter 10

    43/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 17 / 41

    - - > wxpl ot 2d( [ pdf _wei bul l ( x, 1, 2) , pdf _wei bul l ( x, 3, 1) , pdf _wei bul l ( x, 3, 2) ,pdf _wei bul l ( x, 3, 3) ] , [ x, 0, 10] ) ;

    ( %t 714)

    ( %o714)

    The mean and var i ance of t he Wei bul l di st r i but i on ar e gi ven by:

    - - > [ %mu = beta*gamma( ( al pha+1) / al pha) ,%si gma 2 = beta 2*( gamma( ( al pha+2) / al pha) - gamma( ( al pha+1) / al pha) 2) ] ;

    ( %o715) [ =

    + 1

    , 2=

    + 2

    {

    + 1

    22]

    Usi ng t he f unct i ons def i ned i n t he "di st r i b" package, we can cal cul at e t he

    f ol l owi ng f or t he Wei bul l di st r i but i on:( 1) pdf : pdf _wei bul l ( x, %al pha, %bet a) - use i t t o pl ot t he pdf( 2) cdf : cdf _wei bul l ( x, %al pha, %bet a) = F(x) = P( X F( x) : =1- exp( - ( x/ %beta) %al pha) ;

    ( %o716) F( )x: =1{exp

    {

    x

    i t i s possi bl e t o f i nd an expr essi on of t he i nver se cumul at i ve di st r i but i onf unct i on ( I CDF) , x = F ( - 1) ( p) , where 0 < p < 1. Thi s I CDF wi l l pr ovi de t hequant i l es of t he Wei bul l di st r i but i on. An expr essi on f or t he Wei bul l I CDFi s f ound by maki ng F( x) = p, and sol vi ng f or x, namel y:

    10-43 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    44/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 18 / 41

    - - > assume( p>0) $ assume( p0) $ assume( %bet a>0) $

    - - > sol ve( [ 1- exp( - ( x/ %bet a) %al pha) =p] , [ x]) ;

    r at : r epl aced 0. 92 by 23/ 25 = 0. 92

    Is an integer? no;

    ( %o722) [x= l og

    25

    23

    1

    ]

    The Rayl ei gh di st r i but i on- - - - - - - - - - - - - - - - - - - - - - - - -

    The Rayl ei gh di st r i but i on uses a si ngl e par amet er %al pha. I f a cont i nuous r andomvar i abl e X ~ Rayl ei gh( %al pha) , i t s pr obabi l i t y densi t y f unct i on i s gi ven, f orx > 0, by t he expr essi on:

    - - > f ( x, al pha) : =2*x*al pha 2*exp( - ( x 2*al pha 2) ) ;

    ( %o723) f( )x, : =2 x2 exp( ){x2 2

    The f ol l owi ng gr aph shows sever al pl ot s of t he Rayl ei gh di st r i but i on pdf :

    - - > wxpl ot 2d( [ pdf _r ayl ei gh( x, 1) , pdf _r ayl ei gh( x, 2) , pdf _r ayl ei gh( x, 4) ,pdf _r ayl ei gh( x, 8) ] ,[ x, 0, 2] ) ;

    ( %t 724)

    ( %o724)

    Not i ce i n t he out put f r om t hi s gr aph t hat t he di f f er ent Rayl ei gh di st r i but i onpdf ' s ar e shown as Wei bul l di st r i but i ons pdf ' s. The r el at i onshi p bet ween t het wo bei ng:

    X ~ Rayl ei gh( %al pha) = X ~ Wei bul l ( 2, 1/ %al pha)

    I n ot her wor ds, t he Rayl ei gh di st r i but i on wi t h par amet er %al pha i s equi val entt o a Wei bul l di st r i but i on wi t h shape par ameter = 2, and scal e parameter =1/ %al pha.

    10-44 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    45/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 19 / 41

    The mean and var i ance of t he r andom var i abl e X ~ Rayl ei gh( %al pha) are:

    - - > [ %mu = sqr t ( %pi ) / ( 2*%al pha) , %si gma 2 = ( 4- %pi ) / ( 4*%al pha 2) ] ;

    ( %o725) [ =

    p

    2, 2=

    4{

    4 2]

    Usi ng t he f unct i ons def i ned i n t he "di st r i b" package, we can cal cul at e t hef ol l owi ng f or t he Rayl ei gh di st r i but i on:( 1) pdf : pdf _r ayl ei gh( x, %al pha) - use i t t o pl ot t he pdf( 2) cdf : cdf _r ayl ei gh( x, %al pha) = F(x) = P( X 0, %l ambda > 0, i s gi ven by:

    - - > f ( x) : =%l ambda*exp( - ( %l ambda*x) ) ;

    ( %o726) f( )x: = exp( ){ x

    The cumul at i ve di st r i but i on f unct i on f or t he exponent i al di st r i but i on has t heexpr essi on:

    - - > F( x) : =1- exp( - ( %l ambda*x) ) ;( %o727) F( )x: =1{exp( ){ x

    I f you compar e t hi s r esul t wi t h t he cdf of a Wei bul l ( %al pha, %bet a) di st r i but i on,namel y:

    - - > F( x) : =1- exp( - ( x/ %beta) %al pha) ;

    ( %o728) F( )x: =1{exp

    {

    x

    you can easi l y see t hat t he exponent i al di st r i but i on i s equi val ent t o a Wei bul l

    di st r i but i on wi t h %al pha = 1 and %bet a = 1/ %l ambda, i . e. ,

    X ~ exp( %l ambda) = X ~ Wei bul l ( 1, 1/ %l ambda)

    A pl ot showi ng some exampl es of t he exponent i al di st r i but i on pdf i s shown bel ow:

    10-45 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    46/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 20 / 41

    - - > wxpl ot 2d( [ pdf _exp( x, 1/ 2) , pdf _exp( x, 1) , pdf _exp( x, 2) ] , [ x, 0, 5] ) ;

    ( %t 729)

    ( %o729)

    The mean and var i ance of t he exponent i al di st r i but i on ar e gi ven by:

    - - > [ %mu = 1/ %l ambda, %si gma 2 = 1/ %l ambda 2] ;

    ( %o730) [ =1

    , 2=

    1

    2]

    Usi ng t he f unct i ons def i ned i n t he "di st r i b" package, we can cal cul at e t hef ol l owi ng f or t he exponent i al ( exp) di st r i but i on:( 1) pdf : pdf _exp( x, %l ambda) - use i t t o pl ot t he pdf

    ( 2) cdf : cdf _exp( x, %l ambda) = F( x) = P(X

  • 8/13/2019 Maxima Book Chapter 10

    47/80

  • 8/13/2019 Maxima Book Chapter 10

    48/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 22 / 41

    - - > f ( x) : =1/ ( %pi *b*( 1+( x- a) 2/ b 2) ) ;

    ( %o735) f( )x: =1

    b

    1+

    ( )x{a 2

    b2

    - - > wxpl ot 2d( pdf _cauchy( x, 3, 4) , [ x, - 20, 30] ) ;

    ( %t 736)

    ( %o736)

    ( 4) Gumbel : a r eal , b>0, pdf def i ned f or any x, posi t i ve or negat i ve:

    ( %i 1) f ( x, a, b) : =exp( - ( x- a) / b) *exp( - exp( - ( x- a) / b) ) / b;

    ( %o1) f( )x,a ,b : =exp

    {( )x{a

    bexp

    { exp

    {( )x{a

    b

    b

    - - > [ mu = a+%gamma*b, si gma 2 = pi 2*b 2/ 15] ;

    ( %o738) [ 10= b+a , 10=b2 2

    15]

    10-48 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    49/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 23 / 41

    - - > wxpl ot 2d( pdf _gumbel ( x, 3, 4) , [ x, - 20, 30] ) ;

    ( %t 739)

    ( %o739)

    ( 5) Logi st i c: a r eal , b>0, pdf def i ned f or any x, posi t i ve or negat i ve:

    ( %i 3) ' f ( x) = exp( ( x- a) / b) / ( b*( 1+exp( ( x- a) / b) ) 2) ;

    ( %o3) f( )x =%e

    x{ a

    b

    b

    %e

    x{ a

    b + 1

    2

    ( %i 13)[ mu = a, si gma 2 = %pi 2*b 2/ 3] ;

    ( %o13) [ =a , 2=2 b2

    3]

    10-49 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    50/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 24 / 41

    ( %i 16) wxpl ot 2d( pdf _l ogi sti c(x, 3, 4) , [ x, - 25, 30] ) ;

    ( %t 16)

    ( %o16)

    To cal cul at e f unct i ons def i ned i n t he "di st r i b" package f or any of t hesedi st r i but i ons use t he nami ng of f unct i ons summar i zed as:

    ( 1) pdf : pdf _( x, a, b) - use i t t o pl ot t he pdf( 2) cdf : cdf _( x, a, b = F(x) = P( X

  • 8/13/2019 Maxima Book Chapter 10

    51/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 25 / 41

    Fi gur e 1:

    pdf of t he r andom var i abl e X ~ t r i angul ar ( a, b, c)

    The pdf i s def i ned i n t he i nt er val a < x < b. The val ue c, a < c < b, i scal l ed t he "mode" of t he di st r i but i on. The t r i angul ar di st r i but i on i s noti ncl uded i n the "di st r i b" package, however , t he f ol l owi ng commands ( whi chr equi r e package "di st r i b" t o be l oaded, def i ne the pdf , t he cdf , t he mean,var i ance, and standar d devi at i on, quant i l es, and gener at i on of r andomval uesof X ~ t r i angul ar ( a, b, c).

    - - > l oad( "di st r i b") $ pdf _t r i angul ar ( x, a, b, c): =bl ock( i f ( x

  • 8/13/2019 Maxima Book Chapter 10

    52/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 26 / 41

    - - > wxpl ot 2d( pdf _t r i angul ar ( x, 20, 80, 40) , [ x, 0, 100] ) ;

    ( %t 748)

    ( %o748)

    - - > wxpl ot 2d( cdf _t r i angul ar ( x, 20, 80, 40) , [ x, 0, 100] ) ;

    ( %t 749)

    ( %o749)

    The mean, var i ance, and st andar d devi at i on of t he cont i nuous r andomvar i abl e X ~ t r i angul ar ( 20, 80, 40) ar e cal cul at ed next:

    - - > mean_t r i angul ar ( 20, 80, 40) ; f l oat ( %) ;

    ( %o750)140

    3( %o751) 46. 66666666666666

    10-52 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    53/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 27 / 41

    - - > var _t r i angul ar ( 20, 80, 40) ; f l oat ( %) ;

    ( %o752)1400

    9( %o753) 155. 5555555555555

    - - > st d_t r i angul ar ( 20, 80, 40) ; f l oat ( %) ;

    ( %o754) 10p

    143

    ( %o755) 12. 47219128924647

    The quar t i l es of t he t r i angul ar var i abl e X ~ t r i angul ar ( 20, 80, 40) ar ecal cul at ed as f ol l ows:

    - - > Q1 : quant i l e_t r i angul ar ( 0. 25, 20, 80, 40) ;

    ( %o756) 37. 32050807568878

    - - > Q2 : quant i l e_t r i angul ar ( 0. 50, 20, 80, 40) ;

    ( %o757) 45. 35898384862245

    - - > Q3 : quant i l e_t r i angul ar ( 0. 74, 20, 80, 40) ;

    ( %o758) 55. 02000800640641

    The f ol l owi ng command generates 5 val ues of X ~ t r i angul ar ( 20, 80, 40) :

    - - > r andom_t r i angul ar ( 20, 80, 40, 5) ;

    ( %o759) [ 36. 55414804072686 , 57. 04642474553606 , 67. 71835091666662 ,

    40. 48115928256937 , 24. 63952339099573]

    STATI STI CAL SI MULATI ON======================

    Random number s can be used t o generate synt het i c dat a wi t h t he pur pose ofmodel l i ng syst ems t hat depend on data t hat ar e i nherent l y uncer t ai n. Forexampl e, t o si mul ate random mot i on i n two di mensi ons we can st ar t by pl aci nga par t i cl e at poi nt ( 0, 0) and gener at e randomval ues r epr esent i ng a di st ancer i and an angl e qi f or a number of t i me st eps i = 1, 2, . . . , n, and have t hepar t i cl e move by t hat di st ance al ong t hat par t i cul ar angl e i n each t i me step.A pl ot of t he mot i on r epr esent s a model of Br owni an mot i on as skeched bel ow.

    10-53 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    54/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 28 / 41

    Fi gur e 2:

    For exampl e, consi der a r andommot i on i n whi ch t he di st ances r [ i ] ar e normal l y-di st r i buted r andom numbers wi t h mean 100 uni t s and st andard devi at i on 20 uni t s.Al so, and t he corr espondi ng angl es Th[ i ] ar e uni f orm r andomnumber s i n t hei nt er val ( - %pi , %pi ) . The Dx and Dy i ncr ement s ar e cal cul ated as

    Dx[ k] = r [ k]* cos( Th[ k]) and Dy[k] = r [ k]* si n( Th[ k]) ,

    and t he new posi t i ons f or t he movi ng par t i cl e ar e cal cual t ed as

    x[ k+1] = x[ k] + Dx[ k] , y[ k+1] = y[ k] +Dy[ k] .

    Thi s t ype of si mul at i on coul d be used, f or exampl e, t o si mul at e t he r andom mot i onof a l ar ge number of par t i cl es r epr esent i ng a cont ami nant movi ng i n a f l ui d or i n

    gr oundwater . Si mul at i ons wher e synt het i c data i s used as i nput ar e r ef er r ed t o asMont eCar l o si mul at i ons i n honor of t he ci t y of Mont eCar l o, capi t al of t he pr i nci pal t yof Monaco, Sout h of Fr ance, where t he l ar gest casi no i n t he Worl d oper ates.

    The f ol l owi ng ser i es of commands i l l ust r at es t he use of synt het i c data i n cal cul at i ngt he t wo- di mensi onal r andommot i on of a number of part i cl es.

    Fi r st , l oad package "di st r i b" and def i ne t he par amet er s of t he si mul at i on:nP = number of par t i cl es, nT = number of t i me i nt er val s i n the si mul at i onr mean, r st d = mean and st andar d devi at i on of t he radi al di st ance r [ i ]mi nTh, maxTh = mi ni mum and maxi mum val ue of t he angl e Th

    The mat r i ces XP and YP wi l l cont ai n t he x and y coor di nates f or part i cl e ji n t i me i nt er val i . They' r e i ni t i al i zed her e as rows of nP col umns:

    - - > l oad( "di str i b") $nP : 80 $ nT : 100 $r mean : 100 $ r st d : 20 $mi nTh : - %pi $ maxTh : %pi $XP : zer omat r i x(1, nP) $ YP : zer omat r i x(1, nP) $

    10-54 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    55/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 29 / 41

    The next ser i es of commands show an exampl e of pr ogrammi ng a l oop i n Maxi mausi ng t he " f or - do" command wi t h i ndex k runni ng f r om"1 t hr u nT". Thi s l oopgener at es nP r andomnormal number s wi t h mean "r mean" and st andar d devi at i on"r st d", as wel l as nP r andom number s uni f or ml y di st r i but ed i n t he i nt er val[ mi nTh, maxTh] . The l oop t hen cal cul ates the i ncrement s i n x and y, Dx andDy, r espect i vel y, and pr oceeds t o gener at e posi t i ons f or i ndi vi dual par t i cl est hrough t he use of t he i nternal l oop shown bel ow. Once t he nP posi t i ons havebeen gener at ed, t hey are added t o t he mat r i x XP and YP as r ows. Af t er t he

    l oop t hat generates XP and YP i s compl eted, t he mat r i ces ar e t r ansposed. Weare now r eady t o pl ot t hem as shown bel ow.

    - - > f or k : 1 t hr u nT do ( r : r andom_nor mal ( r mean, r st d, nP) , Th : f l oat ( r andom_cont i nuous_uni f orm( mi nTh, maxTh, nP) ) , Dx : makel i st( r [ k] *cos(Th[ k] ) , k, 1, nP) ,

    Dy : makel i st( r [ k] *si n( Th[ k] ) , k, 1, nP) , x : makel i st ( 0, k, 1, nP) , y : makel i st ( 0, k, 1, nP) , f or k : 1 t hr u nP- 1 do ( x[ k+1] : x[ k] + Dx[k] , y[ k+1] : y[ k] + Dy[k] ) , XP : addr ow( XP, x) , YP : addr ow( YP, y)

    ) $XP : t r anspose(XP) $ YP : t r anspose( YP) $

    The f ol l owi ng pl ot s show t he f i r st t hr ee st eps i n t he si mul at i on ( i f you wantt o see t he f ul l si mul at i on, change t he val ue of "3" t o "nT" i n t hi s l oop) :

    10-55 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    56/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 30 / 41

    - - > f or k : 1 t hr u 3 do (xyPoi nts : makel i s t ( [XP[k , j ] , YP[ k, j ] ] , j , 1, nP) ,

    wxdr aw2d( poi nt _t ype=5, poi nt _s i ze=1, xr ange = [ - 1500, 1500] , yr ange = [ - 1500, 1500] , poi nt s(xyPoi nt s)) ) $

    ( %t 772)

    ( %t 773)

    ( %t 774)

    10-56 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    57/80

  • 8/13/2019 Maxima Book Chapter 10

    58/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 32 / 41

    - - > al gsys( [ al pha*bet a = x_bar , al pha*bet a 2 = s2] , [ al pha, beta] ) ;

    ( %o782) [ [ =597789341

    128868750, =

    859125

    298447] ]

    - - > f l oat ( %) ;

    ( %o783) [ [ =4. 638745553130608, =2. 878651820926329] ]

    Not i ce t hat i n t hi s br ut e- f or ce t ype of dat a f i t t i ng we don' t have ( yet ) away t o check how good t he f i t t i ng i s. Ther e i s a st at i st i cal t est t o checkt hi s goodness of f i t , but i t wi l l not be i nt r oduced i n t hi s chapt er .Ri ght now we assume t hat t he pr oposed pr obabi l i t y di st r i but i on i s a good f i tand pr oceed t o f i nd t he par amet er s t hat descr i be t hi s di st r i but i on.

    There ar e cases where exper i ence di ct at es t he t ype of probabi l i t y di st r i but i ont o be f i t t o a dat a set . For exampl e, i t i s wel l known i n t he f i el d ofsedi ment at i on and sedi ment t r anspor t i n r i ver s t hat t he di amet er s of i ndi vi dualpar t i cl es i n a sedi ment sampl e ( e. g. , sand, gr avel s) f ol l ows a l og- nor maldi st r i but i on. Thus, f i t t i ng a l og- nor mal di st r i but i on t o such dat a woul d be

    j ust i f i ed.

    PROBABI LI TY PLOTS=================

    I n t he pr evi ous sect i on we pr esent ed a si mpl e way t o f i t dat a to a gi ven pr obabi l i t ydi st r i but i on by cal cul at i ng t he mean, x_bar , and var i ance, s2, of t he dat a . I n t hi ssect i on we pr esent a gr aphi cal appr oach t o check t he goodness of t he dat a f i t t i ng.

    Pr obabi l i t y pl ot s f or t he cont i nuous uni f or m di str i but i on:- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    The f i r st st ep i n t hi s pr ocedure consi st s i n or der i ng t he data or i gi nal l y gi ven as[ x1, x2, . . . , xn] i n i ncr easi ng or der . Thi s can be accompl i shed by usi ng f unct i on

    "sor t ". To i l l ust r at e t hi s sor t i ng, we wi l l gener at e a r andom dat a set of si ze 100,f r om t he cont i nuous uni f or m di st r i but i on i n t he range [0, 10] :

    - - > xdata : r andom_cont i nuous_uni f orm( 0, 10, 100) $

    Funct i on "sort " i s used t o or der t he dat a set i n i ncreasi ng or der :

    - - > xdat a : sor t ( xdat a) $

    Consi der a uni f or m di st r i but i on f or a r andom var i abl e Y i n t he r ange ( 0, 1) . The CDFf or t hi s r andom var i abl e i s gi ven by F(y) = ( y- 0) / ( 1- 0) = y, so t hat t he i nver secumul at i ve di st r i but i on f unct i on ( I CDF) i s al so F ( - 1) ( y) = y. Let ' s assume t hat

    t he sort ed dat a set {x1, x2, . . . , xn} r epr esent val ues of a r andom var i abl e X t hatf ol l ows t he uni f orm di st r i but i on wi t h par ameter s a and b. We can r el at e X and Y byt he equat i on X = a + Y*( b- a) , so t hat when y = 0, x = a, and when y = 1, x = b.

    Thus, cor r espondi ng t o data val ue xi , t here wi l l be a val ue yi such t haty[ i ] = ( x[i ] - a) / ( b- a) . The f i gur e bel ow shows t he r el at i onshi p bet ween x and y,and shows t he uni f or m pr obabi l i t y densi t y f unct i on ( pdf ) f ( y) as wel l as t he ar ear epr esent i ng t he CDF of Y, F( y) .

    10-58 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    59/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 33 / 41

    Fi gur e 3:

    I f t he dat a x[ i ] , and, t he cor r espondi ng val ues y[ i ] , ar e di st r i but ed uni f or ml y, t hent he i nt er val ( 0, 1) i s spl i t i nt o ( n+1) i nt er val s of equal pr obabi l i t y, so t hat t he CDFcor r espondi ng t o y[i ] i s gi ven by t he pl ot t i ng posi t i on val ues:

    p[ i ] = F( y[ i ] ) = i / ( n+1) ,

    f or i = 1, 2, . . . , n.

    Because t he I CDF f or t he r andom var i abl e Y i s F ( - 1) ( y) = y, t he pl ott i ng posi t i ons f ot hi s di st r i but i on r epr esent al so t he t heor et i cal val ues of t he var i abl e y cor r espondi nt o i ndex i , i . e. , y[ i ] . Al so, because t her e i s a l i near r el at i onshi p bewt een x[ i ] andy[ i ] , i t i s expected t hat a pl ot of x[ i ] vs. p[ i ] shoul d show a str ai ght l i ne.

    We can check, f or exampl e, whether t he or dered dat a i n var i abl e "xdata", above, auni f or m di st r i but i on by cal cul at i ng t he pl ot t i ng posi t i ons p[ i ] = i / ( n+1) , and pl ot t i nx[ i ] agai nst t hose pl ot t i ng posi t i ons. The pr ocedur e t o pr oduce t hi s pl ot i s shown n

    - - > n : l engt h( xdat a) ;

    ( %o786) 100

    - - > pp : f l oat ( makel i st( k/ ( n+1) , k, 1, n) ) $

    - - > wxpl ot 2d( [ di scr et e, pp, xdat a] , [ styl e, [ poi nt s, 1, 2, 1] ] ) ;

    ( %t 788)

    ( %o788)

    10-59 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    60/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 34 / 41

    The f i gur e shows t he dat a ( pp[ i ] , xdat a[ i ] ) f ol l owi ng a st r ai ght l i ne,t hus, suggest i ng t hat t he dat a i s i ndeed uni f or ml y di st r i but ed.

    Compare t hese resul t s wi t h t hose obt ai ned f r omr andomdat a gener at ed f r oma Nor mal di st r i bui on:

    - - > xdata : r andom_normal ( 1200, 300, 100) $ xdata : sor t ( xdata) $

    n : l engt h( xdat a) $ pp : f l oat ( makel i st ( k/ ( n+1) , k, 1, n) ) $wxpl ot 2d( [ di scr et e, pp, xdat a] , [ styl e, [ poi nt s, 1, 2, 1] ] ) ;

    ( %t 793)

    ( %o793)

    Obvi ousl y, t hese dat a set does not f ol l ow a uni f or m di st r i but i on.

    10-60 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    61/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 35 / 41

    Pr obabi l i t y pl ot s f or t he cont i nuous uni f or m di str i but i on:- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    The pl ot t i ng posi t i ons p[ i ] f or t he st andar d normal di st r i but i on do not have cl osed-f or m expr essi ons, as i n t he case of t he uni f or m di st r i but i on. I nst ead, t hey ar eapproxi mated by t he expr essi on,

    p[ i ] = Phi ( z[ i ] ) = ( i - c)/ ( n- 2*c+1) ,

    wher e Phi ( z) r epr esents t he CDF of t he st andar d normal var i ate Z~N( 0, 1) , n i s t he numbof dat a poi nt s i n t he sampl e, and c i s a const ant . For sampl es wi t h si ze n < 30, Fi l l[ Fi l l i ben, J . J . , ( 1975) , "The pr obabi l i t y pl ot corr el at i on coef f i ci ent t est f or normal i

    Technomet r i cs , Vol . 17, pp. 111- 117] used c = - 0. 3175, so t hat t he pl ot t i ng posi t i ons gi ven by

    p[ i ] = ( i - 0. 3175) / ( n+0. 3650) .

    I n addi t i on, Fi l l i ben t ook p[ n] = 0. 5 ( 1/ n) , and p[ 1] = 1 p[ n] . For l ar ger sampl esi . e. , n > 30, t he f ol l owi ng pl ot t i ng posi t i on val ues ar e commonl y used ( l et ' s r ef er t oi t as t he si mpl e appr oach) : p[ i ] = ( i - 0. 5) / n.

    As i ndi cat ed above, t he nor mal pl ot t i ng posi t i ons ar e used t o cal cul at e t he so- cal l ednor mal scor es, t he val ues of z[ i ] cor r espondi ng t o a CDF p[ i ] , i . e. , z[ i ] =Phi ( _1) ( p[ iFor a normal var i abl e X ~ N( mu, si gma) , t he nor mal scor es ar e def i ned by z[ i ] =( x[i ] - mu) / si gma. Ther ef or e, i f t he dat a set f ol l ows t hi s nor mal var i abl e, t hen t he vaof x[ i ] shoul d be l i near l y r el at ed t o t he nor mal scor es, i . e. , x[i ] = mu+z[ i ] *si gma) .

    Thus, a pl ot of x[ i ] - vs z[ i ] shoul d pr oduce a st r ai ght - l i ne i f t he data i s normal l ydi st r i but ed. Fur t her mor e, t he sl ope of t he st r ai ght l i ne i s t he st andar d devi at i on,si gma, and the i nt er cept i s t he mean, mu, of t he normal var i abl e X.

    As an exampl e, consi der t he dat a "xdat a" gener at ed bel ow f r oma normal di st r i but i on, asubsequent l y sor t ed. Usi ng Fi l l i ben' s appr oach, t he pl ot t i ng posi t i ons wi l l be cal cul aas f ol l ows:

    - - > xdata : r andom_normal ( 1200, 300, 20) $ xdata : sor t ( xdata) $n : l engt h( xdat a) $ pp : makel i st ( ( i - 0. 3175) / ( n+0. 3650) , i , 1, n) $pp[ n] : 0. 5 ( 1/ n) $ pp[ 1] : 1- pp[ n] $

    Then, we cal cul at e t he nor mal scor es, and pl ot x[i ] - vs- z[ i ] :

    - - > x_bar : ( 1/ n) *sum( xdat a[ k], k, 1, n) ;s2 : ( 1/ ( n- 1) ) *sum( ( xdat a[ k]- x_bar ) 2, k, 1, n) $s : sqr t ( s2) ;

    ( %o800) 1237. 280995156626( %o802) 377. 7857948408741

    - - > xscor es : f l oat ( makel i st ( quant i l e_nor mal ( pp[ k] , x_bar , s) , k, 1, n) ) $

    10-61 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    62/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 36 / 41

    - - > wxpl ot 2d( [ di scr et e, xdat a, xscor es], [ styl e, [ poi nt s, 3, 2, 2] ] ) ;

    ( %t 804)

    ( %o804)

    Not i ce t hat f or t hi s dat a set , gener at ed f r om a nor mal di st r i but i on, t he pr obabi l i t ypl ot shows t he dat a f ol l owi ng a st r ai ght l i ne.

    For a l ar ger set gener at ed f r om a nor mal di st r i but i on, we use the si mpl er appr oacht o cal cul at e t he pl ot t i ng posi t i ons:

    10-62 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    63/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 37 / 41

    - - > xdata : r andom_normal ( 600, 20, 100) $ xdata : sor t ( xdata) $n : l engt h( xdat a) $ pp : makel i st( ( i - 0. 5) / n, i , 1, n) $x_bar : ( 1/ n) *sum( xdat a[ k], k, 1, n) ;s2 : ( 1/ ( n- 1) ) *sum( ( xdat a[ k]- x_bar ) 2, k, 1, n) $s : sqr t ( s2) ;xscor e : f l oat ( makel i st( quant i l e_nor mal ( pp[ i ] , x_bar , s), i , 1, n) ) $wxpl ot 2d( [ di scr et e, xdat a, xscor e] , [ styl e, [ poi nt s, 3, 2, 2] ] ) ;

    ( %o809) 598. 8195641040642( %o811) 18. 87262587921254

    ( %t 813)

    ( %o813)

    Once agai n, t he dat a f ol l ows on a st r ai ght l i ne, conf i r mi ng i t s nor mal i t y( i . e. , t hat t hey f ol l ow a nor mal di str i but i on.

    I n t he f ol l owi ng exampl e we use dat a generat ed f r oma bet a di st r i but i on. Thepr obabi l i t y pl ot shows t hat t he dat a does not f ol l ow a st r ai ght l i ne, asexpect ed.

    10-63 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    64/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 38 / 41

    - - > xdat a : r andom_bet a( 0. 2, 0. 3, 50) $ xdat a : sort ( xdat a) $n : l engt h( xdat a) $ pp : makel i st( ( i - 0. 5) / n, i , 1, n) $x_bar : ( 1/ n) *sum( xdat a[ k], k, 1, n) ;s2 : ( 1/ ( n- 1) ) *sum( ( xdat a[ k]- x_bar ) 2, k, 1, n) $s : sqr t ( s2) ;xscor e : f l oat ( makel i st( quant i l e_nor mal ( pp[ i ] , x_bar , s), i , 1, n) ) $wxpl ot 2d( [ di scr et e, xdat a, xscor e] , [ styl e, [ poi nt s, 3, 2, 2] ] ) ;

    ( %o818) 0. 48215382075017( %o820) 0. 4263972072499

    ( %t 822)

    ( %o822)

    I n t hi s l ast exampl e we use dat a gener at ed f r om a l og- nor mal di st r i but i on.The pr obabi l i t y pl ot shows t hat t he data does not f ol l ow a st r ai ght l i ne,as expect ed.

    10-64 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    65/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 39 / 41

    - - > xdat a : r andom_l ognormal ( 0. 2, 0. 5, 50) $ xdat a : sor t ( xdat a) $n : l engt h( xdat a) $ pp : makel i st( ( i - 0. 5) / n, i , 1, n) $x_bar : ( 1/ n) *sum( xdat a[ k], k, 1, n) ;s2 : ( 1/ ( n- 1) ) *sum( ( xdat a[ k]- x_bar ) 2, k, 1, n) $s : sqr t ( s2) ;xscor e : f l oat ( makel i st( quant i l e_nor mal ( pp[ i ] , x_bar , s), i , 1, n) ) $wxpl ot 2d( [ di scr et e, xdat a, xscor e] , [ styl e, [ poi nt s, 3, 2, 2] ] ) ;

    ( %o827) 1. 425385698283374( %o829) 1. 132724219433316

    ( %t 831)

    ( %o831)

    10-65 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    66/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 40 / 41

    PERI OD OF RETURN================Consi der t he case i n whi ch val ues of a peri odi c measur ement are t aken, e. g. : dai l ydi schar ges i n a r i ver , maxi mun dai l y t emper atur e at a l ocat i on, annual maxi mum di schari n a r i ver , et c. Suppose t hat t he r andom var i abl e Y[ i ] r epr esent s t he measur ement f orper i od i . Let p = P( Y[ i ] >y) r epr esent t he pr obabi l i t y t hat Y wi l l exceed a cer t ai nval ue y at per i od i , and l et t he val ues Y[ i ] be i ndependent of each ot her . Let Xr epr esent t he number of per i ods bewt een exceedences of t he val ue y. Theref ore, t he

    pr obabi l i t y t hat t he t i me between exceedence i s X = x, i s cal cul at ed as

    P( X=x) = P( Y[1] < y) *P( Y[ 2] < y) * . . . *P(Y[x- 1] < y)* P( Y[x] >y),

    si nce t her e wi l l be ( x- 1) per i ods of no exceedence bef or e t he f i r st exceedence. Thus,X, t he per i od bet ween exceedence, f ol l ows a geomet r i c di st r i but i on def i ned sl i ght l ydi f f er ent t han t he one used i n package "di st r i b. " I n t he geomet r i c di st r i but i on def i ni n t hi s package, X i s t he number of i nst ances unt i l , but not i ncl udi ng, t he f i r stsuccessf ul out come of a ser i es of Ber noul l i t r i al s. For t he pur poses of def i ni ng aper i od of r et ur n i n t hi s sect i on, t he r andom var i abl e X r epr esent s t he number ofi nst ances unt i l , and i ncl udi ng, t he f i r st successf ul out come ( exceedence) . Thedi st r i but i on par amet er i n t hi s case i s t he pr obabi l i t y of exceedence, p = P( Y[ i ] >y) .

    The cor r espondi ng expect ed val ue ( mean) i s cal cul at ed as

    T = E[ X] =1/ p = 1/ P( Y[ i ] >y) .

    We r ef er t o t hi s val ue as t he r et ur n per i od ( or per i od of r et ur n) of t he eventwi t h magni t ude y.

    The per i od of r et ur n r epresent s t he number of measur ement per i ods t hat woul d, on t heaverage, occur bef ore the next t i me the measured event exceeds t he val ue y. Forexampl e, i f Y[ i ] r epr esent s t he di schar ge at day i at a gi ven r i ver , and i f we f i ndt hat f or a val ue y = 1000 cf s ( cubi c f eet per second) , P(Y[ i ] >y) = 0. 005, t hen t hecorr espondi ng per i od of r et ur n i s T = 1/ P(Yi >y) = 1/ 0. 005 = 200 days. Thi s i si nt er pr et ed as sayi ng t hat , on t he aver age, t he dai l y di schar ge i n t hat par t i cul arr i ver wi l l exceed 1000 cf s ever y 200 days. Not i ce t hat t hi s i s onl y an aver age( or expected) val ue, and does not ensure that exact l y ever y 200 days t he di schar ge

    wi l l be 1000 cf s or more. I t coul d happen t hat t he di scharge i s l ar ger t han 1000cf s i n t wo consecut i ve days, or t hat i t wi l l not exceed 1000 cf s f or more t han200 days. However , i n t he l ong r un, t he di schar ge wi l l exceed 1000 cf s, on t heaver age, every 200 days.

    The per i odi c measur ement Y[ i ] can f ol l ow any of t he known paramet r i c di st r i but i ons.Al l what i t ' s needed t o cal cul at e t he per i od of r et ur n T f or a val ue y, i s t hepr obabi l i t y P( Y[ i ] >y) . I f an or der ed dat a set {y1, y2, . . . , yn} i s avai l abl e,we can cal cul at e the cor r espondi ng pl ott i ng posi t i ons p[i ] usi ng the appr oachespr esent ed i n t he pr evi ous sect i on, and t hen cal cul ate exceedence pr obabi l i t y asP( Y[ i ] >y) = 1 p[ i ] . The r et ur n per i ods f or each val ue y[i ] wi l l be gi ven by

    T[ i ] = 1/ ( 1- p[ i ] ) .

    Exampl e: Suppose that t he di schar ge X i n a r i ver f ol l ows t he nor mal di st r i but i onwi t h mean = 800 cf s and st andard devi at i on = 50 cf s, i . e. , X ~ N( 800, 50) , and thatwe gener at e 10 val ues of X as:

    - - > X : r andom_nor mal ( 800, 50, 10) ;

    ( %o917) [ 794. 5070404275007, 851. 837000001178, 874. 0628789073442,

    788. 529641720006, 845. 7111896437867 , 777. 3205386450994 , 767. 7294056391739,

    797. 2166045233589, 830. 1017952741952 , 778. 2168180282833]

    10-66 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    67/80

    ProbabilityDistributionsExamplesCONTINUOUS.wxmx 41 / 41

    Next , we sor t t he dat a, cal cul at e pl ot t i ng posi t i ons, and r et ur n per i od:

    - - > Xs : sor t ( X) ;

    ( %o918) [ 767. 7294056391739, 777. 3205386450994, 778. 2168180282833,

    788. 529641720006, 794. 5070404275007 , 797. 2166045233589 , 830. 1017952741952,

    845. 7111896437867, 851. 837000001178, 874. 0628789073442]

    - - > n : l engt h( Xs) $ pp : makel i st( ( i - 0. 5) / n, i , 1, n) $T : makel i st ( 1/ ( 1- pp[ i ] ) , i , 1, n) ;

    ( %o921) [ 1. 052631578947368, 1. 176470588235294, 1. 333333333333333,

    1. 538461538461538, 1. 818181818181818, 2. 222222222222222, 2. 857142857142857,

    4. 0 , 6. 666666666666666, 19. 99999999999998]

    A pl ot of r et ur n per i od, T, vs di schar ge, Xs, i s shown bel ow:

    - - > wxpl ot 2d( [ di scr et e, Xs, T] , [ styl e, [ poi nt s, 3, 2, 2] ] ) ;

    ( %t 923)

    ( %o923)

    10-67 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    68/80

    ProbabilityDistributionsForINFERENCE.wxmx 1 / 13

    - - > l oad("di s t r i b" ) $

    PROBABI LI TY DI STRI BUTI ONS USED I N STATI STI CAL I NFERENCE=======================================================There ar e some probabi l i t y di st r i but i ons t hat ar e commonl y used i n st at i st i cali nf er ence appl i cat i ons. St at i st i cal i nf er ence t echni ques ar e used t o obt ai ni nf ormat i on about popul at i ons based on t he st at i st i cs of one or more sampl est aken f r om t hat popul at i on. The pr obabi l i t y di st r i but i ons used i n st at i st i cali nf er ence ar e ( 1) t he st andar d nor mal di st r i but i on; ( 2) t he St udent t di st r i but i on;( 3) t he chi - squar e di st r i but i on; and t he F di st r i but i on.

    The st andar d normal di st r i but i on ( r evi si t ed)- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -The st andar d normal di st r i but i on was descr i bed ear l i er . The st andar d normalvar i abl e Z f ol l ows a normal di st r i but i on wi t h mean = 0 and st andard devi at i on= 1, i . e. , Z ~ N( 0, 1) . I n an ear l i er sect i on we pr esent ed cal cul at i ons of t hest andar d nor mal di st r i but i on' s CDF, Phi ( z) , and i t s i nver se. I n t hi s secti onwe i nt r oduce t he i dea of t he upper - t ai l pr obabi l i t y and i t s associ at ed val ueknown as a cri t i cal val ue. The upper - t ai l pr obabi l i t y ( al pha) i s def i nedas:

    - - > P( Z>z[ al pha] ) = al pha;

    ( %o2) P( )Z>z =

    The def i ni t i on of z[al pha] i s i l l ustr at ed i n t he f ol l owi ng f i gur e.

    Fi gur e 1:

    Usi ng t he pr obabi l i t y of a compl ement , we can wr i t e:

    - - > al pha = 1- Phi ( z[ al pha] ) ;

    ( %o3) = 1{ ( )z

    The cri t i cal val ue z[ al pha] cor r espondi ng t o t he upper - t ai l pr obabi l i t yal pha i s, t her ef or e, t he quant i l e cor r espondi ng t o Phi ( z) = 1 - al pha, i . e. ,

    10-68 (c) 2009 Gilberto E. Urroz

  • 8/13/2019 Maxima Book Chapter 10

    69/80

    ProbabilityDistributionsForINFERENCE.wxmx 2 / 13

    - - > z[ al pha] = quant i l e_nor mal ( 1- al pha, 0, 1) ;

    ( %o26) z = quant i l e_nor mal( )1{ , 0, 1

    I n stati st i cal i nf er ence, t he val ue of "al pha" i s al so r ef er r ed t oas t he "s i gni f i cance l evel of a stati st i cal t est. " Typi cal val uesused i n st at i st i cal i nf er ence ar e, f or exampl e, 0. 01, 0. 05, and 0. 10.The cr i t i cal val ues f or t hese si gni f i cance l evel s ar e:

    - - > z[ 0. 01] = f l oat ( quant i l e_nor mal ( 1- 0. 01, 0, 1) ) ;

    ( %o10) z0. 01=2. 326347874040842

    - - > z[ 0. 05] = f l oat ( quant i l e_nor mal ( 1- 0. 05, 0, 1) ) ;

    ( %o11) z0. 05=1. 644853626951472

    - - > z[ 0. 10] = f l oat ( quant i l e_nor mal ( 1- 0. 10, 0, 1) ) ;

    ( %o12) z0. 1=1. 281551565544601

    Of i nt er est i n stati st i cal t ests, besi des z[ al pha] , i s the val uez[ - al pha/ 2] = z[ 1- al pha] , whi ch i s cal cul at ed as:

    z[ - al pha] = z[ 1- al pha] = quant i l e_nor mal ( al pha, 0, 1)

    Thi s r esul t f ol l ows f r om t he symmet r y of t he st andar d normal di st r i but i onabout z = 0, i . e. , P( Zz[ al pha] ) . Thi s st at ement i nst andar d mat hemat i cal not at i on woul d read:

    - - > P(Zz[ al pha] ) ;

    ( %o30) P( )Zz

    The r el at i onshi p bet ween z[ - al pha] , z[ al