fitHReg: Fits Three Parameter Harmonic Regression

Description Usage Arguments Details Value Author(s) Examples

Description

Estimates A, B and f in the harmonic regression, y(t)=mu+A*cos(2*pi*f*t)+B*sin(2*pi*f*t)+e(t). The default algorithm is enumerative but an exact non-linear LS option is also provided.

Usage

1
fitHReg(y, t = 1:length(y), algorithm = c("enumerative", "exact"))

Arguments

y

series.

t

Time points.

algorithm

method for the optimization

Details

Program is interfaced to C for efficient computation.

Value

Object of class "HReg" produced.

Author(s)

A.I. McLeod and Yuanhao Lai

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
set.seed(193)
z <- simHReg(10,f=2.5/10,1,1)
ans <- fitHReg(z)
ans$freq #optimal frequency = 0.2376238 
#
#ORF06806 in Cc dataset. 
z<-c(0.42, 0.89, 1.44, 1.98, 2.21, 2.04, 0.82, 0.62, 0.56, 0.8, 1.33)
ans2 <- fitHReg(z, algorithm="exact")
sum(resid(ans2)^2) #0.2037463
ans1 <- fitHReg(z)
sum(resid(ans1)^2) #0.242072
#compare with nls()
t <- 1:length(z)
ans <- nls(z ~ mu+alpha*cos(2*pi*lambda*t+phi), 
              start=list(mu=1, alpha=1, lambda=0.1, phi=0.0))
coefficients(ans)
sum(resid(ans)^2) #0.2037

                                                        

ptest documentation built on May 2, 2019, 5:58 a.m.