harmonic: Construct harmonic functions for fitting harmonic trend model

Description Usage Arguments Value Author(s) See Also Examples

View source: R/harmonic.R

Description

The function creates a matrix of the first m pairs of harmonic functions for fitting a harmonic trend (cosine-sine trend, Fourier regresssion) models with the response being x, a time series.

Usage

1
harmonic(x, m = 1)

Arguments

x

a time series

m

the number of pairs of harmonic functions to be created; 2m must be less than or equal to the frequency of x

Value

a matrix consisting of \cos(2k π t), \sin(2k π t), k=1,2,...,m, excluding any zero functions.

Author(s)

Kung-Sik Chan

See Also

season

Examples

1
2
3
4
5
data(tempdub)
# first creates the first pair of harmonic functions and then fit the model
har.=harmonic(tempdub,1)
model4=lm(tempdub~har.)
summary(model4)

Example output

Loading required package: leaps
Loading required package: locfit
locfit 1.5-9.1 	 2013-03-22
Loading required package: mgcv
Loading required package: nlme
This is mgcv 1.8-17. For overview type 'help("mgcv-package")'.
Loading required package: tseries

Attaching package: 'TSA'

The following objects are masked from 'package:stats':

    acf, arima

The following object is masked from 'package:utils':

    tar


Call:
lm(formula = tempdub ~ har.)

Residuals:
     Min       1Q   Median       3Q      Max 
-11.1580  -2.2756  -0.1457   2.3754  11.2671 

Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
(Intercept)      46.2660     0.3088 149.816  < 2e-16 ***
har.cos(2*pi*t) -26.7079     0.4367 -61.154  < 2e-16 ***
har.sin(2*pi*t)  -2.1697     0.4367  -4.968 1.93e-06 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 3.706 on 141 degrees of freedom
Multiple R-squared:  0.9639,	Adjusted R-squared:  0.9634 
F-statistic:  1882 on 2 and 141 DF,  p-value: < 2.2e-16

TSA documentation built on July 2, 2018, 1:04 a.m.