The normality of the data is the basis of many statistical methods, so the normality test is also necessary, the following describes the use of R to test the normality of several methods
1.shaprio-wilk Inspection
The comparison between sample data and normal distribution is significantly different, using the Shapiro.test () function, in the form of shapiro.test (data), which requires data to be in vector format.
2.kolmogorov-smirnov Inspection
The test is used to compare two distributions, or to compare a sample to a known distribution, using the Ks.test () function, in the form of ks.test (x, y ...), where X. is the vector to be tested, Y is a vector in contrast to X, or for a distribution sensation, such as Qmorm (), The format is also required for vector format.
3.QQ figure
Also known as the division-scale graph, if the two distributions are the same, the resulting data points will fall on a straight line, using the Qqplot () function to achieve a comparison of two distributions or vectors, such as Qqplot (Rpois (50,5), Rnorm (50,5,1)), Qqplot ( DATA2,DATA1).
Here we need to add a line to make it easy for us to judge that using the Abline () function can be done, but the function needs to specify the slope and intercept of the line, so we need to do some calculations such as:
> Qqp<-qqplot (Data2,rnorm (50,5,2))
> Abline (LM (qqp$x~qqp$y))
First, when using Qqplot (), the returned result contains the X and Y values, which we named Qqp so that the LM () function is then used to extract the two values to fit the linear model to get the slope and intercept as the parameters of the Abline.
In addition, there is a qqnorm () function specifically for comparison with the normal distribution, and there is a special qqline () function to do the comparison straight line.
Test of normality of R language