Luigi Marongiu
2020-Jun-25 10:18 UTC
[R] invalid type (list) for variable 'y' in library minpack.lm
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
Rasmus Liland
2020-Jun-25 11:24 UTC
[R] invalid type (list) for variable 'y' in library minpack.lm
Dear Luigi, On 2020-06-25 12:18 +0200, Luigi Marongiu wrote:> 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.Me neither ...> 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?)I got past the error by give minpack.lm::nlsLM X and Y in a data.frame minpack.lm::nlsLM( formula = y~(a*x^2)/(b^2 + x^2), start=c(a=A, b=B), data=data.frame(x=X, y=Y)) as per ?minpack.lm::nlsLM: data: an optional data frame in which to evaluate the variables in?formula? and ?weights?. Can also be a list or an environment, but not a matrix.> - 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?These other questions seem good and interesting, I hope someone else can answer them. Best, Rasmus -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20200625/0684db7f/attachment.sig>
Bert Gunter
2020-Jun-25 14:52 UTC
[R] invalid type (list) for variable 'y' in library minpack.lm
"These other questions seem good and interesting, I hope someone else can answer them." Perhaps, but not appropriate for this list, imo. Statistics issue mostly belong elsewhere, e.g. on stats.stackexchange.com. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Thu, Jun 25, 2020 at 4:25 AM Rasmus Liland <jral at posteo.no> wrote:> Dear Luigi, > > On 2020-06-25 12:18 +0200, Luigi Marongiu wrote: > > 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. > > Me neither ... > > > 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?) > > I got past the error by give > minpack.lm::nlsLM X and Y in a data.frame > > minpack.lm::nlsLM( > formula = y~(a*x^2)/(b^2 + x^2), > start=c(a=A, b=B), > data=data.frame(x=X, y=Y)) > > as per ?minpack.lm::nlsLM: > > data: an optional data frame in which to evaluate the variables > in?formula? and ?weights?. Can also be a list or an > environment, but not a matrix. > > > - 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? > > These other questions seem good and > interesting, I hope someone else can answer > them. > > Best, > Rasmus > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]