[R] Error in nls model.frame

Rafael Barros de Rezende rafabarros at cedeplar.ufmg.br
Wed Oct 24 15:23:21 CEST 2007


   Error in model.frame

   When I run the following nls model an error message appears and I dont
   know how to solve that. Could you help me??

   mat = c(1,2,3,4,5,6,7,8,9,12,16,24,36,48,60)

   for (i in 1:length(j30)) {
   bliss = nls(c(j[i,1:length(mat)]) ~ b0 + b1*((1-exp(-k1*mat))/(k1*mat)) +
   b2*(((1-exp(-k2*mat))/(k2*mat))-exp(-k2*mat)),
   start = list(k1=0.1993, k2=0.1993, b0= 22.0046, b1=-2.7661, b2=-5.8912),
   trace = TRUE)
   }

   Error in  model.frame(formula,  rownames, variables, varnames, extras,
   extranames,  :
           variable lengths differ (found in 'mat')

   j is a (1883 x 15) matrix so I have 1883 nls regressions of j lines on mat
   as we can see in model bliss.

   The traceback() shows the following:

   > traceback()
   6: model.frame.default(formula = ~j + mat)
   5: model.frame(formula = ~j + mat)
   4: eval(expr, envir, enclos)
   3: eval(expr, p)
   2: eval.parent(mf)
   1: nls(c(j[i, 1:length(mat)]) ~ b0 + b1 * ((1 - exp(-k1 * mat))/(k1 *
          mat)) + b2 * (((1 - exp(-k2 * mat))/(k2 * mat)) - exp(-k2 *
          mat)), start = list(k1 = 0.1993, k2 = 0.1993, b0 = 22.0046,
          b1 = -2.7661, b2 = -5.8912), trace = TRUE)

   It seems that the error is in 6: model.frame.default(formula = ~j + mat) or
   5: model.frame(formula = ~j + mat), cause the formula should be (formula = j
   ~ mat).

   Am I right about that?? Again, how could I fix this problem?? I need a help
   here...

   Thanks.
   Rafael Barros de Rezende
   Economics MPhill Candidate - Curriculum Lattes:
   [1]http://lattes.cnpq.br/9826095609825249
   Cedeplar - Development and Regional Planning Center
   Face, UFMG ([2]http://www.cedeplar.ufmg.br) - Brazil

   --
   Esta mensagem foi verificada pelo sistema de antivírus e
   acredita-se estar livre de perigo.

References

   1. http://lattes.cnpq.br/9826095609825249
   2. http://www.cedeplar.ufmg.br/


More information about the R-help mailing list