Learning matlab (four) - Probability and Statistics

Probability and statistics is an important part of university mathematics, whether in science or engineering practice has a very wide range of applications. In MATLAB Statistics Toolbox provides specialized Staticstics, the toolkit has hundreds of functions dedicated to solving probability and mathematical statistics problem. This section describes in detail the random number generation, digital signature and the probability density function of random variables, and hypothesis testing, plotting and statistical analysis of variance and the like.

0. random number

Random number generation is the basis of probability and statistics, probability theory and mathematical statistics is a variety of sample data for analysis. In MATLAB, a variety of sample data can be represented by some classical random number distribution. Next, the conventional binomial distribution, a uniform distribution, exponential distribution, normal distribution random data in detail.

<1> binomial random distribution

In MATLAB, using the function binornd () binomial distribution of the generated random data. The function is invoked as follows: R = binornd (N, P): In this function, the two parameters N and P is the binomial distribution, subject to parameters return binomial random number N and P. R = binornd (N, P, M): In the function parameter M specifies the number of random numbers, the same number of dimension R and return results.

<2> Poisson

In MATLAB, using the function poissrnd () Poisson distribution of the generated random data. The function is called as follows: R = poissrnd (LAMBDA): In this function LAMBDA parameter Poisson distribution, subject to parameters LAMBDA return Poisson distributed random number, wherein R is the same LAMBDA dimension. R = poissrnd (LAMBDA, M, N): In this function LAMBDA parameter Poisson distribution, subject to parameters LAMBDA return Poisson distributed random number matrix

<3> Exponential Distribution

In MATLAB, using the function exprnd () generates a random exponential distribution. Call format which follows: R = exprnd (MU): This function returns the exponential distribution random number as a parameter of the MU, with the number of dimensions in which R and MU. R == exprnd (MU, M, N): This function returns a random number in a matrix MU parameter exponential distribution

<4> uniform

(1) Continuous

In MATLAB, using the function unifrnd () to generate random data a uniform distribution. The function is called as follows: R = unifrnd (A, B): Returns a uniform continuous on the interval [A, B] profile. R = unifrnd (A, B, M, N): Returns the interval [A, B] continuous uniform distribution on the matrix.

(2) Discrete

In MATLAB, using the function unidrnd () generates random data discrete uniform distribution. The function is called as follows: R = unidrnd (N): Returns a discrete uniform distribution, R N, and the same number of dimensions; R = unidrnd (N, MM, NN): Returns a discrete uniform distribution matrix,

<5> normal

In MATLAB function using normrnd (normally distributed random data generation parameter to the MU and SIGMA). The function is called as follows: R = normrnd (MU, SIGMA): This function returns a MU mean, the standard deviation of the normally distributed random data SIGMA, wherein R may be a vector, a matrix may be. R = normrnd (MU, SIGMA, M): This function parameter M specifies the number of the random number, the return value of R is the same dimension. R = normrnd (MU, SIGMA, M, N): This function returns a matrix.

For other common data generating random distribution, which function call the same as above. The table lists the commonly used random data generation function. For detailed user usage of these functions can be viewed by MATLAB help system, or via the command input help function names and line viewing and use of certain functions

1. probability density function

Function binopdf () generating binomial distribution density function call format is: Y = binopdf (X, N, P), generates parameters N and P binomial distribution. Function poisspdf () generates Poisson distribution density function, call format is: Y = poisspdf (X, LAMBDA), generating a Poisson distribution parameters LAMBDA. GeoPDF function () is generated geometric distribution density function, the function call format is: Y = geopdf (X, P). For discrete uniform distribution, using function unidpdf () function to generate a probability density function, which calls the format Y = unidpdf (X, n), the parameter discrete uniform distribution is n, the output parameter Y and input parameters X have the same dimension.

