필터 지우기
필터 지우기

Do I need to add a column of ones on the predictor matrix for use in LinearModel.fit(X,y)

조회 수: 2 (최근 30일)
I have a predictor matrix X and I want to create a model using mdl=LinearModel.fit(X,y,'interactions'). Is it necessary to add a column of ones in the predictor matrix.
Also can I use the function "x2fx" with LinearModel.fit(X,y)

채택된 답변

Teja Muppirala
Teja Muppirala 2012년 10월 10일
By default, LinearModel.fit also includes a column of ones.
For example
X = rand(10,2);
y = 3*X(:,1) + 4*X(:,2) + 5*X(:,1).*X(:,2) + 6;
LinearModel.fit(X,y,'interactions')
You will see that the value of (intercept) is correctly found as 6.
You can specify to not use it by setting the 'intercept' argument to false.
LinearModel.fit(X,y,'interactions','intercept',false)
I am not sure what you mean by using x2fx with LinearModel.fit. You certainly could, but LinearModel.fit gives you a great number of options such as 'interactions', 'purequadratic', 'quadratic', and you can also specify custom interactions, so that you don't really have to worry about x2fx.
  댓글 수: 1
Chimezie Umezie
Chimezie Umezie 2012년 10월 10일
I observed that when I used the coded variables for the factors at two levels(±1) the result is outrageous however when I used the predictor matrix the result is ok. Can you explain that.I am actually trying to develop a second order model using central composite design for four factors. Can I use Linearmodel.fit for a second order model?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by