[Gmm-commits] r241 - in pkg/momentfit: . R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Jul 4 21:19:48 CEST 2024
Author: chaussep
Date: 2024-07-04 21:19:48 +0200 (Thu, 04 Jul 2024)
New Revision: 241
Modified:
pkg/momentfit/NEWS
pkg/momentfit/R/momentModel-methods.R
pkg/momentfit/R/momentModel.R
pkg/momentfit/R/sysMomentModel.R
pkg/momentfit/R/validity.R
Log:
added the option order.by for HAC vcov
Modified: pkg/momentfit/NEWS
===================================================================
--- pkg/momentfit/NEWS 2024-06-04 21:34:54 UTC (rev 240)
+++ pkg/momentfit/NEWS 2024-07-04 19:19:48 UTC (rev 241)
@@ -10,6 +10,8 @@
o The gmm estimation does not work well when the weighting matrix is singular or nearly singular. It was shown that using a generalized inverse instead of the regular inverse is preferred. It is now optional to use a Moore-Penrose inverse when ever it is needed.
+o It is now possible to add the argument order.by to the vcovOptions argument of momentModel. This is passed to vcovHAC and is relevant when the data are not properly ordered.
+
Changes in version 0.5
o The Makevars was modified. The previous version was hard to install on most MAC because of an unnecessary flag. It is no longer the case.
Modified: pkg/momentfit/R/momentModel-methods.R
===================================================================
--- pkg/momentfit/R/momentModel-methods.R 2024-06-04 21:34:54 UTC (rev 240)
+++ pkg/momentfit/R/momentModel-methods.R 2024-07-04 19:19:48 UTC (rev 241)
@@ -546,10 +546,10 @@
}
weights <- weightsAndrews(x = gmat, bw = bw, kernel = options$kernel,
prewhite = options$prewhite, tol = options$tol)
- w <- meatHAC(x = gmat, order.by = NULL, weights = weights,
+ w <- meatHAC(x = gmat, order.by = options$order.by, weights = weights,
prewhite = options$prewhite, ar.method = options$ar.method,
adjust = options$adjust, diagnostics = FALSE)
- attr(w, "Spec") <- list(weights = weights, bw = bw, kernel = options$kernel)
+ attr(w, "Spec") <- list(weights = weights, bw = bw, kernel = options$kernel, order.by = options$order.by)
w
})
Modified: pkg/momentfit/R/momentModel.R
===================================================================
--- pkg/momentfit/R/momentModel.R 2024-06-04 21:34:54 UTC (rev 240)
+++ pkg/momentfit/R/momentModel.R 2024-07-04 19:19:48 UTC (rev 241)
@@ -9,7 +9,7 @@
crit = 1e-06,
bw = "Andrews", prewhite = 1L,
ar.method = "ols", approx = "AR(1)",
- tol = 1e-07, adjust=TRUE)
+ tol = 1e-07, adjust=TRUE, order.by=NULL)
if (length(addO) > 0)
{
if (!all(names(addO) %in% names(option)))
@@ -28,6 +28,23 @@
else
if (!existsFunction(paste("bw",option$bw,sep="")))
stop("The bandwidth function does not exist")
+ if (!is.null(option$order.by))
+ {
+ if (!inherits(option$order.by, c("numeric","integer","formula")))
+ stop("order.by must be either a numeric or integer vector, or a formula")
+ if (inherits(option$order.by, c("numeric", "integer")))
+ if (length(option$order.by) != nrow(data))
+ stop("order.by must have the same length as the number of rows in data")
+ if (inherits(option$order.by, "formula"))
+ {
+ fn <- all.vars(option$order.by[[length(option$order.by)]])
+ if (length(fn)>1)
+ stop("The order.by formula must contain only one variable.")
+ option$order.by <- try(data[[fn]], silent=TRUE)
+ if (inherits(option$order.by,"try-error"))
+ stop("The variable in the order.by formula is not in data")
+ }
+ }
} else if (type=="CL") {
option <- list(cluster=NULL, type="HC0", cadjust=TRUE,
multi0=FALSE)
Modified: pkg/momentfit/R/sysMomentModel.R
===================================================================
--- pkg/momentfit/R/sysMomentModel.R 2024-06-04 21:34:54 UTC (rev 240)
+++ pkg/momentfit/R/sysMomentModel.R 2024-07-04 19:19:48 UTC (rev 241)
@@ -70,6 +70,8 @@
if (!is.list(vcovOptions) | !is.list(survOptions))
stop("vcovOptions and survOptions must be a list")
vcovOptions <- .getVcovOptions(vcov, data, vcovOptions, FALSE)
+ if (!is.null(vcovOptions$order.by))
+ stop("The HAC option order.by is not available for systems of equations")
survOptions <- .getSurvOptions(data, survOptions)
if (!is.list(data) && !is.environment(data))
stop("'data' must be a list or an environment")
Modified: pkg/momentfit/R/validity.R
===================================================================
--- pkg/momentfit/R/validity.R 2024-06-04 21:34:54 UTC (rev 240)
+++ pkg/momentfit/R/validity.R 2024-07-04 19:19:48 UTC (rev 241)
@@ -445,9 +445,9 @@
}
if (length(object at wSpec)>0)
{
- if (!all(names(object at wSpec) %in% c("bw", "kernel","weights")))
+ if (!all(names(object at wSpec) %in% c("bw", "kernel","weights", "order.by")))
{
- msg <- "wSpec must contain 'bw', 'kernel', and 'weights'"
+ msg <- "wSpec must contain 'bw', 'kernel', order.by and 'weights'"
error <- c(error, msg)
}
}
More information about the Gmm-commits
mailing list