Skip to content

Commit b783ea1

Browse files
committed
add srr roclets; some other improvements
1 parent 3665670 commit b783ea1

24 files changed

Lines changed: 452 additions & 65 deletions

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Imports:
2626
magrittr,
2727
dplyr,
2828
tidyr,
29+
pillar,
2930
ggplot2,
3031
car,
3132
sandwich,

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ S3method(summary,lst_efficient)
1717
S3method(summary,revision_summary)
1818
S3method(summary,tbl_pubdate)
1919
S3method(summary,tbl_release)
20+
S3method(tbl_sum,tbl_pubdate)
21+
S3method(tbl_sum,tbl_release)
2022
export(colors_reviser)
2123
export(diagnose)
2224
export(get_days_to_release)
@@ -43,3 +45,4 @@ importFrom(calculus,"%mx%")
4345
importFrom(calculus,"%prod%")
4446
importFrom(calculus,"%sum%")
4547
importFrom(magrittr,"%>%")
48+
importFrom(pillar,tbl_sum)

R/graphs.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ plot_vintages <- function(
314314
#' @param ... Additional arguments passed to plot_vintages.
315315
#'
316316
#' @return A ggplot2 object.
317+
#' @srrstats {TS5.0} Implements default plot methods for implemented class system
318+
#' @srrstats {TS4.2} Explicitly documents the type and class of return values
317319
#' @method plot tbl_pubdate
318320
#' @family revision graphs
319321
#' @export
@@ -327,6 +329,8 @@ plot.tbl_pubdate <- function(x, ...) {
327329
#' @param ... Additional arguments passed to plot_vintages.
328330
#'
329331
#' @return A ggplot2 object.
332+
#' @srrstats {TS5.0} Implements default plot methods for implemented class system
333+
#' @srrstats {TS4.2} Explicitly documents the type and class of return values
330334
#' @method plot tbl_release
331335
#' @family revision graphs
332336
#' @export
@@ -340,6 +344,12 @@ plot.tbl_release <- function(x, ...) {
340344
#' @param state String. The name of the state to visualize.
341345
#' @param type String. Type of estimate: "filtered" or "smoothed".
342346
#' @param ... Additional arguments passed to theme_reviser.
347+
#' @srrstats {G1.4a} Internal function documented with @noRd tag
348+
#' @srrstats {TS5.0} Implements plot methods for class system
349+
#' @srrstats {TS5.7} Includes model (input) values in plot with forecast (output) values (in-sample vs out-of-sample)
350+
#' @srrstats {TS5.8} Provides clear visual distinction between model and forecast values (different colors/samples)
351+
#' @srrstats {TS5.6} Indicates distributional limits (confidence intervals) on plot by default
352+
#' @return ggplot object
343353
#'
344354
#' @keywords internal
345355
#' @noRd

R/jvn.R

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,44 @@
4646
#' \item{bic}{Bayesian Information Criterion}
4747
#' \item{data}{Input data}
4848
#' }
49+
#'
50+
#' @srrstats {G1.0} Primary reference: Jacobs & Van Norden (2011)
51+
#' @srrstats {G1.1} First implementation in R of the Jacobs-Van Norden state-space model
52+
#' @srrstats {G1.3} Statistical terminology clearly defined (news, noise, spillovers)
53+
#' @srrstats {G2.0} Input assertions on lengths (e, h, ar_order must be single values)
54+
#' @srrstats {G2.0a} Documents expectations on input lengths in parameter descriptions
55+
#' @srrstats {G2.1} Input type assertions (checks for list, numeric types)
56+
#' @srrstats {G2.1a} Documents data type expectations for all inputs
57+
#' @srrstats {G2.2} Restricts multivariate input to univariate parameters (e, h, ar_order)
58+
#' @srrstats {G2.3a} Uses match.arg() equivalent for method parameter validation
59+
#' @srrstats {G2.3b} Documents case-sensitivity requirements
60+
#' @srrstats {G2.4} Type conversion mechanisms (round() for ar_order)
61+
#' @srrstats {G2.4a} Explicit conversion to integer via round()
62+
#' @srrstats {G2.7} Accepts multiple tabular forms (matrix, data.frame, list)
63+
#' @srrstats {G2.8} Pre-processing routines (vintages_check, vintages_wide)
64+
#' @srrstats {G2.9} Diagnostic messages for type conversions (suppressWarnings)
65+
#' @srrstats {G2.10} Consistent column extraction behavior
66+
#' @srrstats {G2.13} Checks for missing data (complete.cases in init_params)
67+
#' @srrstats {G2.14} Options for handling missing data (implicit via KFAS)
68+
#' @srrstats {G2.15} Never assumes non-missingness
69+
#' @srrstats {G3.0} Numerical stability considerations (epsilon parameter)
70+
#' @srrstats {G5.2} Error and warning behavior tested
71+
#' @srrstats {TS1.0} Uses explicit time series class systems
72+
#' @srrstats {TS1.1} Documents types/classes of input data
73+
#' @srrstats {TS1.2} Validation routines for input classes (vintages_check)
74+
#' @srrstats {TS1.3} Pre-processing to validate and transform input (vintages_wide)
75+
#' @srrstats {TS1.4} Maintains time/date components of input data
76+
#' @srrstats {TS1.5} Ensures strict ordering of time index
77+
#' @srrstats {TS1.6} Catches ordering violations in pre-processing
78+
#' @srrstats {TS1.8} Explicit about monthly time intervals (frequency calculation)
79+
#' @srrstats {TS2.0} Handles explicit vs implicit missing values
80+
#' @srrstats {TS2.1} Options for handling missing data
81+
#' @srrstats {TS4.0b} Returns unique class-defined format (jvn_model)
82+
#' @srrstats {TS4.2} Explicitly documents return value types/classes
83+
#' @srrstats {TS4.3} Return values include time scales
84+
#' @srrstats {TS4.6b} Forecasting returns first- and second-order moments
85+
#' @srrstats {TS4.6c} Error indication for forecast estimates (confidence intervals)
86+
#' @srrstats {TS4.7c} Distinguishes model vs forecast values (sample column)
4987
#'
5088
#' @references Jacobs, Jan P.A.M. and Van Norden, Simon, "Modeling Data
5189
#' Revisions: Measurement Error and Dynamics of 'True' Values", Journal of
@@ -783,6 +821,11 @@ jvn_nowcast <- function(
783821
#'
784822
#' Constructs the state-space matrices Z, T, R, H, Q according to the
785823
#' Jacobs & Van Norden (2011) specification.
824+
#'
825+
#' @srrstats {G1.4a} Internal function documented with @noRd tag
826+
#' @srrstats {G2.0} Input assertions on parameter dimensions
827+
#' @srrstats {G2.1} Type checking for parameters
828+
#' @srrstats {G3.0} Numerical stability in matrix construction
786829
#'
787830
#' @keywords internal
788831
#' @noRd
@@ -977,6 +1020,9 @@ jvn_matrices <- function(
9771020

9781021

9791022
#' Update Model Matrices with Estimated Parameters
1023+
#' @srrstats {G1.4a} Internal function documented with @noRd tag
1024+
#' @srrstats {G2.1} Parameter type validation
1025+
#' @srrstats {G3.0} Numerical operations with appropriate precision
9801026
#' @keywords internal
9811027
#' @noRd
9821028
jvn_update_matrices <- function(model_struct, params) {
@@ -1043,6 +1089,9 @@ jvn_update_matrices <- function(model_struct, params) {
10431089

10441090

10451091
#' Negative Log-Likelihood Function
1092+
#' @srrstats {G1.4a} Internal function documented with @noRd tag
1093+
#' @srrstats {G2.15} Handles missing values appropriately
1094+
#' @srrstats {G3.0} Numerical stability in likelihood calculation
10461095
#' @keywords internal
10471096
#' @noRd
10481097
jvn_negloglik <- function(params, model_struct, data, transform_se = TRUE) {
@@ -1434,6 +1483,13 @@ print.jvn_model <- function(x, ...) {
14341483
#' @param state String. The name of the state to visualize.
14351484
#' @param type String. Type of estimate to plot: "filtered" or "smoothed".
14361485
#' @param ... Additional arguments passed to theme_reviser.
1486+
#'
1487+
#' @srrstats {TS5.0} Implements default plot methods for class system
1488+
#' @srrstats {TS5.1} Time axis labeling (delegates to base method)
1489+
#' @srrstats {TS5.2} Time on horizontal axis (delegates to base method)
1490+
#' @srrstats {TS5.6} Distributional limits shown (confidence intervals)
1491+
#' @srrstats {TS5.7} Includes model and forecast values in plot
1492+
#' @srrstats {TS5.8} Visual distinction between model and forecast values
14371493
#'
14381494
#' @return A ggplot2 object visualizing the specified state estimates.
14391495
#' @examples

R/kk.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101
#' @srrstats {TS4.6} Time Series Software which implements or otherwise
102102
#' enables forecasting should return either:
103103
#' @srrstats {TS4.6b} filtered/forecasted point estimates
104+
#' @srrstats {TS4.6c} Error indication for forecast estimates (confidence intervals)
105+
#' @srrstats {TS4.7c} Distinguishes model vs forecast values (sample column)
104106
#' @srrstats {TS4.7} forecast values and models separately returned
105107
#' @srrstats {TS4.7a} only forecast values returned
106108
#' @srrstats {TS4.7b} forecast values and models separately returned
@@ -1398,6 +1400,7 @@ kk_ols_estim <- function(equations, data, model = "KK") {
13981400
#'
13991401
#' @srrstats {G2.4b} convert via via `as.numeric()`
14001402
#' @srrstats {G2.4c} convert via via `as.character()`
1403+
#' @srrstats {G3.0} Uses epsilon for numerical stability (epsilon parameter)
14011404
#'
14021405
#' @examples
14031406
#' # Example 1: Kishor-Koenig model with character matrices
@@ -1609,7 +1612,7 @@ kk_matrices <- function(e, model, params = NULL, type = "numeric") {
16091612
#' \item{\code{Q}}{The state noise covariance matrix.}
16101613
#' \item{\code{R}}{The control matrix.}
16111614
#' }
1612-
#'
1615+
#' @srrstats {G3.0} Numerical stability with epsilon parameter
16131616
#' @details The state space model is represented by the following equations:
16141617
#'
16151618
#' **State Equation:**

R/reviser-package.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ utils::globalVariables(c(
1717
#' @importFrom KFAS SSModel SSMcustom
1818
#' @importFrom magrittr %>%
1919
#' @importFrom calculus %mx% %diff% %sum% %prod%
20+
#' @importFrom pillar tbl_sum
2021
#' @srrstats {G1.4} roxygen2 is used for all documentation.
2122
#' @srrstats {G1.4a} All internal functions are also documented
2223
NULL

R/revisions.R

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,37 @@ print.revision_summary <- function(x, interpretation = TRUE, digits = 3, ...) {
13961396
#' @param ... Additional arguments (not used).
13971397
#'
13981398
#' @return A tibble with diagnostic results.
1399+
#' @examples
1400+
#' # Example usage with revision analysis results
1401+
#' df <- dplyr::select(
1402+
#' get_nth_release(
1403+
#' na.omit(
1404+
#' tsbox::ts_pc(
1405+
#' dplyr::filter(reviser::gdp, id == "US")
1406+
#' )
1407+
#' ),
1408+
#' n = 0:3
1409+
#' ),
1410+
#' -"pub_date"
1411+
#' )
1412+
#'
1413+
#' final_release <- dplyr::select(
1414+
#' get_nth_release(
1415+
#' na.omit(
1416+
#' tsbox::ts_pc(
1417+
#' dplyr::filter(reviser::gdp, id == "US")
1418+
#' )
1419+
#' ),
1420+
#' n = "latest"
1421+
#' ),
1422+
#' -"pub_date"
1423+
#' )
1424+
#'
1425+
#' # Get revision analysis results
1426+
#' results <- get_revision_analysis(df, final_release, degree = 5)
1427+
#'
1428+
#' # Diagnose revision quality
1429+
#' diagnose(results)
13991430
#' @family revision analysis
14001431
#' @export
14011432
diagnose.revision_summary <- function(object, alpha = 0.05, ...) {
@@ -1651,7 +1682,7 @@ diagnose.revision_summary <- function(object, alpha = 0.05, ...) {
16511682

16521683
# Print for this group
16531684
cat(group_id, ":\n")
1654-
print(diagnostics, row.names = FALSE)
1685+
print(diagnostics)
16551686
cat("\n")
16561687

16571688
# Store results
@@ -1699,6 +1730,39 @@ diagnose.revision_summary <- function(object, alpha = 0.05, ...) {
16991730
#' @param ... Additional arguments passed to methods.
17001731
#'
17011732
#' @return Method-specific diagnostic output.
1733+
#'
1734+
#' @examples
1735+
#' # Example usage with revision analysis results
1736+
#' df <- dplyr::select(
1737+
#' get_nth_release(
1738+
#' na.omit(
1739+
#' tsbox::ts_pc(
1740+
#' dplyr::filter(reviser::gdp, id == "US")
1741+
#' )
1742+
#' ),
1743+
#' n = 0:3
1744+
#' ),
1745+
#' -"pub_date"
1746+
#' )
1747+
#'
1748+
#' final_release <- dplyr::select(
1749+
#' get_nth_release(
1750+
#' na.omit(
1751+
#' tsbox::ts_pc(
1752+
#' dplyr::filter(reviser::gdp, id == "US")
1753+
#' )
1754+
#' ),
1755+
#' n = "latest"
1756+
#' ),
1757+
#' -"pub_date"
1758+
#' )
1759+
#'
1760+
#' # Get revision analysis results
1761+
#' results <- get_revision_analysis(df, final_release, degree = 5)
1762+
#'
1763+
#' # Diagnose revision quality
1764+
#' diagnose(results)
1765+
#'
17021766
#' @family revision analysis
17031767
#' @export
17041768
diagnose <- function(object, ...) {
@@ -1714,6 +1778,37 @@ diagnose <- function(object, ...) {
17141778
#' @return The function returns the input \code{object} invisibly.
17151779
#' @method summary revision_summary
17161780
#' @family revision analysis
1781+
#' @examples
1782+
#' # Example usage with revision analysis results
1783+
#' df <- dplyr::select(
1784+
#' get_nth_release(
1785+
#' na.omit(
1786+
#' tsbox::ts_pc(
1787+
#' dplyr::filter(reviser::gdp, id == "US")
1788+
#' )
1789+
#' ),
1790+
#' n = 0:3
1791+
#' ),
1792+
#' -"pub_date"
1793+
#' )
1794+
#'
1795+
#' final_release <- dplyr::select(
1796+
#' get_nth_release(
1797+
#' na.omit(
1798+
#' tsbox::ts_pc(
1799+
#' dplyr::filter(reviser::gdp, id == "US")
1800+
#' )
1801+
#' ),
1802+
#' n = "latest"
1803+
#' ),
1804+
#' -"pub_date"
1805+
#' )
1806+
#'
1807+
#' # Get revision analysis results
1808+
#' results <- get_revision_analysis(df, final_release, degree = 5)
1809+
#'
1810+
#' # Summarize revision quality
1811+
#' summary(results)
17171812
#' @export
17181813
summary.revision_summary <- function(object, interpretation = TRUE, ...) {
17191814
print.revision_summary(object, interpretation = interpretation, ...)

R/srr-stats-standards.R

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,12 @@ NULL
2424
#' @srrstatsNA {G2.5}
2525
#' @srrstatsNA {G2.14c}
2626
#' @srrstatsNA {G2.16}
27-
#' @srrstatsNA {G3.0}
2827
#' @srrstatsNA {G4.0}
2928
#' @srrstatsNA {G5.0}
3029
#' @srrstatsNA {G5.1}
3130
#' @srrstatsNA {G5.3}
3231
#' @srrstatsNA {G5.4b}
3332
#' @srrstatsNA {G5.4c}
34-
#' @srrstatsNA {G5.5}
35-
#' @srrstatsNA {G5.6}
3633
#' @srrstatsNA {G5.6a}
3734
#' @srrstatsNA {G5.6b}
3835
#' @srrstatsNA {G5.7}
@@ -64,11 +61,6 @@ NULL
6461
#' @srrstatsNA {TS4.5b}
6562
#' @srrstatsNA {TS4.5c}
6663
#' @srrstatsNA {TS4.6a}
67-
#' @srrstatsNA {TS4.6c}
68-
#' @srrstatsNA {TS4.7c}
6964
#' @srrstatsNA {TS5.4}
70-
#' @srrstatsNA {TS5.6}
71-
#' @srrstatsNA {TS5.7}
72-
#' @srrstatsNA {TS5.8}
7365
#' @noRd
7466
NULL

0 commit comments

Comments
 (0)