Skip to content

Commit

Permalink
p_function() gets vcov-args (#1013)
Browse files Browse the repository at this point in the history
* `p_function()` gets vcov-args

* desc, news

* add tests

* Update test-p_function.R
  • Loading branch information
strengejacke authored Sep 16, 2024
1 parent 37509c2 commit c4f5abe
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: parameters
Title: Processing of Model Parameters
Version: 0.22.2.7
Version: 0.22.2.8
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
way to test the direction of the effect, which formerly was already (and still
is) possible with `pd = TRUE` in `model_parameters()`.

* `p_function()` gets a `vcov` and `vcov_args` argument to compute robust
standard errors for the confidence curves.

* Revision / enhancement of some documentation.

# parameters 0.22.2

## New supported models
Expand Down
7 changes: 6 additions & 1 deletion R/p_function.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#' @inheritParams model_parameters
#' @inheritParams model_parameters.default
#' @inheritParams model_parameters.glmmTMB
#' @inheritParams standard_error
#'
#' @note
#' Curently, `p_function()` computes intervals based on Wald t- or z-statistic.
Expand Down Expand Up @@ -223,6 +224,8 @@ p_function <- function(model,
exponentiate = FALSE,
effects = "fixed",
component = "all",
vcov = NULL,
vcov_args = NULL,
keep = NULL,
drop = NULL,
verbose = TRUE,
Expand All @@ -234,7 +237,9 @@ p_function <- function(model,
se <- standard_error(
model,
effects = effects,
component = component
component = component,
vcov = vcov,
vcov_args = vcov_args
)$SE

if (is.null(dof) || length(dof) == 0 || .is_chi2_model(model, dof)) {
Expand Down
31 changes: 31 additions & 0 deletions man/p_function.Rd

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

20 changes: 20 additions & 0 deletions tests/testthat/test-p_function.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
skip_if_not_installed("sandwich")

data(iris)
model <- lm(Sepal.Length ~ Species, data = iris)

test_that("p_function ci-levels", {
out <- p_function(model)
expect_equal(
out$CI_low,
c(
4.982759, 0.897132, 1.549132, 4.956774, 0.860384, 1.512384,
4.92192, 0.811093, 1.463093, 4.862126, 0.726531, 1.378531
),
tolerance = 1e-4
)

expect_identical(dim(out), c(12L, 5L))

Expand Down Expand Up @@ -32,6 +42,16 @@ test_that("p_function ci-levels", {
c(0.3, 0.3, 0.3, 0.6, 0.6, 0.6, 0.9, 0.9, 0.9),
tolerance = 1e-4
)

out <- p_function(model, vcov = "HC3")
expect_equal(
out$CI_low,
c(
4.989925, 0.901495, 1.548843, 4.971951, 0.869624, 1.511772,
4.947844, 0.826875, 1.462047, 4.906485, 0.753538, 1.376742
),
tolerance = 1e-4
)
})


Expand Down

0 comments on commit c4f5abe

Please sign in to comment.