% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/spatial-markov.R
\name{spatial_markov}
\alias{spatial_markov}
\title{Estimate Spatial Markov Transition Dynamics}
\usage{
spatial_markov(
  data,
  id,
  time,
  value,
  geometry = NULL,
  listw = NULL,
  nb = NULL,
  k = 5,
  lag_k = k,
  class_method = c("pooled_quantile", "time_quantile", "fixed"),
  zero.policy = TRUE
)
}
\arguments{
\item{data}{A long data frame or \code{sf} object.}

\item{id, time, value}{Columns identifying spatial unit, time, and value.}

\item{geometry}{An \code{sf} tibble with one row per spatial unit (a single time
slice's geography), carrying \code{nb} and \code{wt} list-columns produced by
\code{sfdep::st_contiguity()} and \code{sfdep::st_weights()}. The preferred input.}

\item{listw}{A row-standardized \code{spdep} \code{listw} object. Accepted for
compatibility with prior workflows; use \code{geometry} for new code.}

\item{nb}{A \code{spdep} neighbor list, used only when both \code{geometry} and
\code{listw} are \code{NULL}. Converted with \code{spdep::nb2listw(style = "W")}.}

\item{k}{Number of value classes.}

\item{lag_k}{Number of spatial-lag classes.}

\item{class_method}{Value classification method passed to \code{\link[=classify_dynamics]{classify_dynamics()}}.}

\item{zero.policy}{Passed to \code{spdep} lag/weight helpers.}
}
\value{
A \code{grd_spatial_markov} object.
}
\description{
Estimates transition matrices conditioned on the class of each unit's spatial
lag at the start of the transition period.
}
\examples{
\dontshow{if (identical(Sys.getenv("IN_PKGDOWN"), "true")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
panel <- data.frame(
  id = rep(1:4, each = 3),
  year = rep(2020:2022, times = 4),
  value = c(1, 2, 3, 2, 3, 4, 4, 3, 5, 5, 6, 7)
)

grid <- sf::st_sf(
  id = 1:4,
  geometry = sf::st_make_grid(
    sf::st_bbox(c(xmin = 0, ymin = 0, xmax = 2, ymax = 2)),
    n = c(2, 2)
  )
) |>
  dplyr::mutate(
    nb = sfdep::st_contiguity(geometry),
    wt = sfdep::st_weights(nb)
  )

spatial <- spatial_markov(panel, id, year, value, geometry = grid, k = 2)

spatial
lag_intervals(spatial)
transition_matrix(spatial, "count", lag_class = "Q1")
\dontshow{\}) # examplesIf}
}