In MATLAB function using unifpdf () calculates the density of the uniform distribution function, which calls the format Y = unifpdf (X, A, B), the function generating interval [A, B] on the uniform distribution. In MATLAB function using exppdf () generating an exponential distribution probability density function, which calls the format Y = exppdf (X, MU), the function produces the MU exponential distribution parameter, default parameter value of 1 MU. Y output parameters and input parameters may be vector X, it may be a matrix with the same dimension. In MATLAB function using normpdf () to generate the normal distribution probability density function, which calls the format Y = normpdf (X, MU, SIGMA), which function to generate parameters MU and SIGMA normal distribution. MU SIGMA parameters and default values ​​are 0 and 1, i.e., standard normal distribution.

<1> sampling distribution

1. The chi-square distribution, in MATLAB function using chi2pdf () chi-square distribution is generated, the function call format for Y = chi2pdf (X, V), the function of generating a degree of freedom chi-square distribution is V, the output parameter Y X and input parameters have the same dimension. 2. t distribution, in MATLAB by function TPDF () Probability Density Function t-distribution, which calls the format Y = tpdf (X, V), the degree of freedom for the generated V t distribution. 3. F distribution, in MATLAB function using FPDF () generates a probability density distribution function F, which call the format: Y = fpdf (X, V1, V2), wherein a first degree of freedom V1, V2 of the second degrees of freedom.

2. The mean and median

In MATLAB, using the function Mean () calculate the arithmetic mean of a set of sample data, it calls the format: y = mean (X): This function returns the average value of X, when X is a vector, each element returns X the arithmetic mean; when X is a matrix, a vector arithmetic mean of each column of X element constituting the return. y = mean (X, DIM): This function returns the arithmetic mean on the given dimension of the DIM.

In MATLAB function nanmean () is used to find a set of data the arithmetic mean data other than NaN, which call the format: Y = nanmean (X): This function returns the arithmetic mean value of X except for a NaN. When X is a vector, each element of the arithmetic average return X; and when X is a matrix, a vector arithmetic mean of each column of X element constituting the return. Y = nanmean (X, DIM): This function returns NaN arithmetic mean data other than in the given dimension of the DIM.

MATLAB, using the function GEOMEAN (geometric mean calculated sample data).

In MATLAB function using harmmean () calculates the harmonic mean data sample.

The median is the number of samples in the middle of the data size. In MATLAB function using median (median calculated sample data). The function call format is: Y = median (X): This function returns the median of the data X, when X is a vector, returns the median of the elements X; when X is a matrix, X is returned vector digits in each column elements. Y = median (X, DIM): This function returns the number of bits in a given dimension of the DIM.

Ignore median NaN refers to data other than the sample data size NaN located in the middle of the number. In MATLAB by function nanmedian () calculates the median of the sample data other than the data NaN. The function call format is: Y = nanmedian (X): This function returns the median of the X data other than NaN when X is a vector X to return the median of the elements other than NaN; when X is a matrix, in addition to the vector X NaN median composition of elements of each column is returned. Y = nanmedian (X, DIM): This function returns the number of bits in a given dimension of the DIM except NaN.

3. Sort

Sorting data includes not only the ordering of data, further comprising seeking the maximum and minimum data and the like. The following were introduced. 1. Data ordering: in MATLAB function using sort () to sort data; 2 sort data by rows: in MATLAB function using sortRows () to sort the data row; 3 minimum and maximum requirements. value: in MATLAB, a range () function difference between the maximum and the minimum required data. Using the function minmax (} maximum and minimum data acquisition.

4. expectation and variance

Expectation and variance are the two most important figures characterizations random variable nature of probability theory and mathematical statistics is a very important element. Digital signature can be relatively easily estimated, it is of great significance in theory and practice. Expectation and variance calculation is the basis of probability theory and mathematical statistics. 1, using the function Mean () calculates the desired sample data. 2, using the function var () calculates the variance of the sample data. 3 uses a function STD () to calculate the standard deviation of the sample data.

