1.1 Population and Samples
Overall: the entire study object. One-dimensional or multi-dimensional quantity indicator. Random Variable.
Individual: each study object.
Sample: part of the population.
1.1.1Simple Random Sample
, I. I. d, independent of the same distribution. Unlimited population sampling.
Various random numbers in Matlab can be considered to be independent and distributed, that is, simple random samples. The implementation methods in Matlab are listed below.
, Evenly distributed Samples
N = 10; x = rand (1, n)
N = 10; a =-1; B = 3; x = rand (1, n); x = (B-a) * x +
, Normal distribution sample
N = 10; x = randn (1, n)
Mu = 80.2; sigma = 7.6; m = 1; n = 10;
X = normrnd (mu, sigma, m, n)
First, assign the Overall Mean Value mu = 80.2; then assign sigma = 7.6 to the standard deviation; m = 1; n = 10; assign values to the number of rows and columns of the generated random array, respectively, then, you can use the normrnd function provided by Matlab to generate a random number with a normal distribution.
Similarly, a random matrix of n columns in m rows can be generated, following the specified distribution. The suffix of the function for generating random numbers is rnd, And the prefix is the name of the distribution. The following describes how to generate random numbers for common distributions. You must assign values to parameters before using them.
X = betarnd (a, B, m, n) parameters are beta distributions of a and B;
The x = binornd (N, p, m, n) parameter is the binary distribution of N and p;
X = distribution where Degrees of Freedom of chi2rnd (N, m, n) is N;
X = exprnd (mu, m, n) exponential distribution of the overall expectation of mu;
X = frnd (n1, n2, m, n) degrees of freedom are F distributions of n1 and n2;
X = distribution of gamrnd (a, B, m, n) parameters as a and B;
X = lognrnd (mu, sigma, m, n) parameters are the logarithm normal distribution of mu and sigma;
X = Poisson distribution in which the mean value of the population srnd (mu, m, n) is mu;
X = trnd (N, m, n) tdistributions where degrees of freedom are N;
There are other distributions in the Matlab statistical toolbox, which are not listed one by one.
The following method is used to generate a random number that is subject to the distribution.
In Example 1.1, set the overall density function
We will try to extract a simple random sample with a capacity of 1000 from this population.
Use the matlab editing window to save the following program and save it as ex11.m
N = 1000;
X = zeros (1, n );
K = 0;
While k <n
A = rand * pi-pi/2;
B = rand/2;
If B <(cos (a)/2)
K = k + 1;
X (k) =;
End
End
Understand its principles. If ex11 is executed in the Command window, x is assigned a value. Run the following command to obtain the histogram of the sample with a capacity of 1000.
Hist (x,-pi/2: pi/2)
1.1.2Unlimited Samples
If the finite population is, and you want to extract samples with a capacity of n from them, N and n have been assigned a value here, you can use
R = randperm (N)
Generates a random and full arrangement, that is, r is an n-dimensional vector. Therefore, for the given n-dimensional vector X
X = X (r (1: n ))
Then we can obtain the sampling cost X without replacement with the capacity of n.
When sampling is not put back, the sample points are not independent.
1.2 Statistics
Statistic: A sample function without parameters. values can be calculated immediately based on the observed values of the sample.
The following is a simple random sample from the population and lists some common statistics. The following assumption is a sample, which is a matrix of a row and has been assigned a value in Matlab.
1.2.1SampleKMoment
Called a sampleKFirst-order moment. For a positive integer that has been assigned a valueK, You can use the following command to obtain
A (k) = mean (X. ^ k)
In particular, the first-order initial moment of the sample is the sample mean, which is calculated using mean in matlab.
Called a sampleKCenter moment of order, for positive integers that have been assigned a valueK, You can use the following command to obtain
Mu (k) = mean (X-mean (X). ^ k)
Specifically, called the uncorrected sample variance
It is called the sample variance. It is called the sample standard deviation. In Matlab, var (X) is used to calculate the sample variance, and std (X) is used to calculate the sample standard deviation.
1.2.2Sequence statistics
For a sample, if the value is reordered from small to large
It is called the sequence statistics of the original sample.
It can be proved that if the population is subject to an even distribution on (),
In particular, it is the minimum value in the sample, which can be calculated using min (X); it is the maximum value in the sample. It can be calculated using max (X. Matlab commands
Y = sort (X)
You can obtain the order statistics of X immediately, satisfying
The sort function in MATLAB may be more efficient than self-programmed sorting. When sorting is used repeatedly in loop statements, it should be preferred.
1.2.3Empirical Distribution Functions
Define 1.1 set the overall distribution function as a simple random sample, a sequence statistic, and a record
(1-1)
It is called the empirical distribution function or the sample distribution function.
According to the famous göwenko theorem
A.s.
The following command generates a distribution sample with a degree of freedom of 5 with a sample capacity of 1000 and draws an empirical distribution function for this sample. Result 1-1 is displayed.
Y = chi2rnd (1000,); [f, x] = ECDF (y );
Plot (x, F)
Figure 1-1 empirical Distribution Function
The following program extends the function implementation function. Input and save the following program in the MATLAB editing window as myfn. M. In the future, myfn can be directly called like other library functions. Pay attention to the function files you have compiled. It is best to process matrix vectors directly. The following myfn function files can be debugged, but the compilation process can be more precise, making the calculation more efficient. Please complete the improvement.
Function Y = myfn (t, x)
N = length (x); X = sort (X );
[M, N] = size (t); y = zeros (m, n );
For I = 1: m
For j = 1: N
S = 0;
For k = 1: N
If T (I, j)> = x (k)
S = S + 1;
End
End
Y (I, j) = S/N;
End
End
1.3 three common Distributions
The concepts and properties of the Three Important Distributions in mathematical statistics are listed below.
1.3.1
Distribution
Define 1.2 set the density function of a one-dimensional Continuous Random Variable
(1-2)
It is called the degree of freedomDistribution,.
Figure 1-2 distribution density function
(1) Expectation and variance :,
(2) Source: if the distribution is independent
(3) addition: if, and the two are independent
(4) important conclusion: if
The following shows the density function of the distribution of degrees of freedom 5, 10, and 20, as shown in 1-2.
1.3.2
TDistribution
Define 1.3 set the density function of a one-dimensional Continuous Random Variable
(1-3)
The distribution that follows the degree of freedom is recorded.
Figure 1-3TDistribution density function and standard normal distribution density function
(1) density function features: similar to the standard normal distribution, the variance is large. ,
(Standard normal distribution density function)
Run the Matlab command
X =-.; y5 = tpdf (x, 5); y10 = tpdf (x, 10 );
Y20 = tpdf (x, 20); y = normpdf (x );
Plot (x, y5, x, y10, x, y20, x, y)
Obtain the distribution density function of degrees of freedom 5, 10, 20 and the standard normal distribution density function, as shown in 1-3.
(2) Source: set, and the two are independent, then
(3) important conclusion: set, then
1.3.3
FDistribution
Define 1.4 set the density function of a one-dimensional Continuous Random Variable
(1-4)
Constant
It is called the one with the first degree of freedom and the other with the second degree of freedom.FDistribution, recorded.
(1) density function features: the density function has a large value nearby, which is a single-peak asymmetric function. When both degrees of freedom are large, the values are concentrated nearby with a large probability. The density function drawn by the following Matlab command.
X = 0: 0. 0; y = fpdf (x, 8, 12); plot (x, y );
Result 1-4 is displayed.
Figure 1-4FDISTRIBUTION DENSITY FUNCTION
(2) Source: set, and the two are independent, then
(3) important conclusion: it is set as a simple random sample from the population and is a simple random sample from the population, and the two are independent. If the two sample variance are respectively the same as, then