Get the equation for a linear regression model

79 ビュー (過去 30 日間)
Heather
Heather 2025 年 10 月 7 日 19:32
コメント済み: dpb 2025 年 10 月 9 日 20:12
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 件のコメント
Torsten
Torsten 2025 年 10 月 9 日 19:29
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 2025 年 10 月 9 日 20:12
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.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by