jacob-long / jtools

Tools for summarizing/visualizing regressions and other helpful stuff
https://jtools.jacob-long.com
GNU General Public License v3.0
164 stars 22 forks source link

int.type doesn't have any effect #116

Closed alanocallaghan closed 2 years ago

alanocallaghan commented 3 years ago

int.type="prediction" just returns CIs for effect_plot and make_predictions. Expected behaviour in comment to follow

library("jtools")
mod <- lm(mpg ~ cyl, mtcars)
head(predict(mod, newdata = mtcars, interval = "confidence"))
#>                        fit      lwr      upr
#> Mazda RX4         20.62984 19.46586 21.79382
#> Mazda RX4 Wag     20.62984 19.46586 21.79382
#> Datsun 710        26.38142 24.53365 28.22918
#> Hornet 4 Drive    20.62984 19.46586 21.79382
#> Hornet Sportabout 14.87826 13.21576 16.54075
#> Valiant           20.62984 19.46586 21.79382
head(predict(mod, newdata = mtcars, interval = "prediction"))
#>                        fit       lwr      upr
#> Mazda RX4         20.62984 13.979849 27.27982
#> Mazda RX4 Wag     20.62984 13.979849 27.27982
#> Datsun 710        26.38142 19.578351 33.18448
#> Hornet 4 Drive    20.62984 13.979849 27.27982
#> Hornet Sportabout 14.87826  8.123156 21.63335
#> Valiant           20.62984 13.979849 27.27982
head(make_predictions(mod, new_data = mtcars[, c("mpg", "cyl")], int.type = "confidence"))
#> # A tibble: 6 × 4
#>     mpg   cyl  ymax  ymin
#>   <dbl> <dbl> <dbl> <dbl>
#> 1  20.6     6  21.8  19.5
#> 2  20.6     6  21.8  19.5
#> 3  26.4     4  28.2  24.5
#> 4  20.6     6  21.8  19.5
#> 5  14.9     8  16.5  13.2
#> 6  20.6     6  21.8  19.5
head(make_predictions(mod, new_data = mtcars[, c("mpg", "cyl")], int.type = "prediction"))
#> # A tibble: 6 × 4
#>     mpg   cyl  ymax  ymin
#>   <dbl> <dbl> <dbl> <dbl>
#> 1  20.6     6  21.8  19.5
#> 2  20.6     6  21.8  19.5
#> 3  26.4     4  28.2  24.5
#> 4  20.6     6  21.8  19.5
#> 5  14.9     8  16.5  13.2
#> 6  20.6     6  21.8  19.5
effect_plot(mod, pred = "cyl", interval = TRUE, int.type = "confidence")

effect_plot(mod, pred = "cyl", interval = TRUE, int.type = "prediction")

alanocallaghan commented 3 years ago

Expected behaviour (see #117)

devtools::load_all("/home/alan/Documents/github/jtools")
#> ℹ Loading jtools
mod <- lm(mpg ~ cyl, mtcars)
head(predict(mod, newdata = mtcars, interval = "confidence"))
#>                        fit      lwr      upr
#> Mazda RX4         20.62984 19.46586 21.79382
#> Mazda RX4 Wag     20.62984 19.46586 21.79382
#> Datsun 710        26.38142 24.53365 28.22918
#> Hornet 4 Drive    20.62984 19.46586 21.79382
#> Hornet Sportabout 14.87826 13.21576 16.54075
#> Valiant           20.62984 19.46586 21.79382
head(predict(mod, newdata = mtcars, interval = "prediction"))
#>                        fit       lwr      upr
#> Mazda RX4         20.62984 13.979849 27.27982
#> Mazda RX4 Wag     20.62984 13.979849 27.27982
#> Datsun 710        26.38142 19.578351 33.18448
#> Hornet 4 Drive    20.62984 13.979849 27.27982
#> Hornet Sportabout 14.87826  8.123156 21.63335
#> Valiant           20.62984 13.979849 27.27982
head(make_predictions(mod, new_data = mtcars[, c("mpg", "cyl")], int.type = "confidence"))
#> # A tibble: 6 × 4
#>     mpg   cyl  ymin  ymax
#>   <dbl> <dbl> <dbl> <dbl>
#> 1  20.6     6  19.5  21.8
#> 2  20.6     6  19.5  21.8
#> 3  26.4     4  24.5  28.2
#> 4  20.6     6  19.5  21.8
#> 5  14.9     8  13.2  16.5
#> 6  20.6     6  19.5  21.8
head(make_predictions(mod, new_data = mtcars[, c("mpg", "cyl")], int.type = "prediction"))
#> # A tibble: 6 × 4
#>     mpg   cyl  ymin  ymax
#>   <dbl> <dbl> <dbl> <dbl>
#> 1  20.6     6 14.0   27.3
#> 2  20.6     6 14.0   27.3
#> 3  26.4     4 19.6   33.2
#> 4  20.6     6 14.0   27.3
#> 5  14.9     8  8.12  21.6
#> 6  20.6     6 14.0   27.3
effect_plot(mod, pred = "cyl", interval = TRUE, int.type = "confidence")

effect_plot(mod, pred = "cyl", interval = TRUE, int.type = "prediction")

alanocallaghan commented 2 years ago

bump