| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Curve Fitting Toolbox |
| Contents | Index |
| Learn more about Curve Fitting Toolbox |
| On this page… |
|---|
The Surface Fitting Tool provides some example data generated from Franke's bivariate test function. This data is suitable for trying various fit settings in Surface Fitting Tool.
To load the example data and create, compare, and export surface fits, follow these steps:
To load example data to use in the Surface Fitting Tool, enter load franke at the MATLAB command line. The variables x, y, and z appear in your workspace.
The example data is generated from Franke's bivariate test function, with added noise and scaling, to create suitable data for trying various fit settings in Surface Fitting Tool. For details on the Franke function, see the following paper:
Franke, R., Scattered Data Interpolation: Tests of Some Methods, Mathematics of Computation 38 (1982), pp. 181–200.
To divide the data into fitting and validation data, enter the following syntax:
xv = x(200:293); yv = y(200:293); zv = z(200:293); x = x(1:199); y = y(1:199); z = z(1:199);
To fit a surface using this example data:
Open Surface Fitting Tool. Enter sftool, or select Start > Toolboxes > Curve Fitting > Surface Fitting Tool (sftool).
Select the variables x, y, and z interactively in the Surface Fitting Tool.

Alternatively, you can specify the variables when you enter sftool(x,y,z) to open Surface Fitting Tool (if necessary) and create a default fit.
The Surface Fitting Tool plots the data points as you select variables. When you select x, y, and z, the tool automatically creates a default surface fit. The default fit is an interpolating surface that passes through the data points.

Try a Lowess fit type. Select the Lowess fit type from the drop-down list in the Surface Fitting Tool.

The Surface Fitting Tool creates a local smoothing regression fit.
Try altering the fit settings. Enter 10 in the Span edit box.
By reducing the span from the default to 10% of the total number of data points you produce a surface that follows the data more closely. The span defines the neighboring data points the toolbox uses to determine each smoothed value.

Edit the Fit name to Smoothing regression.
If you divided your data into fitting and validation data in step 2, select this validation data. Use the validation data to help you check that your surface is a good model, by comparing it against some other data not used for fitting.
Select Fit > Specify Validation Data. The Specify Validation Data dialog box opens.
Select the validation variables in the drop-down lists for X input, Y input, and Z output: xv, yv, and zv.
Review your selected validation data in the plots and the validation statistics (SSE and RMSE) in the Results pane and the Table of Fits.

Create another fit to compare by making a copy of the current surface fit. Either select Fit > Duplicate "Smoothing regression", or right-click the fit in the Table of Fits, and select Duplicate
The tool creates a new fit figure with the same fit settings, data, and validation data. It also adds a new row to the table of fits at the bottom.
Change the fit type to Polynomial and edit the fit name to Polynomial.

Change the Degrees of x and y to 3, to fit a cubic polynomial in both dimensions.
Look at the scales on the x and y axes, and read the warning message in the Results pane:
Equation is badly conditioned. Remove repeated data points
or try centering and scaling.
Select the Center and scale check box to normalize and correct for the large difference in scales in x and y.

Normalizing the surface fit removes the warning message from the Results pane.
Look at the Results pane. You can view (and copy if desired):
The model equation
The values of the estimated coefficients
The goodness of fit statistics
The goodness of validation statistics
Linear model Poly33:
f(x,y) = p00 + p10*x + p01*y + p20*x^2 + p11*x*y...
+ p02*y^2 + p30*x^3 + p21*x^2*y
+ p12*x*y^2 + p03*y^3
where x is normalized by mean 1977 and std 866.5
and where y is normalized by mean 0.4932 and std 0.29
Coefficients (with 95% confidence bounds):
p00 = 0.4359 (0.3974, 0.4743)
p10 = -0.1375 (-0.194, -0.08104)
p01 = -0.4274 (-0.4843, -0.3706)
p20 = 0.0161 (-0.007035, 0.03923)
p11 = 0.07158 (0.05091, 0.09225)
p02 = -0.03668 (-0.06005, -0.01332)
p30 = 0.02081 (-0.005475, 0.04709)
p21 = 0.02432 (0.0012, 0.04745)
p12 = -0.03949 (-0.06287, -0.01611)
p03 = 0.1185 (0.09164, 0.1453)
Goodness of fit:
SSE: 4.125
R-square: 0.776
Adjusted R-square: 0.7653
RMSE: 0.1477
Goodness of validation:
SSE : 2.26745
RMSE : 0.155312
To export this fit information to the workspace, select Fit > Save to Workspace. Executing this command also exports other information such as the numbers of observations and parameters, residuals, and the fitted model.
You can treat the fitted model as a function to make predictions or evaluate the surface at values of X and Y. For details see Exporting a Fit to the Workspace.
Display the residuals plot to check the distribution of points relative to the surface. Select View > Residuals Plot.