Next, the mean and variance of the distribution is calculated common, including binomial, uniform, normal, exponential, t distribution and F distribution: 1, function binostat () and variance calculating an expected binomial . 2, the function unifstat () calculates the desired uniform distribution and variance. 3, the function normstat () calculates the mean and variance of the normal distribution. 4, the function expstat () calculates the mean and variance of the exponential distribution. 5, TSTAT function () t is calculated mean and variance of the distribution. 6, FSTAT function () F calculated mean and variance of the distribution.

The covariance and correlation coefficient

In MATLAB by function CoV () covariance, call format is: C = cov (X): the input parameters may be vectors and matrices. When X is a vector, the function returns a value of the variance of the vector. When the parameter X is the input matrix, each row of the matrix represents a set of sample data, each column represents a variable, returns a value of the covariance matrix of the matrix of the function. C = cov (X, Y): This function computes the X and Y input parameters covariance matrix, wherein the number of rows in the same number of input parameters and the X and Y columns. In MATLAB function using corrcoef () calculate the correlation coefficient.

6. The swash skewness and kurtosis

Skewness and kurtosis are used to represent the shape of symmetry distributed random variables. In MATLAB function using Skewness () is calculated skewness sample data. In MATLAB function using the kurtosis () calculates the kurtosis of random variables.

7. parameter estimation, interval estimation, hypothesis testing

<1> Parameter Estimation

Statistics of the most important and most commonly used is the mean and standard deviation, because the sample is a random variable, they naturally as a function of the sample random variables, when they are used to extrapolate overall, how much reliability on probability and statistics distribution, and therefore we need to know the simple nature of several important distribution. Parameter estimation including point and interval estimation.

<2> interval estimation

Interval estimation of unknown parameters will be confidence interval, here a uniform distribution, exponential distribution and normal distribution Beta parameter estimates. 1, using a function uniformly distributed parameter Unifit () calculating an estimated. 2, using the parameters of the function expfit () calculated exponential distribution. 3, a Beta distribution parameters using function betafit () calculating an estimated. 4 uses a function normfit () parameter estimation normal distribution is calculated.

During hypothesis testing, first proposed the hypothesis, then considered under the conditions of this assumption is valid, select the appropriate statistics, the last judgment. Here are several common hypothesis testing.

<3> hypothesis testing

(1) It is known variance Population Mean

In MATLAB, if known population variance and mean, use the function ztest () hypothesis testing.

(2) when the normal population mean variance of unknown hypothesis testing

In MATLAB, if the overall mean and variance unknown, use the function ttest () hypothesis testing.

(3) the difference between the two mean of normal distribution test

If the variance of two normal distributions unknown but equal in function using ttest2 MATLAB () for comparing the two normal distributions hypothesis testing sample mean.

(4) 7.5.4 two distributions consistency test

In MATLAB by function ranksum () function of two test distribution uniformity, i.e., rank sum test.

8. Analysis of variance

ANOVA (Analysis of Variance, ANOVA) is one commonly used data processing method in mathematical statistics. A complex of things, such as product quality, is affected by many factors, these factors restraining and interdependent. Purpose of the analysis of variance factors have a significant influence of the things found through data analysis. This section describes only whether the situation significantly affect one or two factors on the experimental results. Only in the case of one factor called factor analysis of variance, there are two factors in the case known as two-factor analysis of variance.

ANOVA means that only one factor changes the experiment. In MATLAB, analysis of variance (ANOVA) function can be used anova1 () to achieve.

If an experiment, the results influenced by two factors, the experiment is called two-factor experiment. Research on the impact of two factors on the experimental results need to be two-way ANOVA. In MATLAB, two-way ANOVA function can be used anova2 () to achieve.

MATLAB has a strong ability to visualize the data, the data can be plotted in mathematical statistics into a graph, as described in more image graphically. Here's how to draw charts use MATLAB. In MATLAB function using Tabulate () generates a positive integer frequency table, the function call format is: T = tabulate (X). Positive input parameter is a vector of integers and the return value 3, the first unique values ​​as vectors; as the second frequency of occurrence of these values; as a third value corresponding to these frequencies.

