0

My non-linear model is the following:

fhw <- data.frame(
    time=c(10800, 10810, 10820, 10830, 10840, 10850, 10860, 10870, 10880, 10890),
  water=c( 105, 103, 103, 104, 107, 109, 112, 113, 113, 112)
)
nl <- nls(formula = water ~ cbind(1,poly(time,4),sin(omega_1*time+phi_1),
                        sin(omega_2*time+phi_2),
                        sin(omega_3*time+phi_3)), data = fhw, 
          start = list(omega_1=(2*pi)/545, omega_2=(2*pi)/205,
              omega_3=(2*pi)/85, phi_1=pi, phi_2=pi, phi_3=pi),
          algorithm = "plinear", control = list(maxiter = 1000))

Time is between 10800 and 17220, but I want to predict ahead. Using the function predict like this:

predict(nl,data.frame(time=17220:17520))

gives wrong results, since the first value it returns is complete different than the last value it return when I use predict(nl). I think the problem has something to do with poly, but I'm not sure. Furthermore, predicting at one time point, gives the error: degree' must be less than number of unique points. Can anybody help?

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • Is there a reason you are using `cbind()` in your formula rather than the traditional `y~a+b+c` style variable? I can't get the code provided to run myself. I get an error about "singular matrix 'a' in solve" – MrFlick Jan 17 '18 at 20:29
  • I use cbind(), because otherwise nls estimates only one coefficient for the polynomial, instead of 4. – userUnknown Jan 17 '18 at 20:33

0 Answers0