Functions > Data Analysis > Curve Fitting > Example: Rational Function Regression 1
Example: Rational Function Regression 1
rationalfit
Use the rationalfit function to fit a rational polynomial to data.
1. Define a data set.
This data set comes from a NIST study of semiconductor electron mobility. The predictor variable, vx, is the natural log of the density. The response variable, vy, is a measure of electron mobility.
2. Specify an order for the numerator and denominator of the rational function.
The fitting function has the following form:
3. Define a confidence limit.
4. Call the rationalfit function.
The first column of the output contains the values for the parameters. The second and third column contain outputs for the lower and upper confidence limits, respectively.
5. Compare the values of the parameters to the correct values, as found on the NIST web site.
6. Plot the data, the rational function regression, and the fit defined by the NIST parameters.
The fit of the rational function regression is almost perfect, as confirmed by the correlation coefficient:
Plot of Residuals
Create a plot of residuals to visualize the goodness of fit for the above regression.
1. Define the degree of freedom.
2. Calculate the residuals.
3. Calculate the residual sum of squares.
4. Calculate the standard deviation.
5. Repeat steps 2 to 4 with the values from the NIST website.
6. Compare the results for the two fits.
7. Plot the data points and the residuals.
Constraints, Standard Deviation, and Tolerance
There are several optional arguments to rationalfit: the standard deviation vector; the lower and upper bounds matrix; the accuracy; and "no scale". You can use any of the optional arguments alone, but for the first three arguments defined above, the order of the arguments matters.
1. Create a matrix of lower and upper bounds on the parameters.
2. Create a vector of standard deviations for the parameters.
When a vector of standard deviations is entered as an argument to the rationalfit function, the solver minimizes the following function:
If the standard deviation is 0 for a point, then the original, undeviated function is used at that point, that is, StdYi is set to 1.
3. Set the accuracy. The default is 10-7.
4. 4. Call the rationalfit function. Compare the returned parameter values to the correct values from the NIST web site.
The rationalfit function performs an automatic scaling on input data, so that the accuracy can remain scale-invariant. It then rescales the output parameters to match the original data. Most of the time, this ensures that your fit is achieved regardless of the relative scale of your input data. If you are having trouble achieving a good fit, add the “noscale” option string at the end of the argument list to turn off this option.