which modelfun can be used in fitnlm for nonlinear regression?
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Star Strider
le 17 Mai 2015
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 commentaires
Star Strider
le 18 Mai 2015
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Get Started with Curve Fitting Toolbox dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!