Hi! I'm trying to use lm(y~x) amongst others in an automated way; I've gone through the section on indexing in R-lang and I've looked MASS4. How do I find out more about the structure of the returned object? In perl I can look at object structure pretty-printed in the debugger - is there an R equivalent? I've used coef(lm(y~x))[[1]] and coef(lm(y~x))[[2]] to extract the intercept; but while summary(lm(y~x)) prints R-squared... it isn't entirely obvious how to extract this value as a scalar. ?lm doesn't give me the information by saying unlist(summary(lm(y~x))) it prints $r.squared [1] 0.2673333 so now I can say my.r.sq <- summary(lm(y~x))$r.squared but is there a better way? on my small lm model unlist(lm(y~x)) is a pretty long list! :-) Many thanks in advance, Sean O'Riordain
On Tue, 5 Jul 2005, Sean O'Riordain wrote:> Hi! > > I'm trying to use lm(y~x) amongst others in an automated way; I've > gone through the section on indexing in R-lang and I've looked MASS4. > How do I find out more about the structure of the returned object? In > perl I can look at object structure pretty-printed in the debugger - > is there an R equivalent?str(), or browseEnv(), or the improved object browser in the JGR GUI. -thomas
Sean O'Riordain wrote:> ?lm doesn't > give me the informationThat's because the information has come from 'summary' (specifically summary.lm). ?summary.lm: r.squared: R^2, the "fraction of variance explained by the model", - it also lists the other things of interest you can get from an lm fitted object. Baz