I'm trying to make my results more intuitive, and so I want to compare the predicted values at the interquartile range. I'm trying to figure out how to get the predicted value for a given variable, keeping everything else at the median.
I've tried something like this:
x_1 <- rnorm(20) x_2 <- rnorm(20) y <- x_1 + x_2 + rnorm(20) z <- data.frame(y,x_1,x_2) fit <- lm(y~x_1 + x_2,data = z) predict(fit,newdata = data.frame(x_1=c(quantile(x_1),quantile(x_1)), x_2=median(x_2)))
which works, but my actual model has 10+ variables, and this starts to get ugly really quickly, so I figure there must be a better way?