library(DImodels)
library(dplyr)
## Load data
data(sim2)
sim2$AV <- DI_data_E_AV(data = sim2, prop = 3:6)$AV
## Fit model
mod <- glm(response ~ 0 + (p1 + p2 + p3 + p4 + AV), data = sim2)
## Create data for plotting
plot_data <- prediction_contributions_data(data = sim2[c(1,5,9,11,15,19,23), ],
model = mod)
## Create plot
prediction_contributions_plot(data = plot_data)
## Choose distinct colours for groups of coefficients for better visibility
ID_cols <- get_colours(4, FG = c("G", "G", "H", "H"))
int_cols <- "#808080"
cols <- c(ID_cols, int_cols)
## Specify colours using `cols`
prediction_contributions_plot(data = plot_data, colours = cols)
## Show prediction intervals
prediction_contributions_plot(data = plot_data, colours = cols, se = TRUE)
## Change orientation of bars using `bar_orientation`
prediction_contributions_plot(data = plot_data, colours = cols,
se = TRUE, bar_orientation = "horizontal")
## Facet plot based on a variable in the data
prediction_contributions_plot(data = plot_data, colours = cols,
se = TRUE, bar_orientation = "horizontal",
facet_var = "block")
## If multiple plots are desired `add_var` can be specified during
## data preparation and the plots can be arranged using nrow and ncol
sim2$block <- as.character(sim2$block)
new_mod <- update(mod, ~. + block, data = sim2)
plot_data <- prediction_contributions_data(data = sim2[c(1,5,9,11,15,19,23), c(3:6, 8)],
model = new_mod,
add_var = list("block" = c("1", "2")))
## Arrange in two columns
prediction_contributions_plot(data = plot_data, ncol = 2)
Run the code above in your browser using DataLab