00_ statistics toolbox

Download 00_ Statistics Toolbox

If you can't read please download the document

Upload: ahmed-sharba

Post on 28-Oct-2014

108 views

Category:

Documents


6 download

TRANSCRIPT

Computa tionVisua liza tionProgra mmingFor Use w ith MATLABUsers GuideVersion 3StatisticsToolboxHow to Conta ct The Ma thW orks:www.mathworks.com Webcomp.soft-sys.matlab Newsgr [email protected] Technical suppor [email protected] Pr oduct enhancement suggest [email protected] Bug r epor t [email protected] Document at ion er r or r epor t [email protected] Or der st at us, license r enewals, [email protected] Sales, pr icing, and gener al infor mat ion508-647-7000 Phone508-647-7001 FaxThe Mat hWor ks, Inc. Mail3 Apple Hill Dr iveNat ick, MA 01760-2098For cont act infor mat ion about wor ldwide offices, see t he Mat hWor ks Web sit e.S tatistics Toolbox Users Guide COPYRIGHT 1993 - 2001 by The Mat hWor ks, Inc. The soft war e descr ibed in t his document is fur nished under a license agr eement . The soft war e may be used or copied only under t he t er ms of t he license agr eement . No par t of t his manual may be phot ocopied or r epr o-duced in any for m wit hout pr ior wr it t en consent fr om The Mat hWor ks, Inc.FEDERAL ACQUISITION: This pr ovision applies t o all acquisit ions of t he Pr ogr am and Document at ion by or for t he feder al gover nment of t he Unit ed St at es. By accept ing deliver y of t he Pr ogr am, t he gover nment her eby agr ees t hat t his soft war e qualifies as "commer cial" comput er soft war e wit hin t he meaning of FAR Par t 12.212, DFARS Par t 227.7202-1, DFARS Par t 227.7202-3, DFARS Par t 252.227-7013, and DFARS Par t 252.227-7014. The t er ms and condit ions of The Mat hWor ks, Inc. Soft war e License Agr eement shall per t ain t o t he gover nment s use and disclosur e of t he Pr ogr am and Document at ion, and shall super sede any conflict ing cont r act ual t er ms or condit ions. If t his license fails t o meet t he gover nment s minimum needs or is inconsist ent in any r espect wit h feder al pr ocur ement law, t he gover nment agr ees t o r et ur n t he Pr ogr am and Document at ion, unused, t o Mat hWor ks.MATLAB, Simulink, St at eflow, Handle Gr aphics, and Real-Time Wor kshop ar e r egist er ed t r ademar ks, and Tar get Language Compiler is a t r ademar k of The Mat hWor ks, Inc.Ot her pr oduct or br and names ar e t r ademar ks or r egist er ed t r ademar ks of t heir r espect ive holder s.Pr int ing Hist or y: Sept ember 1993 Fir st pr int ing Ver sion 1Mar ch 1996 Second pr int ing Ver sion 2J anuar y 1997 Thir d pr int ing For MATLAB 5May 1997 Revised for MATLAB 5.1 (online ver sion)J anuar y 1998 Revised for MATLAB 5.2 (online ver sion)J anuar y 1999 Revised for Ver sion 2.1.2 (Release 11) (online only)November 2000 Four t h pr int ing Revised for Ver sion 3 (Release 12)May 2001 Fift h pr int ing minor r evisioniContentsPrefaceOvervi ew . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi iWhat Is the Stati sti cs Toolbox? . . . . . . . . . . . . . . . . . . . . . . . . . xi i iHow to Use Thi s Gui de . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi vRelated Products Li st . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvMathemati cal Notati on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi iTypographi cal Conventi ons . . . . . . . . . . . . . . . . . . . . . . . . . . xvi i i1Tutori alIntroducti on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2Pr imar y Topic Ar eas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2Probabi li ty Di stri buti ons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5Over view of t he Funct ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6Over view of t he Dist r ibut ions . . . . . . . . . . . . . . . . . . . . . . . . . . 1-12Descri pti ve Stati sti cs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-43Measur es of Cent r al Tendency (Locat ion) . . . . . . . . . . . . . . . . 1-43Measur es of Disper sion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-45Funct ions for Dat a wit h Missing Values (NaNs) . . . . . . . . . . . 1-46Funct ion for Gr ouped Dat a . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-47Per cent iles and Gr aphical Descr ipt ions . . . . . . . . . . . . . . . . . . 1-49The Boot st r ap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-50i i ContentsCluster Analysi s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-53Ter minology and Basic Pr ocedur e . . . . . . . . . . . . . . . . . . . . . . . 1-53Finding t he Similar it ies Bet ween Object s . . . . . . . . . . . . . . . . 1-54Defining t he Links Bet ween Object s . . . . . . . . . . . . . . . . . . . . . 1-56Evaluat ing Clust er For mat ion . . . . . . . . . . . . . . . . . . . . . . . . . 1-59Cr eat ing Clust er s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-64Li near Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-68One-Way Analysis of Var iance (ANOVA) . . . . . . . . . . . . . . . . . 1-69Two-Way Analysis of Var iance (ANOVA) . . . . . . . . . . . . . . . . . 1-73N-Way Analysis of Var iance . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-76Mult iple Linear Regr ession . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-82Quadr at ic Response Sur face Models . . . . . . . . . . . . . . . . . . . . . 1-86St epwise Regr ession . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-88Gener alized Linear Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-91Robust and Nonpar amet r ic Met hods . . . . . . . . . . . . . . . . . . . . 1-95Nonli near Regressi on Models . . . . . . . . . . . . . . . . . . . . . . . . 1-100Example: Nonlinear Modeling . . . . . . . . . . . . . . . . . . . . . . . . . 1-100Hypothesi s Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-105Hypot hesis Test Ter minology . . . . . . . . . . . . . . . . . . . . . . . . . 1-105Hypot hesis Test Assumpt ions . . . . . . . . . . . . . . . . . . . . . . . . . 1-106Example: Hypot hesis Test ing . . . . . . . . . . . . . . . . . . . . . . . . . 1-107Available Hypot hesis Test s . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-111Multi vari ate Stati sti cs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-112Pr incipal Component s Analysis . . . . . . . . . . . . . . . . . . . . . . . 1-112Mult ivar iat e Analysis of Var iance (MANOVA) . . . . . . . . . . . 1-122Stati sti cal Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-128Box Plot s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-128Dist r ibut ion Plot s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-129Scat t er Plot s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-135Stati sti cal Process Control (SPC) . . . . . . . . . . . . . . . . . . . . . 1-138Cont r ol Char t s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-138Capabilit y St udies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-141i i iDesi gn of Experi ments (DOE) . . . . . . . . . . . . . . . . . . . . . . . . 1-143Full Fact or ial Designs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-144Fr act ional Fact or ial Designs . . . . . . . . . . . . . . . . . . . . . . . . . . 1-145D-Opt imal Designs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-147Demos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-153The dist t ool Demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-154The polyt ool Demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-156The aoct ool Demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-161The r andt ool Demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-169The r smdemo Demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-170The glmdemo Demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-172The r obust demo Demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-172Selected Bi bli ography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1752ReferenceFuncti on Category Li st . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3anova1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-17anova2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-23anovan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-27aoct ool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-33bar t t est . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-36bet acdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-37bet afit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-38bet ainv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-40bet alike . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-41bet apdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-42bet ar nd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-43bet ast at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-44binocdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-45binofit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-46binoinv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-47binopdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-48binor nd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-49i v Contentsbinost at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-50boot st r p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-51boxplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-54capable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-56capaplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-58caser ead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-60casewr it e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-61cdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-62cdfplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-63chi2cdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-65chi2inv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-66chi2pdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-67chi2r nd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-68chi2st at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-69classify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-70clust er . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-71clust er dat a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-73combnk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-75cophenet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-76cor dexch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-78cor r coef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-79cov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-80cr osst ab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-81daugment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-83dcovar y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-84dendr ogr am . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-85dist t ool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-87dummyvar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-88er r or bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-89ewmaplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-90expcdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-92expfit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-93expinv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-94exppdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-95expr nd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-96expst at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-97fcdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-98ff2n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-99finv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-100fpdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-101vfr acfact . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-102fr iedman . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-106fr nd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-110fst at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-111fsur fht . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-112fullfact . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-114gamcdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-115gamfit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-116gaminv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-117gamlike . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-118gampdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-119gamr nd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-120gamst at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-121geocdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-122geoinv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-123geomean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-124geopdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-125geor nd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-126geost at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-127gline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-128glmdemo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-129glmfit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-130glmval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-135gname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-137gplot mat r ix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-139gr pst at s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-142gscat t er . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-143har mmean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-145hist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-146hist fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-147hougen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-148hygecdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-149hygeinv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-150hygepdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-151hyger nd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-152hygest at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-153icdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-154inconsist ent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-155iqr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-157jbt est . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-158vi Contentskr uskalwallis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-160kst est . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-164kst est 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-169kur t osis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-172lever age . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-174lilliet est . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-175linkage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-178logncdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-181logninv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-182lognpdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-184lognr nd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-185lognst at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-186lsline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-187mad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-188mahal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-189manova1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-190manovaclust er . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-194mean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-196median . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-197mle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-198moment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-199mult compar e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-200mvnr nd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-207mvt r nd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-208nanmax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-209nanmean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-210nanmedian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-211nanmin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-212nanst d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-213nansum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-214nbincdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-215nbininv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-216nbinpdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-217nbinr nd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-218nbinst at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-219ncfcdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-220ncfinv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-222ncfpdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-223ncfr nd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-224ncfst at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-225vi inct cdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-226nct inv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-227nct pdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-228nct r nd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-229nct st at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-230ncx2cdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-231ncx2inv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-233ncx2pdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-234ncx2r nd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-235ncx2st at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-236nlinfit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-237nlint ool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-238nlpar ci . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-239nlpr edci . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-240nor mcdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-242nor mfit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-243nor minv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-244nor mpdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-245nor mplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-246nor mr nd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-248nor mspec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-249nor mst at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-250par et o . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-251pcacov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-252pcar es . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-253pdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-254pdist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-255per ms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-258poisscdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-259poissfit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-261poissinv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-262poisspdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-263poissr nd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-264poisst at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-265polyconf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-266polyfit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-267polyt ool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-268polyval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-269pr ct ile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-270pr incomp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-271vi i i Contentsqqplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-272r andom . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-274r andt ool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-275r ange . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-276r anksum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-277r aylcdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-278r aylinv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-279r aylpdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-280r aylr nd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-281r aylst at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-282r coplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-283r efcur ve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-284r efline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-285r egr ess . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-286r egst at s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-288r idge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-290r obust demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-292r obust fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-293r owexch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-297r smdemo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-298r st ool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-299schar t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-300signr ank . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-302signt est . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-304skewness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-306squar efor m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-308st d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-309st epwise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-310sur fht . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-311t abulat e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-312t blr ead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-313t blwr it e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-315t cdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-316t dfr ead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-317t inv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-319t pdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-320t r immean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-321t r nd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-322t st at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-323t t est . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-324i xt t est 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-326unidcdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-328unidinv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-329unidpdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-330unidr nd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-331unidst at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-332unifcdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-333unifinv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-334unifit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-335unifpdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-336unifr nd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-337unifst at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-338var . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-339weibcdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-341weibfit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-342weibinv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-343weiblike . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-344weibpdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-345weibplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-346weibr nd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-347weibst at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-348x2fx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-349xbar plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-350zscor e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-353zt est . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-354x Contents Pr efaceOvervi ew . . . . . . . . . . . . . . . . . . . . . xiiWhat Is the Stati sti cs Toolbox? . . . . . . . . . . . xiiiHow to Use Thi s Gui de . . . . . . . . . . . . . . . xivRelated Products Li st . . . . . . . . . . . . . . . . xvMathemati cal Notati on . . . . . . . . . . . . . . . xviiTypographi cal Conventi ons . . . . . . . . . . . . . xviii Pr e f a c exi iOverviewThis chapt er int r oduces t he St at ist ics Toolbox, and explains how t o use t he document at ion. It cont ains t he following sect ions: What Is t he St at ist ics Toolbox? How t o Use This Guide Relat ed Pr oduct s List Mat hemat ical Not at ion Typogr aphical Convent ionsW h a t Is th e Sta ti sti c s To o l b o x ?xi i iWhat Is the Statistics Toolbox?The St at ist ics Toolbox is a collect ion of t ools built on t he MATLAB numer ic comput ing envir onment . The t oolbox suppor t s a wide r ange of common st at ist ical t asks, fr om r andom number gener at ion, t o cur ve fit t ing, t o design of exper iment s and st at ist ical pr ocess cont r ol. The t oolbox pr ovides t wo cat egor ies of t ools: Building-block pr obabilit y and st at ist ics funct ions Gr aphical, int er act ive t oolsThe fir st cat egor y of t ools is made up of funct ions t hat you can call fr om t he command line or fr om your own applicat ions. Many of t hese funct ions ar e MATLAB M-files, ser ies of MATLAB st at ement s t hat implement specialized st at ist ics algor it hms. You can view t he MATLAB code for t hese funct ions using t he st at ementtype function_nameYou can change t he way any t oolbox funct ion wor ks by copying and r enaming t he M-file, t hen modifying your copy. You can also ext end t he t oolbox by adding your own M-files.Secondly, t he t oolbox pr ovides a number of int er act ive t ools t hat let you access many of t he funct ions t hr ough a gr aphical user int er face (GUI). Toget her , t he GUI-based t ools pr ovide an envir onment for polynomial fit t ing and pr edict ion, as well as pr obabilit y funct ion explor at ion. Pr e f a c exi vHow to Use This GuideIf you are a new user begin wit h Chapt er 1, Tut or ial. This chapt er int r oduces t he MATLAB st at ist ics envir onment t hr ough t he t oolbox funct ions. It descr ibes t he funct ions wit h r egar d t o par t icular ar eas of int er est , such as pr obabilit y dist r ibut ions, linear and nonlinear models, pr incipal component s analysis, design of exper iment s, st at ist ical pr ocess cont r ol, and descr ipt ive st at ist ics.All toolbox users should use Chapt er 2, Refer ence, for infor mat ion about specific t ools. For funct ions, r efer ence descr ipt ions include a synopsis of t he funct ions synt ax, as well as a complet e explanat ion of opt ions and oper at ion. Many r efer ence descr ipt ions also include examples, a descr ipt ion of t he funct ions algor it hm, and r efer ences t o addit ional r eading mat er ial. Use t his guide in conjunct ion wit h t he soft war e t o lear n about t he power ful feat ur es t hat MATLAB pr ovides. Each chapt er pr ovides numer ous examples t hat apply t he t oolbox t o r epr esent at ive st at ist ical t asks.The r andom number gener at ion funct ions for var ious pr obabilit y dist r ibut ions ar e based on all t he pr imit ive funct ions, randn and rand. Ther e ar e many examples t hat st ar t by gener at ing dat a using r andom number s. To duplicat e t he r esult s in t hese examples, fir st execut e t he commands below.seed = 931316785;rand('seed',seed);randn('seed',seed);You might want t o save t hese commands in an M-file scr ipt called init.m. Then, inst ead of t hr ee separ at e commands, you need only t ype init.Re l a te d Pr o d u c ts Li stxvRelated Products ListThe Mat hWor ks pr ovides sever al pr oduct s t hat ar e especially r elevant t o t he kinds of t asks you can per for m wit h t he St at ist ics Toolbox.For mor e infor mat ion about any of t hese pr oduct s, see eit her : The online document at ion for t hat pr oduct if it is inst alled or if you ar e r eading t he document at ion fr om t he CD The Mat hWor ks Web sit e, at http://www.mathworks.com; see t he pr oduct s sect ionNote The t oolboxes list ed below all include funct ions t hat ext end MATLABs capabilit ies. The blockset s all include blocks t hat ext end Simulinks capabilit ies.Product DescriptionDat a Acquisit ion Toolbox MATLAB funct ions for dir ect access t o live, measur ed dat a fr om MATLABDat abase Toolbox Tool for connect ing t o, and int er act ing wit h, most ODBC/J DBC dat abases fr om wit hin MATLABFinancial Time Ser ies ToolboxTool for analyzing t ime ser ies dat a in t he financial mar ket sFinancial Toolbox MATLAB funct ions for quant it at ive financial modeling and analyt ic pr ot ot ypingGARCH Toolbox MATLAB funct ions for univar iat e Gener alized Aut or egr essive Condit ional Het er oskedast icit y (GARCH) volat ilit y modeling Image Pr ocessing ToolboxComplet e suit e of digit al image pr ocessing and analysis t ools for MATLAB Pr e f a c exviMapping Toolbox Tool for analyzing and displaying geogr aphically based infor mat ion fr om wit hin MATLAB Neur al Net wor k Toolbox Compr ehensive envir onment for neur al net wor k r esear ch, design, and simulat ion wit hin MATLAB Opt imizat ion Toolbox Tool for gener al and lar ge-scale opt imizat ion of nonlinear pr oblems, as well as for linear pr ogr amming, quadr at ic pr ogr amming, nonlinear least squar es, and solving nonlinear equat ionsSignal Pr ocessing ToolboxTool for algor it hm development , signal and linear syst em analysis, and t ime-ser ies dat a modelingSyst em Ident ificat ion ToolboxTool for building accur at e, simplified models of complex syst ems fr om noisy t ime-ser ies dat aProduct DescriptionM a th e m a ti c a l N o ta ti o nxvi iMathematical NotationThis manual and t he St at ist ics Toolbox funct ions use t he following mat hemat ical not at ion convent ions. Par amet er s in a linear model.E(x) Expect ed value of x. f(x| a,b) Pr obabilit y densit y funct ion. x is t he independent var iable; a and b ar e fixed par amet er s.F(x| a,b) Cumulat ive dist r ibut ion funct ion.I([a, b]) or I[a, b]Indicat or funct ion. In t his example t he funct ion t akes t he value 1 on t he closed int er val fr om a t o b and is 0 elsewher e.p and q p is t he pr obabilit y of some event . q is t he pr obabilit y of ~p, so q = 1p.E x ( ) t f t ( ) t d= Pr e f a c exvi i iTypographical ConventionsThis manual uses some or all of t hese convent ions.Item Convention Used ExampleExample code Monospace font To assign t he value 5 t o A, ent erA = 5Funct ion names/synt ax Monospace font The cos funct ion finds t he cosine of each ar r ay element .Synt ax line example isMLGetVar ML_var_nameKeys Boldface wit h an init ial capit al let t erPr ess t he Return key.Lit er al st r ings (in synt ax descr ipt ions in r efer ence chapt er s)Monospace bold for lit er als f = freqspace(n,'whole')Mat hemat icalexpr essionsItalics for var iablesSt andar d t ext font for funct ions, oper at or s, and const ant sThis vect or r epr esent s t he polynomialp = x2 + 2x + 3MATLAB out put Monospace font MATLAB r esponds wit hA =5Menu t it les, menu it ems, dialog boxes, and cont r olsBoldface wit h an init ial capit al let t erChoose t he Fi le menu.New t er ms Italics An array is an or der ed collect ion of infor mat ion.Omit t ed input ar gument s (...) ellipsis denot es all of t he input /out put ar gument s fr om pr eceding synt axes. [c,ia,ib] = union(...)St r ing var iables (fr om a finit e list )Monospace italics sysc = d2c(sysd,'method') 1 Tut or ialIntroducti on . . . . . . . . . . . . . . . . . . . . 1-2Probabi li ty Di stri buti ons . . . . . . . . . . . . . . 1-5Descri pti ve Stati sti cs . . . . . . . . . . . . . . . . 1-43Cluster Analysi s . . . . . . . . . . . . . . . . . . 1-53Li near Models . . . . . . . . . . . . . . . . . . . 1-68Nonli near Regressi on Models . . . . . . . . . . . 1-100Hypothesi s Tests . . . . . . . . . . . . . . . . . 1-105Multi vari ate Stati sti cs . . . . . . . . . . . . . . 1-112Stati sti cal Plots . . . . . . . . . . . . . . . . . 1-128Stati sti cal Process Control (SPC) . . . . . . . . . 1-138Desi gn of Experi ments (DOE) . . . . . . . . . . . 1-143Demos . . . . . . . . . . . . . . . . . . . . . . 1-153Selected Bi bli ography . . . . . . . . . . . . . . 1-1751 Tu to r i a l1-2IntroductionThe St at ist ics Toolbox, for use wit h MATLAB, supplies basic st at ist ics capabilit y on t he level of a fir st cour se in engineer ing or scient ific st at ist ics. The st at ist ics funct ions it pr ovides ar e building blocks suit able for use inside ot her analyt ical t ools.Primary Topic AreasThe St at ist ics Toolbox has mor e t han 200 M-files, suppor t ing wor k in t he t opical ar eas below: Pr obabilit y dist r ibut ions Descr ipt ive st at ist ics Clust er analysis Linear models Nonlinear models Hypot hesis t est s Mult ivar iat e st at ist ics St at ist ical plot s St at ist ical pr ocess cont r ol Design of exper iment sProba bility DistributionsThe St at ist ics Toolbox suppor t s 20 pr obabilit y dist r ibut ions. For each dist r ibut ion t her e ar e five associat ed funct ions. They ar e: Pr obabilit y densit y funct ion (pdf) Cumulat ive dist r ibut ion funct ion (cdf) Inver se of t he cumulat ive dist r ibut ion funct ion Random number gener at or Mean and var iance as a funct ion of t he par amet er sFor dat a-dr iven dist r ibut ions (bet a, binomial, exponent ial, gamma, nor mal, Poisson, unifor m, and Weibull), t he St at ist ics Toolbox has funct ions for comput ing par amet er est imat es and confidence int er vals.In tr o d u c ti o n1-3Descriptive Sta tisticsThe St at ist ics Toolbox pr ovides funct ions for descr ibing t he feat ur es of a dat a sample. These descr ipt ive st at ist ics include measur es of locat ion and spr ead, per cent ile est imat es and funct ions for dealing wit h dat a having missing values.Cluster Ana lysisThe St at ist ics Toolbox pr ovides funct ions t hat allow you t o divide a set of object s int o subgr oups, each having member s t hat ar e as much alike as possible. This pr ocess is called cluster analysis.Linea r M odelsIn t he ar ea of linear models, t he St at ist ics Toolbox suppor t s one-way, t wo-way, and higher -way analysis of var iance (ANOVA), analysis of covar iance (ANOCOVA), mult iple linear r egr ession, st epwise r egr ession, r esponse sur face pr edict ion, r idge r egr ession, and one-way mult ivar iat e analysis of var iance (MANOVA). It suppor t s nonpar amet r ic ver sions of one- and t wo-way ANOVA. It also suppor t s mult iple compar isons of t he est imat es pr oduced by ANOVA and ANOCOVA funct ions.N onlinea r M odelsFor nonlinear models, t he St at ist ics Toolbox pr ovides funct ions for par amet er est imat ion, int er act ive pr edict ion and visualizat ion of mult idimensional nonlinear fit s, and confidence int er vals for par amet er s and pr edict ed values.Hypothesis TestsThe St at ist ics Toolbox also pr ovides funct ions t hat do t he most common t est s of hypot hesis t -t est s, Z-t est s, nonpar amet r ic t est s, and dist r ibut ion t est s.M ultiva ria te Sta tisticsThe St at ist ics Toolbox suppor t s met hods in mult ivar iat e st at ist ics, including pr incipal component s analysis, linear discr iminant analysis, and one-way mult ivar iat e analysis of var iance.1 Tu to r i a l1-4Sta tistica l PlotsThe St at ist ics Toolbox adds box plot s, nor mal pr obabilit y plot s, Weibull pr obabilit y plot s, cont r ol char t s, and quant ile-quant ile plot s t o t he ar senal of gr aphs in MATLAB. Ther e is also ext ended suppor t for polynomial cur ve fit t ing and pr edict ion. Ther e ar e funct ions t o cr eat e scat t er plot s or mat r ices of scat t er plot s for gr ouped dat a, and t o ident ify point s int er act ively on such plot s. Ther e is a funct ion t o int er act ively explor e a fit t ed r egr ession model.Sta tistica l Process Control (SPC)For SPC, t he St at ist ics Toolbox pr ovides funct ions for plot t ing common cont r ol char t s and per for ming pr ocess capabilit y st udies.Design of Ex periments (DO E)The St at ist ics Toolbox suppor t s full and fr act ional fact or ial designs and D-opt imal designs. Ther e ar e funct ions for gener at ing designs, augment ing designs, and opt imally assigning unit s wit h fixed covar iat es.Pr o b a b i l i ty D i str i b u ti o n s1-5Probability DistributionsPr obabilit y dist r ibut ions ar ise fr om exper iment s wher e t he out come is subject t o chance. The nat ur e of t he exper iment dict at es which pr obabilit y dist r ibut ions may be appr opr iat e for modeling t he r esult ing r andom out comes. Ther e ar e t wo t ypes of pr obabilit y dist r ibut ions continuous and discrete.Suppose you ar e st udying a machine t hat pr oduces videot ape. One measur e of t he qualit y of t he t ape is t he number of visual defect s per hundr ed feet of t ape. The r esult of t his exper iment is an int eger , since you cannot obser ve 1.5 defect s. To model t his exper iment you should use a discr et e pr obabilit y dist r ibut ion. A measur e affect ing t he cost and qualit y of videot ape is it s t hickness. Thick t ape is mor e expensive t o pr oduce, while var iat ion in t he t hickness of t he t ape on t he r eel incr eases t he likelihood of br eakage. Suppose you measur e t he t hickness of t he t ape ever y 1000 feet . The r esult ing number s can t ake a cont inuum of possible values, which suggest s using a cont inuous pr obabilit y dist r ibut ion t o model t he r esult s. Using a pr obabilit y model does not allow you t o pr edict t he r esult of any individual exper iment but you can det er mine t he pr obabilit y t hat a given out come will fall inside a specific r ange of values.Continuous (data) Continuous (statistics) DiscreteBet a Chi-squar e BinomialExponent ial Noncent r al Chi-squar e Discr et e Unifor mGamma F Geomet r icLognor mal Noncent r al F Hyper geomet r icNor mal t Negat ive BinomialRayleigh Noncent r al t PoissonUnifor mWeibull1 Tu to r i a l1-6This following t wo sect ions pr ovide mor e infor mat ion about t he available dist r ibut ions: Over view of t he Funct ions Over view of t he Dist r ibut ionsOverview of the FunctionsMATLAB pr ovides five funct ions for each dist r ibut ion, which ar e discussed in t he following sect ions: Pr obabilit y Densit y Funct ion (pdf) Cumulat ive Dist r ibut ion Funct ion (cdf) Inver se Cumulat ive Dist r ibut ion Funct ion Random Number Gener at or Mean and Var iance as a Funct ion of Par amet er sProba bility Density Function (pdf)The pr obabilit y densit y funct ion (pdf) has a differ ent meaning depending on whet her t he dist r ibut ion is discr et e or cont inuous.For discr et e dist r ibut ions, t he pdf is t he pr obabilit y of obser ving a par t icular out come. In our videot ape example, t he pr obabilit y t hat t her e is exact ly one defect in a given hundr ed feet of t ape is t he value of t he pdf at 1.Unlike discr et e dist r ibut ions, t he pdf of a cont inuous dist r ibut ion at a value is not t he pr obabilit y of obser ving t hat value. For cont inuous dist r ibut ions t he pr obabilit y of obser ving any par t icular value is zer o. To get pr obabilit ies you must int egr at e t he pdf over an int er val of int er est . For example t he pr obabilit y of t he t hickness of a videot ape being bet ween one and t wo millimet er s is t he int egr al of t he appr opr iat e pdf fr om one t o t wo.A pdf has t wo t heor et ical pr oper t ies: The pdf is zer o or posit ive for ever y possible out come. The int egr al of a pdf over it s ent ir e r ange of values is one.A pdf is not a single funct ion. Rat her a pdf is a family of funct ions char act er ized by one or mor e par amet er s. Once you choose (or est imat e) t he par amet er s of a pdf, you have uniquely specified t he funct ion.Pr o b a b i l i ty D i str i b u ti o n s1-7The pdf funct ion call has t he same gener al for mat for ever y dist r ibut ion in t he St at ist ics Toolbox. The following commands illust r at e how t o call t he pdf for t he nor mal dist r ibut ion.x = [-3:0.1:3];f = normpdf(x,0,1);The var iable f cont ains t he densit y of t he nor mal pdf wit h par amet er s =0 and =1 at t he values in x. The fir st input ar gument of ever y pdf is t he set of values for which you want t o evaluat e t he densit y. Ot her ar gument s cont ain as many par amet er s as ar e necessar y t o define t he dist r ibut ion uniquely. The nor mal dist r ibut ion r equir es t wo par amet er s; a locat ion par amet er (t he mean, ) and a scale par amet er (t he st andar d deviat ion, ).Cumula tive Distribution Function (cdf)If f is a pr obabilit y densit y funct ion for r andom var iable X, t he associat ed cumulat ive dist r ibut ion funct ion (cdf) F is The cdf of a value x, F(x), is t he pr obabilit y of obser ving any out come less t han or equal t o x.A cdf has t wo t heor et ical pr oper t ies: The cdf r anges fr om 0 t o 1. If y > x, t hen t he cdf of y is gr eat er t han or equal t o t he cdf of x.The cdf funct ion call has t he same gener al for mat for ever y dist r ibut ion in t he St at ist ics Toolbox. The following commands illust r at e how t o call t he cdf for t he nor mal dist r ibut ion.x = [-3:0.1:3];p = normcdf(x,0,1);The var iable p cont ains t he pr obabilit ies associat ed wit h t he nor mal cdf wit h par amet er s =0 and =1 at t he values in x. The fir st input ar gument of ever y cdf is t he set of values for which you want t o evaluat e t he pr obabilit y. Ot her ar gument s cont ain as many par amet er s as ar e necessar y t o define t he dist r ibut ion uniquely.F x ( ) P X x ( ) f t ( ) t d x= =1 Tu to r i a l1-8Inverse Cumula tive Distribution FunctionThe inver se cumulat ive dist r ibut ion funct ion r et ur ns cr it ical values for hypot hesis t est ing given significance pr obabilit ies. To under st and t he r elat ionship bet ween a cont inuous cdf and it s inver se funct ion, t r y t he following:x = [-3:0.1:3];xnew = norminv(normcdf(x,0,1),0,1);How does xnew compar e wit h x? Conver sely, t r y t his:p = [0.1:0.1:0.9];pnew = normcdf(norminv(p,0,1),0,1);How does pnew compar e wit h p?Calculat ing t he cdf of values in t he domain of a cont inuous dist r ibut ion r et ur ns pr obabilit ies bet ween zer o and one. Applying t he inver se cdf t o t hese pr obabilit ies yields t he or iginal values. For discr et e dist r ibut ions, t he r elat ionship bet ween a cdf and it s inver se funct ion is mor e complicat ed. It is likely t hat t her e is no x value such t hat t he cdf of x yields p. In t hese cases t he inver se funct ion r et ur ns t he fir st value x such t hat t he cdf of x equals or exceeds p. Tr y t his:x = [0:10];y = binoinv(binocdf(x,10,0.5),10,0.5);How does x compar e wit h y? The commands below illust r at e t he pr oblem wit h r econst r uct ing t he pr obabilit y p fr om t he value x for discr et e dist r ibut ions.p = [0.1:0.2:0.9];pnew = binocdf(binoinv(p,10,0.5),10,0.5)pnew = 0.1719 0.3770 0.6230 0.8281 0.9453The inver se funct ion is useful in hypot hesis t est ing and pr oduct ion of confidence int er vals. Her e is t he way t o get a 99% confidence int er val for a nor mally dist r ibut ed sample.Pr o b a b i l i ty D i str i b u ti o n s1-9p = [0.005 0.995];x = norminv(p,0,1)x = -2.5758 2.5758The var iable x cont ains t he values associat ed wit h t he nor mal inver se funct ion wit h par amet er s =0 and =1 at t he pr obabilit ies in p. The differ ence p(2)-p(1) is 0.99. Thus, t he values in x define an int er val t hat cont ains 99% of t he st andar d nor mal pr obabilit y. The inver se funct ion call has t he same gener al for mat for ever y dist r ibut ion in t he St at ist ics Toolbox. The fir st input ar gument of ever y inver se funct ion is t he set of pr obabilit ies for which you want t o evaluat e t he cr it ical values. Ot her ar gument s cont ain as many par amet er s as ar e necessar y t o define t he dist r ibut ion uniquely.Ra ndom N umber Genera torThe met hods for gener at ing r andom number s fr om any dist r ibut ion all st ar t wit h unifor m r andom number s. Once you have a unifor m r andom number gener at or , you can pr oduce r andom number s fr om ot her dist r ibut ions eit her dir ect ly or by using inver sion or r eject ion met hods, descr ibed below. See Synt ax for Random Number Funct ions on page 1-10 for det ails on using gener at or funct ions.Direct. Dir ect met hods flow fr om t he definit ion of t he dist r ibut ion. As an example, consider gener at ing binomial r andom number s. You can t hink of binomial r andom number s as t he number of heads in n t osses of a coin wit h pr obabilit y p of a heads on any t oss. If you gener at e n unifor m r andom number s and count t he number t hat ar e gr eat er t han p, t he r esult is binomial wit h par amet er s n and p.Inversion. The inver sion met hod wor ks due t o a fundament al t heor em t hat r elat es t he unifor m dist r ibut ion t o ot her cont inuous dist r ibut ions.If F is a cont inuous dist r ibut ion wit h inver se F-1, and U is a unifor m r andom number , t hen F-1(U) has dist r ibut ion F.So, you can gener at e a r andom number fr om a dist r ibut ion by applying t he inver se funct ion for t hat dist r ibut ion t o a unifor m r andom number . Unfor t unat ely, t his appr oach is usually not t he most efficient .1 Tu to r i a l1-10Rejection. The funct ional for m of some dist r ibut ions makes it difficult or t ime consuming t o gener at e r andom number s using dir ect or inver sion met hods. Reject ion met hods can somet imes pr ovide an elegant solut ion in t hese cases.Suppose you want t o gener at e r andom number s fr om a dist r ibut ion wit h pdf f. To use r eject ion met hods you must fir st find anot her densit y, g, and a const ant , c, so t hat t he inequalit y below holds.You t hen gener at e t he r andom number s you want using t he following st eps:1 Gener at e a r andom number x fr om dist r ibut ion G wit h densit y g.2 For m t he r at io .3 Gener at e a unifor m r andom number u.4 If t he pr oduct of u and r is less t han one, r et ur n x.5 Ot her wise r epeat st eps one t o t hr ee.For efficiency you need a cheap met hod for gener at ing r andom number s fr om G, and t he scalar c should be small. The expect ed number of it er at ions is c.Synta x for Ra ndom N umber Functions. You can gener at e r andom number s fr om each dist r ibut ion. This funct ion pr ovides a single r andom number or a mat r ix of r andom number s, depending on t he ar gument s you specify in t he funct ion call.For example, her e is t he way t o gener at e r andom number s fr om t he bet a dist r ibut ion. Four st at ement s obt ain r andom number s: t he fir st r et ur ns a single number , t he second r et ur ns a 2-by-2 mat r ix of r andom number s, and t he t hir d and four t h r et ur n 2-by-3 mat r ices of r andom number s.a = 1;b = 2;c = [.1 .5; 1 2];d = [.25 .75; 5 10];m = [2 3];nrow = 2;ncol = 3;f x ( ) cg x ( ) x rcg x ( )f x ( )-------------- =Pr o b a b i l i ty D i str i b u ti o n s1-11r1 = betarnd(a,b)r1 = 0.4469r2 = betarnd(c,d)r2 = 0.8931 0.4832 0.1316 0.2403r3 = betarnd(a,b,m)r3 = 0.4196 0.6078 0.1392 0.0410 0.0723 0.0782r4 = betarnd(a,b,nrow,ncol)r4 = 0.0520 0.3975 0.1284 0.3891 0.1848 0.5186M ea n a nd Va ria nce a s a Function of Pa ra metersThe mean and var iance of a pr obabilit y dist r ibut ion ar e gener ally simple funct ions of t he par amet er s of t he dist r ibut ion. The St at ist ics Toolbox funct ions ending in "stat" all pr oduce t he mean and var iance of t he desir ed dist r ibut ion for t he given par amet er s.The example below shows a cont our plot of t he mean of t he Weibull dist r ibut ion as a funct ion of t he par amet er s.x = (0.5:0.1:5);y = (1:0.04:2);[X,Y] = meshgrid(x,y);Z = weibstat(X,Y);[c,h] = contour(x,y,Z,[0.4 0.6 1.0 1.8]);clabel(c);1 Tu to r i a l1-12Overview of the DistributionsThe following sect ions descr ibe t he available pr obabilit y dist r ibut ions: Bet a Dist r ibut ion on page 1-13 Binomial Dist r ibut ion on page 1-15 Chi-Squar e Dist r ibut ion on page 1-17 Noncent r al Chi-Squar e Dist r ibut ion on page 1-18 Discr et e Unifor m Dist r ibut ion on page 1-20 Exponent ial Dist r ibut ion on page 1-21 F Dist r ibut ion on page 1-23 Noncent r al F Dist r ibut ion on page 1-24 Gamma Dist r ibut ion on page 1-25 Geomet r ic Dist r ibut ion on page 1-27 Hyper geomet r ic Dist r ibut ion on page 1-28 Lognor mal Dist r ibut ion on page 1-30 Negat ive Binomial Dist r ibut ion on page 1-31 Nor mal Dist r ibut ion on page 1-32 Poisson Dist r ibut ion on page 1-34 Rayleigh Dist r ibut ion on page 1-35 St udent s t Dist r ibut ion on page 1-37 Noncent r al t Dist r ibut ion on page 1-38 Unifor m (Cont inuous) Dist r ibut ion on page 1-39 Weibull Dist r ibut ion on page 1-401 2 3 4 511.21.41.61.82 0.4 0.6 1 1.8Pr o b a b i l i ty D i str i b u ti o n s1-13Beta DistributionThe following sect ions pr ovide an over view of t he bet a dist r ibut ion.Ba ckground on the Beta Distribution. The bet a dist r ibut ion descr ibes a family of cur ves t hat ar e unique in t hat t hey ar e nonzer o only on t he int er val (0 1). A mor e gener al ver sion of t he funct ion assigns par amet er s t o t he end-point s of t he int er val.The bet a cdf is t he same as t he incomplet e bet a funct ion.The bet a dist r ibut ion has a funct ional r elat ionship wit h t he t dist r ibut ion. If Y is an obser vat ion fr om St udent s t dist r ibut ion wit h degr ees of fr eedom, t hen t he following t r ansfor mat ion gener at es X, which is bet a dist r ibut ed.if t hen The St at ist ics Toolbox uses t his r elat ionship t o comput e values of t he t cdf and inver se funct ion as well as gener at ing t dist r ibut ed r andom number s.Definition of the Beta Distribution. The bet a pdf iswher e B( ) is t he Bet a funct ion. The indicat or funct ion I(0,1)(x) ensur es t hat only values of x in t he r ange (0 1) have nonzer o pr obabilit y.Pa ra meter Estima tion for the Beta Distribution. Suppose you ar e collect ing dat a t hat has har d lower and upper bounds of zer o and one r espect ively. Par amet er est imat ion is t he pr ocess of det er mining t he par amet er s of t he bet a dist r ibut ion t hat fit t his dat a best in some sense.One popular cr it er ion of goodness is t o maximize t he likelihood funct ion. The likelihood has t he same for m as t he bet a pdf. But for t he pdf, t he par amet er s ar e known const ant s and t he var iable is x. The likelihood funct ion r ever ses t he r oles of t he var iables. Her e, t he sample values (t he xs) ar e alr eady obser ved. So t hey ar e t he fixed const ant s. The var iables ar e t he unknown par amet er s. X12---12---Y Y2+-------------------- + =Y t ( ) X 2--- 2--- , , _y f x a b , ( )1B a b , ( )-------------------xa 1 1 x ( )b 1 I0 1 , ( )x ( ) = =1 Tu to r i a l1-14Maximum likelihood est imat ion (MLE) involves calculat ing t he values of t he par amet er s t hat give t he highest likelihood given t he par t icular set of dat a.The funct ion betafit r et ur ns t he MLEs and confidence int er vals for t he par amet er s of t he bet a dist r ibut ion. Her e is an example using r andom number s fr om t he bet a dist r ibut ion wit h a = 5 and b = 0.2.r = betarnd(5,0.2,100,1);[phat, pci] = betafit(r)phat = 4.5330 0.2301pci = 2.8051 0.1771 6.2610 0.2832The MLE for par amet er a is 4.5330, compar ed t o t he t r ue value of 5. The 95% confidence int er val for a goes fr om 2.8051 t o 6.2610, which includes t he t r ue value.Similar ly t he MLE for par amet er b is 0.2301, compar ed t o t he t r ue value of 0.2. The 95% confidence int er val for b goes fr om 0.1771 t o 0.2832, which also includes t he t r ue value. Of cour se, in t his made-up example we know t he t r ue value. In exper iment at ion we do not . Exa mple a nd Plot of the Beta Distribution. The shape of t he bet a dist r ibut ion is quit e var iable depending on t he values of t he par amet er s, as illust r at ed by t he plot below.0 0.2 0.4 0.6 0.8 100.511.522.5 a = b = 1 a = b = 4 a = b = 0.75 Pr o b a b i l i ty D i str i b u ti o n s1-15The const ant pdf (t he flat line) shows t hat t he st andar d unifor m dist r ibut ion is a special case of t he bet a dist r ibut ion.Binomia l DistributionThe following sect ions pr ovide an over view of t he binomial dist r ibut ion.Ba ckground of the Binomia l Distribution. The binomial dist r ibut ion models t he t ot al number of successes in r epeat ed t r ials fr om an infinit e populat ion under t he following condit ions: Only t wo out comes ar e possible on each of n t r ials. The pr obabilit y of success for each t r ial is const ant . All t r ials ar e independent of each ot her .J ames Ber noulli der ived t he binomial dist r ibut ion in 1713 (Ars Conjectandi). Ear lier , Blaise Pascal had consider ed t he special case wher e p = 1/2.Definition of the Binomia l Distribution. The binomial pdf iswher e and .The binomial dist r ibut ion is discr et e. For zer o and for posit ive int eger s less t han n, t he pdf is nonzer o.Pa ra meter Estima tion for the Binomia l Distribution. Suppose you ar e collect ing dat a fr om a widget manufact ur ing pr ocess, and you r ecor d t he number of widget s wit hin specificat ion in each bat ch of 100. You might be int er est ed in t he pr obabilit y t hat an individual widget is wit hin specificat ion. Par amet er est imat ion is t he pr ocess of det er mining t he par amet er , p, of t he binomial dist r ibut ion t hat fit s t his dat a best in some sense.One popular cr it er ion of goodness is t o maximize t he likelihood funct ion. The likelihood has t he same for m as t he binomial pdf above. But for t he pdf, t he par amet er s (n and p) ar e known const ant s and t he var iable is x. The likelihood funct ion r ever ses t he r oles of t he var iables. Her e, t he sample values (t he xs) ar e alr eady obser ved. So t hey ar e t he fixed const ant s. The var iables ar e t he y f x n p , ( )nx , _pxq1 x ( )I0 1 n , , , ( )x ( ) = =nx , _n!x! n x ( )!------------------------ = q 1 p =1 Tu to r i a l1-16unknown par amet er s. MLE involves calculat ing t he value of p t hat give t he highest likelihood given t he par t icular set of dat a.The funct ion binofit r et ur ns t he MLEs and confidence int er vals for t he par amet er s of t he binomial dist r ibut ion. Her e is an example using r andom number s fr om t he binomial dist r ibut ion wit h n = 100 and p = 0.9.r = binornd(100,0.9)r = 88[phat, pci] = binofit(r,100)phat = 0.8800pci = 0.7998 0.9364The MLE for par amet er p is 0.8800, compar ed t o t he t r ue value of 0.9. The 95% confidence int er val for p goes fr om 0.7998 t o 0.9364, which includes t he t r ue value. Of cour se, in t his made-up example we know t he t r ue value of p. In exper iment at ion we do not .Exa mple a nd Plot of the Binomia l Distribution. The following commands gener at e a plot of t he binomial pdf for n = 10 and p = 1/2.x = 0:10;y = binopdf(x,10,0.5);plot(x,y,'+')Pr o b a b i l i ty D i str i b u ti o n s1-17Chi- Squa re DistributionThe following sect ions pr ovide an over view of t he 2 dist r ibut ion.Ba ckground of the Chi-Squa re Distribution. The 2 dist r ibut ion is a special case of t he gamma dist r ibut ion wher e b = 2 in t he equat ion for gamma dist r ibut ion below.The 2 dist r ibut ion get s special at t ent ion because of it s impor t ance in nor mal sampling t heor y. If a set of n obser vat ions is nor mally dist r ibut ed wit h var iance 2, and s2 is t he sample st andar d deviat ion, t henThe St at ist ics Toolbox uses t he above r elat ionship t o calculat e confidence int er vals for t he est imat e of t he nor mal par amet er 2 in t he funct ion normfit.0 2 4 6 8 1000.050.10.150.20.25y f x a b , ( )1ba a ( )------------------xa 1 exb--- = =n 1 ( )s22----------------------- 2n 1 ( ) 1 Tu to r i a l1-18Definition of the Chi-Squa re Distribution. The 2 pdf iswher e ( ) is t he Gamma funct ion, and is t he degr ees of fr eedom.Exa mple a nd Plot of the Chi-Squa re Distribution. The 2 dist r ibut ion is skewed t o t he r ight especially for few degr ees of fr eedom (). The plot shows t he 2 dist r ibut ion wit h four degr ees of fr eedom.x = 0:0.2:15;y = chi2pdf(x,4);plot(x,y)N oncentra l Chi- Squa re DistributionThe following sect ions pr ovide an over view of t he noncent r al 2 dist r ibut ion.Ba ckground of the N oncentra l Chi-Squa re Distribution. The 2 dist r ibut ion is act ually a simple special case of t he noncent r al chi-squar e dist r ibut ion. One way t o gener at e r andom number s wit h a 2 dist r ibut ion (wit h degr ees of fr eedom) is t o sum t he squar es of st andar d nor mal r andom number s (mean equal t o zer o.) What if we allow t he nor mally dist r ibut ed quant it ies t o have a mean ot her t han zer o? The sum of squar es of t hese number s yields t he noncent r al chi-squar e dist r ibut ion. The noncent r al chi-squar e dist r ibut ion r equir es t wo par amet er s; t he degr ees of fr eedom and t he noncent r alit y par amet er . The noncent r alit y par amet er is t he sum of t he squar ed means of t he nor mally dist r ibut ed quant it ies.y f x ( )x 2 ( ) 2 ex 2 2v2--- 2 ( )------------------------------------- = =0 5 10 1500.050.10.150.2Pr o b a b i l i ty D i str i b u ti o n s1-19The noncent r al chi-squar e has scient ific applicat ion in t her modynamics and signal pr ocessing. The lit er at ur e in t hese ar eas may r efer t o it as t he Ricean or gener alized Rayleigh dist r ibut ion.Definition of the N oncentra l Chi-Squa re Distribution. Ther e ar e many equivalent for mulas for t he noncent r al chi-squar e dist r ibut ion funct ion. One for mulat ion uses a modified Bessel funct ion of t he fir st kind. Anot her uses t he gener alized Laguer r e polynomials. The St at ist ics Toolbox comput es t he cumulat ive dist r ibut ion funct ion values using a weight ed sum of 2 pr obabilit ies wit h t he weight s equal t o t he pr obabilit ies of a Poisson dist r ibut ion. The Poisson par amet er is one-half of t he noncent r alit y par amet er of t he noncent r al chi-squar e.wher e is t he noncent r alit y par amet er .Exa mple of the N oncentra l Chi-Squa re Distribution. The following commands gener at e a plot of t he noncent r al chi-squar e pdf.x = (0:0.1:10)';p1 = ncx2pdf(x,4,2);p = chi2pdf(x,4);plot(x,p,'--',x,p1,'-')F x , ( )12--- , _jj!--------------e2--- , _Pr 2j +2x [ ]j 0 ==0 2 4 6 8 1000.050.10.150.21 Tu to r i a l1-20Discrete Unifor m DistributionThe following sect ions pr ovide an over view of t he discr et e unifor m dist r ibut ion.Ba ckground of the Discrete Uniform Distribution. The discr et e unifor m dist r ibut ion is a simple dist r ibut ion t hat put s equal weight on t he int eger s fr om one t o N.Definition of the Discrete Uniform Distribution. The discr et e unifor m pdf isExa mple a nd Plot of the Discrete Uniform Distribution. As for all discr et e dist r ibut ions, t he cdf is a st ep funct ion. The plot shows t he discr et e unifor m cdf for N = 10.x = 0:10;y = unidcdf(x,10);stairs(x,y)set(gca,'Xlim',[0 11])To pick a r andom sample of 10 fr om a list of 553 it ems:numbers = unidrnd(553,1,10)numbers =293 372 5 213 37 231 380 326 515 468y f x N ( )1N---- I1 N , , ( )x ( ) = =0 2 4 6 8 1000.20.40.60.81Pr o b a b i l i ty D i str i b u ti o n s1-21Ex ponentia l DistributionThe following sect ions pr ovide an over view of t he exponent ial dist r ibut ion.Ba ckground of the Exponentia l Distribution. Like t he chi-squar e dist r ibut ion, t he exponent ial dist r ibut ion is a special case of t he gamma dist r ibut ion (obt ained by set t ing a = 1)wher e ( ) is t he Gamma funct ion.The exponent ial dist r ibut ion is special because of it s ut ilit y in modeling event s t hat occur r andomly over t ime. The main applicat ion ar ea is in st udies of lifet imes. Definition of the Exponentia l Distribution. The exponent ial pdf isPa ra meter Estima tion for the Exponentia l Distribution. Suppose you ar e st r ess t est ing light bulbs and collect ing dat a on t heir lifet imes. You assume t hat t hese lifet imes follow an exponent ial dist r ibut ion. You want t o know how long you can expect t he aver age light bulb t o last . Par amet er est imat ion is t he pr ocess of det er mining t he par amet er s of t he exponent ial dist r ibut ion t hat fit t his dat a best in some sense.One popular cr it er ion of goodness is t o maximize t he likelihood funct ion. The likelihood has t he same for m as t he exponent ial pdf above. But for t he pdf, t he par amet er s ar e known const ant s and t he var iable is x. The likelihood funct ion r ever ses t he r oles of t he var iables. Her e, t he sample values (t he xs) ar e alr eady obser ved. So t hey ar e t he fixed const ant s. The var iables ar e t he unknown par amet er s. MLE involves calculat ing t he values of t he par amet er s t hat give t he highest likelihood given t he par t icular set of dat a.y f x a b , ( )1ba a ( )------------------xa 1 exb--- = =y f x ( )1---ex--- = =1 Tu to r i a l1-22The funct ion expfit r et ur ns t he MLEs and confidence int er vals for t he par amet er s of t he exponent ial dist r ibut ion. Her e is an example using r andom number s fr om t he exponent ial dist r ibut ion wit h = 700.lifetimes = exprnd(700,100,1);[muhat, muci] = expfit(lifetimes)muhat = 672.8207muci = 547.4338 810.9437The MLE for par amet er is 672, compar ed t o t he t r ue value of 700. The 95% confidence int er val for goes fr om 547 t o 811, which includes t he t r ue value.In our life t est s we do not know t he t r ue value of so it is nice t o have a confidence int er val on t he par amet er t o give a r ange of likely values. Exa mple a nd Plot of the Exponentia l Distribution. For exponent ially dist r ibut ed lifet imes, t he pr obabilit y t hat an it em will sur vive an ext r a unit of t ime is independent of t he cur r ent age of t he it em. The example shows a specific case of t his special pr oper t y.l = 10:10:60;lpd = l+0.1;deltap = (expcdf(lpd,50)-expcdf(l,50))./(1-expcdf(l,50))deltap = 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020The plot below shows t he exponent ial pdf wit h it s par amet er (and mean), , set t o 2.x = 0:0.1:10;y = exppdf(x,2);plot(x,y)Pr o b a b i l i ty D i str i b u ti o n s1-23F DistributionThe following sect ions pr ovide an over view of t he F dist r ibut ion.Ba ckground of the F distribution. The F dist r ibut ion has a nat ur al r elat ionship wit h t he chi-squar e dist r ibut ion. If 1 and 2 ar e bot h chi-squar e wit h 1 and 2 degr ees of fr eedom r espect ively, t hen t he st at ist ic F below is F dist r ibut ed.The t wo par amet er s, 1 and 2, ar e t he numer at or and denominat or degr ees of fr eedom. That is, 1 and 2 ar e t he number of independent pieces infor mat ion used t o calculat e 1 and 2 r espect ively.Definition of the F distribution. The pdf for t he F dist r ibut ion iswher e ( ) is t he Gamma funct ion.Exa mple a nd Plot of the F distribution. The most common applicat ion of t he F dist r ibut ion is in st andar d t est s of hypot heses in analysis of var iance and r egr ession.0 2 4 6 8 1000.10.20.30.40.5F 1 2, ( )11------22------------ =y f x 1 2, ( ) 1 2+ ( )2----------------------- 12------ , _ 22------ , _-------------------------------- 12------ , _12-----x12 2--------------1 12------ , _x +1 2+2------------------------------------------------------------- = =1 Tu to r i a l1-24The plot shows t hat t he F dist r ibut ion exist s on t he posit ive r eal number s and is skewed t o t he r ight .x = 0:0.01:10;y = fpdf(x,5,3);plot(x,y)N oncentra l F DistributionThe following sect ions pr ovide an over view of t he noncent r al F dist r ibut ion.Ba ckground of the N oncentra l F Distribution. As wit h t he 2dist r ibut ion, t he F dist r ibut ion is a special case of t he noncent r al F dist r ibut ion. The F dist r ibut ion is t he r esult of t aking t he r at io of t wo 2 r andom var iables each divided by it s degr ees of fr eedom.If t he numer at or of t he r at io is a noncent r al chi-squar e r andom var iable divided by it s degr ees of fr eedom, t he r esult ing dist r ibut ion is t he noncent r al F dist r ibut ion.The main applicat ion of t he noncent r al F dist r ibut ion is t o calculat e t he power of a hypot hesis t est r elat ive t o a par t icular alt er nat ive. Definition of the N oncentra l F Distribution. Similar t o t he noncent r al 2dist r ibut ion, t he t oolbox calculat es noncent r al F dist r ibut ion pr obabilit ies as a weight ed sum of incomplet e bet a funct ions using Poisson pr obabilit ies as t he weight s.0 2 4 6 8 1000.20.40.60.8F x 1 2 , , ( )12--- , _jj!--------------e2--- , _I1x 2 +1x ------------------------- 12------ j + 22------ , , _j 0 ==Pr o b a b i l i ty D i str i b u ti o n s1-25I(x| a,b) is t he incomplet e bet a funct ion wit h par amet er s a and b, and is t he noncent r alit y par amet er .Exa mple a nd Plot of the N oncentra l F Distribution. The following commands gener at e a plot of t he noncent r al F pdf.x = (0.01:0.1:10.01)';p1 = ncfpdf(x,5,20,10);p = fpdf(x,5,20);plot(x,p,'--',x,p1,'-')Ga mma DistributionThe following sect ions pr ovide an over view of t he gamma dist r ibut ion.Ba ckground of the Ga mma Distribution. The gamma dist r ibut ion is a family of cur ves based on t wo par amet er s. The chi-squar e and exponent ial dist r ibut ions, which ar e childr en of t he gamma dist r ibut ion, ar e one-par amet er dist r ibut ions t hat fix one of t he t wo gamma par amet er s.The gamma dist r ibut ion has t he following r elat ionship wit h t he incomplet e Gamma funct ion.For b = 1 t he funct ions ar e ident ical.When a is lar ge, t he gamma dist r ibut ion closely appr oximat es a nor mal dist r ibut ion wit h t he advant age t hat t he gamma dist r ibut ion has densit y only for posit ive r eal number s. 0 2 4 6 8 10 1200.20.40.60.8 x a b , ( ) gammaincxb--- a , , _=1 Tu to r i a l1-26Definition of the Ga mma Distribution. The gamma pdf iswher e ( ) is t he Gamma funct ion. Pa ra meter Estima tion for the Ga mma Distribution. Suppose you ar e st r ess t est ing comput er memor y chips and collect ing dat a on t heir lifet imes. You assume t hat t hese lifet imes follow a gamma dist r ibut ion. You want t o know how long you can expect t he aver age comput er memor y chip t o last . Par amet er est imat ion is t he pr ocess of det er mining t he par amet er s of t he gamma dist r ibut ion t hat fit t his dat a best in some sense.One popular cr it er ion of goodness is t o maximize t he likelihood funct ion. The likelihood has t he same for m as t he gamma pdf above. But for t he pdf, t he par amet er s ar e known const ant s and t he var iable is x. The likelihood funct ion r ever ses t he r oles of t he var iables. Her e, t he sample values (t he xs) ar e alr eady obser ved. So t hey ar e t he fixed const ant s. The var iables ar e t he unknown par amet er s. MLE involves calculat ing t he values of t he par amet er s t hat give t he highest likelihood given t he par t icular set of dat a.The funct ion gamfit r et ur ns t he MLEs and confidence int er vals for t he par amet er s of t he gamma dist r ibut ion. Her e is an example using r andom number s fr om t he gamma dist r ibut ion wit h a = 10 and b = 5.lifetimes = gamrnd(10,5,100,1);[phat, pci] = gamfit(lifetimes)phat = 10.9821 4.7258pci = 7.4001 3.1543 14.5640 6.2974Not e phat(1) = and phat(2) = . The MLE for par amet er a is 10.98, compar ed t o t he t r ue value of 10. The 95% confidence int er val for a goes fr om 7.4 t o 14.6, which includes t he t r ue value.y f x a b , ( )1ba a ( )------------------xa 1 exb--- = =a bPr o b a b i l i ty D i str i b u ti o n s1-27Similar ly t he MLE for par amet er b is 4.7, compar ed t o t he t r ue value of 5. The 95% confidence int er val for b goes fr om 3.2 t o 6.3, which also includes t he t r ue value.In our life t est s we do not know t he t r ue value of a and b so it is nice t o have a confidence int er val on t he par amet er s t o give a r ange of likely values. Exa mple a nd Plot of the Ga mma Distribution. In t he example t he gamma pdf is plot t ed wit h t he solid line. The nor mal pdf has a dashed line t ype.x = gaminv((0.005:0.01:0.995),100,10);y = gampdf(x,100,10);y1 = normpdf(x,1000,100);plot(x,y,'-',x,y1,'-.')Geometric DistributionThe following sect ions pr ovide an over view of t he geomet r ic dist r ibut ion.Ba ckground of the Geometric Distribution. The geomet r ic dist r ibut ion is discr et e, exist ing only on t he nonnegat ive int eger s. It is useful for modeling t he r uns of consecut ive successes (or failur es) in r epeat ed independent t r ials of a syst em.The geomet r ic dist r ibut ion models t he number of successes befor e one failur e in an independent succession of t est s wher e each t est r esult s in success or failur e. 700 800 900 1000 1100 1200 1300012345x 10-31 Tu to r i a l1-28Definition of the Geometric Distribution. The geomet r ic pdf iswher e q = 1 p.Exa mple a nd Plot of the Geometric Distribution. Suppose t he pr obabilit y of a five-year -old bat t er y failing in cold weat her is 0.03. What is t he pr obabilit y of st ar t ing 25 consecut ive days dur ing a long cold snap?1 - geocdf(25,0.03)ans = 0.4530The plot shows t he cdf for t his scenar io.x = 0:25;y = geocdf(x,0.03);stairs(x,y)Hypergeometric DistributionThe following sect ions pr ovide an over view of t he hyper geomet r ic dist r ibut ion.Ba ckground of the Hypergeometric Distribution. The hyper geomet r ic dist r ibut ion models t he t ot al number of successes in a fixed size sample dr awn wit hout r eplacement fr om a finit e populat ion.The dist r ibut ion is discr et e, exist ing only for nonnegat ive int eger s less t han t he number of samples or t he number of possible successes, whichever is gr eat er . y f x p ( ) pqxI0 1 , , ( )x ( ) = =0 5 10 15 20 2500.20.40.6Pr o b a b i l i ty D i str i b u ti o n s1-29The hyper geomet r ic dist r ibut ion differ s fr om t he binomial only in t hat t he populat ion is finit e and t he sampling fr om t he populat ion is wit hout r eplacement . The hyper geomet r ic dist r ibut ion has t hr ee par amet er s t hat have dir ect physical int er pr et at ions. M is t he size of t he populat ion. K is t he number of it ems wit h t he desir ed char act er ist ic in t he populat ion. n is t he number of samples dr awn. Sampling wit hout r eplacement means t hat once a par t icular sample is chosen, it is r emoved fr om t he r elevant populat ion for all subsequent select ions.Definition of the Hypergeometric Distribution. The hyper geomet r ic pdf isExa mple a nd Plot of the Hypergeometric Distribution. The plot shows t he cdf of an exper iment t aking 20 samples fr om a gr oup of 1000 wher e t her e ar e 50 it ems of t he desir ed t ype.x = 0:10;y = hygecdf(x,1000,50,20);stairs(x,y)y f x M K n , , ( )Kx , _M K n x , _Mn , _------------------------------- = =0 2 4 6 8 100.20.40.60.811 Tu to r i a l1-30Lognor ma l DistributionThe following sect ions pr ovide an over view of t he lognor mal dist r ibut ion.Ba ckground of the Lognorma l Distribution. The nor mal and lognor mal dist r ibut ions ar e closely r elat ed. If X is dist r ibut ed lognor mal wit h par amet er s and 2, t hen lnX is dist r ibut ed nor mal wit h par amet er s and 2. The lognor mal dist r ibut ion is applicable when t he quant it y of int er est must be posit ive, since lnX exist s only when t he r andom var iable X is posit ive. Economist s oft en model t he dist r ibut ion of income using a lognor mal dist r ibut ion. Definition of the Lognorma l Distribution. The lognor mal pdf isExa mple a nd Plot of the Lognorma l Distribution. Suppose t he income of a family of four in t he Unit ed St at es follows a lognor mal dist r ibut ion wit h = log(20,000) and 2= 1.0. Plot t he income densit y.x = (10:1000:125010)';y = lognpdf(x,log(20000),1.0);plot(x,y)set(gca,'xtick',[0 30000 60000 90000 120000])set(gca,'xticklabel',str2mat('0','$30,000','$60,000',...'$90,000','$120,000'))y f x , ( )1x 2------------------eln x ( ) 222----------------------------= =0 $30,000 $60,000 $90,000 $120,000024x 10-5Pr o b a b i l i ty D i str i b u ti o n s1-31N ega tive Binomia l DistributionThe following sect ions pr ovide an over view of t he negat ive binomial dist r ibut ion.Ba ckground of the N ega tive Binomia l Distribution. The geomet r ic dist r ibut ion is a special case of t he negat ive binomial dist r ibut ion (also called t he Pascal dist r ibut ion). The geomet r ic dist r ibut ion models t he number of successes befor e one failur e in an independent succession of t est s wher e each t est r esult s in success or failur e.In t he negat ive binomial dist r ibut ion t he number of failur es is a par amet er of t he dist r ibut ion. The par amet er s ar e t he pr obabilit y of success, p, and t he number of failur es, r.Definition of the N ega tive Binomia l Distribution. The negat ive binomial pdf iswher e .Exa mple a nd Plot of the N ega tive Binomia l Distribution. The following commands gener at e a plot of t he negat ive binomial pdf.x = (0:10);y = nbinpdf(x,3,0.5);plot(x,y,'+')set(gca,'XLim',[-0.5,10.5])y f x r p , ( )r x 1 +x , _prqxI0 1 , , ( )x ( ) = = q 1 p =0 2 4 6 8 1000.050.10.150.21 Tu to r i a l1-32N or ma l DistributionThe following sect ions pr ovide an over view of t he nor mal dist r ibut ion.Ba ckground of the N orma l Distribution. The nor mal dist r ibut ion is a t wo par amet er family of cur ves. The fir st par amet er , , is t he mean. The second, , is t he st andar d deviat ion. The st andar d nor mal dist r ibut ion (wr it t en (x)) set s t o 0 and t o 1.(x) is funct ionally r elat ed t o t he er r or funct ion, erf.The fir st use of t he nor mal dist r ibut ion was as a cont inuous appr oximat ion t o t he binomial.The usual just ificat ion for using t he nor mal dist r ibut ion for modeling is t he Cent r al Limit Theor em, which st at es (r oughly) t hat t he sum of independent samples fr om any dist r ibut ion wit h finit e mean and var iance conver ges t o t he nor mal dist r ibut ion as t he sample size goes t o infinit y.Definition of the N orma l Distribution. The nor mal pdf isPa ra meter Estima tion for the N orma l Distribution. One of t he fir st applicat ions of t he nor mal dist r ibut ion in dat a analysis was modeling t he height of school childr en. Suppose we want t o est imat e t he mean, , and t he var iance, 2, of all t he 4t h gr ader s in t he Unit ed St at es.We have alr eady int r oduced MLEs. Anot her desir able cr it er ion in a st at ist ical est imat or is unbiasedness. A st at ist ic is unbiased if t he expect ed value of t he st at ist ic is equal t o t he par amet er being est imat ed. MLEs ar e not always unbiased. For any dat a sample, t her e may be mor e t han one unbiased est imat or of t he par amet er s of t he par ent dist r ibut ion of t he sample. For inst ance, ever y sample value is an unbiased est imat e of t he par amet er of a nor mal dist r ibut ion. The Minimum Var iance Unbiased Est imat or (MVUE) is t he st at ist ic t hat has t he minimum var iance of all unbiased est imat or s of a par amet er .erf x ( ) 2 x 2 ( ) 1 =y f x , ( )1 2---------------ex ( ) 222----------------------= =Pr o b a b i l i ty D i str i b u ti o n s1-33The MVUEs of par amet er s and 2 for t he nor mal dist r ibut ion ar e t he sample aver age and var iance. The sample aver age is also t he MLE for . Ther e ar e t wo common t ext book for mulas for t he var iance. They ar ewher e Equat ion 1 is t he maximum likelihood est imat or for 2, and equat ion 2 is t he MVUE.The funct ion normfit r et ur ns t he MVUEs and confidence int er vals for and 2. Her e is a playful example modeling t he height s (inches) of a r andomly chosen 4t h gr ade class.height = normrnd(50,2,30,1); % Simulate heights.[mu,s,muci,sci] = normfit(height)mu = 50.2025s = 1.7946muci = 49.5210 50.8841sci = 1.4292 2.41251) s2 1n--- = xix ( )2i 1 =n2) s2 1n 1 ------------- xix ( )2i 1 =n=xxin----i 1 =n=1 Tu to r i a l1-34Exa mple a nd Plot of the N orma l Distribution. The plot shows t he bell cur ve of t he st andar d nor mal pdf, wit h = 0 and = 1.Poisson DistributionThe following sect ions pr ovide an over view of t he Poisson dist r ibut ion.Ba ckground of the Poisson Distribution. The Poisson dist r ibut ion is appr opr iat e for applicat ions t hat involve count ing t he number of t imes a r andom event occur s in a given amount of t ime, dist ance, ar ea, et c. Sample applicat ions t hat involve Poisson dist r ibut ions include t he number of Geiger count er clicks per second, t he number of people walking int o a st or e in an hour , and t he number of flaws per 1000 feet of video t ape.The Poisson dist r ibut ion is a one par amet er discr et e dist r ibut ion t hat t akes nonnegat ive int eger values. The par amet er , , is bot h t he mean and t he var iance of t he dist r ibut ion. Thus, as t he size of t he number s in a par t icular sample of Poisson r andom number s get s lar ger , so does t he var iabilit y of t he number s.As Poisson (1837) showed, t he Poisson dist r ibut ion is t he limit ing case of a binomial dist r ibut ion wher e N appr oaches infinit y and p goes t o zer o while Np = .The Poisson and exponent ial dist r ibut ions ar e r elat ed. If t he number of count s follows t he Poisson dist r ibut ion, t hen t he int er val bet ween individual count s follows t he exponent ial