[R] R-square n p-value

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sun Sep 4 10:43:22 CEST 2005


Dirk Eddelbuettel <edd at debian.org> writes:

> On 3 September 2005 at 17:59, Justin Rhodes wrote:
> | Dear R-help,
> | 
> | Can someone please help me discover what function or code will give 
> | me a p-value from the input: 1) R-square statistic from a simple 
> | linear regression, and 2) sample size, n
> | 
> | This would be greatly appreciated.  I need this because I am using a 
> | database that gives me R-square and sample size for multiple 
> | comparisons, and I wish to determine the false discovery rate using 
> | q-value.  Thanks again,
> 
> Do
> 	> example(lm)			# just to get an lm object
> 	> str(summary(lm.D9))		# to examine summary of an object
> 
> and you'll see that the object returned from summary has the two common R^2
> measures, as well as things like residuals from which can compute n quite
> easily -- which you could obviously also from your regressors and regressand.
> 
> 	> length(summary(lm.D9)$residuals)

I think the problem was somewhat different: The *input* is coming from
some sort of (closed-source or otherwise impenetrable) database which
only gives out n and R^2, right?

Now R^2 = SSDmodel/(SSDmodel+SSDres) and F =
DFres/DFmodel*SSDmodel/SSDres, i.e. 

  1/R^2 = 1 + 1/F*DFmodel/DFres

or 

  F = 1/(1/R^2 - 1)*DFres/DFmodel = R^2/(1-R^2)*DFres/DFmodel

which can be looked up "in the F-table" using 

  pf(F, 1, N-2, lower.tail=FALSE)
 
(provided we have a 1 DF model)

Actually, R^2 itself has a beta distribution and you could use pbeta
directly, but then you'd need to figure out (or recall) what the
relation between the DF and the shape parameters of the beta
distribution are. By my reckoning, this should do it:

  pbeta(Rsq, 1/2, (N-2)/2, lower.tail=FALSE) 

"Proof":

....
Residual standard error: 1.143 on 8 degrees of freedom
Multiple R-Squared: 0.0004207,  Adjusted R-squared: -0.1245
F-statistic: 0.003367 on 1 and 8 DF,  p-value: 0.9552

> pbeta(0.0004207, 1/2, 8/2, lower=F)
[1] 0.9551511


-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907




More information about the R-help mailing list