Skip to Main Content Skip to Search
Product Documentation

Custom Nonlinear Surface Fitting Examples

Example: Fitting Biopharmaceutical Surfaces Interactively

Curve Fitting Toolbox software provides some example data for an anesthesia drug interaction study. You can use Curve 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 in this paper:

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.

To interactively create response surfaces for this drug combination:

  1. Use the Current Folder browser to locate and view the folder matlab\toolbox\curvefit\curvefit.

  2. Right-click the file OpioidHypnoticSynergy.txt, and select Import Data. The Import Wizard appears.

    1. Click Next to accept the default column separator (Tab).

      Click the option button Create vectors from each column using column names. Review the six variables selected for import: Algometry, Laryingoscopy, Propofol, Reminfentanil, Sedation, and Tetany.

    2. 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);
    
  3. 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 cftool command.

    Enter the following to open Curve Fitting Tool (if necessary) and create a new response surface for Algometry:

    cftool(Propofol, Remifentanil, Algometry)

    Review the Curve 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.

  4. Create a copy of the current surface fit by either:

    1. Selecting Fit > Duplicate "Current Fit Name".

    2. Right-clicking a fit in the Table of Fits, and selecting Duplicate.

  5. Select the Custom Equation fit type from the drop-down list to define your own equation to fit the data.

  6. 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 MATLAB 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.

  7. Enter the following text in the custom equation edit box.

    ( x/IC50A + y/IC50B + alpha*( x/IC50A ) .* ( y/IC50B ) ).^n
      ./(( x/IC50A + y/IC50B + alpha*( x/IC50A ) .* 
      ( y/IC50B ) ).^n  + 1);

    Curve Fitting Tool fits a surface to the data using the custom equation model.

  8. Set some of the fit options by clicking Fit Options under your custom equation.

    In the Fit Options dialog box:

    1. Set Robust to Lar

    2. Set the alpha StartPoint to 1 and lower bound to –5.

    3. Leave the other defaults, and click Close.

      The tool refits with your new options.

  9. 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

  10. Display the residuals plot to check the distribution of points relative to the surface by clicking the toolbar button or selecting View > Residuals Plot.

  11. To generate code for all fits and plots in your Curve Fitting Tool session, select File > Generate Code.

    The Curve Fitting Tool generates code from your session and displays the file in the MATLAB Editor. The file includes all fits and plots in your current session.

  12. Save the file with the default name, createFits.m.

  13. You can recreate your fits and plots by calling the 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 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] = createFits(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 Curve Fitting Tool.

  14. Create a new fit to the Tetany response instead of Algometry by entering:

    [fitresult, gof] = createFits(Propofol,...
     Remifentanil, Tetany)

    You need to edit the 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 sfit.

To see how to programmatically fit surfaces to the same example problem, see Example: Fitting Biopharmaceutical Drug Interaction Surfaces at the Command Line.

Example: Fitting Biopharmaceutical Drug Interaction Surfaces at the Command Line

The following code, using Curve Fitting Toolbox methods, reproduces the interactive surface building with the Curve Fitting Tool described in Example: Fitting Biopharmaceutical Surfaces Interactively.

The following code models the response surfaces of four different measures of the analgesic and sedative response to the drug combination of Propofol and Reminfentanil.

Load Data

Load the data from file as follows:

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);

Create the Model Fit Type

Create the model fit type as follows:

ft = fittype( 'Emax*( CA/IC50A + CB/IC50B + alpha*( CA/IC50A ) * ( CB/IC50B ) )^n /(( CA/IC50A + CB/IC50B + alpha*( CA/IC50A ) * ( CB/IC50B ) )^n  + 1 )', ...
    'indep', {'CA', 'CB'}, 'depend', 'z', 'problem', 'Emax' )

Output:

ft = 

     General model:
ft(IC50A,IC50B,alpha,n,Emax,CA,CB) = Emax*...
( CA/IC50A + CB/IC50B + alpha*(CA/IC50A )...
 * ( CB/IC50B ) )^n /(( CA/IC50A + CB/IC50B...
+ alpha*( CA/IC50A ) * ( CB/IC50B ) )^n  + 1 )

Assume Emax = 1:

Emax = 1;

Fit a Surface to Algometry

Set fit options as follows:

opts = fitoptions( ft );
opts.Lower = [0 0 -5 -0];
opts.Robust = 'LAR';
opts.StartPoint = [0.00893838724332152 0.706165672266879...
 1 0.746030748284422];

Fit and plot a surface for Algometry:

[f, gof] = fit( [Propofol, Remifentanil], Algometry, ft,...
 opts, 'problem', Emax )
plot( f, [Propofol, Remifentanil], Algometry );

Fit a Surface to Tetany

Fit a surface to Tetany as follows:

[f, gof] = fit( [Propofol, Remifentanil], Tetany, ft, opts, 'problem', Emax )
plot( f, [Propofol, Remifentanil], Tetany );

Fit a Surface to Sedation

Fit a surface to Sedation as follows:

[f, gof] = fit( [Propofol, Remifentanil], Sedation, ft, opts, 'problem', Emax )
plot( f, [Propofol, Remifentanil], Sedation );

Fit a Surface to Laryingoscopy

Fit a surface to Laryingoscopy as follows:

[f, gof] = fit( [Propofol, Remifentanil], Laryingoscopy, ft, opts, 'problem', Emax )
plot( f, [Propofol, Remifentanil], Laryingoscopy );

  


 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS