# Nonparametric estimate for spectral density and smoothing

We've just learned nonparametric estimate of spectral density, and the book doesn't explain it well. We have a r assignment that need to find a nonparametric estimate and find predominant periods. I am just confused in how much should I smooth, and what am I looking for in the smoothed graph.

Here is the priodogram of the data. And we need to smooth it using kernel and/or taper.

The command for kernel smoothing is kernel("daniell",m). I am just confused on how should I choose m. The book just says try different values of m and find the better one. But I don't know what makes a good m-value. I use kernel("daniell", 4) and the graph looks like this.

Then I try kernel("modified daniell", c(4,4)) and the graph looks like this.

The periodogram with modified daniell is smoother, but I don't know if I've oversmoothed it and I don't know what to look for in the graph. The original data has three peaks, so I found three predominant periods while the last smooth graph had one peak, meaning that I can only find one predominant period. Do we want to smooth the graph but keep the three peaks or just keep a general shape like the last smoothed periodogram? And since we are really just looking at the left portion of raw periodogram, would tapering help in this problem?

I have submitted an answer previously that may help you out, at least with an explanation about the tapering part: Power density spectrum formula in R

I would caution against using a smoothed periodogram; something about "lipstick on a pig" comes to mind :)

In addition, if you decide to use the multitaper package in R (linked post), you can calculate a harmonic F-test (basically tests whether there exists a periodic component that isn't just noise at each frequency).

library("multitaper")
samplingRate <- 0.5 # it looks like this is what you're using
nw <- 4 # time bandwidth parameter for the tapers being used
ntapers <- floor(2*nw-1) # number of tapers

x.spec <- spec.mtm(x, Ftest = TRUE, nw = nw, k = ntapers, deltat = samplingRate, dtUnits = "second") #change dtUnits to appropriate unit
# nw is the time bandwidth parameter, and k is the number of tapers

plot(x.spec$freq, x.spec$mtm\$Ftest, type = 'l')
abline(h = qf(0.99, 2, 2*ntapers - 2)) # set 0.99 to whatever cutoff you think is appropriate
#a heuristic is to use 1 - 1/N, where N is the number of data points being used


At any rate, if there exists two frequencies of interest that are closely spaced together, as it appears from your first plot, the F-test should be able to pick them out. If you smooth the periodogram, you're losing that information and it just looks like one frequency. In fact, you'd be picking the frequency in between the two peaks.

Note: spec.mtm() zero-pads for you, although you can change this behaviour with the nFFT function argument.

If this didn't really help, or if I can help out further, please let me know.

• thanks for nice answer. This is slightly off topic but what text do you recommend for spectral techniques ? percival and walden is popular but I don't have it. they are coming out with a new book in 2020 ? Commented Dec 3, 2019 at 20:13