Density of Multivariate Normal Distribution (MVN): Dimension = 1 or k? I have a very naive question about the density function of the MVN distribution. According to the wiki page, the density function formula sometimes has a constant k (dimension of the MVN variables) and sometimes not. For example, see the PDF on the right-hand side on the wike page, it has no k, whereas, see the PDF in the middle part, it has a k.
To be specific, I wrote a R function for the MVN and tested against mvtnorm::dmvnorm:
dmvnormal <- function(x,mu,sigma, log = FALSE){
  m = t(x-mu)
  h = m%*%solve(sigma)%*%t(m)
  k = 1 # <-------------------------------------- use 1 or k??
  logp = -log(sqrt(det((2*pi)^k*sigma))) - h[1]/2
  if (log) return(logp)
  else return(exp(logp))
}
x = c(0.4,0.6)
mu = rep(0,length(x))
sigma = diag(length(x))
a = dmvnormal(x, mu = mu, sigma = sigma, log = FALSE)

# compared with mvtnorm package
b = mvtnorm::dmvnorm(x,mean=mu,sigma=sigma)
identical(a,b)

It seems by default k=1. So why the k is sometimes expressed in the PDF formula?

Quoting the Wikipedia article, the two expressions you refer to are, first:
$$\det(2\pi\Sigma)^{-\frac{1}{2}} \exp (-\frac{1}{2}(x - \mu)^{T} \Sigma^{-1}(x - \mu) )$$
And, second:
$$\frac{\exp\left(-\frac{1}{2} (x-\mu)^T{\Sigma}^{-1}(x-\mu)\right)}{\sqrt{(2\pi)^k |\Sigma|}}$$
But, determinants have a homogeneity property, such that, for any $k$ by $k$ matrix $A$ and a scalar constant $c$, we have that:
$$\det(cA) = c^k \det(A)$$
So then:
$$\det(2\pi\Sigma) = (2\pi)^k \det(\Sigma)$$
Therefore, they are equivalent formulations. In your implementation, you've put $2\pi$ inside the determinant, so there shouldn't be a $k$.
