Print out prediction type
For functions like estimate_relation(), it is not obvious whether Predicted and CI columns are expectations, new-data predictions or link predictions. Include a line at the bottom of the print out about the prediction type.
That's a good point! But the scale of the predicted values is already printed in the output, however, information on expectations or new-data predictions could be added.
library(modelbased)
model <- glm(vs ~ wt, data = mtcars, family = "binomial")
estimate_relation(model, by = "wt=c(1,2,3)", predict = "link")
#> Model-based Predictions
#>
#> wt | Predicted | SE | 95% CI
#> -------------------------------------
#> 1 | 3.80 | 1.59 | [ 0.68, 6.93]
#> 2 | 1.89 | 0.92 | [ 0.10, 3.69]
#> 3 | -0.02 | 0.44 | [-0.89, 0.86]
#>
#> Variable predicted: vs
#> Predictors modulated: wt=c(1,2,3)
#> Predictions are on the link-scale.
estimate_relation(model, by = "wt=c(1,2,3)")
#> Model-based Predictions
#>
#> wt | Predicted | SE | 95% CI
#> ------------------------------------
#> 1 | 0.98 | 0.03 | [0.66, 1.00]
#> 2 | 0.87 | 0.10 | [0.52, 0.98]
#> 3 | 0.50 | 0.11 | [0.29, 0.70]
#>
#> Variable predicted: vs
#> Predictors modulated: wt=c(1,2,3)
#> Predictions are on the response-scale.
estimate_link(model, by = "wt=c(1,2,3)")
#> Model-based Predictions
#>
#> wt | Predicted | SE | 95% CI
#> -------------------------------------
#> 1 | 3.80 | 1.59 | [ 0.68, 6.93]
#> 2 | 1.89 | 0.92 | [ 0.10, 3.69]
#> 3 | -0.02 | 0.44 | [-0.89, 0.86]
#>
#> Variable predicted: vs
#> Predictors modulated: wt=c(1,2,3)
#> Predictions are on the link-scale.
Created on 2025-04-24 with reprex v2.1.1
Okay, I wasn't even getting those lines.
mtcars$f_cyl <- factor(mtcars$cyl)
m1 <- lm(mpg ~ factor(cyl) * wt + hp, mtcars)
m2 <- lm(mpg ~ f_cyl * wt + hp, mtcars)
modelbased::estimate_relation(m2)
#> Model-based Predictions
#>
#> f_cyl | wt | hp | Predicted | SE | 95% CI
#> ---------------------------------------------------------
#> 4 | 1.51 | 52.00 | 31.61 | 1.26 | [29.02, 34.20]
#> 4 | 1.95 | 52.00 | 29.21 | 0.89 | [27.38, 31.04]
#> 4 | 2.38 | 52.00 | 26.82 | 0.80 | [25.17, 28.46]
#> 4 | 2.82 | 52.00 | 24.42 | 1.06 | [22.24, 26.59]
#> 4 | 1.51 | 83.44 | 30.91 | 1.22 | [28.39, 33.42]
#> 4 | 1.95 | 83.44 | 28.51 | 0.83 | [26.81, 30.21]
#> 4 | 2.38 | 83.44 | 26.11 | 0.71 | [24.65, 27.58]
#> 4 | 2.82 | 83.44 | 23.72 | 0.98 | [21.69, 25.74]
#> 6 | 2.82 | 114.89 | 20.88 | 1.20 | [18.41, 23.35]
#> 6 | 3.25 | 114.89 | 19.47 | 0.95 | [17.52, 21.43]
#> 6 | 2.82 | 146.33 | 20.18 | 1.21 | [17.70, 22.67]
#> 6 | 3.25 | 146.33 | 18.77 | 1.00 | [16.72, 20.83]
#> 8 | 3.25 | 177.78 | 17.42 | 0.96 | [15.45, 19.39]
#> 8 | 3.69 | 177.78 | 16.48 | 0.76 | [14.90, 18.05]
#> 8 | 4.12 | 177.78 | 15.54 | 0.73 | [14.04, 17.04]
#> 8 | 4.55 | 177.78 | 14.60 | 0.86 | [12.82, 16.37]
#> 8 | 4.99 | 177.78 | 13.66 | 1.11 | [11.37, 15.94]
#> 8 | 5.42 | 177.78 | 12.71 | 1.41 | [ 9.80, 15.63]
#> 8 | 3.25 | 209.22 | 16.72 | 0.89 | [14.89, 18.55]
#> 8 | 3.69 | 209.22 | 15.78 | 0.68 | [14.38, 17.17]
#> 8 | 4.12 | 209.22 | 14.84 | 0.63 | [13.54, 16.14]
#> 8 | 4.55 | 209.22 | 13.90 | 0.78 | [12.29, 15.50]
#> 8 | 4.99 | 209.22 | 12.96 | 1.05 | [10.80, 15.11]
#> 8 | 5.42 | 209.22 | 12.01 | 1.36 | [ 9.21, 14.82]
#> 8 | 3.25 | 240.67 | 16.02 | 0.96 | [14.03, 18.00]
#> 8 | 3.69 | 240.67 | 15.08 | 0.77 | [13.49, 16.66]
#> 8 | 4.12 | 240.67 | 14.14 | 0.73 | [12.64, 15.63]
#> 8 | 4.55 | 240.67 | 13.19 | 0.86 | [11.43, 14.96]
#> 8 | 4.99 | 240.67 | 12.25 | 1.10 | [ 9.98, 14.53]
#> 8 | 5.42 | 240.67 | 11.31 | 1.40 | [ 8.42, 14.20]
#> 8 | 3.25 | 272.11 | 15.32 | 1.15 | [12.95, 17.69]
#> 8 | 3.69 | 272.11 | 14.38 | 0.99 | [12.33, 16.42]
#> 8 | 4.12 | 272.11 | 13.44 | 0.96 | [11.47, 15.41]
#> 8 | 4.55 | 272.11 | 12.49 | 1.06 | [10.32, 14.67]
#> 8 | 4.99 | 272.11 | 11.55 | 1.26 | [ 8.95, 14.15]
#> 8 | 5.42 | 272.11 | 10.61 | 1.53 | [ 7.46, 13.77]
#> 8 | 3.25 | 303.56 | 14.62 | 1.41 | [11.72, 17.52]
#> 8 | 3.69 | 303.56 | 13.68 | 1.28 | [11.04, 16.31]
#> 8 | 4.12 | 303.56 | 12.74 | 1.25 | [10.16, 15.31]
#> 8 | 4.55 | 303.56 | 11.79 | 1.33 | [ 9.06, 14.53]
#> 8 | 4.99 | 303.56 | 10.85 | 1.49 | [ 7.77, 13.93]
#> 8 | 5.42 | 303.56 | 9.91 | 1.73 | [ 6.35, 13.47]
#> 8 | 3.25 | 335.00 | 13.92 | 1.70 | [10.41, 17.42]
#> 8 | 3.69 | 335.00 | 12.97 | 1.60 | [ 9.69, 16.26]
#> 8 | 4.12 | 335.00 | 12.03 | 1.57 | [ 8.80, 15.27]
#> 8 | 4.55 | 335.00 | 11.09 | 1.63 | [ 7.73, 14.45]
#> 8 | 4.99 | 335.00 | 10.15 | 1.77 | [ 6.51, 13.80]
#> 8 | 5.42 | 335.00 | 9.21 | 1.97 | [ 5.16, 13.26]
#>
#> Variable predicted: mpg
#> Predictors modulated: f_cyl, wt, hp
packageVersion("modelbased")
#> [1] '0.10.0.30'
Created on 2025-04-24 with reprex v2.1.1
yes, for Gaussian, there's no scale except response. So we keep it minimal.
D'oh, yeah. 🤦 So, it's just about the interval type then.
Maybe the minimal thing to do would be to message whenever the CI is a prediction interval, instead of a confidence or expectation interval?
Yes, that's something we should add.