Dear R users I have run an regression and want to extract the p value of the F statistics, but I can find a way to do that. x<-summary(lm(log(RV2)~log(IV.m),data=b)) Call: lm(formula = log(RV2) ~ log(IV.m), data = b[[11]]) Residuals: Min 1Q Median 3Q Max -0.26511 -0.09718 -0.01326 0.11095 0.29777 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -0.3059 0.1917 -1.595 0.121 log(IV.m) 0.9038 0.1065 8.488 1.38e-09 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.1435 on 31 degrees of freedom Multiple R-squared: 0.6991, Adjusted R-squared: 0.6894 F-statistic: 72.04 on 1 and 31 DF, p-value: 1.379e-09 names(x) [1] "call" "terms" "residuals" [4] "coefficients" "aliased" "sigma" [7] "df" "r.squared" "adj.r.squared" [10] "fstatistic" "cov.unscaled" x$fstatistic value numdf dendf 72.04064 1.00000 31.00000 But can not find the p value of F statistics. Thanks Ted -- View this message in context: http://www.nabble.com/extract-the-p-value-of-F-statistics-from-the-lm-class-tp22891475p22891475.html Sent from the R help mailing list archive at Nabble.com.
Duncan Murdoch
2009-Apr-05 11:48 UTC
[R] extract the p value of F statistics from the lm class
On 05/04/2009 4:18 AM, tedzzx wrote:> Dear R users > > I have run an regression and want to extract the p value of the F > statistics, but I can find a way to do that. > > x<-summary(lm(log(RV2)~log(IV.m),data=b)) > > Call: > lm(formula = log(RV2) ~ log(IV.m), data = b[[11]]) > > Residuals: > Min 1Q Median 3Q Max > -0.26511 -0.09718 -0.01326 0.11095 0.29777 > > Coefficients: > Estimate Std. Error t value Pr(>|t|) > (Intercept) -0.3059 0.1917 -1.595 0.121 > log(IV.m) 0.9038 0.1065 8.488 1.38e-09 *** > --- > Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > Residual standard error: 0.1435 on 31 degrees of freedom > Multiple R-squared: 0.6991, Adjusted R-squared: 0.6894 > F-statistic: 72.04 on 1 and 31 DF, p-value: 1.379e-09 > > names(x) > [1] "call" "terms" "residuals" > [4] "coefficients" "aliased" "sigma" > [7] "df" "r.squared" "adj.r.squared" > [10] "fstatistic" "cov.unscaled" > > x$fstatistic > value numdf dendf > 72.04064 1.00000 31.00000 > > But can not find the p value of F statistics.If you're looking for something like that, the two places to look are: - the man page ?summary.lm (which gives the answer) - unclass(x) will display the object without the fancy printing, so you can see that the man page is accurate. (Sometimes man pages are incomplete, and this way is needed, but not in this case.) Duncan Murdoch
Thomas Petzoldt
2009-Apr-05 11:52 UTC
[R] extract the p value of F statistics from the lm class
Hi, what about the following: ## some test data x <- 1:10 y <- x + rnorm(x) ## model and summary m <- lm(y~x) sm <- summary(m) sm # str(sm) # sm$fstatistic ## and now: the manual case 1 - pf(sm$fstatistic[1], sm$fstatistic[2], sm$fstatistic[3]) Hope it helps, ThPe tedzzx schrieb:> Dear R users > > I have run an regression and want to extract the p value of the F > statistics, but I can find a way to do that. > > x<-summary(lm(log(RV2)~log(IV.m),data=b)) > > Call: > lm(formula = log(RV2) ~ log(IV.m), data = b[[11]]) > > Residuals: > Min 1Q Median 3Q Max > -0.26511 -0.09718 -0.01326 0.11095 0.29777 > > Coefficients: > Estimate Std. Error t value Pr(>|t|) > (Intercept) -0.3059 0.1917 -1.595 0.121 > log(IV.m) 0.9038 0.1065 8.488 1.38e-09 *** > --- > Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > Residual standard error: 0.1435 on 31 degrees of freedom > Multiple R-squared: 0.6991, Adjusted R-squared: 0.6894 > F-statistic: 72.04 on 1 and 31 DF, p-value: 1.379e-09 > > names(x) > [1] "call" "terms" "residuals" > [4] "coefficients" "aliased" "sigma" > [7] "df" "r.squared" "adj.r.squared" > [10] "fstatistic" "cov.unscaled" > > x$fstatistic > value numdf dendf > 72.04064 1.00000 31.00000 > > But can not find the p value of F statistics. > > Thanks > > Ted > > >
Duncan Murdoch
2009-Apr-05 12:00 UTC
[R] extract the p value of F statistics from the lm class
On 05/04/2009 4:18 AM, tedzzx wrote:> Dear R users > > I have run an regression and want to extract the p value of the F > statistics, but I can find a way to do that. > > x<-summary(lm(log(RV2)~log(IV.m),data=b)) > > Call: > lm(formula = log(RV2) ~ log(IV.m), data = b[[11]]) > > Residuals: > Min 1Q Median 3Q Max > -0.26511 -0.09718 -0.01326 0.11095 0.29777 > > Coefficients: > Estimate Std. Error t value Pr(>|t|) > (Intercept) -0.3059 0.1917 -1.595 0.121 > log(IV.m) 0.9038 0.1065 8.488 1.38e-09 *** > --- > Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > Residual standard error: 0.1435 on 31 degrees of freedom > Multiple R-squared: 0.6991, Adjusted R-squared: 0.6894 > F-statistic: 72.04 on 1 and 31 DF, p-value: 1.379e-09 > > names(x) > [1] "call" "terms" "residuals" > [4] "coefficients" "aliased" "sigma" > [7] "df" "r.squared" "adj.r.squared" > [10] "fstatistic" "cov.unscaled" > > x$fstatistic > value numdf dendf > 72.04064 1.00000 31.00000 > > But can not find the p value of F statistics.Sorry, I misread your question: the p-value of that statistic isn't returned. You just need to calculate it yourself, as f <- x$fstatistic pf(f[1], f[2], f[3], lower=FALSE) Duncan Murdoch
(Ted Harding)
2009-Apr-05 12:12 UTC
[R] extract the p value of F statistics from the lm class
On 05-Apr-09 08:18:27, tedzzx wrote:> Dear R users > I have run an regression and want to extract the p value of the F > statistics, but I can find a way to do that. > > x<-summary(lm(log(RV2)~log(IV.m),data=b)) > > Call: > lm(formula = log(RV2) ~ log(IV.m), data = b[[11]]) > > Residuals: > Min 1Q Median 3Q Max > -0.26511 -0.09718 -0.01326 0.11095 0.29777 > > Coefficients: > Estimate Std. Error t value Pr(>|t|) > (Intercept) -0.3059 0.1917 -1.595 0.121 > log(IV.m) 0.9038 0.1065 8.488 1.38e-09 *** > --- > Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > Residual standard error: 0.1435 on 31 degrees of freedom > Multiple R-squared: 0.6991, Adjusted R-squared: 0.6894 > F-statistic: 72.04 on 1 and 31 DF, p-value: 1.379e-09 > > names(x) > [1] "call" "terms" "residuals" > [4] "coefficients" "aliased" "sigma" > [7] "df" "r.squared" "adj.r.squared" > [10] "fstatistic" "cov.unscaled" > > x$fstatistic > value numdf dendf > 72.04064 1.00000 31.00000 > > But can not find the p value of F statistics. > Thanks > TedMaybe you were looking in the wrong place. A few lines above the output from x$fstatistic x$fstatistic value numdf dendf 72.04064 1.00000 31.00000 you will find F-statistic: 72.04 on 1 and 31 DF, p-value: 1.379e-09 and therefore will find the P-value. However, maybe that is not the question you really wanted to ask. If that is what I think it may be, you could 1: Observe that x$fstatistic is a vector with 3 values which are: value of F; numerator df; demoninator df 2: Note (from ?pf) pf(q, df1, df2, ncp, lower.tail = TRUE, log.p = FALSE) 3: Therefore do pf(x$fstatistic[1],x$fstatistic[2],x$fstatistic[3],lower.tail=FALSE) # [1] 1.378626e-09 Note that the P-value is not in the list of values returned by lm() although $fstatistic is one of the values. The computation of the P-value in the displayed output from summary.lm() is done by the 'print' method for summary.lm() (just as in [3] above). Hoping this helps, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 05-Apr-09 Time: 13:12:45 ------------------------------ XFMail ------------------------------