Accessing estimated parameters from nlinfit for weighted regression

4 vues (au cours des 30 derniers jours)
Maximilian Bailey
Maximilian Bailey le 15 Mar 2022
Commenté : Torsten le 17 Mar 2022
Hello,
I am looking to perform a weighted, non-linear regression on some data. I am currently fitting the data using the nlinfit function. I have derived the analytical expression of the variance of the data as a function of the estimated parameters, and I would thus like to use the estimated beta parameters at each fitting step as inputs into my weighted function.
I.e., I essentially want argmin sum((ydata-F(beta,x)).^2./sigma(beta,x).^2)
However, according to the documentation, the weights will only accept the output of the fitted model as a vector. Is there a way to access the estimated parameters during the fitting procedure so that nlinfit can weight the data as desired?
Thank you for your time
(Edit: for now I have simply fitted the parameters using fminsearch for the above expression, but I was wondering if there is an option on nlinfit or otherwise that allows you to adjust the weights during the fitting process as described)

Réponse acceptée

Torsten
Torsten le 15 Mar 2022
Modifié(e) : Torsten le 15 Mar 2022
Use "lsqnonlin" and define the functions f_i as
f_i = (ydata_i - F(beta,xdata_i))/sigma(beta,xdata_i)
"lsqnonlin" is the solver best suited for this kind of problem.
But you can also use nlinfit with the weights returned from a function.
From the documentation of nlinfit:
Weights:
Observation weights, specified as the comma-separated pair consisting of 'Weights' and a vector of real positive weights or a function handle. You can use observation weights to down-weight the observations that you want to have less influence on the fitted model.
If W is a vector, then it must be the same size as Y.
If W is a function handle, then it must accept a vector of predicted response values as input, and return a vector of real positive weights as output.
  4 commentaires
Maximilian Bailey
Maximilian Bailey le 17 Mar 2022
Great - thank you for the explanations. Unfortunately I need to know the beta_i's (because of the analytical form), but the alternative function you proposed works just fine for what I need.
Torsten
Torsten le 17 Mar 2022
I think you only need your model function values y_i, evaluated with the xdata_i and the beta_i, to determine the weights in each step, and this is what nlinfit delivers.
But anyhow, nice to hear that the proposed method works out fine.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by