Using multiple dependent variables in fit function
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Manikanta Aditya
el 26 de Mzo. de 2024
Movida: Matt J
el 26 de Mzo. de 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 comentarios
Manikanta Aditya
el 27 de Mzo. de 2024
Great to know @Jaclyn Rebstock, if you found answer helpful you can accept it so that others can refer it if needed.
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!