Error with ggeffects::ggpredict(): in seq.default(ra.min, ra.max, sqrt(ra.max - ra.min)/10) : 'by' argument is much too small

Viewed 87

I've run into an unknown error when using ggpredict() on model generated with lm():

Error in seq.default(ra.min, ra.max, sqrt(ra.max - ra.min)/10) :
'by' argument is much too small

Reproducible example

I have data about how people rated how much they like eating apples (on 1-7 scale). In addition, I have data about their age. So I want to fit a linear model of i_love_apple ~ age.

data

my_df <- structure(list(i_love_apple = c(3, 5, 6, 5, 4, 1, 1, 4, 6, 5, 
                                5, 7, 7, 1, 2, 3, 6, 5, 6, 7, 1, 3, 2, 5, 1, 1, 2, 1, 7, 3, 6, 
                                5, 4, 5, 4, 7, 2, 2, 7, 4, 4, 4, 5, 7, 4, 1, 7, 4, 5, 4, 2, 3, 
                                2, 7, 7, 3, 4, 7, 2, 4, 5, 6, 7, 7, 7, 5, 4, 3, 5, 4, 6, 5, 6, 
                                5, 7, 4, 2, 4, 5, 4, 5, 5, 3, 5, 4, 5, 6, 4, 3, 7, 5, 5, 5, 3, 
                                3, 7, 4, 7, 4, 6, 3, 5, 5, 4, 3, 3, 7, 6, 4, 4, 5, 4, 5, 5, 2, 
                                7, 6, 5, 3, 2, 4, 5, 5, 5, 5, 6, 7, 4, 6, 3, 5, 5, 5, 7, 2, 6, 
                                6, 5, 5, 2, 3, 3, 6, 6, 7, 5, 4, 5, 5, 6, 6, 3, 5, 4, 6, 5, 7, 
                                1, 5, 5, 4, 7, 6, 5, 4, 5, 5, 2, 3, 2, 4, 4, 7, 1, 4, 1, 2, 7, 
                                4, 4, 6, 1, 1, 4, 4, 3, 6, 7, 2, 4, 5, 3, 7, 7, 7, 5, 6, 6, 1, 
                                3, 1, 5, 5, 5, 7, 3, 5, 5, 4, 2, 6, 7, 5, 3, 6, 7, 4, 4, 1, 5, 
                                5, 5, 4, 5, 2, 3, 1, 5, 7, 4, 3, 5, 5, 7, 7, 6, 4, 5, 7, 6, 5, 
                                5, 6, 6, 4, 4, 1, 1, 4, 6, 6, 4, 7, 4, 5, 5, 5, 3, 1, 3, 1, 1, 
                                4, 2, 4, 5, 6, 5, 5, 2, 7, 1, 5, 5, 7, 7, 5, 1, 6, 6, 7, 4, 4, 
                                1, 6, 7, 7, 5, 5, 6, 6, 6, 6, 4, 4, 7, 4, 5, 7, 1, 3, 7, 3, 7, 
                                7, 6, 4, 7, 7, 7, 6, 3, 5, 7, 6, 2, 7, 4, 7, 5, 6, 1, 2, 3, 6, 
                                5, 4, 6, 3, 4, 6, 6, 5, 4, 4, 6, 3, 3, 6, 1, 5, 6, 4, 5, 5, 1, 
                                4, 1, 2, 4, 2, 5, 4, 6, 7, 7, 7), 
               age = c(22, 10, 48, 50, 32, 
                       18, 44, 63, 40, 43, 26, 37, 44, 33, 60, 51, 38, 50, 22, 63, 18, 
                       22, 47, 44, 22, 39, 46, 60, 45, 21, 49, 50, 34, 70, 23, 51, 23, 
                       17, 23, 18, 55, 69, 24, 52, 45, 34, 60, 45, 20, 50, 21, 56, 35, 
                       39, 61, 49, 38, 42, 35, 36, 61, 49, 58, 36, 60, 59, 21, 65, 17, 
                       54, 31, 21, 70, 50, 56, 55, 55, 1e+35, 57, 67, 36, 33, 56, 46, 
                       42, 29, 64, 52, 56, 34, 68, 40, 42, 55, 33, 56, 12, 55, 70, 45, 
                       35, 48, 62, 19, 27, 60, 60, 63, 55, 50, 35, 47, 34, 50, 41, 55, 
                       56, 46, 41, 46, 41, 23, 53, 19, 41, 44, 74, 40, 42, 63, 65, 70, 
                       62, 68, 38, 47, 75, 28, 37, 49, 48, 55, 35, 55, 29, 47, 48, 54, 
                       47, 41, 49, 36, 22, 69, 48, 56, 59, 38, 67, 43, 20, 21, 29, 55, 
                       20, 50, 47, 40, 54, 37, 44, 68, 38, 28, 44, 47, 30, 33, 18, 29, 
                       99, 43, 60, 35, 43, 40, 65, 43, 19, 24, 35, 20, 63, 66, 23, 45, 
                       56, 55, 21, 48, 63, 60, 37, 50, 60, 71, 56, 77, 35, 65, 60, 34, 
                       28, 47, 52, 45, 61, 50, 59, 31, 50, 50, 64, 63, 23, 40, 51, 64, 
                       44, 58, 39, 54, 45, 54, 35, 60, 44, 49, 42, 41, 45, 29, 46, 33, 
                       34, 22, 44, 43, 15, 43, 37, 20, 24, 55, 58, 48, 49, 42, 20, 478, 
                       43, 30, 77, 22, 44, 56, 48, 47, 65, 50, 44, 22, 51, 45, 20, 26, 
                       45, 11.5, 49, 61, 20, 42, 48, 31, 74, 52, 63, 46, 58, 43, 29, 
                       54, 46, 63, 48, 15, 58, 45, 45, 34, 38, 44, 40, 19, 48, 43, 50, 
                       31, 54, 29, 52, 72, 40, 73, 50, 53, 60, 38, 68, 62, 47, 42, 24, 
                       18, 47, 51, 20, 44, 50, 50, 44, 43, 51, 33, 41, 42, 27, 40, 47, 
                       50, 30, 42, 52, 33, 32, 45, 33, 40, 20, 48, 46, 59, 40, 49, 50, 
                       5, 49)), 
          row.names = c(NA, -357L), 
          class = c("tbl_df", "tbl", 
                    "data.frame"))

