Azzera filtri
Azzera filtri

Using multiple dependent variables in fit function

5 visualizzazioni (ultimi 30 giorni)
I used the curve fitter app to generate a custom fit function with 9 dependent variables. When I run it I only get one goodness of fit (gof). How do I get a goodness of fit for each 9 variables I fit in the function?
Thanks for any help!!
function [fitresult, gof] = createFit(wavenumber, frame1)
%% Fit: 'after_cycle1_-1.25V_frame1'.
[xData, yData] = prepareCurveData( wavenumber, frame1 );
% Set up fittype and options.
ft = fittype( ['intensity_NR*exp(-((frequency_NR)/bandwidth_NR)^2)+...' ...
'intensity_LF*exp(-((x-frequency_LF)/bandwidth_LF)^2)+...' ...
'intensity_HF/(1+((frequency_HF-x)/bandwidth_HF)^2)'],...
'independent', 'x', 'dependent', 'y' );
excludedPoints = (xData < 1900) | (xData > 2175);
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [15 150 100 2080 2055 2030 1300 150 70];
opts.Exclude = excludedPoints;
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );

Risposte (1)

Manikanta Aditya
Manikanta Aditya il 26 Mar 2024
Spostato: Matt J il 26 Mar 2024
Check this:
function [fitresult, gof, paramTests] = createFit(wavenumber, frame1)
%% Fit: 'after_cycle1_-1.25V_frame1'.
[xData, yData] = prepareCurveData(wavenumber, frame1);
% Set up fittype and options.
ft = fittype(['intensity_NR*exp(-((frequency_NR)/bandwidth_NR)^2)+...' ...
'intensity_LF*exp(-((x-frequency_LF)/bandwidth_LF)^2)+...' ...
'intensity_HF/(1+((frequency_HF-x)/bandwidth_HF)^2)'], ...
'independent', 'x', 'dependent', 'y');
excludedPoints = (xData < 1900) | (xData > 2175);
opts = fitoptions('Method', 'NonlinearLeastSquares');
opts.Display = 'Off';
opts.StartPoint = [15 150 100 2080 2055 2030 1300 150 70];
opts.Exclude = excludedPoints;
% Fit model to data.
[fitresult, gof] = fit(xData, yData, ft, opts);
% Extract parameter estimates and confidence intervals
paramEstimates = fitresult.b;
paramCIs = confint(fitresult);
% Perform hypothesis testing on each parameter
alpha = 0.05; % Significance level
numParams = length(paramEstimates);
paramTests = cell(numParams, 1);
for i = 1:numParams
paramValue = paramEstimates(i);
paramCI = paramCIs(:, i);
% Perform t-test (assuming normal distribution)
tStat = paramValue / sqrt(fitresult.covb(i, i));
pValue = 2 * tcdf(-abs(tStat), fitresult.dfe);
% Store the test result
paramTests{i} = struct('Estimate', paramValue, ...
'ConfidenceInterval', paramCI, ...
'tStatistic', tStat, ...
'pValue', pValue);
end
end
  2 Commenti
Jaclyn Rebstock
Jaclyn Rebstock il 26 Mar 2024
Spostato: Matt J il 26 Mar 2024
This worked beautifully. Thanks!!
Manikanta Aditya
Manikanta Aditya il 27 Mar 2024
Great to know @Jaclyn Rebstock, if you found answer helpful you can accept it so that others can refer it if needed.

Accedi per commentare.

Categorie

Scopri di più su Interpolation in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by