Fit a constant only linear regression model using 'fitlm'

12 ビュー (過去 30 日間)
M
M 2015 年 5 月 1 日
コメント済み: M 2015 年 5 月 1 日
I have the following simple regression model
y(t) = B + u(t)
where B=1 and u(t) are random drawings from the standard normal distribution. Also n = 100. I would like to fit a constant only linear regression model but am unsure how to do so. I imagine I have to use 'fitlm', but for some reason cannot specify that there are no predictor variables . My code so far is simply:
b = 1
u = randn(100,1)
y = b + u

採用された回答

Brendan Hamm
Brendan Hamm 2015 年 5 月 1 日
If you wanted to fit this using fitlm you could do the following:
fit1 = fitlm(ones(size(y)),y,'y~1');
  1 件のコメント
M
M 2015 年 5 月 1 日
Thank you very much!

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

その他の回答 (1 件)

John D'Errico
John D'Errico 2015 年 5 月 1 日
Well, you CAN use a tool like fitlm to do this. But that would be like using a Mack truck to take a pea to Boston.
The linear regression estimator of a constant model is just the mean. So...
B = mean(u);
Of course it fails to give you statistics on the model. But it is the mean for god sakes! It won't fit very well, unless your data is constant. So plot your data, and look at the residuals. If there is a pattern in the data, then a constant model might be inadequate for your purposes.
  2 件のコメント
M
M 2015 年 5 月 1 日
Thanks for the reply. I understand what you're saying, however I was required to show that calculating the OLS estimate of beta would yield the same result as mean(u) so this is why I asked for help with fitlm. Cheers
M
M 2015 年 5 月 1 日
mean(y), rather!

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

カテゴリ

Help Center および File ExchangeLinear Regression についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by