如何计算 R 中线性回归中的 Pr(>|t|)? [英] How is Pr(>|t|) in a linear regression in R calculated?

查看:1571
本文介绍了如何计算 R 中线性回归中的 Pr(>|t|)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用什么公式计算R进行线性回归时输出的Pr(>|t|)的值?

What formula is used to calculate the value of Pr(>|t|) that is output when linear regression is performed by R?

我知道 Pr (> | t |) 的值是一个 p 值,但我不明白该值是如何计算的.

I understand that the value of Pr (> | t |) is a p-value, but I do not understand how the value is calculated.

例如,虽然x1Pr(>|t|)的值在下面的输出结果中显示为0.021,我想知道这个值是怎么计算的

For example, although the value of Pr (> | t |) of x1 is displayed as 0.021 in the output result below, I want to know how this value was calculated

x1 <- c(10,20,30,40,50,60,70,80,90,100)
x2 <- c(20,30,60,70,100,110,140,150,180,190)
y <- c(100,120,150,180,210,220,250,280,310,330)

summary(lm(y ~ x1+x2))

Call:
lm(formula = y ~ x1 + x2)

Residuals:
   Min     1Q Median     3Q    Max 
    -6     -2      0      2      6 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  74.0000     3.4226  21.621 1.14e-07 ***
x1            1.8000     0.6071   2.965    0.021 *  
x2            0.4000     0.3071   1.303    0.234    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 4.781 on 7 degrees of freedom
Multiple R-squared:  0.9971,    Adjusted R-squared:  0.9963 
F-statistic:  1209 on 2 and 7 DF,  p-value: 1.291e-09

推荐答案

基本上,t-value 列中的值是通过将系数估计(在 Estimate 列)由标准错误.例如,在您的第二行中,我们得到:

Basically, the values in the column t-value are obtained by dividing the coefficient estimate (which is in the Estimate column) by the standard error. For example in your case in the second row we get that:

tval = 1.8000 / 0.6071 = 2.965

您感兴趣的列是 p 值.它是 t 分布的绝对值大于 2.965 的概率.使用 t 分布的对称性,这个概率是:

The column you are interested in is the p-value. It is the probability that the absolute value of t-distribution is greater than 2.965. Using the symmetry of the t-distribution this probability is:

2 * pt(abs(tval), rdf, lower.tail = FALSE)

这里的 rdf 表示残差自由度,在我们的例子中等于 7:

Here rdf denotes the residual degrees of freedom, which in our case is equal to 7:

rdf = number of observations minus total number of coefficient = 10 - 3 = 7

一个简单的检查表明这确实是 R 所做的:

And a simple check shows that this is indeed what R does:

2 * pt(2.965, 7, lower.tail = FALSE)
[1] 0.02095584

这篇关于如何计算 R 中线性回归中的 Pr(>|t|)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