What does "viewport has zero dimensions" mean in check_model function in the performance package for R?

Viewed 191

Data for Question

Here is my data:

structure(list(Mins_Work = c(435L, 350L, 145L, 135L, 15L, 60L, 
60L, 390L, 395L, 395L, 315L, 80L, 580L, 175L, 545L, 230L, 435L, 
370L, 255L, 515L, 330L, 65L, 115L, 550L, 420L, 45L, 266L, 196L, 
198L, 220L, 17L, 382L, 0L, 180L, 343L, 207L, 263L, 332L, 259L, 
417L, 282L, 685L, 517L, 111L, 64L, 466L, 499L, 460L, 269L, 300L, 
427L, 301L, 436L, 342L, 229L, 379L, 102L, 146L, 94L, 345L, 73L, 
204L, 512L, 113L, 135L, 458L, 493L, 552L, 108L, 335L, 395L, 508L, 
546L, 396L, 159L, 325L, 747L, 650L, 377L, 461L, 669L, 186L, 220L, 
410L, 708L, 409L, 515L, 413L, 166L, 451L, 660L, 177L, 192L, 191L, 
461L, 637L, 297L, 601L, 586L, 270L, 479L, 480L, 397L, 174L, 111L, 
0L, 610L, 332L, 345L, 423L, 160L, 611L, 345L, 550L, 324L, 427L, 
505L, 632L, 560L, 230L, 495L, 235L, 522L, 654L, 465L, 377L, 260L, 
572L, 612L, 594L, 624L, 237L, 38L, 409L, 634L, 292L, 706L, 399L, 
568L, 694L, 298L, 616L, 553L, 581L, 423L, 636L, 623L, 338L, 345L, 
521L, 438L, 504L, 600L, 616L, 656L, 285L, 474L, 688L, 278L, 383L, 
535L, 363L, 470L, 457L, 303L, 123L, 363L, 329L, 513L, 636L, 421L, 
220L, 430L, 428L, 536L, 156L, 615L, 429L, 103L, 332L, 250L, 281L, 
248L, 435L, 589L, 515L, 158L, 649L, 427L, 193L, 225L, 280L, 163L, 
536L, 301L, 406L, 230L, 519L, 303L, 472L, 392L, 326L, 368L, 405L, 
515L, 308L, 259L, 769L, 93L, 517L, 261L, 420L, 248L, 265L, 834L, 
313L, 131L, 298L, 134L, 385L, 648L, 529L, 487L, 533L, 641L, 429L, 
339L, 508L, 560L, 439L, 381L, 397L, 692L, 534L, 148L, 366L, 167L, 
425L, 476L, 384L, 498L, 502L, 308L, 360L, 203L, 410L, 626L, 593L, 
409L, 531L, 157L, 357L, 443L, 615L, 564L, 341L, 352L, 609L, 686L, 
386L, 323L, 362L, 597L, 325L, 51L, 570L, 579L, 284L, 530L, 171L, 
640L, 263L, 112L, 217L, 152L, 203L, 394L, 135L, 234L, 507L, 224L, 
174L, 210L, 138L, 52L, 326L, 413L, 695L, 370L, 256L, 327L, 490L, 
128L, 469L, 567L, 359L, 561L, 478L, 233L, 550L, 390L, 406L, 56L, 
47L, 258L, 332L, 114L), Coffee_Cups = c(3L, 0L, 2L, 6L, 4L, 5L, 
3L, 3L, 2L, 2L, 3L, 1L, 1L, 3L, 2L, 2L, 0L, 1L, 1L, 4L, 4L, 3L, 
0L, 1L, 3L, 0L, 0L, 0L, 0L, 2L, 0L, 1L, 2L, 3L, 2L, 2L, 4L, 3L, 
3L, 4L, 6L, 8L, 3L, 5L, 0L, 2L, 2L, 8L, 6L, 4L, 6L, 4L, 4L, 2L, 
6L, 6L, 5L, 1L, 1L, 5L, 4L, 6L, 5L, 0L, 6L, 6L, 4L, 4L, 2L, 2L, 
6L, 6L, 7L, 3L, 3L, 0L, 5L, 7L, 6L, 3L, 5L, 3L, 3L, 1L, 9L, 9L, 
3L, 3L, 6L, 6L, 6L, 3L, 0L, 7L, 6L, 6L, 3L, 9L, 3L, 8L, 8L, 3L, 
7L, 6L, 3L, 3L, 3L, 6L, 6L, 6L, 1L, 9L, 3L, 2L, 6L, 3L, 6L, 9L, 
6L, 8L, 9L, 6L, 6L, 6L, 0L, 3L, 0L, 3L, 3L, 6L, 3L, 0L, 3L, 0L, 
2L, 0L, 6L, 6L, 6L, 6L, 3L, 9L, 3L, 0L, 0L, 6L, 3L, 3L, 3L, 3L, 
6L, 0L, 6L, 3L, 3L, 5L, 5L, 3L, 0L, 6L, 4L, 2L, 0L, 2L, 4L, 0L, 
6L, 4L, 4L, 2L, 2L, 0L, 9L, 6L, 3L, 6L, 6L, 9L, 0L, 6L, 6L, 6L, 
6L, 6L, 6L, 3L, 3L, 9L, 6L, 3L, 6L, 6L, 1L, 6L, 6L, 6L, 6L, 6L, 
3L, 9L, 6L, 3L, 6L, 9L, 3L, 5L, 6L, 3L, 0L, 6L, 3L, 3L, 5L, 0L, 
6L, 3L, 5L, 3L, 0L, 6L, 7L, 3L, 6L, 6L, 6L, 6L, 3L, 5L, 6L, 7L, 
6L, 6L, 4L, 6L, 4L, 5L, 5L, 6L, 8L, 6L, 6L, 6L, 9L, 3L, 3L, 9L, 
7L, 8L, 4L, 3L, 3L, 6L, 6L, 6L, 3L, 4L, 3L, 3L, 6L, 4L, 3L, 3L, 
4L, 6L, 0L, 3L, 6L, 4L, 3L, 7L, 4L, 4L, 3L, 1L, 6L, 4L, 6L, 5L, 
3L, 6L, 6L, 3L, 6L, 3L, 5L, 6L, 6L, 3L, 6L, 4L, 9L, 7L, 6L, 3L, 
3L, 3L, 4L, 6L, 3L, 6L, 3L, 4L, 4L, 3L, 5L, 5L, 5L), Start_Work = c(1015L, 
1000L, 945L, 1400L, 1500L, 915L, 930L, 1000L, 940L, 840L, 730L, 
1700L, 945L, 1040L, 955L, 945L, 930L, 745L, 800L, 955L, 1030L, 
1115L, 905L, 930L, 815L, 830L, 950L, 1108L, 1430L, 955L, 1313L, 
1125L, 1636L, 1126L, 1027L, 1323L, 1003L, 918L, 950L, 913L, 1244L, 
656L, 930L, 718L, 1744L, 759L, 928L, 912L, 857L, 930L, 907L, 
920L, 1029L, 1027L, 1211L, 914L, 1226L, 1337L, 1900L, 1313L, 
1118L, 800L, 700L, 1544L, 1350L, 905L, 1025L, 0L, 942L, 930L, 
1234L, 1222L, 925L, 0L, 2018L, 945L, 500L, 447L, 0L, 818L, 604L, 
632L, 1015L, 930L, 748L, 732L, 900L, 739L, 848L, 957L, 930L, 
1144L, 627L, 1200L, 825L, 624L, 736L, 846L, 1119L, 933L, 937L, 
631L, 1319L, 931L, 1019L, 2141L, 900L, 820L, 920L, 925L, 619L, 
917L, 1413L, 1014L, 910L, 1300L, 947L, 0L, 825L, 956L, 926L, 
1057L, 959L, 1056L, 1243L, 1147L, 1541L, 945L, 800L, 806L, 1000L, 
816L, 1619L, 806L, 745L, 540L, 710L, 800L, 446L, 926L, 758L, 
930L, 812L, 718L, 0L, 750L, 619L, 1134L, 1206L, 221L, 816L, 726L, 
924L, 850L, 513L, 915L, 800L, 858L, 444L, 807L, 703L, 658L, 1004L, 
700L, 700L, 1015L, 1011L, 1028L, 910L, 822L, 843L, 1052L, 901L, 
700L, 1047L, 802L, 900L, 807L, 2209L, 0L, 930L, 1014L, 842L, 
312L, 824L, 938L, 930L, 813L, 854L, 907L, 715L, 1137L, 1404L, 
942L, 830L, 1152L, 900L, 1017L, 1218L, 1017L, 642L, 832L, 700L, 
838L, 940L, 1300L, 829L, 950L, 848L, 818L, 650L, 1001L, 900L, 
813L, 830L, 746L, 828L, 828L, 751L, 853L, 419L, 517L, 1221L, 
800L, 808L, 747L, 1049L, 606L, 1005L, 958L, 843L, 856L, 0L, 744L, 
1630L, 715L, 1629L, 648L, 657L, 718L, 840L, 711L, 944L, 933L, 
744L, 913L, 750L, 818L, 1048L, 102L, 754L, 1050L, 817L, 728L, 
719L, 643L, 805L, 738L, 738L, 921L, 1200L, 738L, 743L, 704L, 
1725L, 741L, 628L, 447L, 747L, 711L, 601L, 806L, 918L, 921L, 
1015L, 608L, 1149L, 1021L, 641L, 630L, 801L, 805L, 844L, 850L, 
641L, 640L, 736L, 816L, 702L, 533L, 902L, 829L, 628L, 720L, 703L, 
713L, 1100L, 634L, 714L, 906L, 709L, 750L, 645L, 740L, 1005L, 
657L, 1012L), Day_Name = c("Wednesday", "Thursday", "Friday", 
"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", 
"Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", 
"Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", 
"Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", 
"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", 
"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Monday", 
"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", 
"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", 
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", 
"Saturday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", 
"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", 
"Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", 
"Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", 
"Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", 
"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", 
"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", 
"Sunday", "Monday", "Wednesday", "Thursday", "Friday", "Saturday", 
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", 
"Saturday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", 
"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", 
"Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", 
"Thursday", "Friday", "Saturday", "Monday", "Tuesday", "Wednesday", 
"Thursday", "Friday", "Saturday", "Sunday", "Tuesday", "Wednesday", 
"Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", 
"Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", 
"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", 
"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", 
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", 
"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", 
"Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", 
"Thursday", "Friday", "Saturday", "Sunday", "Tuesday", "Wednesday", 
"Thursday", "Friday", "Sunday", "Monday", "Tuesday", "Wednesday", 
"Thursday", "Friday", "Saturday", "Monday", "Tuesday", "Wednesday", 
"Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", 
"Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", 
"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", 
"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", 
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", 
"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", 
"Friday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", 
"Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", 
"Thursday", "Friday", "Sunday", "Monday", "Tuesday", "Wednesday", 
"Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", 
"Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", 
"Tuesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", 
"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", 
"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", 
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", 
"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", 
"Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", 
"Thursday", "Friday", "Saturday", "Sunday")), class = "data.frame", row.names = c(NA, 
-307L))

