help with linear regression function

조회 수: 6 (최근 30일)
miguel antonio
miguel antonio 2013년 10월 3일
댓글: Shashank Prasanna 2013년 10월 3일
bear with me this is goign to be a long description: Im trying to follow the interpret linear regression example from mathworks but I'm getting errors:
I have 3 sets of data: the order is age, weight, BP 52 173 132 59 184 143 67 194 153 73 211 162 64 196 154 74 220 168 54 188 137 61 188 149 65 207 159 46 167 128 72 217 166
I'm trying to set BP as the dependet(predictor) and age and weidgt as the independent columns. this is my code
if true
% code
age=[ 52 59 67 73 64 74 54 61 65 46 72]'
BP=[132 143 153 162 154 168 137 149 159 128 166]'
weight =[173 184 194 211 196 220 188 188 207 167 217]'
x1= age;
x2=weight;
BP=y;
X=[x1,x2,y]
lm= fitlm(X,y,'linear')% when I enter this I get this error
??? Undefined function or method 'fitlm' for
input arguments of type 'double'.
end
can somebody help me? please I need help

채택된 답변

Shashank Prasanna
Shashank Prasanna 2013년 10월 3일
편집: Shashank Prasanna 2013년 10월 3일
fitlm is a convenience interface function for LinearModel.fit that was introduced in MATLAB R2013b. If you are using an earlier release, replace fitlm with the latter.
Here is the release notes that talk about the change:
lm = LinearModel.fit(X,y,'linear')
If you are using a version of MATLAB earlier than R2012a you can use the REGRESS function to do the same.
  댓글 수: 2
miguel antonio
miguel antonio 2013년 10월 3일
thanks for your help, but after I made the change I got this error:
lm = LinearModel.fit(X,y,'linear') ??? Undefined variable "LinearModel" or class "LinearModel.fit".
Shashank Prasanna
Shashank Prasanna 2013년 10월 3일
What version of MATLAB are you using? Do you have the Statistics Toolbox installed? You can find out both the information but running:
>> ver
If you have a version of MATLAB before R2012a use REGRESS (search for it in the MATLAB documentation)

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by