VizTest: Using the sig_diffs Template

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
library(VizTest)
library(carData)
library(dplyr)
library(tidyr)

The viztest() function in the VizTest pacakge will calculate all pairwise tests using normal theory tests (potentially adjusted for multiplicity if the user elects to do so). We imagine there are use cases where users derive the significance of differences using some procedure that is not anticipated by the workflow in the package. We give users who do this the option to input a vector indicating which pairs are significantly different with the sig_diffs argument. This gets somewhat complex, though, so we walk through an example below. Consider the following regression model:

library(VizTest)
data(iris)
mod <- lm(Petal.Width ~ Species, data = iris) 
summary(mod)
v <- viztest(mod)
library(marginaleffects)
preds <- avg_predictions(mod, variables="Species", conf_level = .9999)
preds

data(esoph)
esoph$agegp <- as.factor(as.character(esoph$agegp))
esoph$tobgp <- factor(as.character(esoph$tobgp), levels=c("0-9g/day", "10-19", "20-29", "30+"))
esoph$alcgp <- factor(as.character(esoph$alcgp), levels=c("0-39g/day", "40-79", "80-119", "120+"))

model1 <- glm(cbind(ncases, ncontrols) ~ agegp + tobgp + alcgp,
              data = esoph, family = binomial())
preds <- avg_predictions(model1, variables = "tobgp")

Let's imagine, for the sake of argument that we had a different way of identifying whether there are significant differences between the estimates presented above. We could use make_diff_template() to create a template for inputting these differences. Note that this also taked include_intercept and include_zero logical arguments that must be the same as the ones you will specify in viztest(). Let'see how it works. The first thing we need to do is make a vector of the estimates and apply the appropriate names:

ests <- preds$estimate
names(ests) <- preds$tobgp

Next, we give that vector to make_diff_template().

tmpl <- make_diff_template(ests, include_intercept = FALSE, include_zero = FALSE)
tmpl

At this point, we could make a vector of zeros and ones indicating whether there is a significant difference between the two stimuli.

diff <- c(1,1,1, 0, 0,0)

You could add that to the template and print it to ensure you did it right.

tmpl$sig <- diff
tmpl

Alternatively, you could export tmpl to a CSV file or similar, input by hand the significant differences and read the completed file back in. You would then use the vector of zeros and ones from the imported CSV file as the sig_diffs argument to viztest().

If everything looks alright, you can use this in the viztest() function:

viztest(preds, include_zero=FALSE, include_intercept = FALSE, sig_diffs = diff,range_levels = c(.25, .999))

What we see is that any confidence level between $78\%$ and $96\%$ will have (non-)overlaps that correspond with the pairwise differences we specified. Just so you can see this is different, let's do it without the sig_diffs argument:

viztest(preds, include_zero=FALSE, include_intercept = FALSE)


Try the VizTest package in your browser

Any scripts or data that you put into this service are public.

VizTest documentation built on Dec. 4, 2025, 9:07 a.m.