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!