## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 10,
  fig.height = 6,
  fig.align = "center"
)
library(statuser)

## ----sim-demo-----------------------------------------------------------------
data(tacos_data)
tacos_bin <- tacos_data[!is.na(tacos_data$spicy_bin), ]
nrow(tacos_bin)

interprobe(
  x = spicy_bin, z = tolerance, y = enjoyment,
  data = tacos_bin
)

## ----sim-linear---------------------------------------------------------------
interprobe(
  x = spicy_bin, z = tolerance, y = enjoyment,
  data = tacos_bin,
  model = "linear"
)

## ----tacos-setup--------------------------------------------------------------
data(tacos_data)
tacos_bin <- tacos_data[!is.na(tacos_data$spicy_bin), ]

## ----case-a-------------------------------------------------------------------
res_a <- interprobe(
  x = spicy_bin, z = tolerance, y = enjoyment,
  data = tacos_bin
)

## ----case-b-------------------------------------------------------------------
res_b <- interprobe(
  x = salsa, z = tolerance, y = enjoyment,
  data = tacos_data
)

## ----case-c-------------------------------------------------------------------
res_c <- interprobe(
  x = spicy, z = tolerance, y = enjoyment,
  data = tacos_data
)

## ----case-c-spotlights--------------------------------------------------------
interprobe(
  x = spicy, z = tolerance, y = enjoyment, data = tacos_data,
  spotlights = c(2, 4, 6),
  spotlight.labels = c("Low tolerance (2)", "Mid (4)", "High (6)")
)

## ----case-c-axis--------------------------------------------------------------
interprobe(
  x = spicy, z = tolerance, y = enjoyment, data = tacos_data,
  moderator.on.x.axis = FALSE
)

## ----covariates---------------------------------------------------------------
lm1 <- lm(enjoyment ~ spicy_bin * tolerance + age, data = tacos_bin)
interprobe(model = lm1, x = spicy_bin, z = tolerance)

## ----gam-vs-linear, fig.show = "hold"-----------------------------------------
interprobe(x = spicy_bin, z = tolerance, y = enjoyment, data = tacos_bin)
interprobe(
  x = spicy_bin, z = tolerance, y = enjoyment,
  data = tacos_bin, model = "linear"
)

## ----returned-list------------------------------------------------------------
res <- interprobe(
  x = spicy_bin, z = tolerance, y = enjoyment,
  data = tacos_bin,
  draw = "none"
)
names(res)
head(res$johnson.neyman)
head(res$simple.slopes)

## ----inspect-model------------------------------------------------------------
summary(res$gam_results)

## ----customize, eval = FALSE--------------------------------------------------
# interprobe(
#   x = spicy_bin, z = tolerance, y = enjoyment, data = tacos_bin,
#   draw = "jn",                    # or "simple slopes", "both", "none"
#   cols = c("black", "steelblue"),
#   save.as = "spicy_tolerance_jn.png",
#   xlim = c(1, 7)
# )

