Skip to content

Cosinor Model (Halberg, Bingham) - Multiple components - Linear, Quadratic and Cubic trends

2 messages · Iva P, BXC (Bendix Carstensen)

#
Dear Iva,
First it is normal politeness to identify yourself with name an affiliation at the end of your email to a list like this, many people will not answer anonymous e-mails.

It is a little unclear to me what you mean.

If you are alluding to quadratic or cubic terms in some variable 
you just include then in the model al

lm( y ~ I(z^2) + I(z^3), data=...)

But if you are referring to harmonic functions of higher order you can put hem in as separate sines and cosinse:

lm( y ~ I(cos(2*pi*t/T)) + I(sin(2*pi*t/T)) + I(cos(4*pi*t/T)) + I(sin(4*pi*t/T)) )

Here is a small function and a demo that shows what it does, maybe this is what you are looking for:

harm <-
function( mm, n )
{
  # Function to devise a n'th order harmonic from a
  # numerical vector, scaled to be in the range 0 to 1

  MM <- cbind(
  outer( mm * 2 * pi, 1:n, function(x,y) cos( x*y ) ),
  outer( mm * 2 * pi, 1:n, function(x,y) sin( x*y ) )
              )[,rep(1:n,each=2)+rep(0:1,n)*n]
  colnames( MM ) <- outer( c("cos","sin"), 1:n, paste, sep="" )
  MM
}

x <- seq(0,1,,100)
head( harm(x,3) )
matplot( x, harm(x,3), type="l", lty=1, lwd=2 ) 

Best regards
Bendix Carstensen
Epi package maintainer
______________________________________________

Bendix Carstensen 
Senior Statistician
Epidemiology
Steno Diabetes Center A/S
Niels Steensens Vej 2-4
DK-2820 Gentofte
Denmark
+45 44 43 87 38 (direct)
+45 30 75 87 38 (mobile)
bxc at steno.dk    http://BendixCarstensen.com
www.steno.dk