Hi Tiffany,
It seems like you want to fit a combination of a Gaussian curve and a polynomial curve to your data.
The problem you are referring to is known as segmented regression or piecewise regression, which involves finding a piecewise continuous function to best describe the data.
Typically, to solve a segmented regression problem, the least squares method is applied separately to each segment.
The two regression lines are made to fit the data set as closely as possible while minimizing the sum of squares of the differences (SSD) between observed (y) and calculated (Yr) values of the dependent variable.
Since the exact data is not provided, I have prepared a model dataset by combining samples from a polynomial and a Gaussian curve:
Refer to the following code:
y1 = (6/-119000).*(x1-120);
et1 = -1+2.*rand(size(y1));
et2 = -1+2.*rand(size(y2));
fitSegPoly.m
function [fitresult, gof] = fitSegPoly(x1, y1)
[xData, yData] = prepareCurveData( x1, y1 );
[fitresult, gof] = fit( xData, yData, ft );
figure( 'Name', 'polySegmentFit' );
h = plot( fitresult, xData, yData );
legend( h, 'y1 vs. x1', 'polySegmentFit', 'Location', 'NorthEast', 'Interpreter', 'none' );
xlabel( 'x1', 'Interpreter', 'none' );
ylabel( 'y1', 'Interpreter', 'none' );
fitSegGauss.m
function [fitresult, gof] = fitSegGauss(x2, y2)
[xData, yData] = prepareCurveData( x2, y2 );
ft = fittype( 'gauss1' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Lower = [-Inf -Inf 0];
opts.StartPoint = [0.00810733661388935 125 32.2342882092758];
[fitresult, gof] = fit( xData, yData, ft, opts );
figure( 'Name', 'gaussSegmentFit' );
h = plot( fitresult, xData, yData );
legend( h, 'y2 vs. x2', 'gaussSegmentFit', 'Location', 'NorthEast', 'Interpreter', 'none' );
xlabel( 'x2', 'Interpreter', 'none' );
ylabel( 'y2', 'Interpreter', 'none' );
The following curves are produced for the segments:
Once you identify a suitable breakpoint, you can fit the respective segments using a polynomial and a Gaussian curve separately. Alternatively, you can also try to fit a higher order Gaussian curve to your data, without segmenting.
Refer to the following MATLAB documentation for further reference: