Although,this question looks like a programming query, it needs a good understanding of the underlying statistics. For instance, although in my comment I have posted that I no longer see the error, I am not sure if I did the right thing.

In other words my query is : can we convert any window into a kernel by the trick described in the comment? I do think that, that is a statistics query and hence belongs to stats.stackexchange.com.

There are many windows in the package gsignal.

Here is a link to it's vignette. Section 6 of the above talks about Windowing functions and lists a lot of them.

I wish to use some of them to smooth a periodogram after tapering the input series, with say for example a slepian taper.

I do realize that the vignette says that the windows are for tapering, but I think the same windows can be used for smoothing.

Here is my attempt at smoothing using the above mentioned windows.

# I use the inbuilt dataset lh in R for this example.

# I use the multitaper package to create a slepian taper.
slepian_tapered = lh * dpss(n=length(lh),k=1,nw=1)$v

# I use the gsignal package to create a window of length 11.

s = gausswin(11)

The above is an input to spectrum which needs a kernel of type tskernel to smooth the periodogram. I read this above in ?spec.pgram

To create a kernel of type tskernel I read this

This above suggests that the incantation:

kernel(coef) should do the trick.

where coef is the upper half of the smoothing kernel coefficients (including coefficient zero)

That is why I subset and keep the last 6 coefficients of s.

s = s[6:11]

spectrum(x=slepian_tapered,kernel=kernel(coef = s),method="pgram",taper=0)
Error in kernel(coef = s) : coefficients do not add to 1

It throws an error that the coefficients do not add to 1. Is there a way of fixing this ? Or do I have to use some other package which has a list of smoothing windows ? What is the correct way of doing this?

  • $\begingroup$ I did : t = s/sum(s), and then used kernel = kernel(coef = t[6:11]), and then it no longer gives the error that coefficients do not add to 1. $\endgroup$ Commented Jul 11 at 10:28