% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ild_tvem.R
\name{ild_tvem}
\alias{ild_tvem}
\title{Fit a time-varying effects model (TVEM) for ILD}
\usage{
ild_tvem(
  data,
  outcome,
  predictor,
  time_var = ".ild_time_num",
  k = 10L,
  re_id = TRUE,
  ...
)
}
\arguments{
\item{data}{An ILD object (see [is_ild()]).}

\item{outcome}{Character. Name of the outcome variable.}

\item{predictor}{Character. Name of the predictor with a time-varying effect.}

\item{time_var}{Character. Name of the time variable (default \code{".ild_time_num"}).}

\item{k}{Integer. Basis dimension for smooth terms (default 10).}

\item{re_id}{Logical. If \code{TRUE} (default), include a random intercept by person (\code{s(.ild_id, bs="re")}).}

\item{...}{Passed to [mgcv::gam()].}
}
\value{
A fitted \code{gam} object with class \code{c("tidyild_tvem", "gam", ...)}
  and attribute \code{ild_tvem_meta} (list with \code{outcome}, \code{predictor},
  \code{time_var}, \code{k}, \code{re_id}).
}
\description{
Fits a GAM with a smooth in time and a time-varying coefficient for a
predictor using [mgcv::gam()]. Use [ild_tvem_plot()] to plot the
time-varying effect. Requires \code{.ild_time_num} (or a numeric time column).
}
\examples{
set.seed(1)
d <- ild_simulate(n_id = 10, n_obs_per = 15, seed = 1)
d$x <- rnorm(nrow(d))
x <- ild_prepare(d, id = "id", time = "time")
tv <- ild_tvem(x, "y", "x", k = 5, re_id = TRUE)
ild_tvem_plot(tv)
}
