NonLinearModel
Nonlinear regression model
Description
NonLinearModel is a fitted nonlinear regression model object.
            A regression model describes the relationship between a response and predictors. The
            nonlinearity in a nonlinear regression model refers to a nonlinear combination of
            predictors and predictor coefficients. 
Use the properties of a NonLinearModel object to investigate a fitted
            nonlinear regression model. The object properties include information about coefficient
            estimates, summary statistics, fitting method, and input data. Use the object functions
            to predict responses and to evaluate and visualize the nonlinear regression model. You
            can predict model responses using the predict or feval object function. 
Creation
Create a NonLinearModel object using fitnlm.
Properties
Coefficient Estimates
This property is read-only.
Covariance matrix of coefficient estimates, represented as a
        p-by-p matrix of numeric values. p
      is the number of coefficients in the fitted model, as given by
        NumCoefficients.
For details, see Coefficient Standard Errors and Confidence Intervals.
Data Types: single | double
This property is read-only.
Coefficient names, represented as a cell array of character vectors, each containing the name of the corresponding term.
Data Types: cell
This property is read-only.
Coefficient values, specified as a table.
                                Coefficients contains one row for each
                            coefficient and these columns:
- Estimate— Estimated coefficient value
- SE— Standard error of the estimate
- tStat— t-statistic for a two-sided test with the null hypothesis that the coefficient is zero
- pValue— p-value for the t-statistic
Use coefTest to perform other tests on the
                            coefficients. Use coefCI to find the confidence
                            intervals of the coefficient estimates.
To obtain any of these columns as a vector, index into the property
                            using dot notation. For example, obtain the estimated coefficient vector
                            in the model
                            mdl:
beta = mdl.Coefficients.Estimate
Data Types: table
This property is read-only.
Number of coefficients in the fitted model, specified as a positive
                            integer. NumCoefficients is the same as
                                NumEstimatedCoefficients for
                                NonLinearModel objects.
                                NumCoefficients is equal to the degrees of
                            freedom for regression.
Data Types: double
This property is read-only.
Number of estimated coefficients in the fitted model, specified as a
                            positive integer. NumEstimatedCoefficients is the
                            same as NumCoefficients for
                                NonLinearModel objects.
                                NumEstimatedCoefficients is equal to the degrees
                            of freedom for regression.
Data Types: double
Summary Statistics
This property is read-only.
Degrees of freedom for the error (residuals), equal to the number of observations minus the number of estimated coefficients, represented as a positive integer.
Data Types: double
This property is read-only.
Diagnostic information for the model, specified as a table.
                            Diagnostics can help identify outliers and influential observations.
                                Diagnostics contains the following fields.
| Field | Meaning | Utility | 
|---|---|---|
| Leverage | Diagonal elements of HatMatrix | Leveragefor each observation
                                            indicates to what extent the fit is determined by the
                                            observed predictor values. A value close to1indicates that the fit is
                                            largely determined by that observation, with little
                                            contribution from the other observations. A value close
                                            to0indicates that the fit is
                                            largely determined by the other observations. For a
                                            model withPcoefficients andNobservations, the average value
                                            ofLeverageisP/N. ALeveragevalue greater than2*P/Nindicates
                                            high leverage. | 
| CooksDistance | Cook's distance | CooksDistanceis a measure of
                                            scaled change in fitted values. An observation withCooksDistancegreater than three
                                            times the mean Cook's distance can be an outlier. | 
| HatMatrix | Projection matrix to compute fittedfrom observed
                                            responses | HatMatrixis anN-by-Nmatrix
                                            such thatFitted = HatMatrix*Y,
                                            whereYis the response vector andFittedis the vector of fitted
                                            response values. | 
Diagnostics contains information that is helpful in
                            finding outliers and influential observations.  For more details, see
                                Hat Matrix and Leverage and
                                Cook’s Distance.
Use plotDiagnostics  to plot
                            observation diagnostics.
Rows not used in the fit because of missing values (in
                                ObservationInfo.Missing) or excluded values (in
                                ObservationInfo.Excluded) contain
                                NaN values in the
                                CooksDistance columns and zeros in the
                                Leverage and HatMatrix
                            columns.
To obtain any of these columns as an array, index into the property
                            using dot notation. For example, obtain the Cook's distance vector in
                            the model mdl:
