% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mlmodel-utils.R
\name{vcov.mlmodel}
\alias{vcov.mlmodel}
\title{Variance-Covariance Matrix for mlmodel Objects}
\usage{
\method{vcov}{mlmodel}(
  object,
  type = "oim",
  cl_var = NULL,
  repetitions = 999,
  seed = NULL,
  progress = TRUE,
  ...
)
}
\arguments{
\item{object}{An object of class \code{"mlmodel"} or a model inheriting from it
(e.g. \code{"ml_lm"}).}

\item{type}{Character string specifying the type of variance-covariance
matrix. One of \code{"oim"} (default), \code{"robust"}, \code{"opg"}, \code{"cluster"},
\code{"boot"}, and \code{"jack"} or \code{"jackknife"}.}

\item{cl_var}{Character string or vector. Name of the clustering variable
in the data, or the vector itself.}

\item{repetitions}{Integer. Number of bootstrap replications to use when
\code{type = "boot"}. Default is 999.}

\item{seed}{Integer. Random seed for reproducibility when \code{type = "boot"}.
If \code{NULL}, a random seed is generated.}

\item{progress}{Logical. Should a progress bar be displayed? Default is
\code{TRUE} when \code{type} is \code{"boot"} or \code{"jack"}/\code{"jackknife"}. Ignored for other
types.}

\item{...}{Further arguments passed to methods.}
}
\value{
A symmetric variance-covariance matrix with coefficient names
on the rows and columns.
}
\description{
Returns the variance-covariance matrix of the estimated parameters
using different methods.
}
\details{
The package provides several variance-covariance estimators through the \code{type} argument:
\itemize{
\item \code{"oim"} - Observed Information Matrix (default)
\item \code{"opg"} - Outer Product of Gradients (BHHH)
\item \code{"robust"} - Robust (sandwich) estimator
\item \code{"cluster"} - Alias for \code{"robust"} when clustering the variance but requires \code{cl_var} to be set.
\item \code{"boot"} - Bootstrap (with optional clustering)
\item \code{"jack"} - Jackknife (with optional clustering)
\item \code{"jackknife"} - alias for \code{"jack"}
}

Clustered standard errors are obtained by setting \code{cl_var} when using \code{"robust"}/\code{"cluster"}, \code{"boot"}, or \code{"jack"}.
}
\examples{

data(mroz)
mroz$incthou <- mroz$faminc / 1000

fit <- ml_lm(incthou ~ age + I(age^2) + huswage + educ + unem, 
             data = mroz)

# Different variance-covariance estimators
v_oim   <- vcov(fit, type = "oim")      # Observed Information Matrix (default)
v_opg   <- vcov(fit, type = "opg")      # Outer Product of Gradients (BHHH)
v_robust <- vcov(fit, type = "robust")   # Robust / Sandwich estimator

# Clustered robust standard errors
v_clust <- vcov(fit, type = "robust", cl_var = "age")

# Bootstrap variance-covariance matrix
v_boot  <- vcov(fit, type = "boot", repetitions = 100, seed = 123)

# Jackknife variance-covariance matrix
v_jack  <- vcov(fit, type = "jack")

# Compare standard errors across methods
sterrors <- data.frame(
  oim = sqrt(diag(v_oim)),
  opg = sqrt(diag(v_opg)),
  robust = sqrt(diag(v_robust)),
  cluster = sqrt(diag(v_clust)),
  bootstrap = sqrt(diag(v_boot)),
  jackknife = sqrt(diag(v_jack))
)

sterrors

}
\author{
Alfonso Sanchez-Penalver
}
