Using multiple dependent variables in fit function

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 );

답변 (1개)

Manikanta Aditya
Manikanta Aditya 2024년 3월 26일
이동: Matt J 2024년 3월 26일
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

Jaclyn Rebstock
Jaclyn Rebstock 2024년 3월 26일
이동: Matt J 2024년 3월 26일
This worked beautifully. Thanks!!
Great to know @Jaclyn Rebstock, if you found answer helpful you can accept it so that others can refer it if needed.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

제품

질문:

2024년 3월 26일

댓글:

2024년 3월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by