#使用方法 x | y | 680 | 3314.07 | 1200 | 3270.47 | 1200 | 3456.4 | 1800 | 2293.8 | 326 | 6281.25 | 1300 | 4134.35 | 1601 | 1200 | 1675 | 2240 | 1316 | 2930 | 1530 | 3100 | 725 | 3581.65 | 1100 | 4521.9 | 2550 | 1076.5 | 1840 | 1849.4 | 1100 | 1071 |
以上表格导入,赋值给变量mat > plot(x,y) #做x值和y值的散点图 > abline(lm(y~x)) #线性拟合,切记y的位置在前面
x= mat[,"x"] y=mat[,"y"] > shapiro.test(x) Shapiro-Wilk normality test data: x W = 0.973, p-value = 0.8999 #对x的分布作正态性检验,p大于0.05,符合正态分布 > shapiro.test(y) Shapiro-Wilk normality test data: y W = 0.9423, p-value = 0.4123 #对y的分布作正态性检验,p大于0.05,符合正态分布 | > cor.test(x, y,+ alternative = c("two.sided", "less", "greater"),+ method = c("pearson", "kendall", "spearman"),+ exact = NULL, conf.level = 0.95) |
|
#相关性检验,以下是结果 Pearson's product-moment correlation data: x and y t = -3.8539, df = 13, p-value = 0.001993 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: -0.9042470 -0.3482487 sample estimates: cor -0.7302404 |
| #p值小于0.05,说明显著相关 #-0.7302404 |
附注:简单的相关系数的分类 0.8-1.0 极强相关 0.6-0.8 强相关 0.4-0.6 中等程度相关 0.2-0.4 弱相关 0.0-0.2 极弱相关或无相关
|