Tôi đã cố gắng xác minh tính toán câu trả lời của @ Macro nhưng tìm thấy lỗi dường như là một lỗi nhỏ trong giải pháp hiệp phương sai. Anh ấy đã thu được
∂L∂Σ= - 12( Σ−1−Σ−1(y−μ)(y−μ)′Σ−1)=A
However, it appears that the correct solution is actually
B=2A−diag(A)
The following R script provides a simple example in which the finite difference is calculated for each element of
Σ. It demonstrates that
A provides the correct answer only for diagonal elements while
B is correct for every entry.
library(mvtnorm)
set.seed(1)
# Generate some parameters
p <- 4
mu <- rnorm(p)
Sigma <- rWishart(1, p, diag(p))[, , 1]
# Generate an observation from the distribution as a reference point
x <- rmvnorm(1, mu, Sigma)[1, ]
# Calculate the density at x
f <- dmvnorm(x, mu, Sigma)
# Choose a sufficiently small step-size
h <- .00001
# Calculate the density at x at each shifted Sigma_ij
f.shift <- matrix(NA, p, p)
for(i in 1:p) {
for(j in 1:p) {
zero.one.mat <- matrix(0, p, p)
zero.one.mat[i, j] <- 1
zero.one.mat[j, i] <- 1
Sigma.shift <- Sigma + h * zero.one.mat
f.shift[i, j] <- dmvnorm(x, mu, Sigma.shift)
}
}
# Caluclate the finite difference at each shifted Sigma_ij
fin.diff <- (f.shift - f) / h
# Calculate the solution proposed by @Macro and the true solution
A <- -1/2 * (solve(Sigma) - solve(Sigma) %*% (x - mu) %*% t(x - mu) %*% solve(Sigma))
B <- 2 * A - diag(diag(A))
# Verify that the true solution is approximately equal to the finite difference
fin.diff
A * f
B * f