Skip to content

Commit 8c479f1

Browse files
authored
Inconsistent formatting of p-values (#820)
1 parent a5b488b commit 8c479f1

File tree

6 files changed

+81
-9
lines changed

6 files changed

+81
-9
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: performance
33
Title: Assessment of Regression Models Performance
4-
Version: 0.14.0.1
4+
Version: 0.14.0.2
55
Authors@R:
66
c(person(given = "Daniel",
77
family = "Lüdecke",

NAMESPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,13 @@ S3method(cronbachs_alpha,parameters_pca)
143143
S3method(display,check_itemscale)
144144
S3method(display,compare_performance)
145145
S3method(display,performance_model)
146+
S3method(display,test_likelihoodratio)
146147
S3method(display,test_performance)
147148
S3method(fitted,BFBayesFactor)
148149
S3method(format,compare_performance)
149150
S3method(format,performance_model)
150151
S3method(format,performance_rmse)
152+
S3method(format,test_likelihoodratio)
151153
S3method(format,test_performance)
152154
S3method(logLik,cpglm)
153155
S3method(logLik,iv_robust)
@@ -345,10 +347,12 @@ S3method(print,test_performance)
345347
S3method(print_html,check_group_variation)
346348
S3method(print_html,check_itemscale)
347349
S3method(print_html,compare_performance)
350+
S3method(print_html,test_likelihoodratio)
348351
S3method(print_html,test_performance)
349352
S3method(print_md,check_itemscale)
350353
S3method(print_md,compare_performance)
351354
S3method(print_md,performance_model)
355+
S3method(print_md,test_likelihoodratio)
352356
S3method(print_md,test_performance)
353357
S3method(r2,Arima)
354358
S3method(r2,BBreg)

NEWS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# performance (devel)
2+
3+
## Changes
4+
5+
* Formatting of p-values in `test_likelihoodratio()` is now consistent with
6+
formatted p-values from other functions.
7+
18
# performance 0.14.0
29

310
## Breaking Changes

R/test_likelihoodratio.R

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ plot.test_likelihoodratio <- function(x, ...) {
6767

6868
#' @export
6969
print.test_likelihoodratio <- function(x, digits = 2, ...) {
70+
cat(insight::export_table(format(x, digits = digits, ...), digits = digits, ...))
71+
invisible(x)
72+
}
73+
74+
75+
#' @export
76+
format.test_likelihoodratio <- function(x, digits = 2, p_digits = 3, ...) {
7077
# Footer
7178
if ("LogLik" %in% names(x)) {
7279
best <- which.max(x$LogLik)
@@ -76,22 +83,39 @@ print.test_likelihoodratio <- function(x, digits = 2, ...) {
7683
}
7784

7885
# value formatting
79-
x$p <- insight::format_p(x$p, name = NULL)
86+
x$p <- insight::format_p(x$p, digits = p_digits, name = NULL, ...)
8087

8188
if (is.null(attributes(x)$estimator)) {
8289
estimator_string <- ""
8390
} else {
8491
estimator_string <- sprintf(" (%s-estimator)", toupper(attributes(x)$estimator))
8592
}
8693

87-
cat(insight::export_table(
88-
x,
89-
digits = digits,
90-
caption = c(paste0("# Likelihood-Ratio-Test (LRT) for Model Comparison", estimator_string), "blue"),
91-
footer = footer
92-
))
94+
attr(x, "table_footer") <- footer
95+
attr(x, "table_caption") <- c(paste0("# Likelihood-Ratio-Test (LRT) for Model Comparison", estimator_string), "blue")
96+
x
97+
}
9398

94-
invisible(x)
99+
100+
#' @export
101+
print_md.test_likelihoodratio <- function(x, digits = 2, ...) {
102+
insight::export_table(format(x, digits = digits, ...), format = "markdown", ...)
103+
}
104+
105+
106+
#' @export
107+
print_html.test_likelihoodratio <- function(x, digits = 2, ...) {
108+
insight::export_table(format(x, digits = digits, ...), format = "html", ...)
109+
}
110+
111+
112+
#' @export
113+
display.test_likelihoodratio <- function(object, format = "markdown", digits = 2, ...) {
114+
if (format == "markdown") {
115+
print_md(x = object, digits = digits, ...)
116+
} else {
117+
print_html(x = object, digits = digits, ...)
118+
}
95119
}
96120

97121

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# test_likelihoodratio - print p-digits
2+
3+
Code
4+
test_likelihoodratio(m1, m2)
5+
Output
6+
# Likelihood-Ratio-Test (LRT) for Model Comparison (OLS-estimator)
7+
8+
Name | Model | df | df_diff | Chi2 | p
9+
--------------------------------------------
10+
m1 | lm | 3 | | |
11+
m2 | lm | 7 | 4 | 40.32 | < .001
12+
13+
---
14+
15+
Code
16+
insight::print_md(test_likelihoodratio(m1, m2), p_digits = 3)
17+
Output
18+
[1] "Table: # Likelihood-Ratio-Test (LRT) for Model Comparison (OLS-estimator)"
19+
[2] ""
20+
[3] "|Name | Model| df| df_diff| Chi2| p|"
21+
[4] "|:----|-----:|--:|-------:|-----:|------:|"
22+
[5] "|m1 | lm| 3| | | |"
23+
[6] "|m2 | lm| 7| 4| 40.32| < .001|"
24+
attr(,"format")
25+
[1] "pipe"
26+
attr(,"class")
27+
[1] "knitr_kable" "character"
28+

tests/testthat/test-test_likelihoodratio.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,12 @@ test_that("test_likelihoodratio - lm", {
106106
expect_equal(t1$`Pr(>Chi)`, t2$p, tolerance = 1e-3)
107107
expect_equal(attributes(t2)$estimator, "ols")
108108
})
109+
110+
test_that("test_likelihoodratio - print p-digits", {
111+
data(mtcars)
112+
m1 <- lm(mpg ~ hp, data = mtcars)
113+
m2 <- lm(mpg ~ hp * as.factor(gear), data = mtcars)
114+
115+
expect_snapshot(test_likelihoodratio(m1, m2))
116+
expect_snapshot(insight::print_md(test_likelihoodratio(m1, m2), p_digits = 3))
117+
})

0 commit comments

Comments
 (0)