Last updated on 2026-10-24 03:56:06 CEST.
| Flavor | Version | Tinstall | Tcheck | Ttotal | Status | Flags |
|---|---|---|---|---|---|---|
| r-devel-linux-x86_64-debian-clang | 2.1.0 | 2.87 | 42.38 | 45.25 | OK | |
| r-devel-linux-x86_64-debian-gcc | 2.1.0 | 2.52 | 28.39 | 30.91 | ERROR | |
| r-devel-linux-x86_64-fedora-clang | 2.1.0 | 32.06 | OK | |||
| r-devel-linux-x86_64-fedora-gcc | 2.1.0 | 31.92 | OK | |||
| r-devel-windows-x86_64 | 2.1.0 | 4.00 | 63.00 | 67.00 | OK | |
| r-patched-linux-x86_64 | 2.1.0 | 3.91 | 40.20 | 44.11 | OK | |
| r-release-linux-x86_64 | 2.1.0 | 3.78 | 39.52 | 43.30 | OK | |
| r-release-macos-arm64 | 2.1.0 | 1.00 | 13.00 | 14.00 | OK | |
| r-release-macos-x86_64 | 2.1.0 | 3.00 | 42.00 | 45.00 | OK | |
| r-release-windows-x86_64 | 2.1.0 | 4.00 | 58.00 | 62.00 | OK | |
| r-oldrel-macos-arm64 | 2.1.0 | 1.00 | 19.00 | 20.00 | OK | |
| r-oldrel-macos-x86_64 | 2.1.0 | 3.00 | 40.00 | 43.00 | OK | |
| r-oldrel-windows-x86_64 | 2.1.0 | 6.00 | 66.00 | 72.00 | OK |
Version: 2.1.0
Check: examples
Result: ERROR
Running examples in ‘easyViz-Ex.R’ failed
The error most likely occurred in:
> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: easyViz
> ### Title: Easy Visualization of Conditional Effects from Regression Models
> ### Aliases: easyViz
>
> ### ** Examples
>
> #------------------------------------------
> # Load required packages
> #------------------------------------------
>
> library(MASS)
> library(nlme)
> library(betareg)
> library(survival)
> library(lme4)
Loading required package: Matrix
Attaching package: ‘lme4’
The following object is masked from ‘package:nlme’:
lmList
> library(glmmTMB)
> library(mgcv)
This is mgcv 1.9-4. For overview type '?mgcv'.
>
> #------------------------------------------
> # Simulate dataset
> #------------------------------------------
> set.seed(123)
> n <- 100
> x1 <- rnorm(n)
> x2 <- rnorm(n)
> x3 <- runif(n, 0, 5)
> x4 <- factor(sample(letters[1:3], n, replace = TRUE))
> group_levels <- paste0("G", 1:10)
> group <- factor(sample(group_levels, n, replace = TRUE))
>
> # Generate random intercepts for each group
> group_effects <- rnorm(length(group_levels), mean = 0, sd = 2) # non-zero variance
> names(group_effects) <- group_levels
> group_intercept <- group_effects[as.character(group)]
>
> # Non-linear continuous response
> true_y <- 5 * sin(x3) + 3 * x1 + group_intercept + model.matrix(~x4)[, -1] %*% c(2, -2)
> noise <- rnorm(n, sd = 3)
> y <- as.vector(true_y + noise)
>
> # Binary response with group effect added to logit
> logit_p <- 2 * x1 - 1 + group_intercept
> p <- 1 / (1 + exp(-logit_p))
> binary_y <- rbinom(n, size = 1, prob = p)
>
> # Binomial response: number of successes and failures
> y3 <- sample(10:30, n, replace = TRUE)
> logit_p_prop <- -1.5 * scale(x1)
> p_prop <- 1 / (1 + exp(-logit_p_prop))
> y1 <- rbinom(n, size = y3, prob = p_prop) # successes
> y2 <- y3 - y1 # failures
>
> # Count response with group effect in log(mu)
> mu_count <- exp(1 + 0.8 * x2 - 0.5 * (x4 == "b") + group_intercept)
> size <- 1.2
> count_y <- rnbinom(n, size = size, mu = mu_count)
> # Offset variable
> exposure <- runif(n, 1, 10)
>
> # Assemble dataset
> sim.data <- data.frame(x1, x2, x3, x4, group, y, binary_y, y1, y2, y3, count_y, exposure)
>
> #------------------------------------------
> # 1. Linear model (lm)
> #------------------------------------------
> mod.lm <- lm(y ~ x1 + x4,
+ data = sim.data)
> easyViz(model = mod.lm, data = sim.data, predictor = "x1",
+ by = "x4",
+ pred_range_limit = FALSE,
+ pred_on_top = TRUE,
+ ylim = c(-12,18),
+ xlab = "Predictor x1",
+ ylab = "Response y",
+ point_col = ifelse(sim.data$x4=="a", "red",
+ ifelse(sim.data$x4=="b", "orange",
+ "yellow")),
+ point_cex = 0.5,
+ pred_line_col = c("red", "orange", "yellow"),
+ pred_line_lty = 1,
+ ci_polygon_col = c(rgb(1,0,0,0.5),
+ rgb(1,0.5,0,0.5),
+ rgb(1,1,0,0.5)))
>
> # Numeric x categorical interaction
> # Backtransform response
> # Show conditioning summary
> mod.lm2 <- lm(sqrt(x3) ~ x1 * x4,
+ data = sim.data)
> easyViz(model = mod.lm2, data = sim.data, predictor = "x1",
+ by="x4",
+ pred_transform = function(x) x^2,
+ ylim = c(0,8),
+ show_data_points = FALSE,
+ show_conditioning = TRUE)
Prediction conditioning summary
- Held fixed: none
- Varied in prediction grid: x1, x4
>
> # Polynomial terms
> mod.lm3 <- lm(y ~ poly(x3, 3),
+ data = sim.data)
> easyViz(model = mod.lm3, data = sim.data, predictor = "x3",
+ pred_on_top = TRUE,
+ font_family = "mono",
+ point_col = rgb(1,0,0,0.3),
+ point_pch = "+",
+ ci_level = 0.85,
+ ci_type = "lines",
+ ci_line_lty = 2)
>
> # Extract prediction data
> df.mod.lm <- easyViz(model = mod.lm, data = sim.data, predictor = "x1",
+ by = "x4", ci_level = 0.85, plot = FALSE)
> head(df.mod.lm)
x1 x4 fit 85lcl 85ucl
1 -1.966617 a -2.837348 -5.074907 -0.5997897
2 -1.929082 a -2.746961 -4.961273 -0.5326492
3 -1.891547 a -2.656574 -4.847855 -0.4652929
4 -1.854011 a -2.566187 -4.734659 -0.3977141
5 -1.816476 a -2.475799 -4.621693 -0.3299056
6 -1.778941 a -2.385412 -4.508964 -0.2618601
>
> #------------------------------------------
> # 2. Robust linear model (rlm)
> #------------------------------------------
> mod.rlm <- rlm(y ~ x1 + x4,
+ data = sim.data)
> # Add legend outside of plotting region
> old_xpd_mar <- par(xpd = TRUE, mar = c(5.1, 4.1, 4.1, 5.1))
> easyViz(model = mod.rlm, data = sim.data, predictor = "x1",
+ by = "x4",
+ pred_on_top = TRUE,
+ bty = "n",
+ xlab = "Predictor x1",
+ ylab = "Response y",
+ point_col = ifelse(sim.data$x4=="a", "red",
+ ifelse(sim.data$x4=="b", "orange",
+ "yellow")),
+ point_cex = 0.5,
+ pred_line_col = c("red", "orange", "yellow"),
+ pred_line_lty = 1,
+ ci_polygon_col = c(rgb(1,0,0),
+ rgb(1,0.5,0),
+ rgb(1,1,0)),
+ ci_polygon_alpha = 0.4,
+ legend_position = c(2.25,13),
+ legend_title = "Predictor x4",
+ legend_title_size = 0.9,
+ legend_args = list(legend = c("a", "b", "c"),
+ col = c("red", "orange", "yellow"),
+ lty = c(1, 1, 1),
+ lwd = c(2, 2, 2),
+ pch = c(16, 16, 16),
+ cex = 0.75,
+ bty = "n"))
Robust standard errors for rlm model computed using: HC0
> par(old_xpd_mar)
>
> #------------------------------------------
> # 3. Generalized least squares (gls)
> #------------------------------------------
> mod.gls <- gls(y ~ x1 + x2 + x4,
+ correlation = corAR1(form = ~1|group),
+ data = sim.data)
> easyViz(model = mod.gls, data = sim.data, predictor = "x4",
+ jitter_data_points = TRUE,
+ bty = "n",
+ xlab = "Predictor x4",
+ ylab = "Response y",
+ point_col = rgb(0,0,1,0.2),
+ pred_point_col = "blue",
+ cat_labels = c("group A", "group B", "group C"))
Note: CIs for gls models use the fixed-effect covariance matrix.
>
> # Categorical x categorical interaction & outer legend
> sim.data$x5 <- sample(c(rep("CatA", 50), rep("CatB", 50)))
> mod.gls2 <- gls(y ~ x1 + x2 + x4 * x5,
+ correlation = corAR1(form = ~1|group),
+ data = sim.data)
> old_xpd_mar <- par(xpd = TRUE, mar = c(5.1, 4.1, 4.1, 5.1))
> easyViz(model = mod.gls2, data = sim.data, predictor = "x4",
+ by = "x5",
+ jitter_data_points = TRUE,
+ ylim = c(-15,15),
+ xlab = "Predictor x4",
+ ylab = "Response y",
+ cat_labels = c("group A", "group B", "group C"),
+ point_col = c(rgb(0,0,1,0.2), rgb(1,0,0,0.2)),
+ pred_point_col = c("blue", "red"),
+ ci_bar_col = c("blue", "blue", "blue", "red", "red", "red"),
+ ci_bar_caps = 0,
+ legend_position = c(3.4, 15),
+ legend_args = list(title = "Pred x5",
+ title.cex = 1,
+ legend = c("A", "B"),
+ pt.cex = 1.25,
+ horiz = TRUE,
+ inset = c(-0.2, 0)))
Note: CIs for gls models use the fixed-effect covariance matrix.
> par(old_xpd_mar)
>
> #------------------------------------------
> # 4. Nonlinear least squares (nls)
> #------------------------------------------
> mod.nls <- nls(y ~ a * sin(b * x3) + c,
+ data = sim.data,
+ start = list(a = 5, b = 1, c = 0))
> summary(mod.nls)
Formula: y ~ a * sin(b * x3) + c
Parameters:
Estimate Std. Error t value Pr(>|t|)
a 5.31584 0.54493 9.755 4.53e-16 ***
b 1.08158 0.04723 22.898 < 2e-16 ***
c 0.51338 0.44399 1.156 0.25
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 3.979 on 97 degrees of freedom
Number of iterations to convergence: 3
Achieved convergence tolerance: 3.031e-06
> easyViz(model = mod.nls, data = sim.data, predictor = "x3",
+ pred_on_top = TRUE,
+ font_family = "serif",
+ bty = "n",
+ xlab = "Predictor x3",
+ ylab = "Response y",
+ point_col = rgb(0,1,0,0.7),
+ point_pch = 1,
+ ci_type = "lines",
+ ci_line_col = "black",
+ ci_line_lty = 2)
Note: CIs for nls models use a delta-method approximation.
> text(x = 2.5, y = 11,
+ labels = expression(Y %~% 5.31584 %*% sin(1.08158 %*% X[3]) + 0.51338),
+ cex = 0.7)
>
> #------------------------------------------
> # 5. Generalized linear model (glm)
> #------------------------------------------
> mod.glm <- glm(binary_y ~ x1 + x4 + offset(log(exposure)),
+ family = binomial(link="cloglog"),
+ data = sim.data)
> easyViz(model = mod.glm, data = sim.data, predictor = "x1",
+ fix_values = list(x4="b", exposure=1),
+ xlab = "Predictor x1",
+ ylab = "Response y",
+ binary_data_type = "binned",
+ point_col = "black",
+ ci_polygon_col = "red",
+ ci_polygon_alpha = 1)
>
> # Customize data points
> easyViz(model = mod.glm, data = sim.data, predictor = "x4",
+ bty = "n",
+ xlab = "Predictor x4",
+ ylab = "Response y",
+ binary_data_type = "plain",
+ jitter_data_points = TRUE,
+ point_col = "black",
+ point_pch = "|",
+ point_cex = 0.5)
>
> # Binomial glm for proportion data
> mod.glm2 <- glm(y1/y3 ~ x1 + x4, weights = y3,
+ family = binomial(link="logit"),
+ data = sim.data)
> easyViz(model = mod.glm2, data = sim.data, predictor = "x1",
+ pred_on_top = TRUE,
+ xlab = "Predictor x1",
+ ylab = "Response y",
+ point_col = "black",
+ ci_polygon_col = "red")
Detected successes / trials response. Plotting success proportions.
>
> # Transform response predictions to percentage
> easyViz(model = mod.glm2, data = sim.data, predictor = "x1",
+ pred_transform = function(x) 100 * x,
+ pred_on_top = TRUE,
+ xlab = "Predictor x1",
+ ylab = "Response y",
+ show_data_points = FALSE,
+ point_col = "black",
+ ci_polygon_col = "red",
+ plot_args = list(yaxt = "n"))
Warning: Argument 'pred_transform' is being applied to predictions on the RESPONSE scale.
These predictions have already been transformed via the model's inverse-link function.
Ensure this does not result in an unintended double-transformation.
> axis(2, at = pretty(par("usr")[3:4]),
+ labels = paste0(pretty(par("usr")[3:4]), "%"),
+ las = 1)
>
> #------------------------------------------
> # 6. Negative binomial GLM (glm.nb)
> #------------------------------------------
> mod.glm.nb <- glm.nb(count_y ~ x2 + offset(log(exposure)),
+ data = sim.data)
> easyViz(model = mod.glm.nb, data = sim.data, predictor = "x2",
+ font_family = "mono",
+ bty = "L",
+ plot_args = list(main = "NB model"),
+ xlab = "Predictor x2",
+ ylab = "Response y",
+ ci_polygon_col = "blue")
Offset detected:
plotting (count_y / exposure) * 1 (rate scaled to exposure = 1).
Looks like you are modeling a rate.
Setting exposure 'exposure' to 1 so predictions are on the unit-rate scale.
To obtain predictions on a different rate scale, specify the argument
fix_values = c(exposure = ...).
>
> #------------------------------------------
> # 7. Beta regression (betareg)
> #------------------------------------------
> sim.data$prop <- y1/y3
> mod.betareg <- betareg(prop ~ x1 * x4, offset = log(exposure),
+ data = sim.data, link= "cloglog")
> easyViz(model = mod.betareg, data = sim.data, predictor = "x1",
+ fix_values = c(exposure = 6),
+ xlab = "Predictor x1",
+ ylab = "Response y",
+ ci_polygon_col = "forestgreen",
+ show_conditioning = TRUE)
Note: CIs for betareg models use a delta-method approximation.
Prediction conditioning summary
- Held fixed in prediction grid: x4 = c; exposure = 6
- Varied in prediction grid: x1
>
> #------------------------------------------
> # 8. Survival model (coxph)
> #------------------------------------------
> mod.surviv <- coxph(Surv(y3, binary_y) ~ poly(x1,2) + x4, data=sim.data)
> easyViz(model = mod.surviv, data = sim.data, predictor = "x1",
+ pred_type = "link",
+ xlab = "Predictor x1",
+ ci_polygon_col = "orange2",
+ ci_polygon_alpha = 1,
+ show_conditioning = TRUE)
Detected a coxph model. Raw data points are not plotted for survival models.
Error in a$specials[[i]] : subscript out of bounds
Calls: easyViz ... ez_compute_predictions -> predict -> predict.coxph -> delete.response -> off
Execution halted
Flavor: r-devel-linux-x86_64-debian-gcc