2

I have a daily time series with 30 years of data for a number of stations. I am using the biwavelet package in R to test for periodicity in data using the following code

di <- data.frame(d1$date, d1$t_min)
wt.t1 = wt(di)
par(oma = c(0, 0, 0, 1), mar = c(5, 4, 4, 5) + 0.1)
plot(wt.t1, plot.cb = TRUE, plot.phase = FALSE)

I got this error when when running the codes

Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
0 (non-NA) cases

Some of the datasets I am using have some missing daily value in each year. I am quite new R and programming. It seems that the missing value will lead to such error when using biwavelet package? My question is there any way to solve this issue in R?

Viliam Simko
  • 1,711
  • 17
  • 31
Lam
  • 23
  • 6

2 Answers2

0

I ran into the same problem. I'm not a wavelet or signals processing expert, so sorry for the lack of technicality.

wt won't work if there are missing data (NAs). If you try to get rid of the rows with NAs altogether, it will complain that the data you provided is not taken at "regularly-sampled intervals".

If your missing data is very rare, you could split your data set into "chunks" where there is continuous, regularly-spaced data ... and run wt over each "chunk" independently. However, by dividing the data set into smaller sets, wt loses the ability to find low frequencies. Good if the frequency range you are interested in is high enough to have a few periods in your "chunks" of continuous data.

The alternative would be to try some sort of interpolation to fill the gaps, again, it depends on your data, the extent of your gaps, etc. It would certainly give you weird results in the vicinity of where you interpolated, but at least you keep your data "as a whole" and retain the ability to search for the lower frequencies.

Ant
  • 790
  • 7
  • 18
0

Try replacing NAs with 0.

data[is.na(data)] <- 0
Viliam Simko
  • 1,711
  • 17
  • 31