0

I'm trying to fit some data with a negative exponential model in R, but it doesn't seem to work and I can't find the error or a way to work around it.

    t<-c(1,4,16)
    y<-c(0.8,0.45,0.04)
    tabla<-data.frame(t,y)
    reg<-nls(y~exp(-b*t),tabla,start = list(t=0,b=0))

I get the following error after running the code

Error in qr(.swts * attr(rhs, "gradient")) : 
 dims [product 2] do not match the length of object [3]
In addition: Warning message:
In .swts * attr(rhs, "gradient") :
 longer object length is not a multiple of shorter object length

JeffCJ
  • 15
  • 4
  • it's data, don't know why it didn't appear in the post, just edited! – JeffCJ Jun 03 '19 at 03:50
  • Not directly relevant but perhaps rename `t` to something else. While `R` can handle these issues, `t` might be hard to debug since it also represents the `t`ranspose function. – NelsonGon Jun 03 '19 at 05:23

1 Answers1

1

You are trying to estimate t, when it is the independent variable in your formula

t<-c(1,4,16)
y<-c(0.8,0.45,0.04)
tabla<-data.frame(t,y)
reg<-nls(y~exp(-b*t),tabla,start = list(b=0))

This works fine

JMilner
  • 491
  • 4
  • 12