# cosinor: Cosinor Regression Model for Detecting Seasonality in Yearly... In season: Seasonal Analysis of Health Data

 cosinor R Documentation

## Cosinor Regression Model for Detecting Seasonality in Yearly Data or Circadian Patterns in Hourly Data

### Description

Fits a cosinor model as part of a generalized linear model.

### Usage

```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.

### 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.

### Value

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’).

### References

Barnett, A.G., Dobson, A.J. (2010) Analysing Seasonal Health Data. Springer.

`summary.Cosinor`, `plot.Cosinor`

### 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 data
data(stillbirth)
res = cosinor(stillborn~1, date='dob', data=stillbirth,
{"ft_lang_label":"__label__en","ft_lang_prob":0.62054116,"math_prob":0.8965817,"size":3430,"snap":"2023-40-2023-50","text_gpt3_token_len":904,"char_repetition_ratio":0.10712201,"word_repetition_ratio":0.00754717,"special_character_ratio":0.2489796,"punctuation_ratio":0.1609375,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98084074,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-09-30T08:36:54Z\",\"WARC-Record-ID\":\"<urn:uuid:7927aa8f-8bdb-46b9-8ca3-df8b2ab14f47>\",\"Content-Length\":\"35308\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:6f3acd24-893f-4b79-a512-99af6510cfd0>\",\"WARC-Concurrent-To\":\"<urn:uuid:e0291f4b-4841-44ea-b8d4-d42d45faa750>\",\"WARC-IP-Address\":\"51.81.83.12\",\"WARC-Target-URI\":\"https://rdrr.io/cran/season/man/cosinor.html\",\"WARC-Payload-Digest\":\"sha1:ZSVVWXZTWX24B7TX2MA6ZUEZBMHTOMRC\",\"WARC-Block-Digest\":\"sha1:PDLWCGXIVHNTQIUNC7AIRN4CIIS2CN5Y\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233510671.0_warc_CC-MAIN-20230930082033-20230930112033-00589.warc.gz\"}"}