Problem

I have fit a linear mixed effects model with the following code:

library(lmerTest)
library(performance)
fit.work <- lmer(Mins_Work ~ Coffee_Cups + Start_Work +
                   (1|Day_Name),
                 data = slack.work)

When I try to run the check_model function:

check_model(fit.work)

I get this error:

Error in grid.Call(C_convert, x, as.integer(whatfrom), as.integer(whatto),  : 
  Viewport has zero dimension(s)

However if I save check_model(fit.work) as an object check.fit and run the operators for the object (such as check.fit$PP_CHECK), I have no issues running the plots. What is causing this error? I tried searching for this error but the pages I landed on seemed to not have real info on what was causing this. My best guess is that the plotting window is having issues with fitting all the plots into my plot viewer, but I'm not sure how to fix that.

Edit

I tried fixing the issue by following the advice below and changing the data.

slack.work.fixed <- as.data.frame(slack.work)
fit.work <- lmer(Mins_Work ~ Coffee_Cups + Start_Work +
                   (1|Day_Name),
                 data = slack.work.fixed)

However this gives me a new error:

Error: The RStudio 'Plots' window
  is too small to show this
  set of plots.
  Please make the window
  larger.

No matter how much I maximize the size of my plot window in RStudio, it doesn't do much to fix the issue. check_model(fit.work)

1 Answers

In check_model, there is check_model.default.

check_model.default <- function(x,
                                dot_size = 2,
                                line_size = .8,
                                panel = TRUE,
                                check = "all",
                                alpha = .2,
                                dot_alpha = .8,
                                colors = c("#3aaf85", "#1b6ca8", "#cd201f"),
                                theme = "see::theme_lucid",
                                detrend = FALSE,
                                verbose = TRUE,
                                ...) {
  # check model formula
  if (verbose) {
    insight::formula_ok(x)
  }
  
  minfo <- insight::model_info(x, verbose = FALSE)
  
  if (minfo$is_bayesian) {
    ca <- suppressWarnings(.check_assumptions_stan(x))
  } else if (minfo$is_linear) {
    ca <- suppressWarnings(.check_assumptions_linear(x, minfo))
  } else {
    ca <- suppressWarnings(.check_assumptions_glm(x, minfo))
  }
  # else {
  #   stop(paste0("`check_assumptions()` not implemented for models of class '", class(x)[1], "' yet."), call. = FALSE)
  # }
  
  attr(ca, "panel") <- panel
  attr(ca, "dot_size") <- dot_size
  attr(ca, "line_size") <- line_size
  attr(ca, "check") <- check
  attr(ca, "alpha") <- alpha
  attr(ca, "dot_alpha") <- dot_alpha
  attr(ca, "detrend") <- detrend
  attr(ca, "colors") <- colors
  attr(ca, "theme") <- theme
  attr(ca, "model_info") <- minfo
  attr(ca, "overdisp_type") <- list(...)$plot_type
  ca
}

With your model, error occurs in .check_assumptions_linear first.

.check_assumptions_linear <- function(model, model_info) {
  dat <- list()
  
  dat$VIF <- .diag_vif(model)
  dat$QQ <- .diag_qq(model)
  dat$REQQ <- .diag_reqq(model, level = .95, model_info = model_info)
  dat$NORM <- .diag_norm(model)
  dat$NCV <- .diag_ncv(model)
  dat$HOMOGENEITY <- .diag_homogeneity(model)
  dat$OUTLIERS <- check_outliers(model, method = "cook")
  if (!is.null(dat$OUTLIERS)) {
    threshold <- attributes(dat$OUTLIERS)$threshold$cook
  } else {
    threshold <- NULL
  }
  dat$INFLUENTIAL <- .influential_obs(model, threshold = threshold)
  dat$PP_CHECK <- tryCatch(check_predictions(model), error = function(e) NULL)
  
  dat <- insight::compact_list(dat)
  class(dat) <- c("check_model", "see_check_model")
  dat
}

In .check_assumptions_linear, error occurs in .diag_vif. It seems it works for other .diag_...s.

.diag_vif <- function(model) {
  out <- check_collinearity(model)
  dat <- insight::compact_list(out)
  if (is.null(dat)) {
    return(NULL)
  }
  dat$group <- "low"
  dat$group[dat$VIF >= 5 & dat$VIF < 10] <- "moderate"
  dat$group[dat$VIF >= 10] <- "high"
  
  dat <- datawizard::data_rename(
    dat,
    c("Term", "VIF", "SE_factor", "Component"),
    c("x", "y", "se", "facet")
  )
  
  dat <- datawizard::data_select(dat, c("x", "y", "facet", "group"))
  
  if (insight::n_unique(dat$facet) <= 1) {
    dat$facet <- NULL
  }
  
  attr(dat, "CI") <- attributes(out)$CI
  dat
}

In .diag_vif, error occurs in datawizard::data_rename part.

It works till

out <- check_collinearity(model)
dat <- insight::compact_list(out)
if (is.null(dat)) {
  return(NULL)
}
dat$group <- "low"
dat$group[dat$VIF >= 5 & dat$VIF < 10] <- "moderate"
dat$group[dat$VIF >= 10] <- "high"

where dat is

Low Correlation

        Term  VIF      VIF  CI Increased SE Tolerance Tolerance  CI group
 Coffee_Cups 1.04 [1.00, 1.85]         1.02      0.96  [0.54, 1.00]   low
  Start_Work 1.04 [1.00, 1.85]         1.02      0.96  [0.54, 1.00]   low
Warning message:
In length(other == 1) && paste0(other, "_CI") %in% colnames(x) :
  'length(x) = 2 > 1' in coercion to 'logical(1)'

then error in

dat <- datawizard::data_rename(
  dat,
  c("Term", "VIF", "SE_factor", "Component"),
  c("x", "y", "se", "facet")
)

Error in `colnames<-`(`*tmp*`, value = `*vtmp*`) : 
  attempt to set 'colnames' on an object with less than two dimensions

It's weird that if we check names(dat), we can see

[1] "Term"              "VIF"               "VIF_CI_low"        "VIF_CI_high"      
[5] "SE_factor"         "Tolerance"         "Tolerance_CI_low"  "Tolerance_CI_high"
[9] "group"  

but there is no "SE_factor", "Component" when we view dat

We can remove this error using as.data.frame(dat) instead of dat in datawizard::data_rename

Then, next error occurs when

class(dat) <- c("check_model", "see_check_model")

If we remove this part from .check_assumptions_linear and try check_model.default(fit.work), the function gives proper result, plotting $PP_CHECK things with it's other components.

You may find it's source codes in

check_model, check_model_diagostics, and check_outliers

Related