# Probability and Statistics MATLAB Files

Many of the MATLAB scripts and functions here were originally developed to support a two semester undergraduate course sequence in probability and statistics at the junior/senior level. The course was based on the textbook "Probability and Statistical Inference" by R. V. Hogg and E. A. Tanis.

Make sure you download both the .p and .m files. You can use the function or script with only the .p file, but you'll need the .m file for the associated help. For example, if you download binomialDist.p you can use the binomialDist function, provided you know how to use it. To read how to use it, however, you'll need binomialDist.m. Once you've downloaded binomialDist.m, you can enter help binomialDist in the command window to read instructions on how to use the binomialDist function.

 Files Description ANOVA1factor.m, ANOVA1factor.p Function: 1-factor ANOVA. Uses functions FProbQuad and FPercentilesBisectQuad. AtLeast1IntMatch.m, AtLeast1IntMatch.p Script: Estimates the probability that at least one match occurs when the first m postive integers are selected at random one at a time (with and without replacement) and are arranged in a row. Note: A match occurs when k turns up in the kth position. The script solves the problem for 2, 3, ..., m, where m is provided by the user. binomialDist.m, binomialDist.p Function: Returns probability mass function and the cumulative distribution function of the binomial distribution b(n,p). binomialStudy1.m, binomialStudy1.p Script: Used to explore various properties of the binomial distribution. Uses function binomialDist. boxplot.m, boxplot.p Function: produces a boxplot for each column of an input matrix. candy2.m, candy2.p Script: Displays a table of values and a probability histogram of a hypergeometric probability mass function with N1 = 15, N2 = 5, n = 4. Uses Function hypergeometricPMF. CDFplotDiscrete.m, CDFplotDiscrete.p Function: Plots cumulative distribution function (c.d.f) of a discrete random variable. chiSquareDist.m, chiSquareDist.p Function: Computes probability mass function of the chi-square distribution with r degrees of freedom. chiSquareDist2.m, chiSquareDist2.p Function: Computes probability mass function and the cumumlative distribution function of the chi-square distribution with r degrees of freedom. Ues function chiSquareProb. chiSquarePercentilesBisect.m, chiSquarePercentilesBisect.p Function: Finds the number χα2(r) such that P[X ≥ χα2(r)] = α or P[X ≤ χ1-α2(r)] = α. Uses a bisection algorithm and the chiSquareProb() function. chiSquareProb.m, chiSquareProb.p Function: Computes probabilities related to the chi-square distribution with r degrees of freedom. Makes use of the Symbolic Toolkit. chiSquareProbQuad.m, chiSquareProbQuad.p Function: Computes probabilities related to the chi-square distribution with r degrees of freedom. Makes use of the builtin Matlab quad function. chiSquareStudy.m, chiSquareStudy.p Script: Study of chi-square with r degrees of freedom over the interval [0,xR]. Plots the probability density function, the cumulative ditribution function, and user-specified percentiles. The x-values of the percentiles are also displayed in a table n the command window. Uses a bisection algorithm and the chiSquareDist2 and chiSquareProb() functions. chiSquareSubAlphaPlot.m, chiSquareSubAlphaPlot.p Script: Produces figure showing chiSquareSubAlpha. Uses chiSquarePercentilesBisect and chiSquareProb functions. dice7.m, dice7.p Script: Two players take turns rolling a pair of dice until one of them wins by obtaining a sum of 7. This script estimates the probability that the player who goes first wins. To estimate the probability, the game is played at total of ntrials times, where ntrials is provided by the user of this script. dicemnSumSmatrix.m, dicemnSumSmatrix.p Function: Displays graphical representation of the sample space resulting from a roll of pair dice, one m- and the other n-sided, and summing the face-up sides. discreteuniformDist.m, discreteuniformDist.p Function: Returns probability mass function and the cumulative distribution function of the discrete uniform distribution on first m positive integers. discreteuniformpmf.m, discreteuniformpmf.p Function: Returns probability mass function of the discrete uniform distribution on first m positive integers. expMean20CDF.m, expMean20CDF.p Script: Plots cumulative distribution frunction of exponential with mean 20. exponentialDist.m, exponentialDist.p Function: Returns exponential probabilty density function f(x) and cumulative distribution function F(x). expSim.m, expSim.p Script: Simulate exponential distribution. Uses boxplot to make a boxplot. Also makes q-q plot. FPDF.m, FPDF.p Function: returns values of the probability density function for the F-distribution. FPercentilesBisect.m, FPercentilesBisect.p Function: Finds the number Fα such that P[X ≥ Fα] = α or P[X ≤ Fα -1] = α. Depends on Symbolic toolkit. FPercentilesBisectQuad.m, FPercentilesBisectQuad.p Function: Finds the number Fα such that P[X ≥ Fα] = α or P[X ≤ Fα -1] = α. Does not depend on Symbolic toolkit. FProb.m, FProb.p Function: Computes probabilities related to the F = F(r1,r2) distribution. Depends on Symbolic toolkit. FProbQuad.m, FProbQuad.p Function: Computes probabilities related to the F = F(r1,r2) distribution. Does not depend on Symbolic toolkit. gammaDist.m, gammaDist.p Function: Computes probability mass function of the gamma distribution. gammaProb.m, gammaProb.p Function: Computes probabilities related to the gamma distribution. Makes use of the Symbolic Toolkit. gammaStudy.m, gammaStudy.p Script: Explores gamma distribution. Makes use of the gammaDist function. hypergeometricDist.m, hypergeometricDist.p Function: Returns probability mass function and cumulative distribution function of the hypergeomtric distribution with N1, N2, and n. hypergeometricStudy1.m, hypergeometricStudy1.p Script: Explores hypergeometric distrubtion. Uses hypergeometricDist function. hypergeometricVSbinomial.m, hypergeometricVSbinomial.p Script: Compares hypergeometric and binomial distributions. Makes use of the hypergeometricDist and binomialDist functions. meanvariance.m, meanvariance.p Function: Computes the mean and variance of a discrete random variable X. NegativeBinomialDist.m, NegativeBinomialDist.p Function returns probability mass and cumulative distribution functions of the Negative Binomial distribution. P(X=x) = probability that x is the minimum number of trials required to achieve r successes in a sequence of independent Bernoulli trials, where p is the probability of success on each trial. normalPDF.m, normalPDF.p Function: returns values of the normal probability density function. normalPercentilesBisect.m, normalPercentilesBisect.p Function: Finds the number zα such that P[X ≥ zα] = α See 'help normalPercentilesBisect' (i.e., normalPercentilesBisect.m) for details and requirements. normalPercentilesBisectQuad.m, normalPercentilesBisectQuad.p Function: Finds the number zα such that P[X ≥ zα] = α See 'help normalPercentilesBisectQuad' (i.e., normalPercentilesBisectQuad.m) for details and requirements. normalProb.m, normalProb.p Function: Computes probabilities related to the normal distribution N(μ, σ2). See 'help normalProb' (i.e., normalProb.m) for details and requirements. normalProbQuad.m, normalProbQuad.p Function: Computes probabilities related to the normal distribution N(μ, σ2). See 'help normalProb' (i.e., normalProbQuad.m) for details and requirements. nPr.m, nPr.p Function: nPr returns the number of permutations of n objects taken r at a time. (Order matters and selection is performed without replacement.) . See 'help normalProb' (i.e., normalProbQuad.m) for details and requirements. PairDiceJointDist.m, PairDiceJointDist.p Script: Displays a representation of the space of random variables X and Y, where X is the smaller and Y is the large number when two dice are rolled. The joint probability mass function as well as the marginal probability mass functions are displayed. penniesAND3boxes.m, penniesAND3boxes.p Script: Simulation of the following random experiment: Box 1 contains 2 pennies Box 2 contains 2 nickles Box 3 contains 1 penny and 1 nickle A box is selected at random and a coin is removed from it. Then a box is selected again at random, and a coin is selected from it. Notes: Assume the boxes are equally likely to be selected in both the 1st and 2nd drawings. Also assume that once a box is chosen, coins are selected from a box in a fair manner. So, for example, if Box 3 is chosen when it contains a penny and a nickle, selecting a penny from it is just as likely as selecting a nickle from it. percentileVec.m, percentileVec.p Function: Computes desired πp (percentiles) of user-provided x-vector. User must also provide a vector of desired percentiles. permutationOfMatrix.m, permutationOfMatrix.p Function: permutationOfMatrix returns permutation of matrix entries. PoissonDist.m, PoissonDist.p Function: Returns probability mass and cumulative distribution functions of the Poisson distribution. PoissonVSbinomial.m, PoissonVSbinomial.p Script: Compares Poisson and binomial distributions. Makes use of the PoissonDist and binomialDist functions. randcombinationsUniqueCpts.m, randcombinationsUniqueCpts.p Function to generate random combinations of k components of the distinct components of a user-input vector. randpermutationsUniqueCpts.m, randpermutationsUniqueCpts.p Function to generate random permutations of vector k components of a vector of the distinct components of a user-input vector. stemANDleaf.m, stemANDleaf.p Function: Quick and dirty stem-and-leaf function. studentsTdist.m, studentsTdist.p Function: Computes student's t distribution probability density function: f(x) = (gamma[(r+1)/2]/[sqrt(pi*r)*gamma(r/2)*(1+x^2/r)^(r+1)/2], where gamma(w) denotes the gamma function evaluated at w. studentsTPDF.m, studentsTPDF.p Function: Returns values of the students t probability density function. studentsTPercentilesBisect.m, studentsTPercentilesBisect.p Function: Finds the number tα such that P[T ≥ tα] = α. studentsTPercentilesBisectQuad.m, studentsTPercentilesBisectQuad.p Function: Finds the number tα such that P[T ≥ tα] = α. Does not use the Symboic Toolkit. studentsTprob.m, studentsTprob.p Function: Computes probabilities related to the gamma distribution with probability density function: f(x) = ( f(x) = (gamma[(r+1)/2]/[sqrt(pi*r)*gamma(r/2)*(1+x^2/r)^(r+1)/2], where gamma(w) denotes the gamma function evaluated at w. This function computes and returns: P(a < X < b) = ∫abf(x) dx Depends on Symbolic toolkit. studentsTprobQuad.m, studentsTprobQuad.p Function: Computes probabilities related to the gamma distribution with probability density function: f(x) = ( f(x) = (gamma[(r+1)/2]/[sqrt(pi*r)*gamma(r/2)*(1+x^2/r)^(r+1)/2], where gamma(w) denotes the gamma function evaluated at w. This function computes and returns: P(a < X < b) = ∫abf(x) dx Does not depend on Symbolic toolkit.

Copyright © 2003-2009 Ernest E. Rothman. This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. .