Right-click the residuals plot to select the Go to X-Z view. The X-Z view is not required, but the view makes it easier to see to remove outliers.
To remove outliers, select Tools > Exclude Outliers.
When you move the mouse cursor to the plot, it changes to a cross-hair to show you are in outlier selection mode.
Click a point that you want to exclude in the surface plot or residuals plot. Alternatively, click and drag to define a rectangle and remove all enclosed points.
A removed plot point displays as a red star in the plots.

If you have Auto-fit selected, the Surface Fitting Tool refits the surface without the point. Otherwise, you can click Fit to refit the surface.
To return to rotation mode, select Tools > Rotate 3D.
To compare your fits side-by-side, use the tile tools. Select Window > Left/Right Tile, or use the toolbar buttons.

Review the information in the Table of Fits. Compare goodness of fit statistics for all fits in your session to determine which is best.
To save your interactive surface fitting session, select File > Save Session. You can save and reload sessions to access multiple fits. The session file contains all the fits and variables in your session and remembers your layout.
After interactively creating and comparing fits, you can generate an M-file for all fits and plots in your Surface Fitting Tool session. Select File > Generate M-File.
The Surface Fitting Tool creates an M-file from your session and displays the file in the MATLAB Editor. The file includes all fits and plots in your current session.
Save the file with the default name, createSurfaceFits.m.
You can recreate your fits and plots by calling the M-file from the command line (with your original data or new data as input arguments). In this case, your original variables still appear in the workspace.
Highlight and evaluate the first line of the M-file (excluding the word function). Either right-click and select Evaluate, press F9, or copy and paste the following to the command line:
[fitresult, gof] = createSurfaceFits(x, y, z, xv, yv, zv)
The function creates a figure window for each fit you had in your session. Observe that the polynomial fit figure shows both the surface and residuals plots that you created interactively in the Surface Fitting Tool.
If you want you can use the generated code as a starting point to change the surface fits and plots to fit your needs. For a list of methods you can use, see Surface Fit Methods.
For more information on all fit settings and tools for comparing fits, see:
Curve Fitting Toolbox software provides some example data for an anesthesia drug interaction study. You can use Surface Fitting Tool to fit response surfaces to this data to analyze drug interaction effects. Response surface models provide a good method for understanding the pharmacodynamic interaction behavior of drug combinations.
This data is based on the results found in the following paper:
Kern SE, Xie G, White JL, Egan TD. Opioid-hypnotic synergy: A response surface analysis of propofol-remifentanil pharmacodynamic interaction in volunteers. Anesthesiology 2004; 100: 1373–81.
Anesthesia is typically at least a two-drug process, consisting of an opioid and a sedative hypnotic. This example uses Propofol and Reminfentanil as drug class prototypes. Their interaction is measured by four different measures of the analgesic and sedative response to the drug combination. Algometry, Tetany, Sedation, and Laryingoscopy comprise the four measures of surrogate drug effects at various concentration combinations of Propofol and Reminfentanil.
Perform the following steps to interactively create response surfaces for this drug combination:
Use the Current Folder browser to locate and view the folder matlab\toolbox\curvefit\curvefit.
Right-click the file OpioidHypnoticSynergy.txt, and select Import Data. The Import Wizard appears.
Click Next to accept the default column separator (tab).
Click the option button labeled Create vectors from each column using column names. Review the six variables selected for import: Algometry, Laryingoscopy, Propofol, Reminfentanil, Sedation, and Tetany.
Click Finish to import the dose-response data into the MATLAB workspace.
Alternatively you can import the data programmatically. Enter the following code to read the dose-response data from the file into the MATLAB workspace.
data = importdata( 'OpioidHypnoticSynergy.txt' ); Propofol = data.data(:,1); Remifentanil = data.data(:,2); Algometry = data.data(:,3); Tetany = data.data(:,4); Sedation = data.data(:,5); Laryingoscopy = data.data(:,6);
To create response surfaces you must select the two drugs for the X and Y inputs, and one of the four effects for the Z output. After you load the variables into your workspace, you can either open the tool and select variables interactively, or specify the initial fit variables with the sftool command.
Enter the following to open Surface Fitting Tool (if necessary) and create a new response surface for Algometry:
sftool(Propofol, Remifentanil, Algometry)
Review the Surface Fitting Tool X, Y, and Z input and output controls. The tool displays the selected variables Propofol, Remifentanil and Algometry, with a surface fit. The default fit is an interpolating surface that passes through the data points.

