Skip to content

Commit

Permalink
Add p-value column to tidy.lmodel2() (#592)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattle24 authored and alexpghayes committed Mar 6, 2019
1 parent 86ac694 commit a011830
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Expand Up @@ -39,6 +39,7 @@ TODO: sort out what happens to `glance.aov()`
- `glance.biglm()` now returns a `df.residual` column
- `tidy.htest()` column names are now run through `make.names()` to ensure syntactic correctness (#549 by @karissawhiting) (TODO: use tidyverse name repair?)
- Many `glance()` methods now return the number of observations in a `nobs` column, which is typically the rightmost column.
- `tidy.lmodel2()` now returns a `p.value` column (#570)

### Name changes for consistency

Expand Down
16 changes: 12 additions & 4 deletions R/lmodel2-tidiers.R
Expand Up @@ -7,6 +7,7 @@
#' @evalRd return_tidy(
#' "term",
#' "estimate",
#' "p.value",
#' "conf.low",
#' "conf.high",
#' method = "Either OLS/MA/SMA/RMA"
Expand All @@ -17,6 +18,11 @@
#' (ordinary least squares), MA (major axis), SMA (standard major
#' axis), and RMA (ranged major axis).
#'
#' The returned p-value is one-tailed and calculated via a permutation test.
#' A permutational test is used because distributional assumptions may not not
#' be valid. More information can be found in the vignette
#' (\code{\link{vignette("mod2user")}})
#'
#' @examples
#'
#' library(lmodel2)
Expand All @@ -40,9 +46,9 @@
#' @aliases lmodel2_tidiers
#' @family lmodel2 tidiers
tidy.lmodel2 <- function(x, ...) {
ret <- x$regression.results[1:3] %>%
select(method = Method, Intercept, Slope) %>%
tidyr::gather(term, estimate, -method) %>%
ret <- x$regression.results[c(1:3, 5)] %>%
select(method = Method, Intercept, Slope, p.value = quote("P-perm (1-tailed)")) %>%
tidyr::gather(term, estimate, -method, -p.value) %>%
arrange(method, term)

# add confidence intervals
Expand All @@ -54,7 +60,9 @@ tidy.lmodel2 <- function(x, ...) {
select(method = Method, term, conf.low, conf.high)

ret %>%
inner_join(confints, by = c("method", "term")) %>%
inner_join(confints, by = c("method", "term")) %>%
# change column order so `p.value` is at the end
select(-p.value, dplyr::everything()) %>%
as_tibble()
}

Expand Down
1 change: 1 addition & 0 deletions man/tidy.lmodel2.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test-lmodel2.R
Expand Up @@ -17,7 +17,7 @@ test_that("lmodel2 tidier arguments", {
test_that("tidy.lmodel2", {
td <- tidy(fit)
check_tidy_output(td)
check_dims(td, 8, 5)
check_dims(td, 8, 6)
})

test_that("glance.lmodel2", {
Expand Down

0 comments on commit a011830

Please sign in to comment.