In MATLAB function using Boxplot () to draw sample data cartridge of FIG. The function call format is: H = boxplot (X, 'param1', val1, 'param2', val2, ...). Input parameters of the function matrix, each column of FIG draw box.

In MATLAB, using the function Isline () draw a straight line least squares fit, Isine: return to a known linear least squares fit of the data sample, may be used in addition to - the lines other than a 'and .-' 'and' style graphics rendering. h = lsine: This function returns a handle function.

In MATLAB, using the function normplot () drawn normal probability plot, the function call format is: normplot (X): If the input parameter is a vector, the probability of the normal distribution pattern is displayed; if a matrix, each of the display - normal probability graphic column. H = normplot (X): This function returns a handle function.

In MATLAB, using the function cdfplot () plotted in FIG empirical cumulative distribution function, the function call format is: cdfplot (X): the sample data plotted as a function of the cumulative distribution function of FIG. Input parameters may be subject to a random sample distribution of a particular row or column vector, representative. H = cdfplot (X): This function returns a handle function. [H, stats] = cdfplot (X): This function returns the number of sample data features: stats.min: minimum sample data; stats max:. Maximum sample data; stats mean:. An average value of sample data; stats median: median sample data; stats.std:. sample standard deviation of the data.

In MATLAB, using the function weibplot () Weibull probability plotted in FIG. Weibull probability map drawing object is estimated from the method illustrated by Weibull
distribution of data. The function call format is: weibplot (X): If the input parameter is a vector, Weibull probability map is displayed; if FIG Weibull probability matrix, each column of the display. If Weibull distribution data, the graphics are straight; otherwise, the graphics may produce bending. H = weibplot (X): This function returns a handle to the function of a straight line drawn.

In MATLAB, using the function qqplot () draw quantile quantile FIG. The function call format is: qqplot (X): the input parameters of the function is the row or column vector, quantile quantile plots to draw the sample data and the standard normal distribution. qqplot (X, Y): The function of the input parameters and the quantile quantile FIG. H = qqplot (Song Y): This function returns a handle to a straight line drawn function.

In MATLAB, using the function Refline () to add the current drawing a reference line. The function call format is: refline (slope, intercept): input parameters for the function of the slope of the slope of the line, intercept of a linear intercept. refline (slope): input parameter of the function slope = [a, b], a straight line is added in FIG. y = a * x + b. H = refline (slope): This function returns a handle to the function of a straight line drawn.

In MATLAB, using the function refcurve () to add a current pattern polynomial curve. The function call format is: refcurve (p): p input parameter of the function is the vector of coefficients of the polynomial coefficients of the polynomial are arranged in descending composition. H = refcurve (p): This function returns a handle to the function of the plotted curve.

In MATLAB, using the function capaplot () probabilistic graphical drawing samples, the function returns the probability that a random variable falls within a specified range. The function call format is: capaplot (data, specs): input parameters for the function of the data given sample data for the specified interval parameter specs, the function returns the probability falls within the interval. [P, h] = capaplot (data, specs): This function returns two values, p is the probability of the designated section, h is the graphics rendering function handle.

In MATLAB, using the function histfit () with a normal density histograms plotted curve. The function call format is: histfit (data, nbins): This function is plotted with normal density histogram curve, the vector data input parameters, the parameter nbins given sample data for the specified number of BAR, the default value the square root of the number of data data. h = histfit (data, nbins): This function returns a handle to the graph function.

In MATLAB, using the function normspec () draw a normal density curve in the specified range. The function call format is: normspec (specs): This function is plotted in the specified standard normal density curve section specs desirable mu and standard deviation sigma 1 and 0, respectively. normspec (specs, mu, sigma): The function of the normal distribution and standard deviation for the desired settings. [P, h] = normspec (specs, mu, sigma): This function returns a handle to the graphics rendering function.

 

 

 

 

 

 

Published 347 original articles · won praise 29 · views 50000 +

Guess you like

Origin blog.csdn.net/qq_35789421/article/details/104249174