Hello, i'm trying to get p-value from a fitting performed with fit function, but i cannot find how to do so, i can only get r2 and RMSE.
Should i use some other function rather than fit?
here my code and the data, hope it will be understandable. thanks you very much in advance.
ft = fittype('(m*c*k*x)/((1-k*x)*(1+(c-1)*k*x))', ...
'dependent',{'y'}, ...
'independent',{'x'}, ...
'coefficients',{'m','c','k'});
coef = ["Xm","Cg","K","R2","RMSE"];
figure (1);
[f,gof] = fit(x,y, ft,'StartPoint',[0.2, 5, 1]);
plot(f);
hold on
plot(x,y);
figure(2);
plot(f,x,y,"residuals");
%save coefficients
format long g
c = coeffvalues(f);
R2 = gof.rsquare;
RMSE = gof.rmse;
r = horzcat(c,R2,RMSE);
coef = [coef;r];

 Akzeptierte Antwort

Pratyush
Pratyush am 15 Mai 2024

1 Stimme

Hi federico,
To obtain p-values for the coefficients from a fitting process in MATLAB, you should use the "fitnlm" function from the Statistics and Machine Learning Toolbox instead of the "fit" function from the Curve Fitting Toolbox. The "fitnlm" function fits non-linear models and provides detailed statistical analysis, including p-values for the model coefficients, which help assess their statistical significance. Here's a brief guide on how to adjust your code:
  1. Define your model function directly in the code.
  2. Use "fitnlm" with your data, model function, and initial parameter guesses to fit the non-linear model.
  3. Extract coefficient estimates and their p-values from the fitted model object for analysis.
  4. Use MATLAB's plotting functions to visualize the fit and residuals as needed.
Hope this helps.

3 Kommentare

Hello! thank you for the kind reply, i am tryig to do so but not really doing well, stopping at the very beginning. there what i've written so far, but i get errors immediatley.
% this should my function as before but ewritten
model = @(b,x) (b(1)*b(2)*b(3)*x)/((1-b(3)*x)*(1+(b(2)-1)*b(3)*x))
% these are the initial parameter guesses
beta0 = [0.2 5 1];
% and this should run the non linear fitting
mdl = fitnlm(x,y,model,beta0)
Do you know where is the issue here?
Thanks a lot in advance.
Use array operators ./ and .* to handle array x properly:
model = @(b,x) (b(1)*b(2)*b(3)*x)./((1-b(3)*x).*(1+(b(2)-1)*b(3)*x))
% ^^ ^^
federico drudi
federico drudi am 23 Mai 2024
Lovely! THANK YOU ALL

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Linear and Nonlinear Regression finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by