Create a copy of the current surface fit by either:
Selecting Fit > Duplicate "Current Fit Name".
Right-clicking a fit in the Table of Fits, and selecting Duplicate.
Select the Custom Equation fit type from the drop-down list to define your own equation to fit the data.
Select and delete the example custom equation text in the edit box.
You can use the custom equation edit box to enter MATLAB code to define your model. The equation that defines the model must depend on the input variables x and y and a list of fixed parameters, estimable parameters, or both.
The model from the paper is:

where CA and CB are the drug concentrations, and IC50A, IC50B, alpha, and n are the coefficients to be estimated.
You can define this in M-code as
Effect = Emax*( CA/IC50A + CB/IC50B + alpha*( CA/IC50A )...
.* ( CB/IC50B ) ).^n ./(( CA/IC50A + CB/IC50B + ...
alpha*( CA/IC50A ) .* ( CB/IC50B ) ).^n + 1);Telling the tool which variables to fit and which parameters to estimate, requires rewriting the variable names CA and CB to x, and y. You must include x and y when you enter a custom equation in the edit box. Assume Emax = 1 because the effect output is normalized.
Enter the following text in the custom equation edit box, and click Fit.
( x/IC50A + y/IC50B + alpha*( x/IC50A ) .* ( y/IC50B ) ).^n ./(( x/IC50A + y/IC50B + alpha*( x/IC50A ) .* ( y/IC50B ) ).^n + 1);
Surface Fitting Tool fits a surface to the data using the custom equation model.

Set some of the fit options by clicking Fit Options under your custom equation.
In the Fit Options dialog box:
Set Robust to Lar
Set the alpha Start Point to 1 and lower bound to –5.

Leave the other defaults, and click Close.
In Surface Fitting Tool, click Fit to refit with your new options.
Review the Results pane. View (and, optionally, copy) any of these results:
The model equation
The values of the estimated coefficients
The goodness of fit statistics
Display the residuals plot to check the distribution of points relative to the surface by selecting View > Residuals Plot.

To generate an M-file for all fits and plots in your Surface Fitting Tool session, select File > Generate M-File.
The Surface Fitting Tool creates an M-file from your session and displays the file in the MATLAB Editor. The file includes all fits and plots in your current session.
Save the file with the default name, createSurfaceFits.m.
You can re-create your fits and plots by calling the M-file from the command line (with your original data or new data as input arguments). In this case, your original data still appears in the workspace.
Highlight the first line of the M-file (excluding the word function), and evaluate it by either right-clicking and selecting Evaluate, pressing F9, or copying and pasting the following to the command line:
[fitresult, gof] = createSurfaceFits(Propofol,... Remifentanil, Algometry)
The function creates a figure window for each fit you had in your session. The custom fit figure shows both the surface and residuals plots that you created interactively in the Surface Fitting Tool.
Create a new fit to the Tetany response instead of Algometry by entering:
[fitresult, gof] = createSurfaceFits(Propofol,... Remifentanil, Tetany)
You need to edit the M-file if you want the new response label on the plots. You can use the generated code as a starting point to change the surface fits and plots to fit your needs. For a list of methods you can use, see Surface Fit Methods.
To see how to programmatically fit surfaces to the same example problem, see Biopharmaceutical Drug Interaction Programmatic Surface Fitting Example.
![]() | Fitting a Surface | Selecting Fit Settings | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |