3
$\begingroup$

I am working on the movement of fish species from the centre of a protected area to a non-protected area. Based on the article by R. Abesamis, itself inspired by the work of B. Kaunda-Arar (page 91), I applied to my dataset a logistic decay D = 1/(1+exp(S*(I-d)) where D is the proportion of biomass in the middle of the reserve, d is the distance from the centre of the protected area, S is the slope and I is the inflection point. The parameters to be estimated in this model are S and I. However, I had to use Excel to estimate these parameters because the nls function in R was giving me constant error messages (the well-known singular gradient error). I successfully estimated S and I using the Excel solver, but I need to know the standard errors of these parameters. For this, the article states that a linearization of my logistic model is necessary, but despite my research on this subject I do not understand how to do this.

My questions are therefore the following:

  1. Is it possible to get the standard error of my parameters directly from Excel? If so, how?
  2. If this is not possible in Excel, how can I get the standard errors of my S and I parameters in R? (note: using the nls function, even when applying the values obtained by my Excel model as starting values for S and I, the gradient error message is still displayed. Same thing when using nlsLM.)
$\endgroup$
7
  • 3
    $\begingroup$ You can use the Hessian. Excel's solver probably doesn't give an estimate for this, but for your function it is not difficult to derive it yourself. Alternatively you could use a Monte Carlo approach and resample the data (in Excel this is a bit awkward so you would better get it work in R). $\endgroup$ Dec 2, 2022 at 10:08
  • 2
    $\begingroup$ Your function can, with some reparametrisation, be solved as a GLM. Then use the solution from the GLM output to compute estimates and errors for the other parameters, or use the output as starting conditions for the NLS function. $\endgroup$ Dec 2, 2022 at 10:13
  • 2
    $\begingroup$ Not an answer to your question but a problem with your approach is that you probably have correlated data points. If you measure at different points $d$ but in a single area, then the fluctuations due to natural variation are likely the same for different nearby points. In addition, the use of a ratio also makes that the multiple values will be correlated. $\endgroup$ Dec 2, 2022 at 11:34
  • 1
    $\begingroup$ If you have different area's then you could fit the area's independently and observe the spread of the values of S and I among the different area's. That might possibly be a more relevant measure than the theoretical computed standard deviation. $\endgroup$ Dec 2, 2022 at 11:36
  • 1
    $\begingroup$ As a software solution to get the standard errors for a model fit with nls, you can use the nlstools package. $\endgroup$ Dec 2, 2022 at 13:30

3 Answers 3

5
$\begingroup$

The model

$$y = \frac{1}{1+e^{S(I-x)}}$$

can be reparametrised with $I = -a/b$ and $S=b$ as

$$y = \frac{1}{1+e^{-(a+bx)}}$$

This can be solved with GLM using a logit link function. Then you can use the estimates of $a$ and $b$ to compute the estimates of $I$ and $S$ and use the Delta method to compute the error. Or potentially you use nls with the GLM result as start conditions (although in this approach there would be smarter, faster, methods to generate starting conditions) to have nls compute the Hessian, which can be used as an approximation of the error (you could also derive this Hessian analytically).


Note: these estimates for the error assume that your data points are independent. This may not need to be the case. For instance, if the data points are a time series then likely the error terms are correlated.

Also, the error might not need to be with equal variance for different values of $x$. Does nls (assuming Gaussian errors with equal variance) make sense? In this case it may be easier to use a Monte Carlo method, which allows you to use whatever structure for the errors of the data and create a straight forward estimate of the fitted coefficients by simulations.

Another addition, if your model is misspecified, then estimates of the variance based on the Hessian or residual variance are not correct. This will overestimate the variance/error of the estimates. (In your case you might for instance think about a missing baseline term which causes such misspecification)

$\endgroup$
2
  • $\begingroup$ Thank you for your answers! I am not used to work with glm or with R in general. How do I practically write the above model y=1/(1+e-(a+bx)) in the glm function? $\endgroup$
    – Florian B.
    Dec 3, 2022 at 16:45
  • 1
    $\begingroup$ @FlorianB. while writing the answer I was thinking of adding an example and the main line would be a function call like glm(y ~ x, family = gaussian(link = 'logit'), start = c(0,0)) bit then I realised that fitting the model is actually a very bad idea because your data may be distributed a lot different. $\endgroup$ Dec 3, 2022 at 17:17
5
$\begingroup$

I'd be tempted to approach this with Bayesian methods, especially if observations are correlated and you also want to model this. For example, using the brms R package makes it very easy to fit models with non-linear terms in them as illustrated in the vignette on this topic. By having at least vague prior information (which you probably have based on simple physical limitations one can deduce) any problems in identifying them model parameters are often substantially reduced. The standard deviation of MCMC samples from the posterior for a parameter then play a similar role as a SE in frequentist inference (but you could also look at the posterior median and credible intervals based on distribution quantiles).

$\endgroup$
1
  • 2
    $\begingroup$ I was thinking about Bayesian models to. But, it doesn't solve misspecification of the model and only gives an alternative to Monte Carlo simulations for expressing the significance/deviation/accuracy of the model. On the other hand, with Bayesian modelling tools, one could easily make more complex models. In the case of the amount of fishes at the edge of no fishing zones (the background here) one could model directly the migration rate at different distances instead of using the clumsy logistic curve. $\endgroup$ Dec 2, 2022 at 12:38
3
$\begingroup$

If your model is $$ D=\frac{1}{1+e^{S(I-d)}}, $$ then you get $$ 1-D=1-\frac{1}{1+e^{S(I-d)}} = \frac{1+ e^{S(I+d)}-1}{1+e^{S(I+d)}} =\frac{e^{S(I-d)}}{1+e^{S(I-d)}} $$ Which means that $$ \frac{1-D}{D}=e^{S(I-d)} $$ and $$ \ln e^{S(I-d)} = S(I-d), $$ i.e., a linear function. You can apply methods for estimating parameters of a linear model now.

$\endgroup$
2
  • 1
    $\begingroup$ The term on the left in the last equation has a copy-paste-error/typo. $\endgroup$ Dec 2, 2022 at 10:47
  • 2
    $\begingroup$ Linearisation is not really a complete solution to finding standard errors of a non-linear model; it is a way to avoid the question. $\endgroup$ Dec 2, 2022 at 11:00

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.