4

I have a series of high-low tide values, approx. every 6h, and each one has the corresponding time. I would like to get (an estimation of) the values between each record. I was thinking I could create a sinusoidal curve but I am not sure if just simply giving the min-max y-values are enough.

Here is a part of the data:

y <- c(0.96, 0.27, 1.11, 0.35, 0.90, 0.35, 1.06, 0.34, 0.90, 0.38, 1.06, 0.28)
t <- c(42489.02, 42489.27, 42489.55, 42489.82, 42490.07, 42490.32, 42490.60, 42490.88, 42491.13, 42491.39, 42491.66, 42491.94)

I tried to apply the following formula (following this question: Fit a sinusoidal term to data):

res <- nls(y ~ A*sin(omega*t+phi)+C, data=data.frame(t,y), start=list(A=1,omega=1,phi=1,C=1))

But I got this error:

Error in nls(y ~ A * sin(omega * t + phi) + C, data = data.frame(t, y),  : 
  step factor 0.000488281 reduced below 'minFactor' of 0.000976562

1º Question: Is this approach correct for the result I want?

2º Question: If it is, how can I solve this error?

Nick Cox
  • 48,377
  • 8
  • 110
  • 156
mtao
  • 471
  • 5
  • 14
  • 3
    I think it's easier to use least squares on sine and cosine. That way the phase is implicit but recoverable. See e.g. https://stats.stackexchange.com/questions/163837/linear-regression-with-sine-cosine-elements https://www.stata-journal.com/sjpdf.html?articlenum=st0116 (esp. p.567) – Nick Cox Jun 11 '18 at 11:23
  • 1
    Use the direct and inverse Fourier transforms, way easier (and equivalent to regression on sine and cosine terms). – Firebug Jun 11 '18 at 11:44
  • 1
    Tidal data tends not to be sinusoidal: the pattern is asymmetric. Consider obtaining some data about the intervening times. – whuber Jun 11 '18 at 13:38
  • 1
    Tide table predictions are fairly well established and behave a bit like train schedules, e.g., here, https://tidesandcurrents.noaa.gov/predmach.html, see formulas #1 and #2. Along with time if you have date, location and plugging average values in for the unknowns into the NOAA formulas you would have a much greater chance of obtaining reasonable estimates. – Mike Hunter Jun 11 '18 at 13:41
  • @NickCox How can I apply that in R? I've been trying to find good examples but I am not having a lot of success... – mtao Jun 11 '18 at 17:34
  • @Firebug is the "fourierin" package enough to estimate it?? – mtao Jun 11 '18 at 17:35
  • @DJohnson, but I don't have most of the parameters they ask... Basically I only have "h" and "t"... – mtao Jun 11 '18 at 17:46
  • 1
    Not a routine R user, sorry, but how do anything in any particular software is off-topic here unless there is a statistical issue. (I quoted the _Stata Journal_ paper for its explanation of principles, not its Stata code.) The positive point is that the recommended procedure is just regression (notwithstanding other key comments that tides have a different basis). – Nick Cox Jun 11 '18 at 18:05
  • 1
    You'll have to do some research into the guts of the NOAA formulas to discern appropriate and reasonable starting assumptions for the parameters based on averages and/or modal values. Once that's done simply plug them into the formulas as required. Given those plugs the only things that will vary are your observed minima and maxima by time. – Mike Hunter Jun 11 '18 at 19:13

0 Answers0