3
$\begingroup$

I am trying to fit a nonlinear function with four parameters to a dataset. It works, but standard errors are very high with the warning message "FittedModel::constr: The property values {ParameterTable} assume an unconstrained model. The results for these properties may not be valid, particularly if the fitted parameters are near a constraint boundary."

How to fix this problem? Following is the code with datapoints and function to be fitted. Will appreciate any help. Thanks

    Y = {{1., 20.243}, {2., 19.869}, {4., 19.687}, {6., 19.566}, {8., 
      19.496}, {10., 19.451}, {20., 19.235}, {40., 19.09}, {60., 
      18.971}, {80., 18.934}, {100., 18.904}, {200., 18.799}, {400., 
      18.8}};

    nlm = NonlinearModelFit[Y, {Abs[a*(Log[1/(2 Pi*o*t)])^-n + b], {1000 > a > 0, 100 > b > 0, 
        1 > n > 0, t > 0}}, {{a, 0.01}, { b, 0.00005}, {t, 10000000}, {n, 0.2}}, o, ConfidenceLevel -> 99/100, MaxIterations -> Infinity] 
      
Show[LogLogPlot[nlm[o], {o, 0.9, 500}], ListLogLogPlot[Y, PlotStyle -> PointSize[Large], PlotRange -> {{0.9, 500}, {0.18, 0.21}}], Frame -> True]

nlm["ParameterTable"]
$\endgroup$
3
  • 3
    $\begingroup$ Mathematica 12.2 gives no error message! But you should use more points (>>4) to fit 4 parameters a ,b,t,n! $\endgroup$ Jun 14, 2023 at 8:59
  • $\begingroup$ 13.2 does give the FittedModel::constr warning with all the information you need to know. The way Mathematica calculates the vlaues on "ParameterTable" assumes no constraints, but you have constraints, therefore the assumption is invalid and the parameters are not valid. $\endgroup$
    – rhermans
    Jun 14, 2023 at 9:37
  • 2
    $\begingroup$ @rhermans I would quibble about "parameters are not valid." The warning concerns the estimates of the standard errors of the parameters and not the estimates of the parameters. $\endgroup$
    – JimB
    Jun 14, 2023 at 12:21

1 Answer 1

6
$\begingroup$

This is not an error but just a warning. And it is not a warning about the parameters. The parameter estimates are fine. It is a warning about the "properties" which specifically is about the estimated variances and covariances (from which t-statistics and P-values follow) being constructed assuming an unconstrained model.

While the OP does state that only a subset of their data is used to provide an example, as @UlrichNeumann states in a comment, one needs far more than 4 data points to obtain standard errors for 4 parameters.

When the model is constrained standard errors (and covariances) can still be obtained using a bootstrap approach.

Update

Given the newly added data, more inferences can be made. In short, the model is over-parameterized for the data. This is not about the number of data points but rather that the shape of the relationship doesn't require such a complicated model.

The main indication of this is the correlation matrix:

nlm["CorrelationMatrix"] // Quiet // MatrixForm

Correlation matrix

One can see that most of the correlations are near +1 which suggests an overparameterized model. When plotting the data and the fit, things don't look so bad but the complaint about very high standard errors is also a symptom of over-parameterization.

A simpler model provides a slightly better but near identical fit:

nlm2 = NonlinearModelFit[Y, a + b Log[o] + c Log[o]^2, {a, b, c}, o]
Show[ListPlot[Y], 
  Plot[{nlm[o], nlm2[o]}, {o, 1, 400}, PlotRange -> All, 
    PlotLegends -> {"Original model", "Simpler model"}]]  

Data and two fits

So...if there is a theoretical reason for the given model, one needs to figure out (1) if the theory is wrong, or (2) if the collected data is not generated by the model, or (3) if the range of the predictor variable is insufficient to obtain good estimates of the parameters.

Overparameterization doesn't imply poor predictions. But it does mean you can't trust the estimates of the individual parameters.

$\endgroup$
2
  • $\begingroup$ The modified post has more data points, however the high standard errors problem remains, along with the "warning message." Will appreciate any further suggestion on it. Thanks $\endgroup$
    – user49535
    Jun 15, 2023 at 13:23
  • $\begingroup$ Thanks. The additional data was essential for diagnosing the issue. $\endgroup$
    – JimB
    Jun 15, 2023 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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