From 7c697bd3097ec0717252191b0ebf739c25107634 Mon Sep 17 00:00:00 2001 From: John Fox Date: Wed, 21 Aug 2024 11:16:56 -0400 Subject: [PATCH] fix bug in hatvalues.ivreg(); correct some @exportS3Method markup --- DESCRIPTION | 6 +++--- NEWS.md | 4 ++++ R/ivregDiagnostics.R | 2 +- R/ivregMethods.R | 10 +++++----- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 310cbfa..afebf8b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: ivreg Title: Instrumental-Variables Regression by '2SLS', '2SM', or '2SMM', with Diagnostics -Version: 0.6-3 -Date: 2024-04-20 +Version: 0.6-4 +Date: 2024-08-21 Authors@R: c(person(given = "John", family = "Fox", role = "aut", email = "jfox@mcmaster.ca", comment = c(ORCID = "0000-0002-1196-8012")), person(given = "Christian", family = "Kleiber", role = "aut", email = "Christian.Kleiber@unibas.ch", comment = c(ORCID = "0000-0002-6781-4733")), person(given = "Achim", family = "Zeileis", role = c("aut", "cre"), email = "Achim.Zeileis@R-project.org", comment = c(ORCID = "0000-0003-0918-3766")), @@ -32,4 +32,4 @@ LazyData: true VignetteBuilder: knitr BugReports: https://github.com/zeileis/ivreg/issues/ URL: https://zeileis.github.io/ivreg/ -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 diff --git a/NEWS.md b/NEWS.md index 8e82ae5..4e86434 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# Version 0.6-4 + +* Fixed bug in computing larger of stage-1 and -2 hatvalues in `hatvalues.ivreg()` (reported by Vasilis Syrgkanis). + # Version 0.6-3 * Enhanced `predict.ivreg()` method, which optionally provides standard errors, diff --git a/R/ivregDiagnostics.R b/R/ivregDiagnostics.R index 81fdfa9..468de19 100644 --- a/R/ivregDiagnostics.R +++ b/R/ivregDiagnostics.R @@ -288,7 +288,7 @@ hatvalues.ivreg <- function(model, type = c("stage2", "both", "maximum", "stage1 # model$coefficients1) # hat1 <- lm.influence(model)$hat/mean1 hat1 <- if (model$method == "OLS"){ - hats[, "stage_1"] + hats[, "stage_1"]/mean1 } else { nendog <- ncol(hats) - 1 if (type == "both"){ diff --git a/R/ivregMethods.R b/R/ivregMethods.R index a6c690d..1bec991 100644 --- a/R/ivregMethods.R +++ b/R/ivregMethods.R @@ -136,13 +136,13 @@ confint.ivreg <- function (object, parm, level = 0.95, } #' @rdname ivregMethods -#' @exportS3Method sandwich::bread ivreg +#' @exportS3Method sandwich::bread bread.ivreg <- function (x, ...) x$cov.unscaled * x$nobs #' @rdname ivregMethods #' @importFrom stats weights -#' @exportS3Method sandwich::estfun ivreg +#' @exportS3Method sandwich::estfun estfun.ivreg <- function (x, ...) { xmat <- model.matrix(x, component = "projected") @@ -157,7 +157,7 @@ estfun.ivreg <- function (x, ...) } #' @rdname ivregMethods -#' @exportS3Method sandwich::vcovHC ivreg +#' @exportS3Method sandwich::vcovHC vcovHC.ivreg <- function (x, ...) { class(x) <- c("ivreg_projected", "ivreg") sandwich::vcovHC.default(x, ...) @@ -659,7 +659,7 @@ residuals.ivreg <- function(object, type=c("response", "projected", "regressors" #' @rdname ivregMethods #' @param focal.predictors Focal predictors for effect plot, see \code{\link[effects:effect]{Effect}}. -#' @exportS3Method effects::Effect ivreg +#' @exportS3Method effects::Effect Effect.ivreg <- function (focal.predictors, mod, ...) { mod$contrasts <- mod$contrasts$regressors NextMethod() @@ -680,7 +680,7 @@ formula.ivreg <- function(x, component = c("complete", "regressors", "instrument } #' @rdname ivregMethods -#' @exportS3Method insight::find_formula ivreg +#' @exportS3Method insight::find_formula find_formula.ivreg <- function(x, ...) { list(conditional=formula(x, "regressors"), instruments=formula(x, "instruments")) }