[R] invalid type (list) for variable 'y' in library minpack.lm
Luigi Marongiu
m@rong|u@|u|g| @end|ng |rom gm@||@com
Thu Jun 25 12:18:49 CEST 2020
Hello,
I am trying to find the best fit to a function for epidemic analysis.
I am trying with the package minpack.lm but I don't really know how to
use it. I am getting the error:
```
Error in model.frame.default(formula = ~y + x, data = list(Y)) :
invalid type (list) for variable 'y'
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
```
So I have some questions:
- how to solve the list problem? (what is the input for nlsLM? I have
a vector with the actual values, shall I convert in a dataframe?)
- how to avoid infinitives?
- is there another function other than nlsLM that I should use?
- is there another function that could fit a sigmoid profile other
than Holling type III?
This is the working example:
```
holling = function(a, b, x) {
y = (a * x^2) / (b^2 + x^2)
return(y)
}
Y = c(8, 24, 39, 63, 89, 115, 153, 196, 242, 287, 344, 408, 473,
546, 619, 705, 794, 891, 999, 1096, 1242, 1363, 1506, 1648, 1753,
1851, 1987, 2101, 2219, 2328, 2425, 2575, 2646, 2698, 2727, 2771, 2818,
2853, 2895, 2926, 2964, 2995, 3025, 3053, 3080, 3102, 3119, 3141, 3152,
3159, 3172, 3182, 3196, 3209, 3220, 3231, 3239, 3246, 3252, 3261)
X = 1:60
A = 3261
B = 10
plot(X, Y,
col = "red", pch =16, lwd = 2,
main = paste("Starting values: a=", A, "; b=", B, sep =""),
xlab = expression(bold("Days of infection")),
ylab = expression(bold("Cumulative incidence")))
HL = holling(A, B, X)
points(X, HL, type = "l", lty = 2)
# estimation
library("minpack.lm")
init_parms = c(a=A, b=B)
est = nlsLM(formula = y~(a*x^2)/(b^2 + x^2), start=init_parms, data=list(Y))
```
--
Best regards,
Luigi
More information about the R-help
mailing list