[英]How is Pr(>|t|) in a linear regression in R calculated?
使用R進行線性回歸時,使用什么公式來計算輸出的Pr(>|t|)
值?
我知道Pr (> | t |)
的值是p值,但是我不知道該值是如何計算的。
例如,盡管在下面的輸出結果中x1
的Pr (> | t |)
的值顯示為0.021
,但我想知道如何計算該值
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
列中t-value
是通過將系數估算值(在“ Estimate
列中)除以標准誤差而獲得的。 例如,在您的第二行中,我們得到:
tval = 1.8000 / 0.6071 = 2.965
您感興趣的列是p值。 t分布的絕對值大於2.965的可能性。 使用t分布的對稱性,該概率為:
2 * pt(abs(tval), rdf, lower.tail = FALSE)
這里rdf
表示剩余的自由度,在我們的例子中等於7:
rdf = number of observations minus total number of coefficient = 10 - 3 = 7
一個簡單的檢查表明這確實是R所做的:
2 * pt(2.965, 7, lower.tail = FALSE)
[1] 0.02095584
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.