From 487325d4fe58351f5c90ad5e91d344c5fe5973c6 Mon Sep 17 00:00:00 2001 From: AQLT Date: Mon, 22 Jul 2024 14:45:08 +0200 Subject: [PATCH 1/4] simplify print output for SARIMA/RegARIMA --- R/display.R | 42 +++++++++++++++++++++++------------------- R/zzz.R | 3 +++ man/jd3_print.Rd | 9 ++++++++- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/R/display.R b/R/display.R index c4036d18..e0ba06fb 100644 --- a/R/display.R +++ b/R/display.R @@ -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 @@ -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) } @@ -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", ...) @@ -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=" ") @@ -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 @@ -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,...){ diff --git a/R/zzz.R b/R/zzz.R index e98f9ffb..22e2dd66 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -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) + } diff --git a/man/jd3_print.Rd b/man/jd3_print.Rd index aefeaba0..d658114c 100644 --- a/man/jd3_print.Rd +++ b/man/jd3_print.Rd @@ -23,7 +23,12 @@ \method{print}{JD3_LIKELIHOOD}(x, ...) -\method{print}{JD3_REGARIMA_RSLTS}(x, digits = max(3L, getOption("digits") - 3L), ...) +\method{print}{JD3_REGARIMA_RSLTS}( + x, + digits = max(3L, getOption("digits") - 3L), + summary_info = getOption("summary_info"), + ... +) } \arguments{ \item{x}{the object to print.} @@ -31,6 +36,8 @@ \item{...}{further unused parameters.} \item{digits}{minimum number of significant digits to be used for most numbers.} + +\item{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 \code{"summary_info"} it used, which initialized to \code{TRUE}.} } \description{ JD3 print functions From c29d437490701592fa94dca811358d2bb49de29c Mon Sep 17 00:00:00 2001 From: AQLT Date: Mon, 22 Jul 2024 16:52:28 +0200 Subject: [PATCH 2/4] extra space removed --- R/display.R | 52 +++++++++++++++++++++++------------------------ R/tests_regular.R | 4 ++-- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/R/display.R b/R/display.R index e0ba06fb..0d5e37de 100644 --- a/R/display.R +++ b/R/display.R @@ -15,9 +15,9 @@ print.JD3_ARIMA<-function(x, ...){ m <- x if (m$var > 0 || length(m$delta)>1){ cat(m$name, "\n\n") - if (length(m$ar)>1) cat("AR: ", m$ar, "\n") - if (length(m$delta)>1)cat("DIF: ", m$delta, "\n") - if (length(m$ma)>1)cat("MA: ", m$ma, "\n") + if (length(m$ar)>1) cat("AR:", m$ar, "\n") + if (length(m$delta)>1)cat("DIF:", m$delta, "\n") + if (length(m$ma)>1)cat("MA:", m$ma, "\n") cat("var: ", m$var, "\n\n") } invisible(x) @@ -43,10 +43,10 @@ print.JD3_UCARIMA<-function(x,...){ print.JD3_SARIMA<-function(x, ...){ m <- x cat("SARIMA model: ", .arima_node(length(m$phi), m$d, length(m$theta)), .arima_node(length(m$bphi), m$bd, length(m$btheta)), m$period, "\n") - if (length(m$phi)>0) cat("phi: ", m$phi, "\n") - if (length(m$theta)>0)cat("theta: ", m$theta, "\n") - if (length(m$bphi)>0) cat("bphi: ", m$bphi, "\n") - if (length(m$btheta)>0)cat("btheta: ", m$btheta, "\n") + if (length(m$phi)>0) cat("phi:", m$phi, "\n") + if (length(m$theta)>0)cat("theta:", m$theta, "\n") + if (length(m$bphi)>0) cat("bphi:", m$bphi, "\n") + if (length(m$btheta)>0)cat("btheta:", m$btheta, "\n") } #' @rdname jd3_print #' @export @@ -54,7 +54,7 @@ print.JD3_SARIMA_ESTIMATION<-function(x, digits = max(3L, getOption("digits") - tables <- .sarima_coef_table(x, ...) orders <- tables$sarima_orders - cat("SARIMA model: ", + cat("SARIMA model:", .arima_node(orders$p, orders$d, orders$q), .arima_node(orders$bp, orders$bd, orders$bq)) if (!is.null(orders$period)) # when sarima_estimate() is used @@ -86,7 +86,7 @@ summary.JD3_SARIMA_ESTIMATION<-function(object, ...){ print.summary.JD3_SARIMA_ESTIMATION<-function(x, digits = max(3L, getOption("digits") - 3L), signif.stars = getOption("show.signif.stars"), ...){ orders <- x$sarima_orders - cat("SARIMA model: ", + cat("SARIMA model:", .arima_node(orders$p, orders$d, orders$q), .arima_node(orders$bp, orders$bd, orders$bq)) if (!is.null(orders$period)) # when sarima_estimate() is used @@ -203,15 +203,15 @@ print.JD3_SPAN <- function(x, ...){ #' @export print.JD3_LIKELIHOOD<-function(x, ...){ ll <- x - cat("Number of observations: ", ll$nobs, "\n") - cat("Number of effective observations: ", ll$neffectiveobs, "\n") - cat("Number of parameters: ", ll$nparams, "\n\n") - cat("Loglikelihood: ", ll$ll, "\n") - if (ll$ll != ll$adjustedll)cat("Adjusted loglikelihood: ", ll$adjustedll, "\n\n") - cat("Standard error of the regression (ML estimate): ", sqrt(ll$ssq/ll$neffectiveobs), "\n") - cat("AIC: ", ll$aic, "\n") - cat("AICC: ", ll$aicc, "\n") - cat("BIC: ", ll$bic, "\n\n") + cat("Number of observations:", ll$nobs, "\n") + cat("Number of effective observations:", ll$neffectiveobs, "\n") + cat("Number of parameters:", ll$nparams, "\n\n") + cat("Loglikelihood:", ll$ll, "\n") + if (ll$ll != ll$adjustedll)cat("Adjusted loglikelihood:", ll$adjustedll, "\n\n") + cat("Standard error of the regression (ML estimate):", sqrt(ll$ssq/ll$neffectiveobs), "\n") + cat("AIC:", ll$aic, "\n") + cat("AICC:", ll$aicc, "\n") + cat("BIC:", ll$bic, "\n\n") invisible(x) } #' @export @@ -234,13 +234,13 @@ summary.JD3_LIKELIHOOD<-function(object, ...){ print.summary.JD3_LIKELIHOOD<-function(x, ...){ cat("Number of observations: ", x$nobs, ", Number of effective observations: ", x$neffectiveobs, - ", Number of parameters: ", x$nparams, "\n") - cat("Loglikelihood: ", x$ll) - if (x$ll != x$adjustedll)cat(", Adjusted loglikelihood: ", x$adjustedll) - cat("\nStandard error of the regression (ML estimate): ", x$se, "\n") - cat("AIC: ", x$aic, ", ") - cat("AICc: ", x$aicc, ", ") - cat("BIC: ", x$bic, "\n") + ", Number of parameters: ", x$nparams, "\n", sep = "") + cat("Loglikelihood:", x$ll) + if (x$ll != x$adjustedll)cat(", Adjusted loglikelihood:", x$adjustedll) + cat("\nStandard error of the regression (ML estimate):", x$se, "\n") + cat("AIC:", x$aic, ", ") + cat("AICc:", x$aicc, ", ") + cat("BIC:", x$bic, "\n") invisible(x) } @@ -277,7 +277,7 @@ print.JD3_SARIMA_ESTIMATE<-function(x, digits = max(3L, getOption("digits") - 3L tables <- .sarima_coef_table(x, ...) orders <- tables$sarima_orders - cat("SARIMA model: ", + cat("SARIMA model:", .arima_node(orders$p, orders$d, orders$q), .arima_node(orders$bp, orders$bd, orders$bq)) if (!is.null(orders$period)) # when sarima_estimate() is used diff --git a/R/tests_regular.R b/R/tests_regular.R index 2598ee39..d9ca4696 100644 --- a/R/tests_regular.R +++ b/R/tests_regular.R @@ -35,8 +35,8 @@ statisticaltest<-function(val, pval, dist=NULL){ #' @rdname statisticaltest #' @export print.JD3_TEST<-function(x, details=FALSE, ...){ - cat('Value: ', x$value, '\n') - cat('P-Value: ', sprintf('%.4f', x$pvalue), '\n') + cat('Value:', x$value, '\n') + cat('P-Value:', sprintf('%.4f', x$pvalue), '\n') if (details){ dist<-attr(x, "distribution") if (! is.null(dist)){ From b85ee847a7c579be7460e2fd50590f6774761b62 Mon Sep 17 00:00:00 2001 From: AQLT Date: Mon, 22 Jul 2024 17:45:46 +0200 Subject: [PATCH 3/4] AICc space correction --- R/display.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/display.R b/R/display.R index 0d5e37de..82e0c84b 100644 --- a/R/display.R +++ b/R/display.R @@ -238,9 +238,9 @@ print.summary.JD3_LIKELIHOOD<-function(x, ...){ cat("Loglikelihood:", x$ll) if (x$ll != x$adjustedll)cat(", Adjusted loglikelihood:", x$adjustedll) cat("\nStandard error of the regression (ML estimate):", x$se, "\n") - cat("AIC:", x$aic, ", ") - cat("AICc:", x$aicc, ", ") - cat("BIC:", x$bic, "\n") + cat("AIC: ", x$aic, ", ", + "AICc: ", x$aicc, ", ", + "BIC: ", x$bic, "\n", sep = "") invisible(x) } From 9134fb8d1de67fcecc3ff49de02133b88f676574 Mon Sep 17 00:00:00 2001 From: AQLT Date: Wed, 24 Jul 2024 15:57:28 +0200 Subject: [PATCH 4/4] add method in summary --- R/display.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/display.R b/R/display.R index 82e0c84b..199bff75 100644 --- a/R/display.R +++ b/R/display.R @@ -375,6 +375,9 @@ summary.JD3_SARIMA_ESTIMATE <-function(object, ...){ } #' @export print.summary.JD3_REGARIMA_RSLTS <- function(x, digits = max(3L, getOption("digits") - 3L), signif.stars = getOption("show.signif.stars"), ...){ + if (!is.null(x$method)) # Used to add the method when regarima/tramo function is used + cat("Method:", x$method, "\n") + if (!is.null(x$log)) cat("Log-transformation:",if (x$log) {"yes"} else {"no"},"\n",sep=" ")