[R] Extracting elements of model output

David C. Howell David.Howell at uvm.edu
Mon Oct 14 19:01:35 CEST 2013


I am having difficulty extracting specific results from the model 
object. The following code shows where I am stuck.

I want to run resamplings of a data set. For each I want to extract a 
particular F for the contrasts. If I run a very simple model
(e.g. model1 <- aov(time~group) ) I can get the relevant coefficients, 
for example, by using "model1$coefficients". That's fine. But I don't 
want the coefficients of the model, I want the contrasts. So I tried
model2=summary(model1, split = list(group = list("1&3 vs 2"=1, "1 vs 3" 
= 2)))
This gives me the printout summary table that I want. i.e.

model2
Df Sum Sq Mean Sq F value Pr(>F)
group 2 4090 2045 8.081 0.000682 ***
group: 1&3 vs 2 1 1483 1484 5.863 0.017988 *
group: 1 vs 3 1 2606 2606 10.300 0.001987 **
Residuals 72 18219 253

That's the summary table that I want, but I want to extract, for example 
the F value of 5.863.

Looking at the structure of that object I get

str(model2)
List of 1
$ :Classes ‘anova’ and 'data.frame': 4 obs. of 5 variables:
..$ Df : Named num [1:4] 2 1 1 72
.. ..- attr(*, "names")= chr [1:4] "" "1&3 vs 2" "1 vs 3" ""
..$ Sum Sq : Named num [1:4] 4090 1483 2606 18219
.. ..- attr(*, "names")= chr [1:4] "" "1&3 vs 2" "1 vs 3" ""
..$ Mean Sq: Named num [1:4] 2045 1483 2606 253
.. ..- attr(*, "names")= chr [1:4] "" "1&3 vs 2" "1 vs 3" ""
..$ F value: Named num [1:4] 8.08 5.86 10.3 NA
.. ..- attr(*, "names")= chr [1:4] "" "1&3 vs 2" "1 vs 3" ""
..$ Pr(>F) : Named num [1:4] 0.000682 0.017988 0.001987 NA

What I would like to do is to request result$"F value[2]"
but that just gives "NULL."

I note that if I request the structure for model 1, the first element is 
$Df. But when I ask for the structure of model2, the first element is 
..$Df. I assume that those two dots represent an ellipsis, but nothing 
is ?str, ?attr, or other help screens tell me how to interpret and use 
..Df or any of the other elements.

Any help?

Thanks,
Dave Howell



More information about the R-help mailing list