% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fit.R
\name{fit_mobility}
\alias{fit_mobility}
\title{Fit a mobility distribution to an observed symptomatic time series}
\usage{
fit_mobility(
  times,
  I_obs,
  params,
  K = 3,
  m_grid = seq(0, 1, length.out = 51),
  I_seed = 1e-04,
  start = NULL,
  n_restarts = 5,
  control = list(maxit = 500),
  verbose = FALSE
)
}
\arguments{
\item{times}{Numeric vector of observation times (starting at 0).}

\item{I_obs}{Observed aggregate symptomatic fraction at each time.}

\item{params}{A \code{"seair_params"} object holding fixed
transmission and stage parameters.}

\item{K}{Number of Beta-mixture components (default 3).}

\item{m_grid}{Mobility grid for the solver.}

\item{I_seed}{Initial symptomatic fraction in \eqn{[0,1)}.}

\item{start}{Optional finite user-supplied starting parameter vector of
length \eqn{3K - 1}.}

\item{n_restarts}{Number of random restarts (default 5).}

\item{control}{List of \code{\link[stats]{optim}} control options.}

\item{verbose}{Logical; if \code{TRUE}, print progress.}
}
\value{
A list with \code{weights}, \code{shape1}, \code{shape2}
  (the fitted Beta-mixture parameters), \code{f_hat} (density on
  \code{m_grid}), \code{m_grid}, \code{loss} (final SSE),
  \code{I_fit} (simulated aggregate symptomatic time series at
  \code{times}), and \code{optim_result}.
}
\description{
Fits a Beta-mixture mobility distribution \eqn{f} by minimising the
sum of squared errors between an observed aggregate symptomatic
time series \eqn{\langle I \rangle(t)} and the simulated output of
the mobility-based SEAIR model at the same times.  All transmission
and stage parameters are held fixed.
}
\details{
The unconstrained optimisation parameter is, for each component
\eqn{k = 1, \ldots, K}, a triple
\eqn{(\log a_k, \log b_k, \log \tilde{w}_k)} with mixture weights
recovered as \eqn{w_k = \tilde{w}_k / \sum_j \tilde{w}_j}.  The
first weight's log is fixed to 0 to remove the scale ambiguity,
so the parameter vector has length \eqn{3 K - 1}.
}
\examples{
pars <- seair_params(beta = 1.5, sigma = 0.3, kappa = 0.2,
                     gamma_A = 0.1, gamma_I = 0.13,
                     alpha = 0.5, delta = 0.3)
m <- seq(0, 1, length.out = 21)
f_true <- dbeta(m, 3, 3)
init <- seair_init(m, f_true, I_seed = 1e-4)
times <- seq(0, 20, by = 5)
sol <- seair_solve(init, pars, times)
I_obs <- seair_aggregate(sol)$I

fit <- fit_mobility(times, I_obs, pars,
                    K = 1, m_grid = m,
                    start = log(c(3, 3)),
                    n_restarts = 0,
                    control = list(maxit = 20))
fit$loss

}
