LL 实际上只是一个数字(带有属性)。打印LL 时看到的行是由print.logLik 函数创建的,如下所示:
getAnywhere(print.logLik)
A single object matching ‘print.logLik’ was found
It was found in the following places
registered S3 method for print from namespace stats
namespace:stats
with value
function (x, digits = getOption("digits"), ...)
{
cat("'log Lik.' ", paste(format(c(x), digits = digits), collapse = ", "),
" (df=", format(attr(x, "df")), ")\n", sep = "")
invisible(x)
}
这是在您运行 LL 时调用的,但 LL 实际上只有一个数字(长度为 1 的数字向量)。 cat 函数用于打印您在控制台上看到的 'log Lik.' -343 (df=4)。
为了得到你可以做的df值(从上面的函数也可以看出):
format(attr(LL[['logLik']], "df"))
查看示例(来自 lmer 的文档):
fm1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
a <- summary(fm1)# (with its own print method)
> a[['logLik']]
'log Lik.' -871.8141 (df=6)
> format(attr(a[['logLik']], "df"))
[1] "6"
并且根据@BenBolker 在评论format 中提到的仅将其转换为字符。
> attr(a[['logLik']], "df")
[1] 6
可能更好。