Get the equation for a linear regression model

15 visualizzazioni (ultimi 30 giorni)
Heather
Heather il 7 Ott 2025
Commentato: dpb il 9 Ott 2025
What code do I use to get the software to display the acutal equation instead of "[Linear formula with 18 terms in 7 predictors]"?
  11 Commenti
Torsten
Torsten il 9 Ott 2025
It seems that if second-order or interaction terms are present in the linear model, the main effects are not included in the formula for the regression model.
The example
Terms Matrix for Matrix Input
under
shows this (illogical) behaviour, but without commenting on it or giving a justification.
dpb
dpb il 9 Ott 2025
Well, it is logical in a sense, just not well documented what mdl.Formula property returns...it is the Wilkinson representation of the model in which "x1*x2" implies the interaction term plus all lower terms. There's a difference in specifying "x1*x2" and "x1:x2" which is easy to miss--the latter says to include only the specific interaction term.
I haven't yet investigated fully whether the returned formula property is always in Wilkinson notation regardless of how the input model is specified or whether it just reflects the user input specification.
I'll try to do some more spelunking and see; at least the doc needs to be explicit in what the user should expect; certainly for @Heather's Q? here, it isn't what she's looking for; one would have to build that expression from the table of coefficients similarly as your earlier examples. If that were to be so, that seems rude to be the only way to be able to generate the full representation of the model for presentation purposes, for example.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Descriptive Statistics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by