CooksDistance = mdl.Diagnostics.CooksDistance;
Data Types: table
This property is read-only.
Fitted (predicted) response values based on input data, specified as
                            an n-by-1 numeric vector. n is the
                            number of observations in the input data. Use predict  to compute
                            predictions for other predictor values, or to compute confidence bounds
                            on Fitted.
Data Types: single | double
This property is read-only.
Loglikelihood of the model distribution at the response values, specified as a numeric value. The mean is fitted from the model, and other parameters are estimated as part of the model fit.
Data Types: single | double
This property is read-only.
Criterion for model comparison, represented as a structure with these fields:
- AIC— Akaike information criterion.- AIC = –2*logL + 2*m, where- logLis the loglikelihood and- mis the number of estimated parameters.
- AICc— Akaike information criterion corrected for the sample size.- AICc = AIC + (2*m*(m + 1))/(n – m – 1), where- nis the number of observations.
- BIC— Bayesian information criterion.- BIC = –2*logL + m*log(n).
- CAIC— Consistent Akaike information criterion.- CAIC = –2*logL + m*(log(n) + 1).
Information criteria are model selection tools that you can use to compare multiple models fit to the same data. These criteria are likelihood-based measures of model fit that include a penalty for complexity (specifically, the number of parameters). Different information criteria are distinguished by the form of the penalty.
When you compare multiple models, the model with the lowest information criterion value is the best-fitting model. The best-fitting model can vary depending on the criterion used for model comparison.
To obtain any of the criterion values as a scalar, index into the property using dot
            notation. For example, obtain the AIC value aic in the model
                mdl:
aic = mdl.ModelCriterion.AIC
Data Types: struct
This property is read-only.
F-statistic of the regression model, specified as a structure containing these fields:
- Fstats— F-statistic of the fitted model versus the null model
- Pvalue— p-value for the F-statistic
- NullModel— Null model type, specified as '- constant' or '- zero'
If the fitted model contains an intercept term,
                                NullModel is 'constant'
                            (contains only an intercept term). Otherwise,
                                NullModel is 'zero' (contains
                            no terms). 
Data Types: struct
This property is read-only.
Mean squared error, specified as a numeric value. The mean squared error is an estimate of the variance of the error term in the model.
Data Types: single | double
This property is read-only.
Residuals for the fitted model, specified as a table that contains one row for each observation and the columns described in this table.
| Column | Description | 
|---|---|
| Raw | Observed minus fitted values | 
| Pearson | Raw residuals divided by the root mean squared error (RMSE) | 
| Standardized | Raw residuals divided by their estimated standard deviation | 
| Studentized | Raw residual divided by an independent estimate of the residual standard deviation. The residual for observation i is divided by an estimate of the error standard deviation based on all observations except observation i. | 
Use plotResiduals to create a plot of the residuals. For details, see
        Residuals.
Rows not used in the fit because of missing values (in
        ObservationInfo.Missing) or excluded values (in
        ObservationInfo.Excluded) contain NaN values.
To obtain any of these columns as a vector, index into the property using dot notation.
      For example, obtain the raw residual vector r in the model
        mdl:
r = mdl.Residuals.Raw
Data Types: table
This property is read-only.
Root mean squared error (residuals), specified as a numeric value.
RMSE = sqrt(MSE),
where RMSE is the root mean squared error and MSE is the mean squared error. RMSE is an estimate of the standard deviation of the error term in the model.
Data Types: single | double
This property is read-only.
R-squared value for the model, specified as a structure with two fields:
- Ordinary— Ordinary (unadjusted) R-squared
- Adjusted— R-squared adjusted for the number of coefficients
The R-squared value is the proportion of the total sum of squares
                            explained by the model. The ordinary R-squared value relates to the
                                SSR and SST properties:
Rsquared = SSR/SST,
where SST is the total sum of
                            squares, and SSR is the regression sum of squares.
                            For details, see Coefficient of Determination (R-Squared).
Note that the ordinary and adjusted R-squared statistics are not useful metrics for most nonlinear regression models.
Data Types: struct
This property is read-only.
Sum of squared errors (residuals), specified as a numeric value. If the model was
            trained with observation weights, the sum of squares in the SSE
            calculation is the weighted sum of squares.
