Plotting curved confidence intervals for linear regression

14 visualizaciones (últimos 30 días)
Xen
Xen el 9 de Jun. de 2018
Editada: Chris Angeloni el 20 de Jul. de 2020
I am using coefCI function to estimate the confidence intervals of a linear model. I can plot this and get linear confidence bands for the regression line, but, I've seen plots of linear regression where the bands are curved. How can I get those? Thanks.

Respuesta aceptada

Star Strider
Star Strider el 22 de Jul. de 2018
I did not see your post before.
Use the appropriate version of the predict (link) function for a compact linear model, predict (link) for a generalised linear model, or others, depending on what you are doing.
Those will give the confidence intervals. If you want to plot smooth curves, use:
xv = linspace(min(x), max(x), 1000);
for the independent variable ‘Xnew’ to use with predict.
  8 comentarios
Prabhjot Dhami
Prabhjot Dhami el 4 de Ag. de 2019
This answer appears to work great for a model with a single predictor.
However, when trying to use it with a model in which I have multiple predictors (e.g. 5), I get the following error:
Error using classreg.regr.CompactTermsRegression/designMatrix (line 166)
X must have 5 columns.
Error in LinearModel/predict (line 337)
design = designMatrix(model,Xpred);
Any idea as to how to plot confidence intervals from a fitlm structure based on a multiple linear regression model?
Chris Angeloni
Chris Angeloni el 20 de Jul. de 2020
Editada: Chris Angeloni el 20 de Jul. de 2020
The short answer is that you get this error because you have multiple predictors, so the values in Xnew (or xv in the example above) should have a column for each predictor. (ie. you need to make an xv for every predictor in your multiple regression).
This makes visualizing the data tricky, because for every additional predictor, you add another dimension to your plot, I believe. The question here I think was focused mostly on linear regression with one predictor.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by