Skip to content

Commit 360f9b3

Browse files
authored
Merge pull request #68 from SebKrantz/development
Development
2 parents 3320175 + 29b9beb commit 360f9b3

File tree

14 files changed

+83
-53
lines changed

14 files changed

+83
-53
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
^dfms\.Rproj$
22
^\.Rproj\.user$
33
misc
4+
^README\.html$
45
.RData
56
LICENSE
67
^\.github$

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ vignettes/*.pdf
5353
.Rproj.user
5454
# docs
5555
inst/doc
56+
docs

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
S3method(as.data.frame,dfm)
44
S3method(as.data.frame,dfm_forecast)
5+
S3method(coef,dfm)
56
S3method(fitted,dfm)
7+
S3method(logLik,dfm)
68
S3method(plot,ICr)
79
S3method(plot,dfm)
810
S3method(plot,dfm_forecast)

R/DFM.R

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
#' Efficient estimation of a Dynamic Factor Model via the EM Algorithm - on stationary data
1212
#' with time-invariant system matrices and classical assumptions, while permitting missing data.
1313
#'
14-
#' @param X a \code{T x n} numeric data matrix or frame of stationary time series. May contain missing values.
15-
#' @param r integer. number of factors.
16-
#' @param p integer. number of lags in factor VAR.
17-
#' @param \dots (optional) arguments to \code{\link{tsnarmimp}}.
18-
#' @param idio.ar1 logical. Model observation errors as AR(1) processes: \eqn{e_t = \rho e_{t-1} + v_t}{e(t) = rho e(t-1) + v(t)}. \emph{Note} that this substantially increases computation time, and is generaly not needed if \code{n} is large (>30). See theoretical vignette for details.
14+
#' @param X a \code{T x n} numeric data matrix or frame of stationary time series. May contain missing values. \emph{Note} that data is internally standardized (scaled and centered) before estimation.
15+
#' @param r integer. Number of factors.
16+
#' @param p integer. Number of lags in factor VAR.
17+
#' @param \dots (optional) arguments to \code{\link{tsnarmimp}}. The default settings impute internal missing values with a cubic spline and the edges with the median and a 3-period moving average.
18+
#' @param idio.ar1 logical. Model observation errors as AR(1) processes: \eqn{e_t = \rho e_{t-1} + v_t}{e(t) = rho e(t-1) + v(t)}. \emph{Note} that this substantially increases computation time, and is generally not needed if \code{n} is large (>30). See theoretical vignette for details.
1919
#' @param quarterly.vars character. Names of quarterly variables in \code{X} (if any). Monthly variables should be to the left of the quarterly variables in the data matrix and quarterly observations should be provided every 3rd period.
20-
#' @param rQ character. restrictions on the state (transition) covariance matrix (Q).
21-
#' @param rR character. restrictions on the observation (measurement) covariance matrix (R).
20+
#' @param rQ character. Restrictions on the state (transition) covariance matrix (Q).
21+
#' @param rR character. Restrictions on the observation (measurement) covariance matrix (R).
2222
#' @param em.method character. The implementation of the Expectation Maximization Algorithm used. The options are:
2323
#' \tabular{llll}{
2424
#' \code{"auto"} \tab\tab Automatic selection: \code{"BM"} if \code{anyNA(X)}, else \code{"DGR"}. \cr\cr
@@ -77,9 +77,11 @@
7777
#' \eqn{\textbf{R}}{R} \tab\tab \eqn{n \times n}{n x n} observation covariance matrix. It is diagonal by assumption 2 and identical to \eqn{\textbf{R}}{R} as stated in the dynamic form.\cr\cr
7878
#' }
7979
# that \eqn{E[\textbf{f}_t|\textbf{F}_{t-1}] = E[\textbf{f}_t|\textbf{f}_{t-1}] = \textbf{A}_1 \textbf{f}_{t-1}}{E[f(t)|F(t-1)] = E[f(t)|f(t-1)] = A1 f(t-1)} (all relationships between lagged factors are captured in \eqn{\textbf{A}_1}{A1}).\cr\cr
80+
#' The filter is initialized with PCA estimates on the imputed dataset---see \code{\link{SKFS}} for a complete code example.
81+
#'
8082
#'
8183
#' @returns A list-like object of class 'dfm' with the following elements:
82-
#' \item{\code{X_imp}}{\eqn{T \times n}{T x n} matrix with the imputed and standardized (scaled and centered) data - with attributes attached allowing reconstruction of the original data:
84+
#' \item{\code{X_imp}}{\eqn{T \times n}{T x n} matrix with the imputed and standardized (scaled and centered) data---after applying \code{\link{tsnarmimp}}. It has attributes attached allowing for reconstruction of the original data:
8385
#' \tabular{llll}{
8486
#' \code{"stats"} \tab\tab is a \eqn{n \times 5}{n x 5} matrix of summary statistics of class \code{"qsu"} (see \code{\link[collapse]{qsu}}).\cr\cr
8587
#' \code{"missing"} \tab\tab is a \eqn{T \times n}{T x n} logical matrix indicating missing or infinite values in the original data (which are imputed in \code{X_imp}).\cr\cr
@@ -104,6 +106,7 @@
104106
#' \item{\code{converged}}{single logical valued indicating whether the EM algorithm converged (within \code{max.iter} iterations subject to \code{tol}).}
105107
#' \item{\code{anyNA}}{single logical valued indicating whether there were any (internal) missing values in the data (determined after removal of rows with too many missing values). If \code{FALSE}, \code{X_imp} is simply the original data in matrix form, and does not have the \code{"missing"} attribute attached.}
106108
#' \item{\code{rm.rows}}{vector of any cases (rows) that were removed beforehand (subject to \code{max.missing} and \code{na.rm.method}). If no cases were removed the slot is \code{NULL}. }
109+
#' \item{\code{quarterly.vars}}{names of the quarterly variables (if any).}
107110
#' \item{\code{em.method}}{The EM method used.}
108111
#' \item{\code{call}}{call object obtained from \code{match.call()}.}
109112
#'

R/dfms.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#'
33
#' @description
44
#'
5-
#' *dfms* provides efficient estimation of Dynamic Factor Models via the EM Algorithm --- following Doz, Giannone & Reichlin (2011, 2012) and Banbura & Modugno (2014). The package has the following contents:
5+
#' *dfms* provides efficient estimation of Dynamic Factor Models via the EM Algorithm --- following Doz, Giannone & Reichlin (2011, 2012) and Banbura & Modugno (2014). Contents:
66
#'
7-
#' **Information Criteria**
7+
#' **Information Criteria to Determine the Number of Factors**
88
#'
99
#' \code{\link[=ICr]{ICr()}}\cr
1010
#'

R/methods.R

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
#'
4444
#' @title DFM Summary Methods
4545
#'
46-
#' @description Summary and print methods for class 'dfm'. \code{print.dfm} just prints basic model information and the factor transition matrix \eqn{\textbf{A}}{A},
47-
#' \code{summary.dfm} returns all system matrices and additional residual and goodness of fit statistics - with a print method allowing full or compact printout.
46+
#' @description Summary and print methods for class 'dfm'. \code{print.dfm} just prints basic model information and the factor transition matrix \eqn{\textbf{A}}{A}, \code{coef.dfm} returns \eqn{\textbf{A}}{A} and \eqn{\textbf{C}}{C} in a plain list, whereas
47+
#' \code{summary.dfm} returns all system matrices and additional residual and goodness of fit statistics---with a print method allowing full or compact printout.
4848
#'
4949
#' @param x,object an object class 'dfm'.
5050
#' @param digits integer. The number of digits to print out.
@@ -73,10 +73,18 @@ print.dfm <- function(x, digits = 4L, ...) {
7373
return(invisible(x))
7474
}
7575

76+
#' @rdname summary.dfm
77+
#' @export
78+
coef.dfm <- function(object, ...) list(A = object$A, C = object$C)
79+
80+
#' @rdname summary.dfm
81+
#' @export
82+
logLik.dfm <- function(object, ...) object$loglik[length(object$loglik)]
83+
7684
#' @rdname summary.dfm
7785
#' @param method character. The factor estimates to use: one of \code{"qml"}, \code{"2s"} or \code{"pca"}.
7886
#' @param \dots not used.
79-
#' @return Summary information following a dynamic factor model estimation.
87+
#' @return Summary information following a dynamic factor model estimation. \code{coef()} returns \eqn{\textbf{A}}{A} and \eqn{\textbf{C}}{C}.
8088
#' @importFrom stats cov
8189
#' @importFrom collapse pwcov
8290
#' @export

R/my_RcppExports.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Estep <- function(X, A, C, Q, R, F_0, P_0) {
44

55
#' (Fast) Stationary Kalman Filter
66
#'
7-
#' @description A simple and fast C++ implementation of the Kalman Filter for stationary data with time-invariant system matrices and missing data.
7+
#' @description A simple and fast C++ implementation of the Kalman Filter for stationary data (or random walks - data should be mean zero and without a trend) with time-invariant system matrices and missing data.
88
#' @param X numeric data matrix (\eqn{T \times n}{T x n}).
99
#' @param A transition matrix (\eqn{rp \times rp}{rp x rp}).
1010
#' @param C observation matrix (\eqn{n \times rp}{n x rp}).
@@ -103,7 +103,7 @@ FIS <- function(A, F, F_pred, P, P_pred, F_0 = NULL, P_0 = NULL) {
103103
#' @inheritParams SKF
104104
#'
105105
#' @returns All results from \code{\link{SKF}} and \code{\link{FIS}}, and additionally
106-
#' a \eqn{rp \times rp \times T}{rp x rp x T} matrix \code{PPm_smooth}, which is equal to the estimate of \eqn{Cov(F^smooth_t, F^smooth_{t-1} | T)}{Cov(F_smooth(t), F_smooth(t-1) | T)} and needed for EM iterations.
106+
#' a \eqn{rp \times rp \times T}{rp x rp x T} matrix \code{PPm_smooth}, which is equal to the estimate of \eqn{Cov(F^{smooth}_t, F^{smooth}_{t-1} | T)}{Cov(F_smooth(t), F_smooth(t-1) | T)} and needed for EM iterations.
107107
#' See 'Property 6.3: The Lag-One Covariance Smoother' in Shumway & Stoffer (2017).
108108
#'
109109
#'

_pkgdown.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ external-articles:
9393

9494
articles:
9595
- title: Introduction to dfms
96-
desc: Provides a walk-through of all main features
96+
desc: Introduces the package, including a walk-through of all main features.
9797
contents:
9898
- introduction
9999
- title: Dynamic Factor Models - A Very Short Introduction
100-
desc: Provides a short theoretical overview of dynamics factor models as used in the economics literature
100+
desc: Provides a short overview of dynamics factor models as used in the economics literature.
101101
contents:
102102
- dynamic_factor_models

man/DFM.Rd

Lines changed: 10 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/SKF.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)