set.seed(42)
n_obs <- 30; n_pts <- 15
mock_data <- list(
age = list(
xvirtual = seq(30, 80, length.out = n_pts),
xorg = sample(seq(30, 80, by = 5), n_obs, replace = TRUE),
yhat.par = matrix(rnorm(n_obs * n_pts), nrow = n_obs),
yhat.nonpar = matrix(rnorm(n_obs * n_pts), nrow = n_obs),
yhat.causal = matrix(rnorm(n_obs * n_pts), nrow = n_obs)
),
sex = list(
xvirtual = c(0, 1),
xorg = sample(c(0, 1), n_obs, replace = TRUE),
yhat.par = matrix(rnorm(n_obs * 2), nrow = n_obs),
yhat.nonpar = matrix(rnorm(n_obs * 2), nrow = n_obs),
yhat.causal = matrix(rnorm(n_obs * 2), nrow = n_obs)
)
)
pp <- gg_partial_varpro(mock_data, scale = "logodds")
plot(pp)
plot(pp, type = "parametric")
## The continuous frame alone, so `+` reaches the plot you meant.
plot(pp, which = "continuous") + ggplot2::labs(title = "Continuous only")
## Per-panel scales. Only 'name' is required; the rest tune one axis each.
spec <- data.frame(name = "age", xlab = "Age (years)",
xmin = 30, xmax = 80, xby = 10, span = 0.6)
plot(pp, type = "parametric", panels = spec, points = TRUE, smooth = TRUE)
## Colour earns its place when several estimators share a panel: two curves
## separate faster by hue than by dash pattern. Any ColorBrewer name works.
plot(pp, type = c("parametric", "nonparametric"), palette = "Set1")
## The default is monochrome, for print.
plot(pp, type = c("parametric", "nonparametric"))
## A patchwork takes `&`, not `+`, to reach every panel.
plot(pp, type = "parametric", panels = spec) & ggplot2::theme_minimal()
## complement = TRUE reads a failure model as its success probability.
## (Mock data has no fit to restore subject levels from, hence the warning.)
pp_prob <- suppressWarnings(gg_partial_varpro(mock_data, scale = "prob"))
plot(pp_prob, type = "parametric", complement = TRUE)
Run the code above in your browser using DataLab