Skip to content

Commit

Permalink
simplify print output for SARIMA/RegARIMA
Browse files Browse the repository at this point in the history
  • Loading branch information
AQLT committed Jul 22, 2024
1 parent 33b1547 commit 487325d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
42 changes: 23 additions & 19 deletions R/display.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ NULL
#'
#' @param x the object to print.
#' @param digits minimum number of significant digits to be used for most numbers.
#' @param summary_info boolean indicating if a message suggesting the use of the summary function for more details should be printed. By default used the option `"summary_info"` it used, which initialized to `TRUE`.
#' @param ... further unused parameters.
#' @name jd3_print
#' @rdname jd3_print
Expand Down Expand Up @@ -61,15 +62,13 @@ print.JD3_SARIMA_ESTIMATION<-function(x, digits = max(3L, getOption("digits") -

cat("\n")

cat("\nCoefficients\n")
cat("\nSARIMA coefficients:\n")
if (is.null(tables$coef_table)){
cat("No SARIMA variables\n")
} else if (ncol(tables$coef_table) == 2){
print(tables$coef_table)
} else {
printCoefmat(tables$coef_table[-2], digits = digits,
P.values= FALSE,
na.print = "NA", ...)
coef <- tables$coef_table[, 1]
names(coef) <- rownames(tables$coef_table)
print(coef, digits = digits, na.print = "NA", ...)
}
invisible(x)
}
Expand Down Expand Up @@ -98,7 +97,7 @@ print.summary.JD3_SARIMA_ESTIMATION<-function(x, digits = max(3L, getOption("dig
if (is.null(x$coef_table)){
cat("No SARIMA variables\n")
} else if (ncol(x$coef_table) == 2){
print(x$coef_table)
print(x$coef_table, ...)
} else {
printCoefmat(x$coef_table[-2], digits = digits, signif.stars = signif.stars,
na.print = "NA", ...)
Expand Down Expand Up @@ -248,7 +247,7 @@ print.summary.JD3_LIKELIHOOD<-function(x, ...){

#' @rdname jd3_print
#' @export
print.JD3_REGARIMA_RSLTS<-function(x, digits = max(3L, getOption("digits") - 3L), ...){
print.JD3_REGARIMA_RSLTS<-function(x, digits = max(3L, getOption("digits") - 3L), summary_info = getOption("summary_info"), ...){
cat("Log-transformation:",if (x$description$log) {"yes"} else {"no"},
"\n", sep=" ")

Expand All @@ -261,15 +260,19 @@ print.JD3_REGARIMA_RSLTS<-function(x, digits = max(3L, getOption("digits") - 3L)
cat("\n")
if (!is.null(xregs)){
cat("Regression model:\n")
printCoefmat(xregs[-2], digits = digits, P.values= FALSE, na.print = "NA", ...)
xregs_coef <- xregs[,1]
names(xregs_coef) <- rownames(xregs)
print(xregs_coef, digits = digits, na.print = "NA", ...)
} else {
cat("No regression variables\n")
}
print(x$estimation$likelihood, ...)
if (summary_info)
cat("\nFor a more detailed output, use the 'summary()' function.\n")

invisible(x)
}
#' @export
print.JD3_SARIMA_ESTIMATE<-function(x, digits = max(3L, getOption("digits") - 3L), ...){
print.JD3_SARIMA_ESTIMATE<-function(x, digits = max(3L, getOption("digits") - 3L), summary_info = getOption("summary_info"), ...){

tables <- .sarima_coef_table(x, ...)
orders <- tables$sarima_orders
Expand All @@ -284,23 +287,24 @@ print.JD3_SARIMA_ESTIMATE<-function(x, digits = max(3L, getOption("digits") - 3L

cat("\nCoefficients\n")
if (is.null(tables$coef_table)){
cat("No SARIMA variables\n")
} else if (ncol(tables$coef_table) == 2){
print(tables$coef_table)
cat("No SARIMA variables\n")
} else {
printCoefmat(tables$coef_table[-2], digits = digits,
P.values= FALSE,
na.print = "NA", ...)
coef <- tables$coef_table[, 1]
names(coef) <- rownames(tables$coef_table)
print(coef, digits = digits, na.print = "NA", ...)
}
xregs <- .regarima_coef_table(x, ...)
cat("\n")
if (!is.null(xregs)){
cat("Regression model:\n")
printCoefmat(xregs[-2], digits = digits, P.values= FALSE, na.print = "NA", ...)
xregs_coef <- xregs[,1]
names(xregs_coef) <- rownames(xregs)
print(xregs_coef, digits = digits, na.print = "NA", ...)
} else {
cat("No regression variables\n")
}
# print(x$likelihood, ...) # likelihood not printed but in summary method
if (summary_info)
cat("\nFor a more detailed output, use the 'summary()' function.\n")
invisible(x)
}
.regarima_coef_table <- function(x,...){
Expand Down
3 changes: 3 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ NULL
DATE_MIN<<-dateOf(1,1,1)
DATE_MAX<<-dateOf(9999, 12, 31)

if(is.null(getOption("summary_info")))
options(summary_info = TRUE)

}
9 changes: 8 additions & 1 deletion man/jd3_print.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 487325d

Please sign in to comment.