% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/pep_simulate.R
\name{pep_simulate}
\alias{pep_simulate}
\title{Simulate Synthetic PEP Data}
\usage{
pep_simulate(pep, min_obs = 20, seed = 42, progress = TRUE)
}
\arguments{
\item{pep}{A \code{pep} object or \code{data.table} with at least the
columns \code{species}, \code{phase_id}, \code{s_id}, \code{year}, and
\code{day}.}

\item{min_obs}{Integer. Minimum number of observations required per
station-species-phase group to attempt GAM fitting.
Groups with fewer observations keep their original \code{day} values
unchanged. Default is 20.}

\item{seed}{Integer. Random seed for reproducibility. Default is 42.}

\item{progress}{Logical. Show a progress bar? Default \code{TRUE}.}
}
\value{
A \code{\link[=new_pep]{pep}} object with the same rows and columns
as the input.  The \code{day} column is overwritten with synthetic values
for groups that meet the \code{min_obs} threshold; other rows retain their
original values.
}
\description{
Generates synthetic phenological observations by fitting a GAM smooth
(\code{day ~ s(year)}) per station-species-phase group and replacing the
observed \code{day} values with predictions plus Gaussian noise.  The
station-year-species-phase structure of the input data is kept intact.
}
\details{
For each qualifying group (station x species x phase with at least
\code{min_obs} observations), a GAM is fitted and synthetic day-of-year
values are generated as \code{round(predicted + rnorm(n, sd = residual_sd))}.

Groups where the GAM fit fails receive a fallback: the species-phase median
day plus Gaussian jitter (sd = 5 days).

Groups below the \code{min_obs} threshold are left unchanged.  A message
reports how many rows were not simulated.
}
\examples{
\donttest{
pep <- pep_download()
# Single species + country for fast example
vine_ch <- pep[species == "Vitis vinifera" & country == "Switzerland"]
pep_synth <- pep_simulate(vine_ch)
}
}
\author{
Matthias Templ
}
