2

I want to extract the fstatistic value from summary(lm()). So far the only way I've found is

summary(lm(this_vector ~ that_vector))["fstatistic"][[1]][1]

Is there a less verbose way to get that cell value? The question is a bit pedantic but I thought the answer might provide some interesting info on how to use R lists.

4

2 に答える 2

4

Try either of these:

summary(lm(this_vector ~ that_vector))$fstatistic[1]
summary(lm(this_vector ~ that_vector))[["fstatistic"]][1]

["fstatistic"] returns a list with elements that have names that match what's inside the single brackets, so you need the [[1]] to get the first element. Double brackets return the element itself, as does using the $ notation.

于 2011-12-12T21:17:43.040 に答える
0

The package broom contains functions to convenietly extract estimates and model fit statistics from various models (among them lm). For extracting the F statistic, use broom's glance() function. See the example mentioned here https://github.com/dgrtwo/broom.

In your case, that would be

glance(lm(this_vector ~ that_vector))$statistic
于 2015-07-07T08:44:05.580 に答える