Cosinor Regression Model for Detecting Seasonality in Yearly Data or Circadian Patterns in Hourly Data
Cosinor Regression Model for Detecting Seasonality in Yearly Data or Circadian Patterns in Hourly Data
Fits a cosinor model as part of a generalized linear model.
cosinor( formula, date, data, family = gaussian(), alpha =0.05, cycles =1, rescheck =FALSE, type ="daily", offsetmonth =FALSE, offsetpop =NULL, text =TRUE)
Arguments
formula: regression formula.
date: a date variable if type=daily , or an integer between 1 and 53 if type=weekly , or an integer between 1 and 12 if type=monthly , or a POSIXct date if type=hourly .
data: data set as a data frame.
family: a description of the error distribution and link function to be used in the model. Available link functions: identity, log, logit, cloglog. Note, it must have the parentheses.
alpha: significance level, set to 0.05 (default).
cycles: number of seasonal cycles per year if type=daily , weekly or monthly ; number of cycles per 24 hours if type=hourly
rescheck: plot the residual checks (TRUE/FALSE), see seasrescheck.
type: daily for daily data (default), or weekly for weekly data, or monthly for monthly data, or hourly for hourly data.
offsetmonth: include an offset to account for the uneven number of days in the month (TRUE/FALSE). Should be used for monthly counts (type=monthly ) (with family=poisson()).
offsetpop: include an offset for the population (optional), this should be a variable in the data frame. Do not log-transform this offset, as the transform is applied by the code.
text: add explanatory text to the returned phase value (TRUE) or return a number (FALSE). Passed to the invyrfraction function.
Returns
Returns an object of class Cosinor with the following parts: - call: the original call to the cosinor function. - glm: an object of class glm (see glm). - fitted: fitted values for intercept and cosinor only (ignoring other independent variables). - fitted.plus: standard fitted values, including all other independent variables. - residuals: residuals. - date: name of the date variable (in Date format when type=daily ).
Details
The cosinor model captures a seasonal pattern using a sinusoid. It is therefore suitable for relatively simple seasonal patterns that are symmetric and stationary. The default is to fit an annual seasonal pattern (cycle=1), but other higher frequencies are possible (e.g., twice per year: cycle=2). The model is fitted using a sine and cosine term that together describe the sinusoid. These parameters are added to a generalized linear model, so the model can be fitted to a range of dependent data (e.g., Normal, Poisson, Binomial). Unlike the nscosinor model, the cosinor model can be applied to unequally spaced data.
Examples
## cardiovascular disease data (offset based on number of days in...## ...the month scaled to an average month length)data(CVD)res = cosinor(cvd~1, date='month', data=CVD, type='monthly', family=poisson(), offsetmonth=TRUE)summary(res)seasrescheck(res$residuals)# check the residuals## stillbirth datadata(stillbirth)res = cosinor(stillborn~1, date='dob', data=stillbirth, family=binomial(link='cloglog'))summary(res)plot(res)## hourly indoor temperature datares = cosinor(bedroom~1, date='datetime', type='hourly', data=indoor)summary(res)# to get the p-values for the sine and cosine estimatessummary(res$glm)
References
Barnett, A.G., Dobson, A.J. (2010) Analysing Seasonal Health Data. Springer.