0

I want to find the value which makes the following function predict the observations contained in the following dataset.

require(mosaic)
d=data.frame(t=c(41.5,44,42.77,47), y=c(230,76.4/60,3.4,1))
fitModel(y~(-(47-t)*I/(35-t)*(1+exp((42.77-t)*I))),
     data=d,start=list(I=3.1,t=47))

It seems I am replicating exactly what the example in the function's help says, but yet it reports a rather obscure error message.

Error in qr(.swts * gr) : dims [product 2] does not match the length of object [4]

Any suggestions?

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
Agus camacho
  • 868
  • 2
  • 9
  • 24

1 Answers1

2

t is your independent variable, it should not be included in the “start” list.

Try:

require(mosaic)
d=data.frame(t=c(41.5, 44, 42.77, 47), y=c(230, 76.4/60, 3.4, 1))

fitModel(y~(-(47-t)*I/(35-t)*(1+exp((42.77-t)*I))),
     data=d, start=list(I=3.1))

Using nls() as alternative to fitModel():

nls(y~(-(47-t)*I/(35-t)*(1+exp((42.77-t)*I))),
          data=d, start=list(I=3.1))

Nonlinear regression model
  model: y ~ (-(47 - t) * I/(35 - t) * (1 + exp((42.77 - t) * I)))
   data: d
    I 
3.432 
 residual sum-of-squares: 1.126

Number of iterations to convergence: 4 
Achieved convergence tolerance: 4.092e-07
Dave2e
  • 22,192
  • 18
  • 42
  • 50