mdl1 = addTerms(mdl,terms)
Terms to add to the mdl regression model. Specify as either a:
Linear model, the same as mdl but with additional terms given in terms. You can set mdl1 equal to mdl to overwrite mdl.
Wilkinson notation describes the factors present in models. The notation relates to factors present in models, not to the multipliers (coefficients) of those factors.
|Wilkinson Notation||Factors in Standard Notation|
|1||Constant (intercept) term|
|A^k, where k is a positive integer||A, A2, ..., Ak|
|A + B||A, B|
|A*B||A, B, A*B|
|-B||Do not include B|
|A*B + C||A, B, C, A*B|
|A + B + C + A:B||A, B, C, A*B|
|A*B*C - A:B:C||A, B, C, A*B, A*C, B*C|
|A*(B + C)||A, B, C, A*B, A*C|
Statistics Toolbox™ notation always includes a constant term unless you explicitly remove the term using -1.
For details, see Wilkinson and Rogers .
Create a model of the carsmall data without any interactions, then add an interaction term.
Load the carsmall data and make a model of the MPG as a function of weight and model year.
load carsmall ds = dataset(MPG,Weight); ds.Year = ordinal(Model_Year); mdl = fitlm(ds,'MPG ~ Year + Weight^2');
Add an interaction term to mdl.
terms = 'Year*Weight'; mdl1 = addTerms(mdl,terms)
mdl1 = Linear regression model: MPG ~ 1 + Weight*Year + Weight^2 Estimated Coefficients: Estimate SE tStat pValue (Intercept) 48.045 6.779 7.0874 3.3967e-10 Weight -0.012624 0.0041455 -3.0454 0.0030751 Year_76 2.7768 3.0538 0.90931 0.3657 Year_82 16.416 4.9802 3.2962 0.0014196 Weight:Year_76 -0.00020693 0.00092403 -0.22394 0.82333 Weight:Year_82 -0.0032574 0.0018919 -1.7217 0.088673 Weight^2 1.0121e-06 6.12e-07 1.6538 0.10177 Number of observations: 94, Error degrees of freedom: 87 Root Mean Squared Error: 2.76 R-squared: 0.89, Adjusted R-Squared 0.882 F-statistic vs. constant model: 117, p-value = 1.88e-39
 Wilkinson, G. N., and C. E. Rogers. Symbolic description of factorial models for analysis of variance. J. Royal Statistics Society 22, pp. 392–399, 1973.
Use stepwiselm to select a model from a starting model, continuing until no single step is beneficial.
Use removeTerms to remove particular terms.
Use step to optimally improve the model by adding or removing terms.