Skip to content

Commit

Permalink
df.residual methods (#1299)
Browse files Browse the repository at this point in the history
* df.residual methods

* test tolerance
  • Loading branch information
vincentarelbundock authored Dec 11, 2024
1 parent 5e43fa5 commit 4b9c2e6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ S3method(coef,hypotheses)
S3method(coef,marginalmeans)
S3method(coef,predictions)
S3method(coef,slopes)
S3method(df.residual,comparisons)
S3method(df.residual,predictions)
S3method(df.residual,slopes)
S3method(get_coef,afex_aov)
S3method(get_coef,betareg)
S3method(get_coef,bracl)
Expand Down
22 changes: 20 additions & 2 deletions R/methods.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' @noRd
#' @export
vcov.comparisons <- function(object, ...) {
attr(object, "jacobian") %*% attr(object, "vcov") %*% t(attr(object, "jacobian"))
attr(object, "jacobian") %*% attr(object, "vcov") %*% t(attr(object, "jacobian"))
}


Expand Down Expand Up @@ -60,4 +60,22 @@ coef.predictions <- coef.comparisons

#' @export
#' @noRd
coef.hypotheses <- coef.comparisons
coef.hypotheses <- coef.comparisons


#' @export
#' @noRd
df.residual.comparisons <- function(x, ...) {
out <- tryCatch(stats::df.residual(attr(x, "model")), error = function(e) NULL)
return(out)
}


#' @export
#' @noRd
df.residual.predictions <- df.residual.comparisons


#' @export
#' @noRd
df.residual.slopes <- df.residual.comparisons
5 changes: 2 additions & 3 deletions inst/tinytest/test-pkg-mice.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ cmp1 <- suppressWarnings(avg_comparisons(fits,
comparison = "lnratioavg",
transform = "exp"))
expect_equivalent(cmp1$estimate, 0.3380001, tol = 1e-6)
expect_equivalent(cmp1$conf.low, 0.2386019, tol = 1e-6)
expect_equivalent(cmp1$conf.low, 0.2386019, tol = 1e-2)
cmp2 <- suppressWarnings(avg_comparisons(fits,
variables = "married",
comparison = "lnratioavg"))
expect_equivalent(cmp2$estimate, -1.084709, tol = 1e-6)
expect_equivalent(cmp2$conf.low, -1.432959, tol = 1e-6)
expect_equivalent(cmp2$conf.low, -1.432959, tol = 1e-2)


source("helpers.R")

4 changes: 2 additions & 2 deletions man/posterior_draws.Rd

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

0 comments on commit 4b9c2e6

Please sign in to comment.