fitting the model

fit <- lm(i_love_apple ~ age, my_df)

using ggpredict() over fit

library(ggeffects)

ggpredict(fit, terms = "age")

Error in seq.default(ra.min, ra.max, sqrt(ra.max - ra.min)/10) : 
  'by' argument is much too small

I've never seen this error and it doesn't make a lot of sense to me, because the model did converge. Any idea?

1 Answers

The error is generated because of mistakes in your input data. Subject 260 has an age of 478, and subject 78's age is given as 1e+35, which would make them several trillion trillion times older than the visible universe. The function ggpredict throws when it tries to generate pretty breaks from this data set via the function pretty_range, in this line here:

ra <- seq(ra.min, ra.max, sqrt(ra.max - ra.min)/10)

which translates to:

ra <- seq(5, 1e35, 3.162278e16)

And seq sensibly refuses to attempt to allocate a vector with 3 quintillion elements (since even if you had enough memory this vector length is greater than .Machine$integer.max and therefore some of its elements couldn't be accessed directly in R).

Assuming these are data input errors, and the values are supposed to be 47 and 35 respectively, then we get the following result:

ggpredict(fit, terms = "age")
#> # Predicted values of i_love_apple
#> 
#> age | Predicted |       95% CI
#> ------------------------------
#>   0 |      3.57 | [2.99, 4.14]
#>  10 |      3.79 | [3.33, 4.25]
#>  30 |      4.23 | [3.98, 4.48]
#>  40 |      4.45 | [4.26, 4.64]
#>  50 |      4.67 | [4.48, 4.87]
#>  60 |      4.90 | [4.63, 5.16]
#>  70 |      5.12 | [4.75, 5.49]
#> 100 |      5.78 | [5.07, 6.50]
Related