Hey! Can someone explain me the following syntax:
modelfun=@(b,x)b(1) + b(2)*x(:,1).^b(3)+... b(4)*x(:,2).^b(5); beta0=[-50 500 -1 500 -1]; mdl = fitnlm(ds,modelfun,beta0)
mdl = MPG~ b1 + b2*Horsepower^b3 + b4*Weight^b5
In particular I dont understand: (b,x)- this doesnt take any column of the dataset,right? x(:,1)- does this give me the first column of the dataset? x(:,1)-does this give me the second column of the dataset?
In beta0 I specify then the values of b1, b2 and b4? Or what is it for?
Thanks for your help!

 채택된 답변

Roger Wohlwend
Roger Wohlwend 2014년 6월 16일

0 개 추천

The variable modelfun is a function handle and it defines the nonlinear model. Perhaps you should read the Matlab documentation about function handles first before you proceed with the regression. The first part of the handle - @(b,x) - tells matlab that the equation contains two variables: b (the coefficients) and x (the independent variables). Afterwards it shows the model.
Yes, x(:,1) is the first column of the matrix x.
beta0 specifys the inital values for the regression coefficients. Matlab needs them as a starting point for the optimization.

댓글 수: 6

Tania
Tania 2014년 6월 17일
편집: Tania 2014년 6월 17일
Thank you for your answer, helped a lot!Apart from fitnlm I saw there is also the command nlinfit, I dont really understand the difference.Do you know it? Also, how can I specify the values of beta0, I there a certain technique to specify them?And how do I decide on a equation? Do I have a look at the spread of the data & then choose a function I think is most appropriate? Thanks so much!
Roger Wohlwend
Roger Wohlwend 2014년 6월 17일
No, I don't know the difference between the two functions. Both seem appropriate for nonlinear regression, but I would prefer fitnlm.
There's a good technique to specify inital values. It's called gridsearch. Vary each coefficient in a certain range and find out which values yield the best model. Then use these values as inital values. In other words, calculate the model for different values for the coefficients and use that set of values as initial values that yielded the best model.
Tania
Tania 2014년 6월 18일
Thank you. I cant find gridsearch, is gridsearch the same as patternsearch?
Roger Wohlwend
Roger Wohlwend 2014년 6월 18일
No, gridsearch is probably not the same as patternsearch. You don't search for patterns. It is quite a simple concept. If you need a more detailed explanation, just ask.
Tania
Tania 2014년 6월 18일
Thanks, where can I find gridsearch in the documenation?Thanks!
Roger Wohlwend
Roger Wohlwend 2014년 6월 18일
It is not in the Matlab documentation. I found it in books.

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

추가 답변 (0개)

카테고리

질문:

2014년 6월 16일

댓글:

2014년 6월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by