Я сдался и поиграл с кодом, чтобы произвести нечто подобное. Не самая красивая вещь, хотя. Если кто-то захочет улучшить его - я буду рад использовать ваш код.
print.summary.lm.xtable <- function (x, digits = max(3, getOption("digits") - 3), symbolic.cor = x$symbolic.cor,
signif.stars = getOption("show.signif.stars"), ...)
{
if(!require(xtable)) stop("This function requires the package 'xtable' - please make sure you get it")
cat("\\begin{verbatim}")
cat("\nCall:\n", paste(deparse(x$call), sep = "\n", collapse = "\n"),
"\n\n", sep = "")
resid <- x$residuals
df <- x$df
rdf <- df[2L]
cat(if (!is.null(x$w) && diff(range(x$w)))
"Weighted ", "Residuals:\n", sep = "")
if (rdf > 5L) {
nam <- c("Min", "1Q", "Median", "3Q", "Max")
rq <- if (length(dim(resid)) == 2L)
structure(apply(t(resid), 1L, quantile), dimnames = list(nam,
dimnames(resid)[[2L]]))
else {
zz <- zapsmall(quantile(resid), digits + 1)
structure(zz, names = nam)
}
print(rq, digits = digits, ...)
}
else if (rdf > 0L) {
print(resid, digits = digits, ...)
}
else {
cat("ALL", df[1L], "residuals are 0: no residual degrees of freedom!\n")
}
# if (length(x$aliased) == 0L) {
# cat("\nNo Coefficients\n")
# }
# else {
# if (nsingular <- df[3L] - df[1L])
# cat("\nCoefficients: (", nsingular, " not defined because of singularities)\n",
# sep = "")
# else cat("\nCoefficients:\n")
# coefs <- x$coefficients
# if (!is.null(aliased <- x$aliased) && any(aliased)) {
# cn <- names(aliased)
# coefs <- matrix(NA, length(aliased), 4, dimnames = list(cn,
# colnames(coefs)))
# coefs[!aliased, ] <- x$coefficients
# }
# printCoefmat(coefs, digits = digits, signif.stars = signif.stars,
# na.print = "NA", ...)
# }
cat("\\end{verbatim}")
print(xtable(x), latex.environments = "left") # x is a summary of some lm object
cat("\\begin{verbatim}")
cat("Residual standard error:", format(signif(x$sigma,
digits)), "on", rdf, "degrees of freedom\n")
if (nzchar(mess <- naprint(x$na.action)))
cat(" (", mess, ")\n", sep = "")
if (!is.null(x$fstatistic)) {
cat("Multiple R-squared:", formatC(x$r.squared, digits = digits))
cat(",\tAdjusted R-squared:", formatC(x$adj.r.squared,
digits = digits), "\nF-statistic:", formatC(x$fstatistic[1L],
digits = digits), "on", x$fstatistic[2L], "and",
x$fstatistic[3L], "DF, p-value:", format.pval(pf(x$fstatistic[1L],
x$fstatistic[2L], x$fstatistic[3L], lower.tail = FALSE),
digits = digits), "\n")
}
correl <- x$correlation
if (!is.null(correl)) {
p <- NCOL(correl)
if (p > 1L) {
cat("\nCorrelation of Coefficients:\n")
if (is.logical(symbolic.cor) && symbolic.cor) {
print(symnum(correl, abbr.colnames = NULL))
}
else {
correl <- format(round(correl, 2), nsmall = 2,
digits = digits)
correl[!lower.tri(correl)] <- ""
print(correl[-1, -p, drop = FALSE], quote = FALSE)
}
}
}
cat("\n")
cat("\\end{verbatim}")
invisible(x)
}