% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/diagnostics.R
\name{diagnose_moran}
\alias{diagnose_moran}
\title{Run Moran's I diagnostic on a gwpr_fit object}
\usage{
diagnose_moran(object, spatial_weights, panel_index, ...)
}
\arguments{
\item{object}{A `gwpr_fit` object returned by `fit_gwpr()` or similar.}

\item{spatial_weights}{A row-standardised n x n spatial weights matrix.
`n` must equal the number of spatial individuals in the fitted model.}

\item{panel_index}{A data.frame or list with columns/elements `id` and
`time` that identify each element of `object$residuals`.}

\item{...}{Currently ignored.}
}
\value{
A named list compatible with the `diagnostics` slot of a
  `gwpr_diagnostics` object.  Contains the elements returned by
  `compute_panel_moran()` plus `residual_type`.
}
\description{
Extracts residuals from a fitted GWPR model (Pearson residuals for logistic
models, raw residuals for linear models) and computes the panel Moran's I
statistic.
}
\details{
**Applicable models**: gaussian (linear residuals) and binomial (Pearson
residuals).

**Panel balance**: See `compute_panel_moran()`.

**Failure conditions**: Fails if `object` is not a `gwpr_fit`, if
`object$residuals` is `NULL`, or if `spatial_weights` dimensions do not
match the number of individuals.

**Logistic interpretation limit**: Moran's I computed on Pearson residuals
is exploratory; the asymptotic distribution differs from the linear case.
}
\examples{
\donttest{
library(sf)
pts <- sf::st_as_sf(
  data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)),
  coords = c("X", "Y"), crs = NA_integer_
)
dat <- data.frame(
  id   = rep(1:4, each = 5),
  time = rep(1:5, 4),
  y    = rnorm(20),
  x1   = rnorm(20)
)
fit <- fit_gwpr(y ~ x1, data = dat, spatial = pts, id = "id",
                time = "time", bandwidth = 2, workers = 1)
W <- matrix(1/3, nrow = 4, ncol = 4); diag(W) <- 0
idx <- dat[, c("id", "time")]
diagnose_moran(fit, W, idx)
}

}
