首页 > 编程知识 正文

R语言知道相关性怎么求p值,R中对数据分析

时间:2023-05-06 15:05:49 阅读:256590 作者:3694

很多同学包括楼主喜欢R语言的原因就是因为它小巧简洁,不需要太多的代码就可以得到很好的结果。比如线性回归时利用lm()就是一个很好的例子,用简单的代码就可以得到回归表达式,以及各种系数检验等等,但是这些结果是怎么呈现到我们面前的呢,接下来就解释R语言lm()的输出结果。

data(iris) fit<-lm(iris$Sepal.Width ~ iris$Petal.Width) summary(fit) Call:lm(formula = iris$Sepal.Width ~ iris$Petal.Width)Residuals: Min 1Q Median 3Q Max -1.09907 -0.23626 -0.01064 0.23345 1.17532 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 3.30843 0.06210 53.278 < 2e-16 iris$Petal.Width -0.20936 0.04374 -4.786 4.07e-06 Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1Residual standard error: 0.407 on 148 degrees of freedomMultiple R-squared: 0.134, Adjusted R-squared: 0.1282 F-statistic: 22.91 on 1 and 148 DF, p-value: 4.073e-06

很简单的代码就得到一个线性回归方程,很多书上都已经介绍了线性回归方程的原理和各种解释变量的意义。故仅在此处贴出利用R如何计算出t值

(tstats <- coef(fit) / sqrt(diag(vcov(fit)))) (Intercept) Petal.Width 53.277950 -4.786461

利用R如何计算出P值

2 * pt(abs(tstats), df = df.residual(fit), lower.tail = FALSE) (Intercept) Petal.Width 1.835999e-98 4.073229e-06

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。