1
$\begingroup$

This is my experimental data:

data = {{0, 5.5455}, {1, 5.561}, {3, 5.6075}, {10, 5.5455}, {30, 
    5.4835}, {100, 5.0965}, {300, 4.6935}, {1000, 4.438}, {14462, 
    4.012}, {23082, 3.9345}};

I need to fit to this model

model = 4.00 + p1 Exp[-(t/tau1)^mu1] + p2 Exp[-(t/tau2)^mu2];

with these conditions:

4.6 <= p1 <= 5.5

4.0 <= p2 <= 4.7

0<=mu1<=1

0<=mu2<=1

mi code is:

 NonlinearModelFit[data, model, {p1, p2, tau1, tau2, mu1, mu2}, t]

 But it gives this error:

FindFit::fitm: Unable to solve for the fit parameters; the design matrix is nonrectangular, non-numerical, or could not be inverted.

Power::indet: Indeterminate expression 0.^0. encountered.
Power::indet: Indeterminate expression 0.^0. encountered.
NonlinearModelFit::nrjnum: The Jacobian is not a matrix of real numbers at {p1,p2,tau1,tau2,mu1,mu2} = {1.,1.,1.,1.,1.,1.}.

the original result: enter image description here

I try this, but is nothing do

 With[{4.6 <= p1 <= 5.5, 4.0 <= p2 <= 4.3, 0 <= mu1 <= 1, 
      0 <= mu2 <= 1, 3.85 <= p0 <= 4.0}, 
      NonlinearModelFit[data, model, {p0, p1, p2, tau1, tau2, mu1, mu2}, 
      t]]
$\endgroup$
  • 3
    $\begingroup$ Your model is way too complex for the available data: 7 parameters and just 10 data points. You need to put in the constraints you mention and starting values that are consistent with the constraints (as the default starting values for all parameters is 1.0). $\endgroup$ – JimB May 11 '18 at 1:27
  • $\begingroup$ my data are from this experiment and the fit was made with the OriginLab $\endgroup$ – Andres May 11 '18 at 2:18
  • 2
    $\begingroup$ Your data is too small to make reliable conclusions. Statistics begins from sample size 30 (see google.com.ua/… ). $\endgroup$ – user64494 May 11 '18 at 4:21
2
$\begingroup$

It appears from your figure that you're really attempting to fit 8 parameters with just 10 data points. While the fit provides a good description of the data, it does not necessarily do much of anything predicting any new observations. And the variances of the parameter estimates can't even be estimated.

If we plot the data and the curve using the estimates in the figure, we get the following:

data = {{0, 5.5455}, {1, 5.561}, {3, 5.6075}, {10, 5.5455}, {30, 
    5.4835}, {100, 5.0965}, {300, 4.6935}, {1000, 4.438}, {14462, 
    4.012}, {23082, 3.9345}};

model = p0 + p1 Exp[-(t/tau1)^mu1] + p2 Exp[-(t/tau2)^mu2];

Show[ListPlot[data, PlotRangePadding -> {1000, 0.1}, 
  PlotRange -> {{0, 25000}, {3.5, 6}}, AxesOrigin -> {-1000, 3.5}], 
 Plot[model /. {p0 -> 3.87, p1 -> 0.98, p2 -> 1.15, tau1 -> 166, 
    tau2 -> 7255, mu1 -> 0.72, mu2 -> 0.75}, {t, 0, 23082}, 
  PlotRange -> All]]

Original fit

This doesn't look anything like the figure provided.

Consider the following set of parameters:

Show[ListPlot[data, PlotRangePadding -> {1000, 0.1}, 
  PlotRange -> {{0, 25000}, {3.5, 6}}, AxesOrigin -> {-1000, 3.5}], 
 Plot[model /. {p0 -> 3.833, p1 -> 1.246, p2 -> 0.808, tau1 -> 100, 
    tau2 -> 7480, mu1 -> 0.672, mu2 -> 0.612}, {t, 0, 23082}, 
  PlotRange -> All]]

Other fit

So with the above parameters we can reproduce a close facsimile of the original 10 data points.

But this doesn't mean we should be happy with the fit. If a nonlinear regression is performed using the above values as starting values for the parameters we see that that standard errors of the parameters can't even be estimated. One MUST be able to provide some estimate of precision for the parameters or the results are at best of unknown value and at worst completely misleading.

