There are several method for curve fitting should be summarized for latter use.
1. "Solver" in Excel
Step1 Define the objective parameters;
Step2 Calculate the objective function with initial estimation of parameters and the observation data;
Step3 Calculate and sum " { y_obs [ i ]-y_pred [ i ] }^2 ";
Step4 Click "Solver" in the "Tool" tab;
Step5 Select the "objective cell" and let "Solver" guess the "changed cell", and press "Solve"
Advantage: Easy to implement without coding;
Disadvantage: Time-consuming in estimating the reasonable initial value of parameters without priori-knowledge.
2. "lsqcurvefit" and "nlinfit"function F=fun(x,xdata)F=(x(1)./(xdata-x(2))).^(x(3)+1).*exp(-x(1)./(xdata-x(2)))/(x(1)*gamma(x(3)));
xdata=[0.00020381 0.000305715 0.00045857];
ydata=[11.14050727 20.10060944 30.02599];x0=[0.00397 -0.0028687 0.822];
[x,resnorm]=nlinfit(xdata,ydata,@fun,x0) or[x,resnorm]=lsqcurvefit(@fun,x0,xdata,ydata)
MaxValue=max(xdata);
MinValue=min(xdata);
x1=[MinValue:MaxValue/25:MaxValue];
y1=(x(1)./(xdata-x(2))).^(x(3)+1).*exp(-x(1)./(xdata-x(2)))/(x(1)*gamma(x(3)));
loglog(xdata, ydata, 'ko',xdata,y1,'k-')
Summary: The "Isqcurvefit" doesn't need very accurate initial estimation of parameters,however, the result is much worse than solver or good initial estimation of parameters. The "nlinfit" needs good estimation of initial parameters to get results.
3. Maximum Likelihood Estimation
The advantage of this method is the loose need for the accurate initial estimation of the parameters. And, it is super-good method to do the curve fitting for the data set span several orders of magnitude.
Open the M file of “Inverse_Gamma”
Step1. Prepare Input Data
Copy the bin of landslide area into “A_L” at line 5;
Copy the calculated probability into “y” at line 11;
Copy the frequency of landslides into “y_freq” at line 15;
Step2. Change function ‘mlecustom’ in MATLAB Open ‘mlecustom’ with the path of “InstallationDrive:Matlabtoolboxstatsprivatemlecustom.m”;
Or type ‘mlecustom’ in MATLAB Editor, then, select the string, right-click the string, and select ‘Open Selection’ in the popup list;
Right after the function head, type in “global y_freq”;
At line 150, replace “uncensFreq=freq(c);” with “uncensFreq =y_freq;”
Step3. Output
Run the script (Inverse_Gamma.m) in MATLAB Editor;
The optimized parameters and the coefficient of determination will be showed in the command window;
The fitting curve is showed in the figure window;