Skip to content

Instantly share code, notes, and snippets.

@rentrop
Last active March 25, 2017 00:53
Show Gist options
  • Save rentrop/4f026bc7e1f401b02dbad610479fe107 to your computer and use it in GitHub Desktop.
Save rentrop/4f026bc7e1f401b02dbad610479fe107 to your computer and use it in GitHub Desktop.
Compact print for summary.lmrob - this does not print all row-indices of all outliers
# By default print.summary.lmrob shows all outlier-rowindices.
# This sometimes is way too much information,
# especially data sets with lots of outliers.
# This function just removes the observations from the print output
compact_print_lmrob_summary <- function(...){
out <- capture.output(...)
observations_ind <- grep("observations c\\(", out)
# Remove numbers of observations
out[observations_ind] <- sub("observations c\\(.*", "observations", out[observations_ind])
# Combine this and the next line
next_line_content <- sub("\t ", "", out[observations_ind + 1L], fixed = TRUE)
out[observations_ind] <- paste(out[observations_ind], next_line_content)
# remove next line
out <- out[-(observations_ind + 1)]
cat(out, sep = "\n")
}
## Example
require(robustbase)
data(starsCYG, package = "robustbase")
dat <- do.call(rbind, replicate(100, starsCYG, simplify = FALSE))
print(summ <- summary(lmrob(log.light ~ log.Te, data = dat))) # Prints all 400 row-indices
compact_print_lmrob_summary(summ) # just prints summary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment