How to manually calculate the p-value of t-statistics in linear regression

I did a linear regression for two tail t-tests with 178 degrees of freedom. The summary function gives me two p-values ​​for my two t-values.

 t value Pr(>|t|) 5.06 1.04e-06 *** 10.09 < 2e-16 *** ... ... F-statistic: 101.8 on 1 and 178 DF, p-value: < 2.2e-16 

I want to manually calculate the p-value of t-values ​​using this formula:

 p = 1 - 2*F(|t|) p_value_1 <- 1 - 2 * pt(abs(t_1), 178) p_value_2 <- 1 - 2 * pt(abs(t_2), 178) 

I do not get the same p values ​​as in the model summary. Therefore, I want to know how the function summary Pr(>|t|) differs from my formula because I cannot find the definition of Pr(>|t|) .

Could you help me? Thank you very much!

+5
source share
2 answers

it

 2 * pt(-abs(t_value), df) 

For instance:

 2 * pt(-5.06, 178) #[1] 1.038543e-06 2 * pt(-10.09, 178) #[1] 3.223683e-19 

Alternatively use

 2 * pt(abs(t_value), df, lower.tail = FALSE) 
+3
source

We can calculate the value of p Pr (> | t |) in the following ways:

 tval <- 5.06 df <- 178 # compute area under the t-pdf integrate(function(x) dt(x, df), -Inf, -tval)$value + integrate(function(x) dt(x, df), tval, Inf)$value # sum of two areas # [1] 1.038543e-06 1-integrate(function(x) dt(x, df), -tval, tval)$value # [1] 1.038543e-06 # 2-sided t-test: Pr_T(|t|>|tval|) = 2*(1 - F_T(|tval|)) = 2*F_T(-|tval|), where T~t(df=178) 2*(1 - pt(tval, df)) # [1] 1.038543e-06 2*pt(tval, df, lower.tail = FALSE) # [1] 1.038543e-06 1 - (pt(tval, df) - pt(-tval, df)) # [1] 1.038543e-06 2*pt(-tval, df) # [1] 1.038543e-06 

Below we show the same geometrically with a different (less extreme) value of t-statistics, as we see, there are two (symmetrical) blue areas that together represent the corresponding probability, for a two-sided t-test.

 df <- 178 x <- seq(-6, 6,0.01) y <- dt(x, df) tval <- 1.25 plot(x, y, type='l', main='t-distribution and p-value (5% significance level, 2-sided t-test)') abline(h=0) abline(v = c(tval, -tval), col='red') index1 <- which(x >= -tval)[1] index2 <- which(x >= tval)[1] polygon(x = c(x[1:index1], x[index1], x[1]), y = c(y[1:index1], 0, 0), col = "blue") polygon(x = c(x[index2], x[index2], x[index2:length(x)]), y = c(0, y[index2], y[index2:length(y)]), col = "blue") 

enter image description here

+3
source

Source: https://habr.com/ru/post/1262417/


All Articles