3
$\begingroup$

Consider the following data

data = {{2, -2.99380668585}, {4, -2.99413053462}, {6, -2.99439488497}, {8, -2.99467836024},
 {10, -2.99491958936}, {12, -2.99519218472}, {14, -2.99538900867}, {16, -2.99562768004}, 
{18, -2.99584876062}, {20, -2.99601713877}, {22, -2.99619549077}, {24, -2.99637350562}}

I am trying to fit to this data the (displaced) real part of some powers of a complex number

fit = NonlinearModelFit[ data, 
-a + \[Rho] r^m Cos[m \[Phi] + \[Psi]], {a, \[Rho], \[Phi], \[Psi], r},
 m,  MaxIterations -> 1000]

Even though the fit looks good

DiscretePlot[fit["BestFit"], {m, 2, 24, 2},  Epilog -> { Point[data]}]

I would like to know if the NonlinearModelFit::cvmit error that NonlinearModelFit shows can be removed by (somehow) improving the fit. I tried using some starting values, but I was unsuccessful.

$\endgroup$
7
  • 1
    $\begingroup$ Setting MaxIterations->100000 doesn't seem to give an error and the speed of the code is not affected. $\endgroup$
    – Hans Olo
    May 22 at 19:59
  • 1
    $\begingroup$ Add option `Method->"NMinimize" and MMA evauates withoud message! $\endgroup$ May 22 at 20:20
  • $\begingroup$ @UlrichNeumann For me, the NMinimize method gives a complex-valued fit. Adding a constraint to the form, {-a + \[Rho] r^m Cos[m \[Phi] + \[Psi]], r > 0}, fixes it. $\endgroup$
    – Michael E2
    May 22 at 20:38
  • $\begingroup$ @MichaelE2 Interesting, v12.2 NonlinearModelFit[data, -a + \[Rho] r^m Cos[m \[Phi] + \[Psi]], {a, \[Rho], \[Phi], \[Psi], r}, m,Method -> "NMinimize"] gives a real fit! $\endgroup$ May 22 at 21:01
  • $\begingroup$ @UlrichNeumann I should have mentioned I was using 12.3. $\endgroup$
    – Michael E2
    May 22 at 21:49
2
$\begingroup$

I think there are few issues with what you're attempting to do:

  • Fitting 6 parameters ($a$, $\rho$, $\phi$, $\psi$, $r$, and the error variance) to just 12 data points is usually not enlightening. (This is not to say that obtaining more data is easy or even possible to do.)
  • The parameters estimates for $\rho$, $\phi$, and $\psi$ are not even close to being statistically significant.
  • The correlation matrix estimate has nearly every correlation equal to 1. In other words, the model is way overparameterized given the available data. Predictions might be OK but you should definitely avoid interpreting coefficients (either the magnitude or the sign).

Here is the issue with the parameter estimates:

fit = NonlinearModelFit[data, -a + ρ r^m Cos[m ϕ + ψ], {a, ρ, ϕ, ψ, r}, m,
  MaxIterations -> 1000, Method -> "NMinimize"]
fit["ParameterTable"]

Parameter table with no restrictions on r

Here is the issue with the correlation matrix:

fit["CorrelationMatrix"] // MatrixForm 

Correlation matrix

The model is just overparameterized given the available data. Note that if one rationalizes the data, only the P-value for $a$ remains statistically significant:

fit2 = NonlinearModelFit[Rationalize[data, 0], {-a + ρ r^m Cos[m ϕ + ψ]}, {a, ρ, ϕ, ψ, r}, m, 
   MaxIterations -> 1000, Method -> "NMinimize", WorkingPrecision -> 30];
fit2["ParameterTable"]

Parameter table with rationalized data

fit2["CorrelationMatrix"] // MatrixForm

Correlation matrix with rationalized data

$\endgroup$
2
  • $\begingroup$ thanks for your answer, I learned a lot from it. From your analysis, it seems like fit2 = NonlinearModelFit[data, -a + \[Rho] r^m , {a, \[Rho], r}, m, MaxIterations -> 1000, Method -> "NMinimize"] fit2["ParameterTable"] is a better option. I would like to ask you, how many points do you think I should use for the original expression? $\endgroup$
    – David
    May 24 at 18:10
  • 1
    $\begingroup$ A very loose rule-of-thumb in the biological sciences is a minimum of 20 points plus 5 points for every parameter. And that results in a bare minimum sample size. What is "adequate" depends on the subject matter and if you just need to predict or if you need to be able to make reasonable interpretations of the parameters (both size and sign of the parameters). $\endgroup$
    – JimB
    May 24 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.