Data Types: single | double
This property is read-only.
Regression sum of squares, specified as a numeric value.
                                                SSR is equal to the sum of the
                                    squared deviations between the fitted values and the mean of the
                                    response. If the model was trained with observation weights, the
                                    sum of squares in the SSR calculation is
                                    the weighted sum of squares.
Data Types: single | double
This property is read-only.
Total sum of squares, specified as a numeric value. SST is equal
            to the sum of squared deviations of the response vector y from the
                mean(y). If the model was trained with observation weights, the
            sum of squares in the SST calculation is the weighted sum of
            squares.
Data Types: single | double
Fitting Method
This property is read-only.
Robust fit information, specified as a structure with the following fields:
| Field | Description | 
|---|---|
| WgtFun | Robust weighting function, such as 'bisquare'(seeRobust
                                                Options) | 
| Tune | Value specified for tuning parameter (can be []) | 
| Weights | Vector of weights used in final iteration of robust fit | 
This structure is empty unless fitnlm constructed the
                            model using robust regression.
Data Types: struct
Input Data
This property is read-only.
Model information, specified as a NonLinearFormula
                            object.
Display the formula of the fitted model mdl by
                            using dot notation.
mdl.Formula
This property is read-only.
Information about the fitting process, specified as a structure with the following fields:
- InitialCoefs— Initial coefficient values (the- beta0vector)
- IterOpts— Options included in the- Optionsname-value pair argument for- fitnlm.
Data Types: struct
This property is read-only.
Number of observations the fitting function used in fitting, specified
                                    as a positive integer. NumObservations is the
                                    number of observations supplied in the original table, dataset,
                                    or matrix, minus any excluded rows (set with the
                                                'Exclude' name-value pair
                                    argument) or rows with missing values.
Data Types: double
This property is read-only after object creation.
Number of predictor variables used to fit the model, represented as a positive integer.
Data Types: double
This property is read-only after object creation.
Number of variables in the input data, represented as a positive integer.
                NumVariables is the number of variables in the original table, or
            the total number of columns in the predictor matrix and response vector.
NumVariables also includes any variables not used to fit the model
            as predictors or as the response.
Data Types: double
This property is read-only.
Observation information, specified as an n-by-4 table, where
                n is equal to the number of rows of input data.
                ObservationInfo contains the columns described in this
            table.
| Column | Description | 
|---|---|
| Weights | Observation weights, specified as a numeric value. The default value
                            is 1. | 
| Excluded | Indicator of excluded observations, specified as a logical value. The
                            value is trueif you exclude the observation from the
                            fit by using the'Exclude'name-value pair
                            argument. | 
| Missing | Indicator of missing observations, specified as a logical value. The
                            value is trueif the observation is missing. | 
| Subset | Indicator of whether or not the fitting function uses the
                            observation, specified as a logical value. The value is trueif the observation is not excluded or
                            missing, meaning the fitting function uses the observation. | 
To obtain any of these columns as a vector, index into the property using dot
            notation. For example, obtain the weight vector w of the model
                mdl:
w = mdl.ObservationInfo.Weights
Data Types: table
This property is read-only after object creation.
Observation names, returned as a cell array of character vectors containing the names of the observations used to fit the model.
- If the fit is based on a table containing observation names, this property contains those names. 
- Otherwise, this property is an empty cell array. 
Data Types: cell
This property is read-only after object creation.
Names of predictors used to fit the model, represented as a cell array of character vectors.
Data Types: cell
This property is read-only after object creation.
Response variable name, represented as a character vector.
Data Types: char
This property is read-only after object creation.
Information about the variables contained in Variables,
            represented as a table with one row for each variable and the columns described
            below.
| Column | Description | 
|---|---|
| Class | Variable class, specified as a cell array of character vectors, such
                            as 'double'and'categorical' | 
| Range | Variable range, specified as a cell array of vectors 
 
 | 
| InModel | Indicator of which variables are in the fitted model, specified as a
                            logical vector. The value is trueif the model
                            includes the variable. | 
| IsCategorical | Indicator of categorical variables, specified as a logical vector.
                            The value is trueif the variable is
                            categorical. | 
VariableInfo also includes any variables not used to fit the model
            as predictors or as the response.
