harmonic.regression: Harmonic Regression

Description Usage Arguments Details Value References


Estimates amplitudes and phases along with confidence intervals and p-values from a set of time series that may oscillate with a specified period. A model, per default

y = m + a cos(ω t) + b sin(ω t),

is fitted to the time series. This model is equivalent to the model

m + c cos(ω t - φ),

with amplitude c = √(a^2 + b^2) and phase φ = atan2(b, a). P-values for c > 0 (more precisely: either a or b > 0 ) are computed by an F-test. Confidence intervals for the amplitudes and phases are computed by a linear error propagation approximation.


harmonic.regression(inputts, inputtime, Tau = 24, normalize = TRUE,
  norm.pol = FALSE, norm.pol.degree = 1, trend.eliminate = FALSE,
  trend.degree = 1)



Matrix of time series. Rows correspond to time points, columns to samples. If a vector is provided, it is coerced to a matrix.


Vector of the time points corresponding to the row in the time series matrix.


Scalar giving the oscillation period to estimate and test for.


Boolean, set to TRUE if normalization is to be performed (default). Unless norm.pol=TRUE, normalization is performed by dividing with the mean.


Boolean, set to TRUE if a polynomial should be fitted to each time series, and used for normalization. In this case, each point in a time series will be divided by the value of the fitted polynomial. Defaults to FALSE.


Scalar indicating the polynomial degree for the normalization (ignored if norm.pol=FALSE).


Boolean, set to TRUE if trend elimination is to be performed (see Details above). Defaults to FALSE.


Integer indicading the polynomial degree for the trend elimination, default is 1. Ignored when trend.eliminate=FALSE, which is the default.


The default setting is that the time series are normalized with their mean values. Optionally a polynomial of degree 1 or more is first fitted to each time series, whereupon the original time series are normalized by dividing with the fitted values at each point, thus trends in a fold-change sense are assumed. Another option is trend elimination, in which case the same model plus a polynomial: y = m + a cos(ω t) + b sin(ω t) + et + ft^2 + ... is fitted to the (possibly normalized) data. In this case, returned p-values still only concern the alternative c > 0 as defined above.

Values returned include normalized time series (if normalization is performed), normalization weights (means or polynomial coefficients if polynomial normalilzation is used), fitted normalized curves, fitted non-normalized curves, a data frame of amplitudes and phases (in radians), p-values according to an F-test (Halberg 1967), Benjamini-Hochberg adjusted p-values, a data frame of approximately 1.96 standard deviations for the amplitude and phase estimates, a matrix of coefficients a and b and possibly c,... , the sum square resuduals after the fit for each time series, and the covariance matrix for the three independent variables (1, cos(ω t), and sin(ω t)). The latter can be used in post-processing e.g. to obtain individual p-values for coefficients by t-tests.


A list containing:

means Vector (if norm.pol=FALSE) or matrix (otherwise) of the means or coefficients of the fitted polynomial used for the normalization
normts Matrix of mean-scaled or normalized-by-polynomial time series, same dimensionality as inputts
fit.vals Matrix of model fitted values to inputts
norm.fit.vals Matrix of model fitted values to the normalized (trend eliminated or mean scaled) time series
pars Data frame of estimated amplitudes and phases (in radians, between 0 and )
pvals Vector of p-values according to an F-test of the model fit against a restricted model (mean-centering only)
qvals Vector of Benjamini-Hochberg adjusted p-values
ci Data frame of one-sided approximative 95% () confidence intervals for the estimated amplitudes and phases
coeffs Matrix of estimated model parameters a and b
ssr Vector of sum square residuals for the model fits
df Scalar if inputts does not contain NAs and Vector otherwise, representing the degrees of freedom of the residual from the fit
ssx Matrix (3 times 3, if inputts does not contain NAs, a list of such matrices, one for each time series, otherwise) of covariances for the dependent variables corresponding to (m, a cos(ω t), and b sin(ω t), respecively)


Halberg F, Tong YL, Johnson EA: Circadian System Phase – An Aspect of Temporal Morphology; Procedures and Illustrative Examples. in: The Cellular Aspects of Biorhythms, Springer 1967.

HarmonicRegression documentation built on May 1, 2019, 6:50 p.m.