Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: modelbased
Title: Estimation of Model-Based Predictions, Contrasts and Means
Version: 0.19.0.3
Version: 0.19.0.4
Authors@R:
c(person(given = "Dominique",
family = "Makowski",
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
also returned in increasing order for decreasing inverse links (e.g.,
`Gamma("inverse")`).

* `estimate_slopes()` with `p_adjust = "esarey"` now returns the p-value of
each row at its own value of the moderator, adjusted by the same factor as
the confidence intervals. Before, the p-values were unadjusted and taken from
other values of the moderator, and some were `NA` when the output had more
than 10 rows.

# modelbased 0.19.0

## Breaking Changes
Expand Down
13 changes: 5 additions & 8 deletions R/p_adjust.R
Original file line number Diff line number Diff line change
Expand Up @@ -470,13 +470,10 @@
x$conf.low <- x$estimate - tcrit * x$std.error
x$conf.high <- x$estimate + tcrit * x$std.error

# update p-values - we need to ensure that length of "statisic" matches number
# of rows, so we pick just as many values from "statistic" as required
range_mod <- floor((1:nrow(x)) * (nrow(x) / 100) * length(range_sequence))
if (length(range_sequence) == length(statistic)) {
statistic <- statistic[range_mod]
# update p-values
x$p.value <- 2 * stats::pt(abs(statistic), df = dof, lower.tail = FALSE)
}
# update p-values, using the statistic of each row. They are scaled by the
# same factor as the significance level, so that p < 1 - ci exactly when the
# confidence interval excludes zero
p_rows <- 2 * stats::pt(abs(x$estimate / x$std.error), df = dof, lower.tail = FALSE)
x$p.value <- pmin(1, p_rows / multipliers[i])
x
}
22 changes: 21 additions & 1 deletion tests/testthat/test-estimate_slopes.R
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ test_that("estimate_slopes, johnson-neyman p-adjust", {
)
expect_equal(
out$p,
c(0.03438, 0.14813, 0.50393, 0.83427, 0.24689, 0.03326, 0.00219, 9e-05, 0, 0),
c(0.01624, 0.09023, 0.44097, 1, 1, 0.19092, 0.0123, 0.00041, 1e-05, 0),
tolerance = 1e-2
)

Expand Down Expand Up @@ -244,6 +244,26 @@ test_that("estimate_slopes, johnson-neyman p-adjust", {
})


test_that("estimate_slopes, esarey p-values belong to their rows", {
data(iris)
model <- lm(Sepal.Width ~ Petal.Width * Petal.Length, data = iris)
for (n in c(10, 20)) {
unadjusted <- estimate_slopes(model, "Petal.Width", by = "Petal.Length", length = n)
out <- estimate_slopes(
model,
"Petal.Width",
by = "Petal.Length",
length = n,
p_adjust = "esarey"
)
expect_false(anyNA(out$p))
expect_true(all(out$p >= unadjusted$p))
# p < .05 exactly when the 95% CI excludes zero
expect_identical(out$p < 0.05, out$CI_low > 0 | out$CI_high < 0)
}
})


test_that("estimate_slopes, custom comparison", {
data(iris)
m <- lm(Sepal.Width ~ Sepal.Length * Species, data = iris)
Expand Down
Loading