Dear all,
a customer is asking if possible to plot the contours for his model predictions and/or prediction intervals across the entire range of possible values for my independent variables.
He gets it in R (using the expand.grid function), where the dotted line is the lower 95% prediction interval (attachment 1).
The best he was able to do (and me too) is the attachment 2 and, in short, he and I where not able to have the dotted line. (I have also a dummy set of data with the graph)
He also posted the question in the community.
Do you have any suggestion?
thanks
Hi @MarcoSalfi ,
The expand.grid function acts like FacetGrid in Seaborn for Python or facet_grid function in R's ggplot2. It basically does all possible combinations of one or more factors fed in as a formula or matrix. What is the full line of R code used with expand.grid function? I am guessing the rest of the plotting code is what is giving the plot for density with the dashed line box.
Hi Marco,
One option might be to create a space filling design to adequately cover the range of possibilities your user wishes to explore and then evaluate the formula for all combinations in the space filling design.
However, I would try asking what information he is wishing to obtain by creating the plot? A better alternative may be a profiler graph of the formula or the regression model - without and with extrapolation control. The profiler is a much better way of taming complexity of the high dimensionality of this problem. We might wish to give the usual warning about the danger of extrapolating outside the range of the X space (or design space) when using empirical models.
Malcolm
hi @Chris_Kirchberg , following the code used by the customer:
## Transform variables
log.AlphaLISA = log(AlphaLISA)
log.rabbit = log(Rabbit.Ab)
log.mouse = log(Mouse.Ab)
log.lysate = log(Lysate)
fit = lm( Log.AlphaLISA ~ Ab*(log.rabbit+log.mouse+log.lysate)^2 +
Ab*I(log.rabbit^2) + Ab*I(log.mouse^2) +
Ab*I(log.lysate^2) )
d.grid = expand.grid(
Ab=c("R1-M1", "R1-M2", "R2-M1", "R2-M2", "R3-M1", "R3-M2"),
log.rabbit=seq(log(0.3), log(3), length=5),
log.mouse=seq(log(0.3), log(3), length=10),
log.lysate=seq(log(0.25), log(2), length=10)
)
## 95% lower prediction interval
d.grid = cbind(d.grid,
predict(fit, newdata=d.grid, interval="prediction", level=0.9))
d.grid[,"lower95p"] = exp(d.grid[,"lwr"])
thanks Malcolm,
discussion is going to this direction. Actually the customer is also open to other options.