I am trying to run a quadratic plateau model on some proportion data where values are bound between 0 and 100. I would like some help troubleshooting some errors I have encountered, and correctly interpreting results as well as understanding the equation and how to write it out correctly. If anyone has experience with these models any help will be greatly appreciated as I have hit a wall.
Example data:
Days Type Area
0 Abrasion 0
11 Abrasion 65.6513749
13 Abrasion 79.1887936
15 Abrasion 88.3947998
26 Abrasion 98.2726653
38 Abrasion 100
0 Abrasion 0
70 Abrasion 93.5047459
124 Abrasion 100
0 Abrasion 0
7 Abrasion 78.2666991
8 Abrasion 78.3624009
9 Abrasion 78.9448106
14 Abrasion 81.6443138
24 Abrasion 97.9969096
29 Abrasion 98.8788699
50 Abrasion 99.4708654
53 Abrasion 100
0 Laceration 0
8 Laceration 8.05965381
22 Laceration 67.1254163
83 Laceration 100
0 Laceration 0
8 Laceration 59.1650901
69 Laceration 96.1942307
74 Laceration 100
0 Laceration 0
49 Laceration 82.5396751
133 Laceration 100
0 Laceration 0
125 Laceration 100
0 Laceration 0
16 Laceration 48.5178133
X = Days Y = Area
I want to fit a quadratic plateau model to this data.
Code I am using:
### Find reasonable initial values for parameters
fit.lm = lm(Area ~ Days, data=healing)
a.ini = fit.lm$coefficients[1]
b.ini = fit.lm$coefficients[2]
clx.ini = mean(healing$Area)
### Define quadratic plateau function
quadplat = function(x, a, b, clx) {
ifelse(x < clx, a + b * x + (-0.5*b/clx) * x * x,
a + b * clx + (-0.5*b/clx) * clx * clx)}
### Find best fit parameters
model = nls(Area ~ quadplat(Days, a, b, clx),
data = healing,
start = list(a = a.ini,
b = b.ini,
clx = clx.ini),
trace = FALSE,
nls.control(maxiter = 1000))
summary(model)
When I run this on some data it works fine but other times I get the following error:
Error in nls(Area ~ quadplat(Days, a, b, clx), data = healing, :
singular gradient
I am unsure as to why I get this with some data and not with others. For example, when I run the Laceration
subset the model runs fine. Model output:
Formula: Area ~ quadplat(Days, a, b, clx)
Parameters:
Estimate Std. Error t value Pr(>|t|)
a 1.2304 3.8509 0.320 0.753
b 3.0869 0.5595 5.518 2.54e-05 ***
clx 62.7697 11.0592 5.676 1.80e-05 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 11.86 on 19 degrees of freedom
Number of iterations to convergence: 8
Achieved convergence tolerance: 3.234e-06
I interpret this as the critical threshold where there is no statistical change in Y with an increase in X is 62.7697 days. Is that a correct interpretation?
Plot below:
To me, this plot looks good.
However, when I run the same analysis with the abrasion
subset I get the singular gradient
error. Why might this be, is this because the data is not fitting well?
Please can someone with knowledge of nls help me by explaining exactly what this quadratic model is doing and why I might get an error. I don't want to 'black box' this analysis and I think I am missing key understanding. Additionally, if anyone out there is good at interpreting formulas, can you help me by writing up this code into a readable formula?
function(x, a, b, clx) {
ifelse(x < clx, a + b * x + (-0.5*b/clx) * x * x,
a + b * clx + (-0.5*b/clx) * clx * clx)}
Any information on this question is greatly appreciated or directions toward good resources on nls. I really need some help here and can attach my full dataset if needed.
nls
(least squares) to fit proportions is not statistically suitable. One solution, then, would be to reconsider both your model and the fitting procedure, rather than working to make this one run without errors. Perhaps the computational errors are telling you something important! $\endgroup$