cosinor(angle,x=NULL,code=NULL,period=24,opti=FALSE)
circadian.mean(angle, hours=TRUE)
circadian.cor(angle, hours=TRUE)
circadian.linear.cor(angle,x,hours=TRUE)
The cosinor function will either iteratively fit cosines of the angle to the observed data (opti=TRUE) or use the circular by linear regression to estimate the best fitting phase angle. If cos.t <- cos(time) and sin.t = sin(time) (expressed in hours), then beta.c and beta.s may be found by regression and the phase is $sign(beta.c) * acos(beta.c/\sqrt(beta.c^2 + beta.s^2)) * 12/pi$
Simulations (see examples) suggest that with incomplete times, perhaps the optimization procedure yields slightly better fits with the correct phase than does the linear model, but the differences are very small.
time <- seq(1:24)
pure <- matrix(time,24,18)
pure <- cos((pure + col(pure))*pi/12)
matplot(pure,type="l")
p <- cosinor(time,pure)
set.seed(42)
noisey <- pure + rnorm(24*18)
n <- cosinor(time,noisey)
small.pure <- pure[c(6:18),]
small.noisey <- noisey[c(6:18),]
sp <- cosinor(time[c(6:18)],small.pure)
spo <- cosinor(time[c(6:18)],small.pure,opti=TRUE)
sn <- cosinor(time[c(6:18)],small.noisey)
sno <- cosinor(time[c(6:18)],small.noisey,opti=TRUE)
sum.df <- data.frame(pure=p,noisey = n, small=sp,small.noise = sn, small.opt=spo,small.noise.opt=sno)
round(sum.df,2)
round(circadian.cor(sum.df[,c(1,3,5,7,9,11)]),2) #compare alternatives
round(cor(sum.df[,c(2,4,6,8,10,12)]),2)
Run the code above in your browser using DataLab