benbhansen-stats / propertee

Prognostic Regression Offsets with Propagation of ERrors, for Treatment Effect Estimation (IES R305D210029).
https://benbhansen-stats.github.io/propertee/
Other
2 stars 0 forks source link

propertee internal confint function #163

Closed jwasserman2 closed 7 months ago

jwasserman2 commented 7 months ago

Our current confint method wraps around the stats:::confint.lm method, but we discovered that the ... arguments provided to stats:::confint.lm aren't passed on to the vcov call within:

confint.lm <- function (object, parm, level = 0.95, ...) 
{
    cf <- coef(object)
    ses <- sqrt(diag(vcov(object)))
    pnames <- names(ses)
    if (is.matrix(cf)) 
        cf <- setNames(as.vector(cf), pnames)
    if (missing(parm)) 
        parm <- pnames
    else if (is.numeric(parm)) 
        parm <- pnames[parm]
    a <- (1 - level)/2
    a <- c(a, 1 - a)
    fac <- qt(a, object$df.residual)
    pct <- .format_perc(a, 3)
    ci <- array(NA_real_, dim = c(length(parm), 2L), dimnames = list(parm, 
        pct))
    ci[] <- cf[parm] + ses[parm] %o% fac
    ci
}

This prevents us from providing any vcovDA estimates other than the default model-based HC0 estimate, since we've created a vcov method that wraps around vcovDA and passes on any ... arguments to the vcovDA call. We need to create our own confint.lm method that does pass on the ... arguments. This may only require one change to the original confint.lm:

.confint_lm <- function (object, parm, level = 0.95, ...) 
{
    cf <- coef(object)
    ses <- sqrt(diag(vcov(object, ...)))
    ...
}

Then our confint method would be:

confint.DirectAdjusted <- function (object, parm, level = 0.95, ...) 
{
    call <- match.call()
    call[[1L]] <- quote(.confint_lm)
    ci <- eval(call, parent.frame())
    return(ci)
}
josherrickson commented 7 months ago

We should figure out some way to track if any of these (confint.lm, expand.model.frame, others?) change in core R so we can update accordingly, and potentially switch on R version.