[R] lm with data=(means,sds,ns)

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sun Apr 18 14:04:45 CEST 2004


(Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> writes:

> Thanks, Brian!
> 
> On 18-Apr-04 Prof Brian Ripley wrote:
> > The short answer is no, as there is no way to recover the fitted values
> 
> Well, the fitted values (a + b*x_i) would be available, as would be
> the estimates and SEs of coefficients, sums of squares, and relevant
> F ratios and P values.

Not quite. You can get the estimates and per-group fitted values
alright from a weighted regression, but the SEs require that you have
the residual sum of squares and the within-group part of the SS is not
obtainable, although trivially computable as sum(s^2*(n-1))

(I did go through some of this for the trypsin example in Ch 10.4 in
ISwR)  

> > and residuals so you can't get a proper fit object of class "lm" (and 
> > hence get `summaries and all').
> 
> Residuals granted. However, much of what is useful in 'summary.lm'
> would be supported. So also (which is what I really wanted a lazy
> route to) would be the requisite summary statistics to generate
> confidence and prediction bands as in 'predict.lm'.
> 
> > Your pseudo-data method needs to fix the u_i to be mean zero,
> > variance one in the sample.  That is probably the quickest method. 
> > The elegant one is to create a new class "groupedlm" and write a
> > constructor etc for it
> 
> That's the sort of thing I feared! No time for that at the moment,
> though one day I may find it to be an absorbing exercise in extending
> my R skills and understanding.
> 
> Anyway, I'm grateful to know what the position is. At least I can now
> feel happy about having to roll up my sleeves and get stuck in the
> hard way.

Actually, I susppect that it's only about half an hour's work:

1) The constructor returns (with class lmG or so)
   list(wlm=lm(y~formula,weights=n), withinSS=sum(s^2*(n-1)),
        withinDF=sum(n-1))  

2) summary.lmG is like summary.lm except that resvar adds in the
   withinSS and withinDF. Likewise anova and predict methods.

3) done

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list