分离种属
> i1=iris[which(iris$Species=="setosa"),1:2] > i1 Sepal.Length Sepal.Width 1 5.1 3.5 2 4.9 3.0 3 4.7 3.2 4 4.6 3.1 5 5.0 3.6 6 5.4 3.9 7 4.6 3.4 123456789101112
> plot(i1)1
求相关系数
相关系数是否显著,不能只根据值的大小还需要进行假设检验
> cor(i1[1],i1[2]) Sepal.Width Sepal.Length 0.7425467123
相关分析的例子
相关系数显著性的假设检验假设r0为总体相关系数,r0=0则说明没有相关关系,建立假设H0:r0=0,H1:r0<>0(alpha=0.05)计算相关系数r的t值和P-值> cor.test(i1$Sepal.Length,i1$Sepal.Width) Pearson's product-moment correlation data: i1$Sepal.Length and i1$Sepal.Width t = 7.6807, df = 48, p-value = 6.71e-10 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: 0.5851391 0.8460314 sample estimates: cor 0.7425467 1234567891011121314