$\endgroup$
  • $\begingroup$ very usefull your code. It was a big problem for me. Thanks for helping $\endgroup$ – Andres May 11 '18 at 12:24
  • $\begingroup$ my teacher told me that the parameters had to be between the ranges (the ones that I propose) at the beginning, and that there must be some method of iteration that allows to introduce these ranges and be able to make the adjustment. P2 is not between 4.0 and 4.7 and that's what I need. $\endgroup$ – Andres May 11 '18 at 15:39
  • $\begingroup$ With[{4.6 <= p1 <= 5.5, 4.0 <= p2 <= 4.3, 0 <= mu1 <= 1, 0 <= mu2 <= 1, 3.85 <= p0 <= 4.0}, NonlinearModelFit[data, model, {p0, p1, p2, tau1, tau2, mu1, mu2}, t]] $\endgroup$ – Andres May 11 '18 at 16:04
  • 1
    $\begingroup$ The documentation on NonlinearModelFit shows how to include restrictions. (See my comment on your question.) nlm = NonlinearModelFit[ data, {model, 4.6 <= p1 <= 5.5 && 4. <= p2 <= 4.3 && 0 <= mu1 <= 1 && 0 <= mu2 <= 1 && 3.85 <= p0 <= 4.}, {{p0, 3.9}, {p1, 5}, {p2, 5}, {tau1, 150}, {tau2, 150}, {mu1, 0.4}, {mu2, 0.8}}, t]. This doesn't produce a great fit of the data. However, there are no estimates of the standard errors for the parameter estimates. In short: don't do it. The model is too complex for the data and/or the data is inadequate for the model. $\endgroup$ – JimB May 11 '18 at 16:35
1
$\begingroup$

A simpler double exponential decay model works a lot better here:

simpleModel = const + p1 Exp[-t/tau1] + p2 Exp[-t/tau2];
nlm = NonlinearModelFit[data, simpleModel, {const, p1, p2, tau1, tau2}, t];

nlm["BestFitParameters"]
nlm["RSquared"]

(*Out: 
  {const -> 3.88251, p1 -> 1.09949, p2 -> 0.611069, tau1 -> 184.794, tau2 -> 9344.11} 
  0.999967
*)

Compare also graphically:

Plot[
  nlm[x], {x, 0, 23100},
  Epilog -> {Red, PointSize[0.02], Point[data]},
  PlotRange -> All, Axes -> False, Frame -> True,
  FrameLabel -> {"Time (s)", "P* (\[Mu]C/\!\(\*SuperscriptBox[\(cm\), \(2\)]\))"}
]

Mathematica graphics

$\endgroup$
  • $\begingroup$ good code. Thanks for helping. $\endgroup$ – Andres May 11 '18 at 12:26
  • 3
    $\begingroup$ This, too, is misleading. Consider nlm["ParameterTable"] which shows huge standard errors. nlm["CorrelationMatrix"] with so many correlations among the parameter estimates being 1.0 shows that even this simpler model is way over parameterized. Measures of precision are essential. Don't leave home without them! $\endgroup$ – JimB May 11 '18 at 14:07
  • $\begingroup$ $$\left( \begin{array}{ccccc} \text{} & \text{Estimate} & \text{Standard Error} & \text{t-Statistic} & \text{P-Value} \\ \text{const} & 4.04941 & 0.105127 & 38.5193 & \text{2.222196271454996$\grave{ }$*${}^{\wedge}$-7} \\ \text{p1} & -227.582 & 234.855 & -0.969033 & 0.377035 \\ \text{p2} & 229.085 & 234.799 & 0.975662 & 0.374041 \\ \text{tau1} & 421.324 & 1.25003\times 10^9 & \text{3.3705203548810786$\grave{ }$*${}^{\wedge}$-7} & 1. \\ \text{tau2} & 421.324 & 1.24183\times 10^9 & \text{3.392775884413001$\grave{ }$*${}^{\wedge}$-7} & 1. \\ \end{array} \right)$$ $\endgroup$ – JimB May 11 '18 at 14:08
  • $\begingroup$ nlm["CorrelationMatrix"]: $$\left( \begin{array}{ccccc} 1. & -0.340924 & 0.340551 & -0.340738 & -0.340738 \\ -0.340924 & 1. & -1. & 1. & 1. \\ 0.340551 & -1. & 1. & -1. & -1. \\ -0.340738 & 1. & -1. & 1. & 1. \\ -0.340738 & 1. & -1. & 1. & 1. \\ \end{array} \right)$$ $\endgroup$ – JimB May 11 '18 at 14:09
  • $\begingroup$ my teacher told me that the parameters had to be between the ranges (the ones that I propose) at the beginning, and that there must be some method of iteration that allows to introduce these ranges and be able to make the adjustment. P2 is not between 4.0 and 4.7 and that's what I need. $\endgroup$ – Andres May 11 '18 at 15:39

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.