?vcov -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA "The business of the statistician is to catalyze the scientific learning process." - George E. P. Box
> -----Original Message----- > From: r user [mailto:[EMAIL PROTECTED] > Sent: Thursday, September 21, 2006 2:11 PM > To: Berton Gunter; 'rhelp' > Subject: "summarry.lm" and NA values > > Gentlemen, > > (I am using R 2.2.1 in a Windows environment.) > > I apologize but I did not fully comprehend all of your > answer. I have a dataframe called "data1". I run > several liner regression using the lm function similar > to: > > reg <- ( lm(lm(data1[,2] ~., data1[,2:4])) ) > > > I see from generous answers below how I can use > "coef(reg)" to extract the coefficient estimates. (If > the coefficient for a variable is for some reason NA, > "coef(reg)" returns NA for that coefficient, which > is what I want.) > > My question: > What is the best way to get the standard errors, > including NA values that "go with" each of these > coefficient estimates? (i.e. If the coefficient > estimate is NA, I similarly want the standard error to > come back as NA, so that the length of coef(reg) is > the same as the length of the vector that contains the > standard errors. ) > > Thanks very much for all your help, and I apologize > for my need of additional assistance. > > > > > > > --- Berton Gunter <[EMAIL PROTECTED]> wrote: > > > "Is there a way to..." always has the answer "yes" > > in R (or C or any > > language for that matter). The question is: "Is > > there a GOOD way...?" where > > "good" depends on the specifics of the situation. So > > after that polemic, > > below is an effort to answer, (adding to what Petr > > Pikal already said): > > > > -- Bert Gunter > > Genentech Non-Clinical Statistics > > South San Francisco, CA > > > > "The business of the statistician is to catalyze the > > scientific learning > > process." - George E. P. Box > > > > > > > > > -----Original Message----- > > > From: [EMAIL PROTECTED] > > > [mailto:[EMAIL PROTECTED] On > > Behalf Of r user > > > Sent: Tuesday, August 15, 2006 7:01 AM > > > To: rhelp > > > Subject: [R] question re: "summarry.lm" and NA > > values > > > > > > Is there a way to get the following code to > > include > > > NA values where the coefficients are "NA"? > > > > > > ((summary(reg))$coefficients) > > BAAAD! Don't so this. Use the extractor on the > > object: coef(reg) > > This suggests that you haven't read the > > documentation carefully, which tends > > to arouse the ire of would-be helpers. > > > > > > > > explanation: > > > > > > Using a loop, I am running regressions on several > > > "subsets" of "data1". > > > > > > "reg <- ( lm(lm(data1[,1] ~., data1[,2:l])) )" > > ??? There's an error here I think. Do you mean > > update()? Do you have your > > subscripting correct? > > > > > > > > My regression has 10 independent variables, and I > > > therefore expect 11 coefficients. > > > After each regression, I wish to save the > > coefficients > > > and standard errors of the coefficients in a table > > > with 22 columns. > > > > > > I successfully extract the coefficients using the > > > following code: > > > "reg$coefficients" > > Use the extractor, coef() > > > > > > > > I attempt to extract the standard errors using : > > > > > > aperm((summary(reg))$coefficients)[2,] > > > > BAAAD! Use the extractor vcov(): > > sqrt(diag(vcov(reg))) > > > > > > ((summary(reg))$coefficients) > > > > > > My problem: > > > For some of my subsets, I am missing data for one > > or > > > more of the independent variables. This of course > > > causes the coefficients and standard erros for > > this > > > variable to be "NA". > > Not it doesn't, as Petr said. > > > > One possible approach: Assuming that a variable is > > actually missing (all > > NA's), note that coef(reg) is a named vector, so > > that the character string > > names of the regressors actually used are available. > > You can thus check for > > what's missing and add them as NA's at each return. > > Though I confess that I > > see no reason to put things ina matrix rather than > > just using a list. But > > that's a matter of personal taste I suppose. > > > > > > > > Is there a way to include the NA standard errors, > > so > > > that I have the same number of standard erros and > > > coefficients for each regression, and can then > > store > > > the coefficients and standard erros in my table of > > 22 > > > columns? > > > > > > ______________________________________________ > > > [email protected] 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. > > > > > > > > > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > ______________________________________________ [email protected] 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.
