% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/var_rho_inv.R
\name{var_rho_inv}
\alias{var_rho_inv}
\title{Compute the Inverse Variance of the Spatial Autoregressive Parameter (rho)}
\usage{
var_rho_inv(A, W, X, beta, family, y, offs = NULL, weights = NULL, phi = 1)
}
\arguments{
\item{A}{Matrix. The spatial transformation matrix \eqn{\mathbf{A} = \mathbf{I} - \rho \mathbf{W}}, 
typically of class `Matrix`.}

\item{W}{Matrix. Row-standardized spatial weights matrix \eqn{\mathbf{W}} of dimension \eqn{n \times n}.}

\item{X}{Matrix. Design matrix of covariates, dimension \eqn{n \times p}.}

\item{beta}{Numeric vector. Current estimates of regression coefficients \eqn{\pmb{\beta}}, length \eqn{p}.}

\item{family}{GLM family object. The response distribution family (e.g., `gaussian()`, `poisson()`, `binomial()`, `Gamma()`, `Negative Binomial()`).}

\item{y}{response variable}

\item{offs}{Numeric vector. Optional offset vector, length \eqn{n}. Default is 0.}

\item{weights}{Numeric vector. Observation weights \eqn{m_i} (e.g., number of trials for binomial data), length \eqn{n}.}

\item{phi}{Numeric. Dispersion parameter, used for `gaussian`, `Gamma`, or `Negative Binomial` families. Default is 1.}
}
\value{
Numeric. The inverse of the variance of \eqn{\hat{\rho}} (\eqn{\operatorname{Var}(\hat{\rho})^{-1}}).
}
\description{
This function calculates the inverse of the variance of the spatial autoregressive parameter 
\eqn{\rho} in a generalized spatial autoregressive (GSAR) or GEE-SAR model. 
The calculation is based on the quasi-likelihood derivatives with respect to \eqn{\rho} 
for different exponential family distributions.
}
\details{
The function computes first and second derivatives of the mean \eqn{\mu_i} with respect to 
\eqn{\rho}, and then applies the appropriate formula for the inverse variance based on the 
selected family. This generalizes the quasi-likelihood derivations for spatially correlated 
generalized linear models.

For binomial families with large \eqn{m_i}, it is recommended to truncate \eqn{\mu_i} within 
\eqn{[1e-10, 1-1e-10]} to avoid numerical instability.
}
\examples{
\dontrun{
library(Matrix)
n <- 10
W <- Matrix(0,n,n)
diag(W[-1,]) <- 1
X <- matrix(rnorm(n*2), n, 2)
beta <- c(0.5, -0.2)
rho <- 0.3
A <- Diagonal(n) - rho*W
family <- binomial()
weights <- rep(1,n)
var_rho_inv(A, W, X, beta, family, weights)
}

}
