Running examples in ‘modelbased-Ex.R’ failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: estimate_slopes
> ### Title: Estimate Marginal Effects
> ### Aliases: estimate_slopes
> 
> ### ** Examples
> 
> ## Don't show: 
> if (all(insight::check_if_installed(c("marginaleffects", "emmeans", "effectsize", "mgcv", "ggplot2", "see"), quietly = TRUE))) withAutoprint({ # examplesIf
+ ## End(Don't show)
+ library(ggplot2)
+ # Get an idea of the data
+ ggplot(iris, aes(x = Petal.Length, y = Sepal.Width)) +
+   geom_point(aes(color = Species)) +
+   geom_smooth(color = "black", se = FALSE) +
+   geom_smooth(aes(color = Species), linetype = "dotted", se = FALSE) +
+   geom_smooth(aes(color = Species), method = "lm", se = FALSE)
+ 
+ # Model it
+ model <- lm(Sepal.Width ~ Species * Petal.Length, data = iris)
+ # Compute the marginal effect of Petal.Length at each level of Species
+ slopes <- estimate_slopes(model, trend = "Petal.Length", by = "Species")
+ slopes
+ 
+ # What is the *average* slope of Petal.Length? This can be calculated by
+ # taking the average of the slopes across all Species, using `comparison`.
+ # We pass a function to `comparison` that calculates the mean of the slopes.
+ estimate_slopes(
+   model,
+   trend = "Petal.Length",
+   by = "Species",
+   comparison = ~I(mean(x))
+ )
+ 
+ ## Not run: 
+ ##D # Plot it
+ ##D plot(slopes)
+ ##D standardize(slopes)
+ ##D 
+ ##D model <- mgcv::gam(Sepal.Width ~ s(Petal.Length), data = iris)
+ ##D slopes <- estimate_slopes(model, by = "Petal.Length", length = 50)
+ ##D summary(slopes)
+ ##D plot(slopes)
+ ##D 
+ ##D model <- mgcv::gam(Sepal.Width ~ s(Petal.Length, by = Species), data = iris)
+ ##D slopes <- estimate_slopes(model,
+ ##D   trend = "Petal.Length",
+ ##D   by = c("Petal.Length", "Species"), length = 20
+ ##D )
+ ##D summary(slopes)
+ ##D plot(slopes)
+ ##D 
+ ##D # marginal effects, grouped by Species, at different values of Petal.Length
+ ##D estimate_slopes(model,
+ ##D   trend = "Petal.Length",
+ ##D   by = c("Petal.Length", "Species"), length = 10
+ ##D )
+ ##D 
+ ##D # marginal effects at different values of Petal.Length
+ ##D estimate_slopes(model, trend = "Petal.Length", by = "Petal.Length", length = 10)
+ ##D 
+ ##D # marginal effects at very specific values of Petal.Length
+ ##D estimate_slopes(model, trend = "Petal.Length", by = "Petal.Length=c(1, 3, 5)")
+ ##D 
+ ##D # average marginal effects of Petal.Length,
+ ##D # just for the trend within a certain range
+ ##D estimate_slopes(model, trend = "Petal.Length=seq(2, 4, 0.01)")
+ ## End(Not run)
+ ## Don't show: 
+ }) # examplesIf
> library(ggplot2)
> ggplot(iris, aes(x = Petal.Length, y = Sepal.Width)) + geom_point(aes(color = Species)) + 
+     geom_smooth(color = "black", se = FALSE) + geom_smooth(aes(color = Species), 
+     linetype = "dotted", se = FALSE) + geom_smooth(aes(color = Species), method = "lm", 
+     se = FALSE)
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
`geom_smooth()` using formula = 'y ~ x'
> model <- lm(Sepal.Width ~ Species * Petal.Length, data = iris)
> slopes <- estimate_slopes(model, trend = "Petal.Length", by = "Species")
Error in `[.data.table`(out, , `:=`(tmp_idx, seq_len(.N)), by = tmp) : 
  attempt access index 10/10 in VECTOR_ELT
Calls: withAutoprint ... eval -> eval -> estimate_slopes -> get_marginaltrends
Execution halted
Examples with CPU (user + system) or elapsed time > 5s
                     user system elapsed
estimate_contrasts 10.105  0.456  16.696