View source: R/model_matrix_functions.R
| cosinor | R Documentation |
Builds a design matrix of sin/cos pairs for use in models
with periodic predictors. Can be used directly or inside formulas passed
to make_matrices (where expansion is handled automatically).
cosinor(x, period = 24)
x |
Numeric vector of the periodic variable. |
period |
Numeric vector of period lengths, e.g. |
The resulting columns form the basis for linear predictors of the form
\eta_t = \beta_0 + \sum_k \Bigl(
\beta_{1k} \sin\!\Bigl(\tfrac{2 \pi x_t}{\text{period}_k}\Bigr) +
\beta_{2k} \cos\!\Bigl(\tfrac{2 \pi x_t}{\text{period}_k}\Bigr)
\Bigr).
A numeric matrix with 2 * length(period) columns named
sin(2*pi*x/period) / cos(2*pi*x/period).
cosinor(1:24, period = 24)
cosinor(1:24, period = c(24, 12, 6))
## In model formulas (expand_cosinor handles the expansion):
form <- ~ x + temp * cosinor(hour, c(24, 12))
data <- data.frame(x = runif(24), temp = rnorm(24, 20), hour = 1:24)
modmat <- make_matrices(form, data = data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.