diff --git a/.Rbuildignore b/.Rbuildignore
index cb2c0ac..f9b1bf2 100644
--- a/.Rbuildignore
+++ b/.Rbuildignore
@@ -21,4 +21,5 @@
^hex\.png$
^LICENSE\.md$
^\.github$
-^pkgdown$
\ No newline at end of file
+^pkgdown$
+^interactions\.Rproj$
diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml
index 8ce0323..0f2fe08 100644
--- a/.github/workflows/R-CMD-check.yaml
+++ b/.github/workflows/R-CMD-check.yaml
@@ -1,4 +1,4 @@
-# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
+# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
@@ -8,6 +8,8 @@ on:
name: R-CMD-check
+permissions: read-all
+
jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}
@@ -18,7 +20,7 @@ jobs:
fail-fast: false
matrix:
config:
- - {os: macOS-latest, r: 'release'}
+ - {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
@@ -29,7 +31,7 @@ jobs:
R_KEEP_PKG_SOURCE: yes
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
- uses: r-lib/actions/setup-pandoc@v2
@@ -41,26 +43,10 @@ jobs:
- uses: r-lib/actions/setup-r-dependencies@v2
with:
- extra-packages: rcmdcheck
-
- - name: Set CRAN mirror
- run: echo "options(repos = c(CRAN='https://cloud.r-project.org/'))" > ~/.Rprofile
+ extra-packages: any::rcmdcheck
+ needs: check
- - name: Install lme4 from source to fix Matrix errors
- run: |
- install.packages('lme4', type = 'source')
- shell: Rscript {0}
-
- uses: r-lib/actions/check-r-package@v2
-
- - name: Show testthat output
- if: always()
- run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
- shell: bash
-
- - name: Upload check results
- if: failure()
- uses: actions/upload-artifact@main
with:
- name: ${{ runner.os }}-r${{ matrix.config.r }}-results
- path: check
+ upload-snapshots: true
+ build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml
index 332d0fb..6905849 100644
--- a/.github/workflows/pkgdown.yaml
+++ b/.github/workflows/pkgdown.yaml
@@ -1,29 +1,31 @@
-# Jacob copied from https://github.com/r-lib/pkgdown/blob/main/.github/workflows/pkgdown.yaml
-# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
+# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
tags: ['*']
pull_request:
- branches: [master, main]
+ branches: [main, master]
+ release:
+ types: [published]
+ workflow_dispatch:
name: pkgdown
+permissions: read-all
+
jobs:
pkgdown:
- if: github.event_name == 'push' || github.event.pull_request.head.repo.fork == false
runs-on: ubuntu-latest
+ # Only restrict concurrency for non-PR jobs
+ concurrency:
+ group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
- NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
- NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
- isPush: ${{ github.event_name == 'push' }}
-
+ permissions:
+ contents: write
steps:
- - uses: actions/checkout@v3
-
- - uses: r-lib/actions/setup-tinytex@v2
+ - uses: actions/checkout@v4
- uses: r-lib/actions/setup-pandoc@v2
@@ -38,7 +40,7 @@ jobs:
- name: Install package
run: R CMD INSTALL .
-
+
- name: Build and deploy pkgdown site
if: contains(env.isPush, 'true')
run: |
@@ -50,7 +52,7 @@ jobs:
run: |
pkgdown::build_site()
shell: Rscript {0}
-
+
- name: Create index file
if: contains(env.isPush, 'false')
run: |
diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml
index 2c5bb50..fefc52e 100644
--- a/.github/workflows/test-coverage.yaml
+++ b/.github/workflows/test-coverage.yaml
@@ -8,6 +8,8 @@ on:
name: test-coverage
+permissions: read-all
+
jobs:
test-coverage:
runs-on: ubuntu-latest
@@ -15,7 +17,7 @@ jobs:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
- uses: r-lib/actions/setup-r@v2
with:
@@ -23,28 +25,37 @@ jobs:
- uses: r-lib/actions/setup-r-dependencies@v2
with:
- extra-packages: any::covr
+ extra-packages: any::covr, any::xml2
needs: coverage
- name: Test coverage
run: |
- covr::codecov(
+ cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
- install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package")
+ install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
+ covr::to_cobertura(cov)
shell: Rscript {0}
+ - uses: codecov/codecov-action@v4
+ with:
+ fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }}
+ file: ./cobertura.xml
+ plugin: noop
+ disable_search: true
+ token: ${{ secrets.CODECOV_TOKEN }}
+
- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
- find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
+ find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash
- name: Upload test results
if: failure()
- uses: actions/upload-artifact@v3
+ uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
diff --git a/DESCRIPTION b/DESCRIPTION
index 8b25c3b..1a1e7de 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -16,8 +16,8 @@ URL: https://interactions.jacob-long.com
BugReports: https://github.com/jacob-long/interactions/issues
License: MIT + file LICENSE
Encoding: UTF-8
-Imports: ggplot2,
- crayon,
+Imports:
+ ggplot2 (>= 3.4.0),
cli,
generics,
jtools (>= 2.0.3),
@@ -26,17 +26,17 @@ Imports: ggplot2,
Suggests:
broom,
cowplot,
- ggstance,
+ broom.mixed,
glue,
huxtable (>= 3.0.0),
lme4,
margins,
sandwich,
survey,
- knitr,
- rmarkdown,
- testthat,
- vdiffr
+ knitr,
+ rmarkdown,
+ testthat,
+ vdiffr
Enhances:
brms,
rstanarm
diff --git a/NAMESPACE b/NAMESPACE
index 0ff33ff..7b90ef3 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -37,11 +37,6 @@ import(jtools)
import(rlang)
importFrom(cli,cat_rule)
importFrom(cli,rule)
-importFrom(crayon,bold)
-importFrom(crayon,inverse)
-importFrom(crayon,italic)
-importFrom(crayon,red)
-importFrom(crayon,underline)
importFrom(generics,glance)
importFrom(generics,tidy)
importFrom(stats,aggregate)
diff --git a/R/interact_plot.R b/R/interact_plot.R
index 3e5a045..ecb2d81 100755
--- a/R/interact_plot.R
+++ b/R/interact_plot.R
@@ -136,8 +136,8 @@
#' appears above the legend. If \code{NULL}, the name of the moderating
#' variable is used.
#'
-#' @param colors See [jtools_colors] for details on the types of arguments
-#' accepted. Default is "CUD Bright" for factor
+#' @param colors See [`jtools_colors`][jtools::jtools_colors] for details on the
+#' types of arguments accepted. Default is "CUD Bright" for factor
#' moderators, "Blues" for +/- SD and user-specified \code{modx.values}
#' values.
#'
@@ -446,11 +446,14 @@ interact_plot <- function(model, pred, modx, modx.values = NULL, mod2 = NULL,
# Check for factor predictor and send to plot_cat() if so
if (!is.numeric(d[[pred]])) {
# Warn users that this is kinda janky
- msg_wrap("Detected factor predictor. Plotting with cat_plot() instead.
- Consult cat_plot() documentation (?cat_plot) for full details
- on how to specify models with categorical predictors. If you
- experience errors or unexpected results, try using cat_plot()
- directly.")
+ cli::cli_inform(c(
+ x = "Detected factor predictor.",
+ i = "Plotting with cat_plot() instead.",
+ i = "See {.help interactions::cat_plot} for full details on
+ how to specify models with categorical predictors.",
+ i = "If you experience errors or unexpected results, try using
+ cat_plot() directly."
+ ))
# Gather arguments for plot_cat()
args <- list(predictions = pm, pred = pred, modx = modx, mod2 = mod2,
data = d, modx.values = modxvals2, mod2.values = mod2vals2,
diff --git a/R/johnson_neyman.R b/R/johnson_neyman.R
index 514aff4..ef2c9f8 100644
--- a/R/johnson_neyman.R
+++ b/R/johnson_neyman.R
@@ -622,7 +622,6 @@ johnson_neyman <- function(model, pred, modx, vmat = NULL, alpha = 0.05,
}
#' @export
-#' @importFrom crayon bold inverse underline
print.johnson_neyman <- function(x, ...) {
@@ -630,9 +629,9 @@ print.johnson_neyman <- function(x, ...) {
# Describe whether sig values are inside/outside the interval
if (atts$inside == FALSE) {
- inout <- inverse("OUTSIDE")
+ inout <- cli::style_inverse("OUTSIDE")
} else {
- inout <- inverse("INSIDE")
+ inout <- cli::style_inverse("INSIDE")
}
b_format <- num_print(x$bounds, atts$digits)
@@ -641,13 +640,16 @@ print.johnson_neyman <- function(x, ...) {
pmsg <- paste("p <", alpha)
# Print the output
- cat(bold(underline("JOHNSON-NEYMAN INTERVAL")), "\n\n")
+ cli::cat_line(
+ cli::style_bold(cli::style_underline("JOHNSON-NEYMAN INTERVAL")),
+ "\n"
+ )
if (all(is.finite(x$bounds))) {
cat_wrap("When ", atts$modx, " is ", inout, " the interval [",
b_format[1], ", ", b_format[2], "], the slope of ", atts$pred,
" is ", pmsg, ".", brk = "\n\n")
- cat_wrap(italic("Note: The range of observed values of", atts$modx,
- "is "), "[", m_range[1], ", ", m_range[2], "]", brk = "\n\n")
+ cat_wrap(cli::style_italic("Note: The range of observed values of ", atts$modx,
+ " is "), "[", m_range[1], ", ", m_range[2], "]", brk = "\n\n")
} else {
cat_wrap("The Johnson-Neyman interval could not be found.
Is the p value for your interaction term below
diff --git a/R/simple_margins.R b/R/simple_margins.R
index baf96cf..8dc8475 100644
--- a/R/simple_margins.R
+++ b/R/simple_margins.R
@@ -247,7 +247,6 @@ sim_margins <- function(model, pred, modx, mod2 = NULL, modx.values = NULL,
#' @export
#' @importFrom cli cat_rule rule
-#' @importFrom crayon red bold italic
print.sim_margins <- function(x, ...) {
@@ -308,7 +307,10 @@ print.sim_margins <- function(x, ...) {
}
# Clearly label simple slopes
- cat(bold(underline("SIMPLE MARGINS")), "\n\n")
+ cli::cat_line(
+ cli::style_bold(cli::style_underline("SIMPLE MARGINS")),
+ "\n"
+ )
for (i in seq_along(x$modx.values)) {
@@ -329,8 +331,8 @@ print.sim_margins <- function(x, ...) {
modx_label <- paste0(m[i, x$modx])
}
- cat(italic(paste0("Average marginal effect of ", x$pred, " when ",
- x$modx, " = ", modx_label, ": \n\n")))
+ cli::cat_line(cli::style_italic(paste0("Average marginal effect of ", x$pred, " when ",
+ x$modx, " = ", modx_label, ": \n")))
print(md_table(slopes, digits = x$digits, format = "pandoc",
row.names = FALSE, sig.digits = FALSE))
diff --git a/R/simple_slopes.R b/R/simple_slopes.R
index f9de4d6..8f70007 100644
--- a/R/simple_slopes.R
+++ b/R/simple_slopes.R
@@ -775,7 +775,6 @@ sim_slopes <- function(model, pred, modx, mod2 = NULL, modx.values = NULL,
#' @export
#' @importFrom cli cat_rule rule
-#' @importFrom crayon red bold italic
print.sim_slopes <- function(x, ...) {
@@ -859,7 +858,10 @@ print.sim_slopes <- function(x, ...) {
}
# Clearly label simple slopes
- cat(bold(underline("SIMPLE SLOPES ANALYSIS")), "\n\n")
+ cli::cat_line(
+ cli::style_bold(cli::style_underline("SIMPLE SLOPES ANALYSIS")),
+ "\n"
+ )
for (i in seq_along(x$modx.values)) {
@@ -882,7 +884,7 @@ print.sim_slopes <- function(x, ...) {
# Print conditional intercept
if (x$cond.int == TRUE | fac_pred == TRUE) {
pred_lab <- if (fac_pred) {slopes[["Coef."]]} else {x$pred}
- cat(italic(paste0("When ", x$modx, " = ", modx_label, ": \n\n")))
+ cli::cat_line(cli::style_italic(paste0("When ", x$modx, " = ", modx_label, ": \n")))
if (x$cond.int) {
ints <- m$ints[i,2:ncol(m$slopes)]
slopes <- as.data.frame(rbind(slopes, ints))
@@ -895,8 +897,8 @@ print.sim_slopes <- function(x, ...) {
print(md_table(slopes %not% "Coef.", digits = x$digits,
format = "pandoc", sig.digits = FALSE))
} else {
- cat(italic(paste0("Slope of ", x$pred, " when ", x$modx, " = ",
- modx_label, ": \n\n")))
+ cli::cat_line(cli::style_italic(paste0("Slope of ", x$pred, " when ", x$modx, " = ",
+ modx_label, ": \n")))
print(md_table(slopes, digits = x$digits, format = "pandoc",
row.names = FALSE, sig.digits = FALSE))
}
@@ -1036,7 +1038,7 @@ nobs.sim_slopes <- function(object, ...) {
#' @param x The [sim_slopes()] object.
#' @param format The method for sharing the slope and associated uncertainty.
#' Default is `"{estimate} ({std.error})"`. See the instructions for the
-#' `error_format` argument of [export_summs()] for more on your
+#' `error_format` argument of [jtools::export_summs()] for more on your
#' options.
#' @param sig.levels A named vector in which the values are potential p value
#' thresholds and the names are significance markers (e.g., "*") for when
diff --git a/README.Rmd b/README.Rmd
index ebbb93b..79ca8f7 100644
--- a/README.Rmd
+++ b/README.Rmd
@@ -22,9 +22,16 @@ library(jtools)
# interactions
-[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version-ago/interactions)](https://cran.r-project.org/package=interactions) [![GitHub tag](https://img.shields.io/github/tag/jacob-long/interactions.svg?label=Github)](https://github.com/jacob-long/interactions) [![Total Downloads](https://cranlogs.r-pkg.org/badges/grand-total/interactions)](https://cran.r-project.org/package=interactions)
-[![Build Status](https://github.com/jacob-long/interactions/workflows/R-CMD-check/badge.svg)](https://github.com/jacob-long/interactions/actions) [![AppVeyor Build status](https://ci.appveyor.com/api/projects/status/qfyn5cwomufqxath?svg=true)](https://ci.appveyor.com/project/jacob-long/interactions) [![codecov](https://codecov.io/gh/jacob-long/interactions/branch/master/graph/badge.svg)](https://codecov.io/gh/jacob-long/interactions)
+
+[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version-ago/interactions)](https://cran.r-project.org/package=interactions)
+[![GitHub tag](https://img.shields.io/github/tag/jacob-long/interactions.svg?label=Github)](https://github.com/jacob-long/interactions)
+[![Total Downloads](https://cranlogs.r-pkg.org/badges/grand-total/interactions)](https://cran.r-project.org/package=interactions)
+[![R-CMD-check](https://github.com/jacob-long/interactions/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/jacob-long/interactions/actions/workflows/R-CMD-check.yaml)
+[![AppVeyor Build status](https://ci.appveyor.com/api/projects/status/qfyn5cwomufqxath?svg=true)](https://ci.appveyor.com/project/jacob-long/interactions)
+[![codecov](https://codecov.io/gh/jacob-long/interactions/branch/master/graph/badge.svg)](https://codecov.io/gh/jacob-long/interactions)
[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://opensource.org/licenses/MIT)
+
+
This package consists of a number of tools for the analysis and
interpretation of statistical interactions in regression models. Some of these
diff --git a/README.md b/README.md
index ff216e9..4b5695a 100644
--- a/README.md
+++ b/README.md
@@ -3,13 +3,14 @@
# interactions
+
+
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version-ago/interactions)](https://cran.r-project.org/package=interactions)
[![GitHub
tag](https://img.shields.io/github/tag/jacob-long/interactions.svg?label=Github)](https://github.com/jacob-long/interactions)
[![Total
Downloads](https://cranlogs.r-pkg.org/badges/grand-total/interactions)](https://cran.r-project.org/package=interactions)
-[![Build
-Status](https://github.com/jacob-long/interactions/workflows/R-CMD-check/badge.svg)](https://github.com/jacob-long/interactions/actions)
+[![R-CMD-check](https://github.com/jacob-long/interactions/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/jacob-long/interactions/actions/workflows/R-CMD-check.yaml)
[![AppVeyor Build
status](https://ci.appveyor.com/api/projects/status/qfyn5cwomufqxath?svg=true)](https://ci.appveyor.com/project/jacob-long/interactions)
[![codecov](https://codecov.io/gh/jacob-long/interactions/branch/master/graph/badge.svg)](https://codecov.io/gh/jacob-long/interactions)
@@ -18,6 +19,7 @@ state and is being actively
developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![MIT
License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://opensource.org/licenses/MIT)
+
This package consists of a number of tools for the analysis and
interpretation of statistical interactions in regression models. Some of
@@ -27,9 +29,9 @@ when done “by hand.”
Quick rundown of features:
-- simple slopes analysis
-- calculation of Johnson-Neyman intervals
-- visualization of predicted and observed values using `ggplot2`
+- simple slopes analysis
+- calculation of Johnson-Neyman intervals
+- visualization of predicted and observed values using `ggplot2`
All of these are implemented in a consistent interface designed to be as
simple as possible with tweaks and guts available to advanced users.
@@ -80,7 +82,7 @@ fiti <- lm(mpg ~ hp * wt, data = mtcars)
sim_slopes(fiti, pred = hp, modx = wt, jnplot = TRUE)
```
- #> JOHNSON-NEYMAN INTERVAL
+ #> JOHNSON-NEYMAN INTERVAL
#>
#> When wt is OUTSIDE the interval [3.69, 5.90], the slope of hp is p < .05.
#>
@@ -88,7 +90,7 @@ sim_slopes(fiti, pred = hp, modx = wt, jnplot = TRUE)
![](man/figures/j-n-plot-1.png)
- #> SIMPLE SLOPES ANALYSIS
+ #> SIMPLE SLOPES ANALYSIS
#>
#> Slope of hp when wt = 2.238793 (- 1 SD):
#>
diff --git a/_pkgdown.yml b/_pkgdown.yml
index 25c9c6e..cbeb632 100644
--- a/_pkgdown.yml
+++ b/_pkgdown.yml
@@ -1,3 +1,5 @@
+url: https://interactions.jacob-long.com
+
template:
bootstrap: 5
params:
diff --git a/man/as_huxtable.sim_margins.Rd b/man/as_huxtable.sim_margins.Rd
index 688229c..0594a4a 100644
--- a/man/as_huxtable.sim_margins.Rd
+++ b/man/as_huxtable.sim_margins.Rd
@@ -20,7 +20,7 @@ as_huxtable.sim_margins(
\item{format}{The method for sharing the slope and associated uncertainty.
Default is \code{"{estimate} ({std.error})"}. See the instructions for the
-\code{error_format} argument of \code{\link[=export_summs]{export_summs()}} for more on your
+\code{error_format} argument of \code{\link[jtools:export_summs]{jtools::export_summs()}} for more on your
options.}
\item{sig.levels}{A named vector in which the values are potential p value
diff --git a/man/as_huxtable.sim_slopes.Rd b/man/as_huxtable.sim_slopes.Rd
index 7cf6e3f..6728542 100644
--- a/man/as_huxtable.sim_slopes.Rd
+++ b/man/as_huxtable.sim_slopes.Rd
@@ -20,7 +20,7 @@ as_huxtable.sim_slopes(
\item{format}{The method for sharing the slope and associated uncertainty.
Default is \code{"{estimate} ({std.error})"}. See the instructions for the
-\code{error_format} argument of \code{\link[=export_summs]{export_summs()}} for more on your
+\code{error_format} argument of \code{\link[jtools:export_summs]{jtools::export_summs()}} for more on your
options.}
\item{sig.levels}{A named vector in which the values are potential p value
diff --git a/man/figures/interact_plot_continuous-1.png b/man/figures/interact_plot_continuous-1.png
index 42da960..b121c01 100644
Binary files a/man/figures/interact_plot_continuous-1.png and b/man/figures/interact_plot_continuous-1.png differ
diff --git a/man/figures/interact_plot_continuous_points-1.png b/man/figures/interact_plot_continuous_points-1.png
index adbccad..8d0bd0d 100644
Binary files a/man/figures/interact_plot_continuous_points-1.png and b/man/figures/interact_plot_continuous_points-1.png differ
diff --git a/man/figures/interact_plot_factor-1.png b/man/figures/interact_plot_factor-1.png
index 9d072ae..108881c 100644
Binary files a/man/figures/interact_plot_factor-1.png and b/man/figures/interact_plot_factor-1.png differ
diff --git a/man/figures/j-n-plot-1.png b/man/figures/j-n-plot-1.png
index 18a2f0e..340670e 100644
Binary files a/man/figures/j-n-plot-1.png and b/man/figures/j-n-plot-1.png differ
diff --git a/man/interact_plot.Rd b/man/interact_plot.Rd
index cd83d18..005e41d 100755
--- a/man/interact_plot.Rd
+++ b/man/interact_plot.Rd
@@ -197,8 +197,8 @@ for the plot. If \code{NULL}, no main title is used.}
appears above the legend. If \code{NULL}, the name of the moderating
variable is used.}
-\item{colors}{See \link{jtools_colors} for details on the types of arguments
-accepted. Default is "CUD Bright" for factor
+\item{colors}{See \code{\link[jtools:jtools_colors]{jtools_colors}} for details on the
+types of arguments accepted. Default is "CUD Bright" for factor
moderators, "Blues" for +/- SD and user-specified \code{modx.values}
values.}
diff --git a/tests/testthat/test_cat_plot.R b/tests/testthat/test_cat_plot.R
index 5784bb4..2f57a0b 100644
--- a/tests/testthat/test_cat_plot.R
+++ b/tests/testthat/test_cat_plot.R
@@ -127,26 +127,25 @@ test_that("cat_plot handles offsets", {
context("cat_plot survey")
-if (requireNamespace("survey")) {
+test_that("cat_plot handles svyglm", {
+ skip_if_not_installed("survey")
library(survey, quietly = TRUE)
data(api)
dstrat <- svydesign(id = ~1, strata = ~stype, weights = ~pw, data = apistrat,
fpc = ~fpc)
regmodel <- svyglm(api00 ~ ell * meals * both + sch.wide, design = dstrat)
- test_that("cat_plot handles svyglm", {
- psvycat <- cat_plot(regmodel, pred = both)
- expect_doppelganger("psvycat", psvycat)
- })
-}
+
+ psvycat <- cat_plot(regmodel, pred = both)
+ expect_doppelganger("psvycat", psvycat)
+})
context("cat_plot merMod")
-if (requireNamespace("lme4")) {
- test_that("cat_plot handles merMod", {
- plme4cat <- cat_plot(mv, pred = mode, modx = Gender, interval = FALSE)
- expect_doppelganger("plme4cat", plme4cat)
- })
-}
+test_that("cat_plot handles merMod", {
+ skip_if_not_installed("lme4")
+ plme4cat <- cat_plot(mv, pred = mode, modx = Gender, interval = FALSE)
+ expect_doppelganger("plme4cat", plme4cat)
+})
context("cat_plot 3-way")
@@ -284,11 +283,11 @@ test_that("cat_plot handles point.shape w/ no mod. (point)", {
expect_doppelganger("p0ptps", p0ptps)
})
-if (requireNamespace("brms")) {
- context("brmsfit plots")
+context("brmsfit plots")
+
+test_that("brmsfit objects are supported", {
+ skip_if_not_installed("brms")
bfit <- readRDS("brmfit.rds")
- test_that("brmsfit objects are supported", {
- pcatbfit <- cat_plot(bfit, pred = "Trt", interval = TRUE)
- expect_doppelganger("pcatbfit", pcatbfit)
- })
-}
+ pcatbfit <- cat_plot(bfit, pred = "Trt", interval = TRUE)
+ expect_doppelganger("pcatbfit", pcatbfit)
+})
diff --git a/tests/testthat/test_interact_plot.R b/tests/testthat/test_interact_plot.R
index dff9891..c24b0d5 100644
--- a/tests/testthat/test_interact_plot.R
+++ b/tests/testthat/test_interact_plot.R
@@ -138,22 +138,22 @@ test_that("interact_plot linearity.check works", {
context("interact_plot svyglm")
-if (requireNamespace("survey")) {
- test_that("interact_plot works for svyglm", {
- psvya <- interact_plot(regmodel, pred = ell, modx = meals, mod2 = both,
- centered = "all")
- expect_doppelganger("psvya", psvya)
- expect_warning(
- psvy1 <- interact_plot(regmodel, pred = ell, modx = meals, mod2 = both,
- centered = "ell")
- )
- expect_doppelganger("psvy1", psvy1)
- })
-}
+test_that("interact_plot works for svyglm", {
+ skip_if_not_installed("survey")
+ psvya <- interact_plot(regmodel, pred = ell, modx = meals, mod2 = both,
+ centered = "all")
+ expect_doppelganger("psvya", psvya)
+ expect_warning(
+ psvy1 <- interact_plot(regmodel, pred = ell, modx = meals, mod2 = both,
+ centered = "ell")
+ )
+ expect_doppelganger("psvy1", psvy1)
+})
context("interact_plot merMod")
-if (requireNamespace("lme4")) {
+test_that("interact_plot works for lme4", {
+ skip_if_not_installed("lme4")
library(lme4, quietly = TRUE)
data(VerbAgg)
VerbAgg$mode_numeric <- as.numeric(VerbAgg$mode)
@@ -162,21 +162,17 @@ if (requireNamespace("lme4")) {
data = VerbAgg)
gm <- glmer(incidence ~ period + (1 | herd), family = poisson, data = cbpp,
offset = log(size))
-
- test_that("interact_plot works for lme4", {
- expect_doppelganger("plme4 interact_plot to cat_plot",
- interact_plot(mve, pred = mode, modx = Gender))
- plme4 <- interact_plot(mv, pred = mode_numeric, modx = Gender)
- expect_doppelganger("plme4", plme4)
- # expect_message(
- plme4i <- interact_plot(mv, pred = mode_numeric, modx = Gender,
- interval = TRUE)
- # )
- expect_doppelganger("plme4i", plme4i)
- })
-
-}
-
+
+ expect_doppelganger("plme4 interact_plot to cat_plot",
+ interact_plot(mve, pred = mode, modx = Gender))
+ plme4 <- interact_plot(mv, pred = mode_numeric, modx = Gender)
+ expect_doppelganger("plme4", plme4)
+ # expect_message(
+ plme4i <- interact_plot(mv, pred = mode_numeric, modx = Gender,
+ interval = TRUE)
+ # )
+ expect_doppelganger("plme4i", plme4i)
+})
context("interact_plot offsets")
set.seed(100)
@@ -225,27 +221,27 @@ test_that("sim_slopes handles offsets", {
#### brms and rstanarm tests #################################################
-if (requireNamespace("brms")) {
- context("brmsfit plots 2")
+context("brmsfit plots 2")
+test_that("brmsfit objects are supported", {
+ skip_if_not_installed("brms")
+
bfit <- readRDS("brmfit.rds")
- test_that("brmsfit objects are supported", {
- pbfcat <- cat_plot(bfit, pred = "Trt", interval = TRUE)
- expect_doppelganger("pbfcat", pbfcat)
- pbfcont <- interact_plot(bfit, pred = "log_Base4_c", modx = "Trt",
- interval = TRUE)
- expect_doppelganger("pbfcont", pbfcont)
- })
-}
+ pbfcat <- cat_plot(bfit, pred = "Trt", interval = TRUE)
+ expect_doppelganger("pbfcat", pbfcat)
+ pbfcont <- interact_plot(bfit, pred = "log_Base4_c", modx = "Trt",
+ interval = TRUE)
+ expect_doppelganger("pbfcont", pbfcont)
+})
-if (requireNamespace("rstanarm") & requireNamespace("lme4")) {
- context("stanreg plots")
+context("stanreg plots")
+
+test_that("stanreg objects are supported", {
rsfit <- readRDS("rsafit.rds")
library(lme4)
data(cbpp)
- test_that("stanreg objects are supported", {
- prsacont <- interact_plot(rsfit, pred = "size", modx = "period",
- interval = TRUE, data = cbpp)
- expect_doppelganger("prsacont", prsacont)
- })
-}
-
+ skip_if_not_installed("lme4")
+ skip_if_not_installed("rstanarm")
+ prsacont <- interact_plot(rsfit, pred = "size", modx = "period",
+ interval = TRUE, data = cbpp)
+ expect_doppelganger("prsacont", prsacont)
+})
diff --git a/tests/testthat/test_sim_margins.R b/tests/testthat/test_sim_margins.R
index 75eca0d..194e1f3 100644
--- a/tests/testthat/test_sim_margins.R
+++ b/tests/testthat/test_sim_margins.R
@@ -1,4 +1,4 @@
-if (requireNamespace("margins")) {
+skip_if_not_installed("margins")
context("sim_margins lm")
states <- as.data.frame(state.x77)
@@ -102,80 +102,76 @@ test_that("sim_margins works for lm w/ non-focal character", {
context("sim_margins methods")
-if (requireNamespace("huxtable") && requireNamespace("broom")) {
- test_that("as_huxtable.sim_margins works", {
- ss3 <- sim_margins(model = fit, pred = Murder, modx = Illiteracy,
- mod2 = HSGrad)
- ss <- sim_margins(model = fit, pred = Murder, modx = Illiteracy)
- expect_is(as_huxtable.sim_margins(ss3), "huxtable")
- expect_is(as_huxtable.sim_margins(ss), "huxtable")
- ss3 <- sim_margins(model = fit, pred = Murder, modx = Illiteracy,
- mod2 = HSGrad, vce = "bootstrap", iterations = 50)
- ss <- sim_margins(model = fit, pred = Murder, modx = Illiteracy,
- vce = "bootstrap", iterations = 50)
- expect_is(as_huxtable.sim_margins(ss3), "huxtable")
- expect_is(as_huxtable.sim_margins(ss), "huxtable")
- ss3 <- sim_margins(model = fit, pred = Murder, modx = Illiteracy,
- mod2 = HSGrad, vce = "simulation", iterations = 50)
- ss <- sim_margins(model = fit, pred = Murder, modx = Illiteracy,
- vce = "simulation", iterations = 50)
- expect_is(as_huxtable.sim_margins(ss3), "huxtable")
- expect_is(as_huxtable.sim_margins(ss), "huxtable")
- })
-}
+test_that("as_huxtable.sim_margins works", {
+ skip_if_not_installed("huxtable")
+ skip_if_not_installed("broom")
+ ss3 <- sim_margins(model = fit, pred = Murder, modx = Illiteracy,
+ mod2 = HSGrad)
+ ss <- sim_margins(model = fit, pred = Murder, modx = Illiteracy)
+ expect_is(as_huxtable.sim_margins(ss3), "huxtable")
+ expect_is(as_huxtable.sim_margins(ss), "huxtable")
+ ss3 <- sim_margins(model = fit, pred = Murder, modx = Illiteracy,
+ mod2 = HSGrad, vce = "bootstrap", iterations = 50)
+ ss <- sim_margins(model = fit, pred = Murder, modx = Illiteracy,
+ vce = "bootstrap", iterations = 50)
+ expect_is(as_huxtable.sim_margins(ss3), "huxtable")
+ expect_is(as_huxtable.sim_margins(ss), "huxtable")
+ ss3 <- sim_margins(model = fit, pred = Murder, modx = Illiteracy,
+ mod2 = HSGrad, vce = "simulation", iterations = 50)
+ ss <- sim_margins(model = fit, pred = Murder, modx = Illiteracy,
+ vce = "simulation", iterations = 50)
+ expect_is(as_huxtable.sim_margins(ss3), "huxtable")
+ expect_is(as_huxtable.sim_margins(ss), "huxtable")
+})
-if (requireNamespace("ggstance") && requireNamespace("broom")) {
- test_that("plot.sim_margins works", {
- ss3 <- sim_margins(model = fit, pred = Murder, modx = Illiteracy,
- mod2 = HSGrad)
- ss <- sim_margins(model = fit, pred = Murder, modx = Illiteracy)
- expect_is(plot(ss3), "ggplot")
- expect_is(plot(ss), "ggplot")
- ss3 <- sim_margins(model = fit, pred = Murder, modx = Illiteracy,
- mod2 = HSGrad, vce = "bootstrap", iterations = 50)
- ss <- sim_margins(model = fit, pred = Murder, modx = Illiteracy,
- vce = "bootstrap", iterations = 50)
- expect_is(plot(ss3), "ggplot")
- expect_is(plot(ss), "ggplot")
- ss3 <- sim_margins(model = fit, pred = Murder, modx = Illiteracy,
- mod2 = HSGrad, vce = "simulation", iterations = 50)
- ss <- sim_margins(model = fit, pred = Murder, modx = Illiteracy,
- vce = "simulation", iterations = 50)
- expect_is(plot(ss3), "ggplot")
- expect_is(plot(ss), "ggplot")
- })
-}
+test_that("plot.sim_margins works", {
+ skip_if_not_installed("broom.mixed")
+ skip_if_not_installed("broom")
+ ss3 <- sim_margins(model = fit, pred = Murder, modx = Illiteracy,
+ mod2 = HSGrad)
+ ss <- sim_margins(model = fit, pred = Murder, modx = Illiteracy)
+ expect_is(plot(ss3), "ggplot")
+ expect_is(plot(ss), "ggplot")
+ ss3 <- sim_margins(model = fit, pred = Murder, modx = Illiteracy,
+ mod2 = HSGrad, vce = "bootstrap", iterations = 50)
+ ss <- sim_margins(model = fit, pred = Murder, modx = Illiteracy,
+ vce = "bootstrap", iterations = 50)
+ expect_is(plot(ss3), "ggplot")
+ expect_is(plot(ss), "ggplot")
+ ss3 <- sim_margins(model = fit, pred = Murder, modx = Illiteracy,
+ mod2 = HSGrad, vce = "simulation", iterations = 50)
+ ss <- sim_margins(model = fit, pred = Murder, modx = Illiteracy,
+ vce = "simulation", iterations = 50)
+ expect_is(plot(ss3), "ggplot")
+ expect_is(plot(ss), "ggplot")
+})
context("sim_margins svyglm")
-if (requireNamespace("survey")) {
- test_that("sim_margins works for svyglm", {
- expect_is(sim_margins(regmodel, pred = ell, modx = meals, mod2 = both),
- "sim_margins")
- # margins bug
- # expect_is(sim_margins(regmodel, pred = ell, modx = meals, mod2 = both,
- # vce = "bootstrap", iterations = 50),
- # "sim_margins")
- # expect_is(sim_margins(regmodel, pred = ell, modx = meals, mod2 = both,
- # vce = "simulation", iterations = 50),
- # "sim_margins")
- })
-}
+test_that("sim_margins works for svyglm", {
+ skip_if_not_installed("survey")
+ expect_is(sim_margins(regmodel, pred = ell, modx = meals, mod2 = both),
+ "sim_margins")
+ # margins bug
+ # expect_is(sim_margins(regmodel, pred = ell, modx = meals, mod2 = both,
+ # vce = "bootstrap", iterations = 50),
+ # "sim_margins")
+ # expect_is(sim_margins(regmodel, pred = ell, modx = meals, mod2 = both,
+ # vce = "simulation", iterations = 50),
+ # "sim_margins")
+})
context("sim_margins merMod")
-if (requireNamespace("lme4")) {
+test_that("sim_margins works for lme4", {
+ skip_if_not_installed("lme4")
library(lme4, quietly = TRUE)
data(VerbAgg)
fmVA0 <- glmer(r2 ~ Anger * Gender + btype + situ + (1|id) + (1|item),
family = binomial, data = VerbAgg, nAGQ=0L)
lmVA0 <- lmer(as.numeric(r2 == "Y") ~ Anger * Gender + btype + situ +
(1|id) + (1|item), data = VerbAgg)
-
- test_that("sim_margins works for lme4", {
- expect_is(sim_margins(lmVA0, pred = Anger, modx = Gender), "sim_margins")
- expect_is(sim_margins(fmVA0, pred = Anger, modx = Gender), "sim_margins")
- })
-
-}
-}
+
+ expect_is(sim_margins(lmVA0, pred = Anger, modx = Gender), "sim_margins")
+ expect_is(sim_margins(fmVA0, pred = Anger, modx = Gender), "sim_margins")
+})
diff --git a/tests/testthat/test_sim_slopes.R b/tests/testthat/test_sim_slopes.R
index bfd9f29..811fc26 100644
--- a/tests/testthat/test_sim_slopes.R
+++ b/tests/testthat/test_sim_slopes.R
@@ -84,54 +84,51 @@ test_that("sim_slopes accepts categorical predictor", {
context("sim_slopes methods")
-if (requireNamespace("huxtable") && requireNamespace("broom")) {
- test_that("as_huxtable.sim_slopes works", {
- ss3 <- sim_slopes(model = fit, pred = Murder, modx = Illiteracy,
- mod2 = HSGrad)
- ss <- sim_slopes(model = fit, pred = Murder, modx = Illiteracy)
- expect_is(as_huxtable.sim_slopes(ss3), "huxtable")
- expect_is(as_huxtable.sim_slopes(ss), "huxtable")
- })
-}
-
-if (requireNamespace("ggstance") && requireNamespace("broom")) {
- test_that("plot.sim_slopes works", {
- ss3 <- sim_slopes(model = fit, pred = Murder, modx = Illiteracy,
- mod2 = HSGrad)
- ss <- sim_slopes(model = fit, pred = Murder, modx = Illiteracy)
- expect_is(plot(ss3), "ggplot")
- expect_is(plot(ss), "ggplot")
- })
-}
+test_that("as_huxtable.sim_slopes works", {
+ skip_if_not_installed("huxtable")
+ skip_if_not_installed("broom")
+ ss3 <- sim_slopes(model = fit, pred = Murder, modx = Illiteracy,
+ mod2 = HSGrad)
+ ss <- sim_slopes(model = fit, pred = Murder, modx = Illiteracy)
+ expect_is(as_huxtable.sim_slopes(ss3), "huxtable")
+ expect_is(as_huxtable.sim_slopes(ss), "huxtable")
+})
+test_that("plot.sim_slopes works", {
+ skip_if_not_installed("broom.mixed")
+ skip_if_not_installed("broom")
+ ss3 <- sim_slopes(model = fit, pred = Murder, modx = Illiteracy,
+ mod2 = HSGrad)
+ ss <- sim_slopes(model = fit, pred = Murder, modx = Illiteracy)
+ expect_is(plot(ss3), "ggplot")
+ expect_is(plot(ss), "ggplot")
+})
context("sim_slopes svyglm")
-if (requireNamespace("survey")) {
- test_that("sim_slopes works for svyglm", {
- expect_is(sim_slopes(regmodel, pred = ell, modx = meals, mod2 = both,
- centered = "all"), "sim_slopes")
- })
-}
+test_that("sim_slopes works for svyglm", {
+ skip_if_not_installed("survey")
+ expect_is(sim_slopes(regmodel, pred = ell, modx = meals, mod2 = both,
+ centered = "all"), "sim_slopes")
+})
context("sim_slopes merMod")
-if (requireNamespace("lme4")) {
+test_that("sim_slopes works for lme4", {
+ skip_if_not_installed("lme4")
library(lme4, quietly = TRUE)
data(VerbAgg)
fmVA0 <- glmer(r2 ~ Anger * Gender + btype + situ + (1|id) + (1|item),
family = binomial, data = VerbAgg, nAGQ=0L)
lmVA0 <- lmer(as.numeric(r2 == "Y") ~ Anger * Gender + btype + situ +
(1|id) + (1|item), data = VerbAgg)
+
+ expect_is(sim_slopes(lmVA0, pred = Anger, modx = Gender,
+ johnson_neyman = FALSE, t.df = "residual"),
+ "sim_slopes")
+ expect_is(sim_slopes(fmVA0, pred = Anger, modx = Gender,
+ johnson_neyman = FALSE), "sim_slopes")
+})
- test_that("sim_slopes works for lme4", {
- expect_is(sim_slopes(lmVA0, pred = Anger, modx = Gender,
- johnson_neyman = FALSE, t.df = "residual"),
- "sim_slopes")
- expect_is(sim_slopes(fmVA0, pred = Anger, modx = Gender,
- johnson_neyman = FALSE), "sim_slopes")
- })
-
-}
### johnson_neyman ###########################################################