フィルターのクリア

Linear Regression: order of estimated coefficients does not match input order

2 ビュー (過去 30 日間)
Isabel Chen
Isabel Chen 2015 年 2 月 22 日
編集済み: John D'Errico 2015 年 2 月 22 日
For example,
mdl = fitlm(data,'EXPOS ~ X1 + X2 + HEIGHT + AGE')
The output
mdl.Coefficients
produces the estimated coefficients in the following order: HEIGHT, AGE, X1 and X2. Why does it do that? It really messes up some calculations! Please help!

採用された回答

John D'Errico
John D'Errico 2015 年 2 月 22 日
If you have created the dataset with those variables in the order (height, age, x1, x2) then that is the order they will appear in the final model, even though you specified the model as
'EXPOS ~ X1 + X2 + HEIGHT + AGE'
  2 件のコメント
Isabel Chen
Isabel Chen 2015 年 2 月 22 日
Oh I see! Thanks. So obvious now that you say it. The reason why this is an issue is because I'm trying to use the function
linhyptest()
which requires an input matrix specifying the linear combinations of the coefficients that I'm testing for (eg, testing the null hypothesis that beta_2=beta_4=0). Clearly if I choose my matrix based on how I specified the input, which is different from how Matlab actually outputs the coefficients, I'm going to be in trouble. Do you have any ideas on how to work around this, apart from checking the data manually?
John D'Errico
John D'Errico 2015 年 2 月 22 日
編集済み: John D'Errico 2015 年 2 月 22 日
You can extract the variable names from the data set, then use regexp (or some other tool, like strtok, or even my own function allwords on the File Exchange) to take apart the model string you will be using. Then sort the two sets of variable names to be consistent.
For example:
allwords('EXPOS ~ X1 + X2 + HEIGHT + AGE',' +~')
ans =
'EXPOS' 'X1' 'X2' 'HEIGHT' 'AGE'

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnalysis of Variance and Covariance についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by