Antonio Silva
2013-Feb-08 01:22 UTC
[R] On p-values presented in the summary of Linear Models
Dear list members I have a doubt on how p-values for t-statistics are calculated in the summary of Linear Models. Here goes an example: x <- rnorm(100,50,10) y <- rnorm(100,0,5) fit1<-lm(y~x) summary(fit1) summary(fit1)$coef[2] # b summary(fit1)$coef[4] # Std. Error summary(fit1)$coef[6] # t-statistic summary(fit1)$coef[8] # Pr(>|t| summary(fit1)$df [2] # degrees of freedom # t-statistic can be calculated as: t<-(summary(fit1)$coef[2])/summary(fit1)$coef[4] t # t-statistic # the critical value for t0.05(2)df can be obtained in a t distribuition table # http://www.math.unb.ca/~knight/utility/t-table.htm or with qt(0.975,summary(fit1)$df[2]) # Two-sided p-value should be estimated with dt(t,summary(fit1)$df[2]) # isn't it? But this value is different from summary(fit1)$coef[8] My question is: how to reach to the same p-value indicated in Pr(>|t|) or summary(fit1)$coef[8]? Thanks in advance, Antonio Olinto [[alternative HTML version deleted]]
Kevin E. Thorpe
2013-Feb-08 01:30 UTC
[R] On p-values presented in the summary of Linear Models
On 02/07/2013 08:22 PM, Antonio Silva wrote:> Dear list members > > I have a doubt on how p-values for t-statistics are calculated in the > summary of Linear Models. > > Here goes an example: > > x <- rnorm(100,50,10) > y <- rnorm(100,0,5) > fit1<-lm(y~x) > summary(fit1) > summary(fit1)$coef[2] # b > summary(fit1)$coef[4] # Std. Error > summary(fit1)$coef[6] # t-statistic > summary(fit1)$coef[8] # Pr(>|t| > summary(fit1)$df [2] # degrees of freedom > > # t-statistic can be calculated as: > t<-(summary(fit1)$coef[2])/summary(fit1)$coef[4] > t # t-statistic > > # the critical value for t0.05(2)df can be obtained in a t distribuition > table > # http://www.math.unb.ca/~knight/utility/t-table.htm or with > qt(0.975,summary(fit1)$df[2]) > > # Two-sided p-value should be estimated with > dt(t,summary(fit1)$df[2]) # isn't it? >The dt() function is giving you the value from the density function, not the probability. Use pt() to obtain probabilities.> But this value is different from summary(fit1)$coef[8] > > My question is: how to reach to the same p-value indicated in Pr(>|t|) or > summary(fit1)$coef[8]? > > Thanks in advance, > > Antonio Olinto > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > >-- Kevin E. Thorpe Head of Biostatistics, Applied Health Research Centre (AHRC) Li Ka Shing Knowledge Institute of St. Michael's Assistant Professor, Dalla Lana School of Public Health University of Toronto email: kevin.thorpe at utoronto.ca Tel: 416.864.5776 Fax: 416.864.3016
Antonio Silva
2013-Feb-08 01:33 UTC
[R] On p-values presented in the summary of Linear Models
OK, I found the answer: 2*pt(t,summary(fit1)$df[2]) Thanks anyway ... 2013/2/7 Antonio Silva <aolinto.lst@gmail.com>> Dear list members > > I have a doubt on how p-values for t-statistics are calculated in the > summary of Linear Models. > > Here goes an example: > > x <- rnorm(100,50,10) > y <- rnorm(100,0,5) > fit1<-lm(y~x) > summary(fit1) > summary(fit1)$coef[2] # b > summary(fit1)$coef[4] # Std. Error > summary(fit1)$coef[6] # t-statistic > summary(fit1)$coef[8] # Pr(>|t| > summary(fit1)$df [2] # degrees of freedom > > # t-statistic can be calculated as: > t<-(summary(fit1)$coef[2])/summary(fit1)$coef[4] > t # t-statistic > > # the critical value for t0.05(2)df can be obtained in a t distribuition > table > # http://www.math.unb.ca/~knight/utility/t-table.htm or with > qt(0.975,summary(fit1)$df[2]) > > # Two-sided p-value should be estimated with > dt(t,summary(fit1)$df[2]) # isn't it? > > But this value is different from summary(fit1)$coef[8] > > My question is: how to reach to the same p-value indicated in Pr(>|t|) or > summary(fit1)$coef[8]? > > Thanks in advance, > > Antonio Olinto >-- Antônio Olinto Ávila da Silva Biólogo / Oceanógrafo Instituto de Pesca (Fisheries Institute) São Paulo, Brasil [[alternative HTML version deleted]]
On 8 Feb 2013, at 01:24, "Antonio Silva" <aolinto.lst at gmail.com> wrote:> # Two-sided p-value should be estimated with > dt(t,summary(fit1)$df[2]) # isn't it?No, on two counts.>First, dt is the density; you need pt, the cumulative probability, not dt. Second, pt(t, ...) would calculate the one sided lower tail probability. You need twice the upper tail probability for a two-sided p-value. Try 2*pt(t, ..., lower.tail=FALSE) (and if thats wrong by a factor of four i've multiplied instead of dividing ... again ....) S ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}