Search code examples
rr-car

marginalModelPlots error "need finite 'xlim' values"


I'm trying to run some diagnostics on a binary logistic regression model. Specifically, the marginal model plots. Unfortunately, I keep getting the "need finite 'xlim' values" error. The code below reproduces the issue. My model includes both numeric and categorical variables (which get converted to dummy variables in the model). Anyway, I know this error can occur when all values are NA, but that isn't the case for any of my data and I'm not sure whats going on.

set.seed(020275)
df <- data.frame(y=sample(c(0,1), 10, replace=TRUE), 
             cat=sample(c("Red", "Blue", "Green"), 10, replace=TRUE), 
             loc=sample(c("North", "South", "East", "West"), 10,  replace=TRUE), 
             count=runif(10, 0, 10),
             stringsAsFactors = FALSE)

glmModel <- glm(y ~ cat + loc + count, family=binomial(), data=df)
glmModel

library(car)
marginalModelPlots(glmModel)

I get the following error:

Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf

Looking for some ideas/suggestions/guidance on how to deal with this.


Solution

  • It appears the character data typed vectors (cat and loc in the example above) are not compatible with marginalModelPlots, at least for the version of the car package I'm currently using (2.1-1). I found I could use the terms parameter to limit the plots to a subset of the variables while also including the Linear Predictor plot (as shown below).

    marginalModelPlots(glmModel, terms= ~ count)
    

    maringalModelPlots image