% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/model_matrix_functions.R
\name{cosinor}
\alias{cosinor}
\title{Trigonometric basis expansion}
\usage{
cosinor(x, period = 24)
}
\arguments{
\item{x}{Numeric vector of the periodic variable.}

\item{period}{Numeric vector of period lengths, e.g. \code{24} for a daily cycle with hourly data or \code{c(24, 12)} for a daily + semi-daily cycle.}
}
\value{
A numeric matrix with \code{2 * length(period)} columns named
  \code{sin(2*pi*x/period)} / \code{cos(2*pi*x/period)}.
}
\description{
Builds a design matrix of \code{sin}/\code{cos} pairs for use in models
with periodic predictors. Can be used directly or inside formulas passed
to \code{make_matrices} (where expansion is handled automatically).
}
\details{
The resulting columns form the basis for linear predictors of the form
\deqn{
  \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).
}
}
\examples{
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)
}
