library(DImodels)
## Load data
data(sim4)
## Fit model
mod <- glm(response ~ 0 + (p1 + p2 + p3 + p4 + p5 + p6)^2, data = sim4)
## Create data for slicing
## We only condition on the variable "p3"
plot_data <- conditional_ternary_data(prop = c("p1", "p2", "p3", "p4", "p5", "p6"),
tern_vars = c("p1", "p2", "p4"),
conditional = data.frame("p3" = c(0, 0.2, 0.5)),
model = mod,
resolution = 1)
## Create plot
conditional_ternary_plot(data = plot_data)
## Condition on multiple variables
cond <- data.frame(p4 = c(0, 0.2), p5 = c(0.5, 0.1), p6 = c(0, 0.3))
cond
plot_data <- conditional_ternary_data(prop = c("p1", "p2", "p3", "p4", "p5", "p6"),
tern_vars = c("p1", "p2", "p3"),
conditional = cond,
model = mod,
resolution = 1)
## Create plot
conditional_ternary_plot(data = plot_data)
## Create multiple plots for additional variables using `add_var`
## Fit model
# \donttest{
mod <- glm(response ~ 0 + (p1 + p2 + p3 + p4 + p5 + p6)^2 + treatment,
data = sim4)
## Notice the additional `.add_str_ID` column
plot_data <- conditional_ternary_data(prop = c("p1", "p2", "p3", "p4", "p5", "p6"),
tern_vars = c("p1", "p2", "p3"),
conditional = data.frame("p4" = c(0, 0.2, 0.5)),
add_var = list("treatment" = c(50, 150)),
model = mod,
resolution = 1)
## Create plot
## Use nrow to align plots
conditional_ternary_plot(data = plot_data, nrow = 2)
# }
Run the code above in your browser using DataLab