I am using fourier()
function of R which has arguments x,h,K. Can any body please explain me what is 'K' in this function and what is the use of it.
Thanks in advance.
I am using fourier()
function of R which has arguments x,h,K. Can any body please explain me what is 'K' in this function and what is the use of it.
Thanks in advance.
You could use any feature selection approach to find an optimal value of $k$.
Feature selection is an important subject in statistics. Explaining it is, however, outside the scope of the question and well covered elsewhere. You can find good references for this on the internet. For example consider chapter 7 of The Elements of Statistical Learning (2nd edition) a very good book on the subject that also happens to be available for free download at the author's website (see link).
There are many tools to perform feature selection. Perhaps the simplest, most intuitive is cross-validation. In the context of the model you try to fit (discrete fourier decomposition), cross-validation can be performed as so:
library(forecast)
library(McSpatial)
y<-ldeaths
n<-length(y)
x<-1:n
qmax<-floor(n/2)-1
The forecast
package doesn't include a tool to perform gcv
on Fourier decomposition fit of a time series. To do that, you can use the fourier
function in the McSpatial
package:
fit_g<-McSpatial::fourier(y~x,minq=1,maxq=qmax-1,crit="gcv")
fit_g$q
According to the gcv
criterion, the optimal value of K
(this parameter is called q
in the McSpatial
) for the ldeaths
dataset is 21. Now you can re-run the Fourier decomposition of the ldeaths
dataset with this optimal value of K
to obtain you final fit that is a valid forecast
object:
fit_f<-forecast::fourier(y,21)