model spec 'polyijk' o=in fitlm does not work as per MATLAB documentation?

3 views (last 30 days)
Hi, I am trying to use 'polyijk' model spec to specify my linear regression model complexity when using fitlm, but i dont seem to be getting what the documentation suggests i should. As per documentation: 'poly13' has an intercept and x1, x2, x2^2, x2^3, x1*x2, and x1*x2^2 terms. but when i try it, the terms i get are: 1 + x1*x2 + x2^2 + x1:(x2^2) + x2^3. so somehow it is missing the x1 and x2 terms.

Accepted Answer

the cyclist
the cyclist on 22 Mar 2024
Edited: the cyclist on 22 Mar 2024
I think you are just misinterpreting the Wilkinson notation of the model spec in the output.
x1*x2 % note the * for interaction, which includes lower-order terms
is short-hand for
x1 + x2 + x1:x2 % note the : for interaction, which does NOT include lower-order terms
Here is an example. Note that all the terms you expect are in the table of estimated coefficients.
load carsmall
X1 = Acceleration;
X2 = Displacement;
X = [X1,X2];
y = Weight;
mdl = fitlm(X,y,"poly13")
mdl =
Linear regression model: y ~ 1 + x1*x2 + x2^2 + x1:(x2^2) + x2^3 Estimated Coefficients: Estimate SE tStat pValue __________ _________ ________ _______ (Intercept) 446.97 1693 0.26401 0.79236 x1 41.114 81.832 0.50242 0.61656 x2 14.69 21.387 0.68685 0.49388 x1:x2 -0.18481 0.92831 -0.19908 0.84263 x2^2 -0.026093 0.068886 -0.37878 0.70571 x1:x2^2 0.0010263 0.0021616 0.47479 0.63605 x2^3 8.6477e-06 5.822e-05 0.14853 0.88224 Number of observations: 100, Error degrees of freedom: 93 Root Mean Squared Error: 315 R-squared: 0.857, Adjusted R-Squared: 0.848 F-statistic vs. constant model: 92.9, p-value = 4.46e-37

More Answers (0)

Products


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!