which modelfun can be used in fitnlm for nonlinear regression?

12 次查看(过去 30 天)
Hi to run the fitnlm I need a function modelfun as input parameter. This function has to be defined. My questions are -
  1. Are there some rules how to define this function?
  2. Are there some "standard"-functions that will be used in that case?
  3. Does this modelfun function has to have sth in common with the original function I would like to approximate with nonlinear regression?
  4. I thought about using a spline function as the modelfun. Does it make sence here?
Thank you & Best Regards

采纳的回答

Star Strider
Star Strider 2015-5-17
There are more ways to define ‘modelfun’ in fitnlm than the other nonlinear fitting functions. However I would use an anonymous function or function file for it, because you can use them with all the other nonlinear fitting functions as well. (You cannot use the string form with the others.) I would not use a spline, since the idea is to estimate the parameters and not get a precise fit.
If for instance you have a decaying exponential of the form:
f(t) = a * exp(b*t) * sin(c*t + d)
your ‘modelfun’ (objective function) would be:
f = @(b,t) b(1).*exp(b(2).*t).*sin(b(3).*t+b(4));
Note that the order of the arguments must be the order of the parameter vector (here ‘b’) first and the independent variable vector second.
The reason to choose the anonymous function or function file is that while fitnlm makes nonlinear curve fitting relatively easy and produces a number of relevant statistics on the fit, it does not provide confidence intervals on the parameters or data. You would need to repeat your regression using nlinfit, and use nlparci and nlpredci to get those statistics, and you can use the anonymous function or function file form for all functions, including those of the Optimization Toolbox and Global Optimization Toolbox.
  6 个评论
uli man
uli man 2015-5-18
I stick on smoothing spline because it´s part of my task. This is an extract with other function: In our first example we set X=(X1;X2) with independent standard normally distributed random variables X1 andX2 and choose m(x1;x2)=2*x1+x2+ 2. In this case Y=m(X) is normally distributed with expectation 2 and variance 5. We estimate the density of Y by the estimate using a fully data- driven smoothing spline estimate to estimate the linear function m.
In my case I have X=(X1,X2,X3), m(x1,x2,x3)=x1^2+x2^2+x3^2 and Y=m(X). And I also want to use data driven smoothing spline but it seems that I don´t know how exactly to use it...
Star Strider
Star Strider 2015-5-18
I did not know you had to use smoothing splines, so I was suggesting you not use them.
The spline functions are part of the Curve Fitting Toolbox. I don’t have it, so I can’t help you with it. You can use the spline function to do interpolation, but I do not know if that is what you want to do.
I will add ‘smoothing spline’ and ‘Curve Fitting Toolbox’ to the appropriate tag fields so that someone who has the toolbox and has used smoothing splines can possibly provide help.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by