Data Types: table
This property is read-only after object creation.
Names of the variables, returned as a cell array of character vectors.
- If the fit is based on a table, this property contains the names of the variables in the table. 
- If the fit is based on a predictor matrix and response vector, this property contains the values specified by the - VarNamesname-value argument of the fitting method. The default value of- VarNamesis- {'x1','x2',...,'xn','y'}.
VariableNames also includes any variables not used to fit the model
            as predictors or as the response.
Data Types: cell
This property is read-only after object creation.
Input data, returned as a table. Variables contains both
            predictor and response values.
- If the fit is based on a table, this property contains all the data from the table. 
- Otherwise, this property is a table created from the input data matrix - Xand the response vector- y.
Variables also includes any variables not used to fit the model as
            predictors or as the response.
Data Types: table
Object Functions
| coefCI | Confidence intervals of coefficient estimates of nonlinear regression model | 
| coefTest | Linear hypothesis test on nonlinear regression model coefficients | 
| partialDependence | Compute partial dependence | 
| profileLikelihood | Profile loglikelihood for nonlinear regression model | 
| plotDiagnostics | Plot diagnostics of nonlinear regression model | 
| plotPartialDependence | Create partial dependence plot (PDP) and individual conditional expectation (ICE) plots | 
| plotProfileLikelihood | Plot profile loglikelihood for nonlinear regression model | 
| plotResiduals | Plot residuals of nonlinear regression model | 
| plotSlice | Plot of slices through fitted nonlinear regression surface | 
Examples
Fit a nonlinear regression model for auto mileage based on the carbig data. Predict the mileage of an average car.
Load the sample data. Create a matrix X containing the measurements for the horsepower (Horsepower) and weight (Weight) of each car. Create a vector y containing the response values in miles per gallon (MPG).
load carbig
X = [Horsepower,Weight];
y = MPG;Fit a nonlinear regression model.
modelfun = @(b,x)b(1) + b(2)*x(:,1).^b(3) + ...
    b(4)*x(:,2).^b(5);
beta0 = [-50 500 -1 500 -1];
mdl = fitnlm(X,y,modelfun,beta0)mdl = 
Nonlinear regression model:
    y ~ b1 + b2*x1^b3 + b4*x2^b5
Estimated Coefficients:
          Estimate      SE        tStat       pValue 
          ________    _______    ________    ________
    b1     -49.383     119.97    -0.41164     0.68083
    b2      376.43     567.05     0.66384     0.50719
    b3    -0.78193    0.47168     -1.6578    0.098177
    b4      422.37     776.02     0.54428     0.58656
    b5    -0.24127    0.48325    -0.49926     0.61788
Number of observations: 392, Error degrees of freedom: 387
Root Mean Squared Error: 3.96
R-Squared: 0.745,  Adjusted R-Squared 0.743
F-statistic vs. constant model: 283, p-value = 1.79e-113
Find the predicted mileage of an average car. Because the sample data contains some missing (NaN) observations, compute the mean using mean with the 'omitnan' option.
Xnew = mean(X,'omitnan')  Xnew = 1×2
103 ×
    0.1051    2.9794
MPGnew = predict(mdl,Xnew)
MPGnew = 21.8073
More About
The hat matrix H is defined in terms of the data matrix X and the Jacobian matrix J:
Here f is the nonlinear model function, and β is the vector of model coefficients.
The Hat Matrix H is
H = J(JTJ)–1JT.
The diagonal elements Hii satisfy
where n is the number of observations (rows of X), and p is the number of coefficients in the regression model.
Leverage is a measure of the effect of a particular observation on the regression predictions due to the position of that observation in the space of the inputs.
The leverage of observation i is the value of the ith diagonal term hii of the hat matrix H. Because the sum of the leverage values is p (the number of coefficients in the regression model), an observation i can be considered an outlier if its leverage substantially exceeds p/n, where n is the number of observations.
The Cook’s distance Di of observation i is
where
- is the jth fitted response value. 
- is the jth fitted response value, where the fit does not include observation i. 
- MSE is the mean squared error. 
- p is the number of coefficients in the regression model. 
Cook’s distance is algebraically equivalent to the following expression:
where ei is the ith residual.
Version History
Introduced in R2012aUse the profileLikelihood function to calculate the profile loglikelihood
                and likelihood-ratio confidence interval for a coefficient in a nonlinear model. Use
                the NonLinearModel to plot the loglikelihood profile, Wald
                approximation, coefficient estimate, and likelihood-ratio and Wald confidence
                intervals.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)