I would like to extract the "Model comparisons" table as a dataframe/matrix from a loolist object.
data(iris)
m1 <- brm(Sepal.Length~Sepal.Width,data=iris)
m2 <- brm(Sepal.Length~Sepal.Width + Petal.Length,data=iris)
looLst <- loo(m1,m2,compare=TRUE)
print(looLst)
This will print a long text summary, the end of which is
Model comparisons:
elpd_diff se_diff
m2 0.0 0.0
m1 -135.4 10.4
Is it possible to extract this table from the loolist object?
You could extract it from the object and write a custom function to add the text "Model comparisons:" with cat
like this:
data(iris)
library(brms)
m1 <- brm(Sepal.Length~Sepal.Width,data=iris)
m2 <- brm(Sepal.Length~Sepal.Width + Petal.Length,data=iris)
looLst <- loo(m1,m2,compare=TRUE)
your_table <- function(df) {
cat("Model comparisons: \n")
df$diffs
}
your_table(looLst)
#> Model comparisons:
#> elpd_diff se_diff
#> m2 0.0 0.0
#> m1 -135.5 10.4
Created on 2023-04-21 with reprex v2.0.2