which modelfun can be used in fitnlm for nonlinear regression?
7 次查看(过去 30 天)
显示 更早的评论
Hi to run the fitnlm I need a function modelfun as input parameter. This function has to be defined. My questions are -
- Are there some rules how to define this function?
- Are there some "standard"-functions that will be used in that case?
- Does this modelfun function has to have sth in common with the original function I would like to approximate with nonlinear regression?
- I thought about using a spline function as the modelfun. Does it make sence here?
Thank you & Best Regards
0 个评论
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Spline Postprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!