要将shapiro wilk测试应用于向量的正态性,我们只需在shapiro.test函数内部简单地命名向量即可,但是如果我们想对R数据帧列执行相同的操作,则该列将必须以适当的方式指定该列。例如,如果数据框名称为df且列名称为x,则该函数将作为shapiro.test(df $x)使用。
x1<-rnorm(1000,1.5) df1<-data.frame(x1) shapiro.test(df1$x1)
输出结果
Shapiro-Wilk normality test data: df1$x1 W = 0.99886, p-value = 0.792
x2<-runif(1000,2,10) df2<-data.frame(x2) shapiro.test(df2$x2)
输出结果
Shapiro-Wilk normality test data: df2$x2 W = 0.9581, p-value = 2.562e-16
x3<-rpois(4000,2) df3<-data.frame(x3) shapiro.test(df3$x3)
输出结果
Shapiro-Wilk normality test data: df3$x3 W = 0.91894, p-value < 2.2e-16
x4<-rpois(4000,5) df4<-data.frame(x4) shapiro.test(df4$x4)
输出结果
Shapiro-Wilk normality test data: df4$x4 W = 0.97092, p-value < 2.2e-16
x5<-sample(1:5,5000,replace=TRUE) df5<-data.frame(x5) shapiro.test(df5$x5)
输出结果
Shapiro-Wilk normality test data: df5$x5 W = 0.88902, p-value < 2.2e-16
x6<-sample(1:10,5000,replace=TRUE) df6<-data.frame(x6) shapiro.test(df6$x6)
输出结果
Shapiro-Wilk normality test data: df6$x6 W = 0.93373, p-value < 2.2e-16
x7<-sample(1:100,5000,replace=TRUE) df7<-data.frame(x7) shapiro.test(df7$x7)
输出结果
Shapiro-Wilk normality test data: df7$x7 W = 0.9556, p-value < 2.2e-16
x8<-sample(2500:3500,5000,replace=TRUE) df8<-data.frame(x8) shapiro.test(df8$x8)
输出结果
Shapiro-Wilk normality test data: df8$x8 W = 0.95117, p-value < 2.2e-16
x9<-rbinom(5000,10,0.5) df9<-data.frame(x9) hapiro.test(df9$x9)
输出结果
Shapiro-Wilk normality test data: df9$x9 W = 0.96629, p-value < 2.2e-16
x10<-rbinom(5000,1000,0.5) df10<-data.frame(x10) shapiro.test(df10$x10)
输出结果
Shapiro-Wilk normality test data: df10$x10 W = 0.9993, p-value = 0.04748