Re: [R] Puzzled in utilising summary.lm() to obtain Var(x)

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Wed 15 Jun 2005 - 19:29:23 EST

Prof Brian Ripley <ripley@stats.ox.ac.uk> writes:

> On Wed, 15 Jun 2005, Ajay Narottam Shah wrote:
>
> >>> I have a program which is doing a few thousand runs of lm(). Suppose
> >>> it is a simple model
> >>> y = a + bx1 + cx2 + e
> >>>
> >>> I have the R object "d" where
> >>> d <- summary(lm(y ~ x1 + x2))
> >>>
> >>> I would like to obtain Var(x2) out of "d". How might I do it?
[snip]
> > var(model.matrix(d0)[,"Sepal.Width"])
>
> but if you really only have the summary (it's wasteful to keep the
> summary here, as it is larger than the fit)
>
> > var(model.matrix(structure(d, class="lm"))[,"Sepal.Width"])

Allow me to interject a little lateral thinking:

   solve(vcov(d)[-1,-1]/d$sigma)[2,2]

should give the requested variance,I think.

-- 
   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@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Wed Jun 15 19:34:32 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:39 EST