Precise Prediction Model Development

I have four coefficient for prediction model, x1, x2, y1 and y2. with the help of these four cofficient I have develop quadratic 15 coefficient model.
Model: y = B0+B1*X1+B2*Y1+B3*X2+B4*Y2+B5*X1Y1+B6*X1X2+B7*X1Y2+B8*Y1X2+B9*Y1Y2+B10*X2Y2+B11*X1^2+B12*Y1^2+B13*X2^2+B14*Y2^2
However, I am going to precise this model
Precise model:
y = B0 + B6*X1X2 + B9*Y1Y2 + B11*X1^2 + B12*Y1^2 + B13*X2^2 + B14*Y2^2
My concern is how can I buid a funciton which could response for the Precise model instead of quadratic one.
respone will be appreciated. Thank you

3 comentarios

Star Strider
Star Strider el 22 de Mayo de 2022
What are you predicting?
How does y fit in with this? Is it a separate vector?
.
suraj karki
suraj karki el 22 de Mayo de 2022
Editada: suraj karki el 22 de Mayo de 2022
Hello Strider
I have used 'fitlm' function to fit the data and y will be the response of the precise model.
suraj karki
suraj karki el 22 de Mayo de 2022
with four independent variable x1, y1, x2 and y2 defined in tabular form I have used fitlm function with quadratic type.
Which have provided 15 coefficient model but I want to develop a model which is going to include 7 coefficient i.e
y = B0 + B6*X1X2 + B9*Y1Y2 + B11*X1^2 + B12*Y1^2 + B13*X2^2 + B14*Y2^2
coeff{i}= fitlm(coeff_table(i).table, 'quadratic','RobustOpts','on');

Iniciar sesión para comentar.

 Respuesta aceptada

Star Strider
Star Strider el 22 de Mayo de 2022
What are you predicting?
How does y fit in with this? Is it a separate vector?
With those concerns met, building the function and estimating ther parameters is straightforward —
xy = [X1(:) X2(:) Y1(:) Y2(:)]
% % b(1) = B0, b(2) = B6, b(3) = B9, b(4) = B11, b(5) = B12, b(6) = B13, b(7) = B14
% yfcn = (b,xy) = b(1) + b(2).*xy(:,1).*xy(:,2) + b(3).*xy(:,3).*xy(:,4) + b(4).*xy(:,1).^2 + b(5).*xy(:,3).^2 + b(6).*xy(:,2).^2 + b(7).*xy(:,4).^2; % Regression Function
DM = [yfcn = (b,xy) = [ones(size(xy(:,1))), xy(:,1).*xy(:,2), *xy(:,3).*xy(:,4), *xy(:,1).^2, *xy(:,3).^2, xy(:,2).^2, xy(:,4).^2]; % Design Matrix
B = DM \ y(:) % Calculate Coefficients
I wrote ‘yfcn’ for record-keeping purposes, although you can use it with nonlilnear parameter estimation problems if you wish. However, since this is a linear problem, the ‘DM’ design matrix and the parameter calculation for ‘B’ in the following line will be most efficient.
Be sure to check it for coding errors in ‘DM’ in case I missed something.
.

4 comentarios

suraj karki
suraj karki el 22 de Mayo de 2022
I didnt understand the steps.
Actually, something like this —
T1 = array2table(randn(10,5),'VariableNames',{'y','X1','X2','Y1','Y2'}) % Create Data
T1 = 10×5 table
y X1 X2 Y1 Y2 _________ _________ ________ ________ _________ 0.49347 -0.39335 1.6959 -1.2509 -0.56473 0.22331 0.31047 1.1232 0.47735 0.40803 -0.6874 -0.069597 1.6491 -1.0242 1.0545 -1.399 -2.1349 1.5589 -0.75855 -0.029821 0.17651 -1.6427 -0.36282 0.1544 1.3891 -0.045791 0.097463 -0.1876 -0.68584 0.25768 -0.25065 -0.47585 0.13079 -0.59787 -0.73703 -0.79733 -0.14262 0.54596 -0.46641 0.69454 -1.3882 0.70808 0.82369 -0.19268 -0.16341 1.3585 1.6211 1.2087 3.1796 -1.2615
y = T1.y;
X1 = T1.X1;
X2 = T1.X2;
Y1 = T1.Y1;
Y2 = T1.Y2;
% DM = [ones(size(X1)), X1.*X2, Y1.*Y2, X1.^2, Y1.^2, X2.^2, Y2.^2];
DM = [X1.*X2, Y1.*Y2, X1.^2, Y1.^2, X2.^2, Y2.^2];
mdl = fitlm(DM,y,'linear')
mdl =
Linear regression model: y ~ 1 + x1 + x2 + x3 + x4 + x5 + x6 Estimated Coefficients: Estimate SE tStat pValue _________ _______ ________ _______ (Intercept) -0.68138 0.39737 -1.7147 0.18491 x1 0.013709 0.4344 0.031559 0.97681 x2 0.78314 0.43259 1.8103 0.16793 x3 -0.17528 0.25733 -0.68114 0.54465 x4 0.48237 0.21669 2.2261 0.1124 x5 -0.069877 0.28059 -0.24904 0.81941 x6 0.53053 0.51561 1.0289 0.37921 Number of observations: 10, Error degrees of freedom: 3 Root Mean Squared Error: 0.652 R-squared: 0.81, Adjusted R-Squared: 0.429 F-statistic vs. constant model: 2.13, p-value = 0.286
B = mdl.Coefficients.Estimate;
fprintf('\n\tB0 = %10.4f\n\tB6 = %10.4f\n\tB9 = %10.4f\n\tB11 = %10.4f\n\tB12 = %10.4f\n\tB13 = %10.4f\n\tB14 = %10.4f\n',B)
B0 = -0.6814 B6 = 0.0137 B9 = 0.7831 B11 = -0.1753 B12 = 0.4824 B13 = -0.0699 B14 = 0.5305
The ‘B0’ (intercept) term is implicit in the model, so it does not need to be explicitly stated, as it would be using the mldivide function to do the regression.
This is how I would do it.
.
suraj karki
suraj karki el 22 de Mayo de 2022
Thank you Strider
Star Strider
Star Strider el 22 de Mayo de 2022
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 22 de Mayo de 2022

Comentada:

el 22 de Mayo de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by