Using multiple dependent variables in fit function
조회 수: 3 (최근 30일)
이전 댓글 표시
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 );
댓글 수: 0
답변 (1개)
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
Manikanta Aditya
2024년 3월 27일
Great to know @Jaclyn Rebstock, if you found answer helpful you can accept it so that others can refer it if needed.
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!