Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ License: GPL-3 + file LICENSE
URL: https://github.com/christophrust/dpca
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Suggests:
testthat (>= 3.0.0),
freqdom (>= 2.0.3),
Expand Down
20 changes: 12 additions & 8 deletions R/dpca.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#' spectral density is evaluated.
#'
#' @param bandwidth Single integer, giving the width of the
#' lag window estimator. If unspecified, the cube root of the number of time
#' observations is used as default.
#' lag window estimator. If unspecified, 0.75 times the square root of the number
#' of time observations is used as default.
#'
#' @param weights Kernel used for the lag window estimation of spectrum.
#'
Expand All @@ -30,6 +30,7 @@
#'
#' @param q_max Maximum numer of dynamic factors considered in the data-driven
#' selection.
#'
#' @param n_path Integer vector specifying which (nested) subsets of the
#' cross section are used in the Hallin & Liska procedure. If unspecified,
#' a regular sequence of length \code{20} from \code{n/2} to \code{n} is used.
Expand Down Expand Up @@ -110,30 +111,33 @@
dpca <- function(
x,
q,
freqs = -20:20 / 20 * pi,
bandwidth = floor(ncol(x)^(1 / 3)),
freqs = -bandwidth:bandwidth / bandwidth * pi,
bandwidth = floor(0.75 * sqrt(tx)),
weights = c(
"bartlett", "trunc", "tukey", "parzen",
"bohman", "daniell", "parzen_cogburn_davis"
),
qsel_crit = c("IC1", "IC2"),
q_max = 15,
n_path = floor(seq(nrow(x) / 2, nrow(x), nrow(x) / 20)),
n_path = floor(seq(nx / 2, nx, nx / 20)),
penalties = (
bandwidth^(-2) + sqrt(bandwidth / ncol(x)) + 1 / n_path
) * log(pmin(n_path, bandwidth^2, sqrt(ncol(x) / bandwidth))),
bandwidth^(-2) + sqrt(bandwidth / tx) + 1 / n_path
) * log(pmin(n_path, bandwidth^2, sqrt(tx / bandwidth))),
penalty_scales = seq(0, 2, by = 0.01)) {
if (length(weights) > 1) {
weights <- "bartlett"
}

## our internal object is n times t
x <- if (is.ts(x) || "zoo" %in% class(x)) {
t(x)
} else if (is.matrix(x)) {
x
} else {
stop("x must either a \"ts\" or \"zoo\" object or a matrix!")
}
nx <- nrow(x)
tx <- ncol(x)

if (!missing(q) && (length(q) > 1 || floor(abs(q)) != q)) {
stop("\"q\" has to be a single positive integer!")
Expand Down Expand Up @@ -186,7 +190,7 @@ dpca <- function(
as.integer(q_max),
select_q,
as.integer(n_path),
as.integer(rep(ncol(x), length(n_path))),
as.integer(rep(tx, length(n_path))),
as.numeric(penalties),
as.numeric(penalty_scales),
PACKAGE = "dpca"
Expand Down
14 changes: 7 additions & 7 deletions man/dpca.Rd

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

Loading