Multiple regression with nonlinear variables

Hello,
I am working with the attached dataset, where the first column represents temperature and the next six columns (2–7) correspond to temperature-dependent properties.
I would like to explore whether it is possible to model temperature as a function of these six properties simultaneously, similar to a multiple regression approach. I have previously done this with linear responses, but in this case, the relationships are nonlinear (sigmoidal, Z-shaped).
I considered using a generalized additive model (GAM), but I have no prior experience with this method and may be overlooking a simpler or more suitable approach.
Could anyone provide insights or suggestions on how to best tackle this?
Thanks in advance! :)

 Réponse acceptée

I am not certain what you want to do.
Fitting a generalized additive model (GAM) for regression using the fitrgam function would go something like this —
T1 = readtable('temp-vs-properties.txt')
T1 = 9x7 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7 ____ _______ _______ _______ _______ _______ _______ 12 10.941 2.2536 1.029 4.8549 10.633 0.45658 25 9.8131 2.2364 1.0215 4.3878 9.6068 0.45674 50 6.7255 2.2287 0.97971 3.0177 6.8649 0.43959 75 3.6134 2.1326 0.88567 1.6944 4.0799 0.4153 100 1.3233 1.7712 0.64251 0.74709 2.0595 0.36275 125 0.51476 1.2776 0.38488 0.40291 1.3374 0.30126 150 0.2727 0.96724 0.24871 0.28194 1.0965 0.25713 175 0.19387 0.85354 0.19718 0.22713 0.98321 0.23101 200 0.16745 0.86259 0.18527 0.19413 0.90385 0.21478
VN = T1.Properties.VariableNames;
figure
plot(T1{:,1}, T1{:,2:end})
grid
xlabel(VN{1})
ylabel('Properties')
legend(VN{2:end}, Location='best')
Mdl = fitrgam(T1, 'Var1')
Mdl =
RegressionGAM PredictorNames: {'Var2' 'Var3' 'Var4' 'Var5' 'Var6' 'Var7'} ResponseName: 'Var1' CategoricalPredictors: [] ResponseTransform: 'none' Intercept: 101.3333 IsStandardDeviationFit: 0 NumObservations: 9
I am not certain that I am plotting your data correctly.
There are other options, such as fitnlm that might be more appropriate, depending on what you want to do.
.

4 commentaires

My goal is to model Var1 as a function of Var2 through Var7 simultaneously, similar to a multiple regression approach.
This fitrgam call does that.
I also creaztted a function that fits each column as gaussians.
The individual columns are fitted to:
The function works, however the initial parameeter extimates could be more appropriate.
T1 = readtable('temp-vs-properties.txt')
T1 = 9x7 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7 ____ _______ _______ _______ _______ _______ _______ 12 10.941 2.2536 1.029 4.8549 10.633 0.45658 25 9.8131 2.2364 1.0215 4.3878 9.6068 0.45674 50 6.7255 2.2287 0.97971 3.0177 6.8649 0.43959 75 3.6134 2.1326 0.88567 1.6944 4.0799 0.4153 100 1.3233 1.7712 0.64251 0.74709 2.0595 0.36275 125 0.51476 1.2776 0.38488 0.40291 1.3374 0.30126 150 0.2727 0.96724 0.24871 0.28194 1.0965 0.25713 175 0.19387 0.85354 0.19718 0.22713 0.98321 0.23101 200 0.16745 0.86259 0.18527 0.19413 0.90385 0.21478
VN = T1.Properties.VariableNames;
figure
plot(T1{:,1}, T1{:,2:end})
grid
xlabel(VN{1})
ylabel('Properties')
legend(VN{2:end}, Location='best')
np = 4;
x = T1{:,2:end};
y = T1{:,1};
Mdl = fitnlm(x, y, @(b,x)gfit(b,x,np), rand(np*size(x,2),1)+5)
Warning: Rank deficient, rank = 15, tol = 3.394038e-14.
Warning: Rank deficient, rank = 6, tol = 2.199340e-14.
Warning: Rank deficient, rank = 6, tol = 2.198351e-14.
Warning: The model is overparameterized, and model parameters are not identifiable. You will not be able to compute confidence or prediction intervals, and you should use caution in making predictions.
Mdl =
Nonlinear regression model: y ~ F(b,x) Estimated Coefficients: Estimate SE tStat pValue ___________ __________ ___________ ___________ b1 -4142.6 3.2032e-16 -1.2933e+19 1.4311e-150 b2 -62.858 1.9618e-32 -3.2041e+33 1.0082e-265 b3 685.64 8.1732e-49 8.3888e+50 0 b4 17.201 3.6866 4.6659 0.0016112 b5 5.865 1.3694e-80 4.2829e+80 0 b6 5.8148 2.4084e-96 2.4144e+96 0 b7 5.9381 5.785e-113 1.0265e+113 0 b8 16.291 3.6866 4.4189 0.0022297 b9 5.9551 0 Inf 0 b10 5.3737 0 Inf 0 b11 5.1931 0 Inf 0 b12 17.173 3.6866 4.6581 0.0016275 b13 805.24 0 Inf 0 b14 8.2765 0 Inf 0 b15 731.55 0 Inf 0 b16 16.91 3.6866 4.5869 0.0017859 b17 -8.8137e+05 0 -Inf 0 b18 8109.5 0 Inf 0 b19 92794 0 Inf 0 b20 17.003 3.6866 4.6121 0.0017279 b21 5.8773 0 Inf 0 b22 5.1137 0 Inf 0 b23 5.6659 0 Inf 0 b24 16.756 3.6866 4.5451 0.0018866 Number of observations: 9, Error degrees of freedom: 8 Root Mean Squared Error: 66.4 R-Squared: 0, Adjusted R-Squared 0 F-statistic vs. zero model: 21, p-value = 0.0018
parameters = array2table(reshape(Mdl.Coefficients.Estimate, 4, []), RowNames={'b(1)','b(2)','b(3)','b(4)'}, VariableNames=compose('Var%d',2:7))
parameters = 4x6 table
Var2 Var3 Var4 Var5 Var6 Var7 _______ ______ ______ ______ ___________ ______ b(1) -4142.6 5.865 5.9551 805.24 -8.8137e+05 5.8773 b(2) -62.858 5.8148 5.3737 8.2765 8109.5 5.1137 b(3) 685.64 5.9381 5.1931 731.55 92794 5.6659 b(4) 17.201 16.291 17.173 16.91 17.003 16.756
function Var1 = gfit(b,Var2_7,np)
% np = 4;
% size(Var2_7,2)
for k = 1:size(Var2_7,2)
bref = (1:np)+np*(k-1);
term(:,k) = b(bref(1)).*exp(-(Var2_7(:,k)-b(bref(2))).^2*b(bref(3))) + b(bref(4));
end
Var1 = sum(term,2);
end
% % for k = 1:7
% % bref = (1:3)+3*(k-1)
% % end
.
That's exactly what I was looking for!
Thanks a lot :)
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by