Plotting confidence band based on a subset result from fitlm

1 次查看(过去 30 天)
Here there,
I was using regress to perform regress on given data but I am looking for a way to plot the confidence level band as well. I search the forum, someone recommend me to use fitlm and predict function. The model I am dealing with include a cross term. I search the MATLAB example and found something similar
load carsmall
X = [Acceleration,Weight];
T = [0 0 0;1 0 0;0 1 0;1 1 0;0 2 0];
mdl = fitlm(X,MPG,T);
% model : Y = a0 + a1*acceleration + a2*weight + a3*acceleration*weight + a4*weight^2
a0 = mdl.Coefficients.Estimate(1);
a1 = mdl.Coefficients.Estimate(2);
a2 = mdl.Coefficients.Estimate(3);
a3 = mdl.Coefficients.Estimate(4);
a4 = mdl.Coefficients.Estimate(5);
N = 200;
newAcc = linspace(min(Acceleration), max(Acceleration),N).';
newW = linspace(min(Weight), max(Weight),N).';
Xn = [newAcc, newW];
Y = a0 + a1*newAcc + a2*newW + a3*newAcc.*newW + a4*newW.^2;
In some threads, someone suggests to use predict to return the confidence level like
% Xn here is the new X input to find the fitted Y
[Yn, cil] = predict(mdl, Xn);
In the page https://www.mathworks.com/help/stats/linearmodel.predict.html, cil is called predict CIs band, is it the same as confidence levels band? I am sure sure if I remember it correctly but I read somewhere predict CIs is different from CIs?
Anyway, here predict estimates the CIs band for model between Y and X but that is not what I am looking for. In my case, I only care the cross term and the corresponding coefficient such that I need to plot the linear relation F = a3*acceleration (ignore weight). That is to say, I use the Y,X model to estimate all coefficients and find the linear relation about acceleration on the cross term. I wonder in this case, how should I compute and plot the CI band on F. Thanks.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Regression 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by