6.7 … para dispersão e precisão

A precisão é o inverso da variância no caso univariado, e o inverso da matriz de covariâncias no caso multivariado.

Univariado
\(P=\frac{1}{\sigma^2}\)

Multivariado
\(\Omega = \Sigma^{-1}\)

6.7.2 Gama inversa

A função densidade da gama inversa pode ser dada por \[\begin{equation} f(x|\alpha,\beta) = \frac{\beta^{\alpha}}{\Gamma(\alpha)} \left( \frac{1}{x} \right)^{\alpha+1} e^{-\beta/x} \tag{6.20} \end{equation}\] onde \(x>0\), \(\alpha>0\) (forma/shape), \(\beta>0\) (escala/scale) e \(\Gamma\) é a função gama. A esperança e variância são dadas por \[\begin{equation} E(X) = \frac{\beta}{\alpha-1}, \;\; \alpha>1 \tag{6.21} \end{equation}\] \[\begin{equation} V(X) = \frac{\beta^2}{(\alpha-1)^2(\alpha-2)}, \;\; \alpha>2 \tag{6.22} \end{equation}\]

A mediana não tem forma fechada, e a moda é dada por \[\begin{equation} Mo(X) = \frac{\beta}{\alpha+1} \tag{6.23} \end{equation}\]

library(LaplacesDemon)
dinvgamma(4.3, 1.1)
## [1] 0.03893829
set.seed(1234); rinvgamma(8, 3.3)
## [1] 0.8737863 0.2984410 0.2912499 0.5844254 0.2694825 0.5206008 0.2133415 0.5389982
# Plot Probability Functions
x <- seq(from=0.1, to=20, by=0.1)
plot(x, dinvgamma(x,1,1), ylim=c(0,1), type="l", main="Probability Function",
     ylab="density", col="red")
lines(x, dinvgamma(x,1,0.6), type="l", col="green")
lines(x, dinvgamma(x,0.6,1), type="l", col="blue")
legend(2, 0.9, expression(paste(alpha==1, ", ", beta==1),
     paste(alpha==1, ", ", beta==0.6), paste(alpha==0.6, ", ", beta==1)),
     lty=c(1,1,1), col=c("red","green","blue"))

6.7.3 Qui-quadrado inversa padronizada

A função densidade da qui-quadrado inversa padronizada pode ser dada por \[\begin{equation} f(x|\nu,\tau) = \frac{(\tau^2 \nu)^{\nu/2}}{\Gamma(\nu/2)} \frac{e^{\frac{-\nu \tau^2}{2x}}}{x^{1+\nu/2}} \tag{6.24} \end{equation}\] onde \(x>0\), \(\nu>0\) (graus de liberdade da qui-quadrado), \(\tau>0\) (escala/scale) e \(\Gamma\) é a função gama. A esperança e variância são dadas por \[\begin{equation} E(X) = \frac{\nu \tau^2}{\nu-2}, \;\; \nu>2 \tag{6.25} \end{equation}\] \[\begin{equation} V(X) = \frac{2\nu^2 \tau^4}{(\nu-2)^2(\nu-4)}, \;\; \nu>4 \tag{6.26} \end{equation}\]

A moda é dada por \[\begin{equation} Mo(X) = \frac{\nu \tau^2}{\nu+2} \tag{6.27} \end{equation}\]

library(LaplacesDemon)
dinvchisq(1,1,1)
## [1] 0.2419707
set.seed(345); rinvchisq(10,1)
##  [1] 7.6275257 2.3461109 1.8776043 2.3980416 1.5938337 5.1493120 0.2201109 0.2321013 0.1950130
## [10] 8.0955823
#Plot Probability Functions
x <- seq(from=0.1, to=5, by=0.01)
plot(x, dinvchisq(x,0.5,1), ylim=c(0,1), type="l", main="Probability Function",
     ylab="density", col="red")
lines(x, dinvchisq(x,1,1), type="l", col="green")
lines(x, dinvchisq(x,5,1), type="l", col="blue")
legend(3, 0.9, expression(paste(nu==0.5, ", ", lambda==1),
     paste(nu==1, ", ", lambda==1), paste(nu==5, ", ", lambda==1)),
     lty=c(1,1,1), col=c("red","green","blue"))

6.7.4 Normal-Gama

A função densidade da normal-gama pode ser dada pela função bivariada \[\begin{equation} f(x,\tau|\mu,\lambda,\alpha,\beta) = \frac{\beta^{\alpha}\sqrt{\lambda}}{\Gamma(\alpha)\sqrt{2\pi}} \tau^{\alpha-\frac{1}{2}} e^{-\beta \tau} e^{-\frac{\lambda \tau (x-\mu)^2}{2}} \tag{6.28} \end{equation}\] onde \(x \in \mathcal{R}\), \(\tau>0\), \(\mu \in \mathcal{R}\), \(\lambda>0\), \(\alpha>0\), \(\beta>0\) e \(\Gamma\) é a função gama. As esperanças marginais são dadas por \[\begin{equation} E(X) = \mu, \;\; E(T)=\frac{\alpha}{\beta} \tag{6.29} \end{equation}\] As variâncias marginais por \[\begin{equation} V(X) = \frac{\beta}{\lambda(\alpha-1)}, \;\; V(T)=\frac{\alpha}{\beta^2} \tag{6.30} \end{equation}\]

A moda bivariada é dada por \[\begin{equation} Mo(X,T) = \left( \mu, \frac{\alpha-\frac{1}{2}}{\beta} \right) \tag{6.31} \end{equation}\]

library(lestat)
plot(normalgamma(3,4,5,6))

6.7.5 Wishart

Occasionally, in the statistical distribution literature, Wishart distributions have been referred to as “multivariate gamma distributions”. We, however, restrict this term to those distributions for which the marginal distribution are of gamma form. (Kotz, Balakrishnan, and Johnson 2000, 431)

De acordo com (G. E. Box and Tiao 1973, 427) e (Statisticat and LLC. 2021)8, a distribuição Wishart (Wishart 1928) é uma generalização multivariada da distribuição qui-quadrado. Não é chamada de distribuição qui-quadrado multivariada, no entanto, pelo fato de a distribuição marginal dos elementos fora da diagonal não ser qui-quadrado.

library(LaplacesDemon)
Omega <- matrix(c(2,-.3,-.3,4),2,2)
LaplacesDemon::dwishart(Omega, 3, matrix(c(1,.1,.1,1),2,2))
## [1] 0.003785585
set.seed(9876); LaplacesDemon::rwishart(3, matrix(c(1,.1,.1,1),2,2))
##            [,1]       [,2]
## [1,]  4.5672769 -0.7975769
## [2,] -0.7975769  0.1724443

Com a parametrização de Cholesky, considerando o fator triangular superior \(U\) da matriz de precisão \(\Omega\).

library(LaplacesDemon)
Omega <- matrix(c(2,-.3,-.3,4),2,2)
U <- chol(Omega)
LaplacesDemon::dwishartc(U, 3, matrix(c(1,.1,.1,1),2,2))
## [1] 0.003785585
set.seed(9876); LaplacesDemon::rwishartc(3, matrix(c(1,.1,.1,1),2,2))
##          [,1]       [,2]
## [1,] 2.137119 -0.3732020
## [2,] 0.000000  0.1821115

6.7.6 Wishart inversa

library(LaplacesDemon)
Sigma <- matrix(c(2,-.3,-.3,4),2,2)
LaplacesDemon::dinvwishart(Sigma, 3, matrix(c(1,.1,.1,1),2,2))
## [1] 0.0001079824
set.seed(1); LaplacesDemon::rinvwishart(3, matrix(c(1,.1,.1,1),2,2))
##           [,1]       [,2]
## [1,]  1.434238 -0.3196810
## [2,] -0.319681  0.2656181

Com a parametrização de Cholesky, considerando o fator triangular superior \(U\) da matriz de covariâncias \(\Sigma\).

library(LaplacesDemon)
Sigma <- matrix(c(2,-.3,-.3,4),2,2)
U <- chol(Sigma)
LaplacesDemon::dinvwishartc(U, 3, matrix(c(1,.1,.1,1),2,2))
## [1] 0.0001079824
set.seed(1); LaplacesDemon::rinvwishartc(3, matrix(c(1,.1,.1,1),2,2))
##          [,1]       [,2]
## [1,] 1.197597 -0.2669354
## [2,] 0.000000  0.4408669

6.7.7 Normal-Wishart

library(LaplacesDemon)
K <- 3
set.seed(1); mu <- rnorm(K)
set.seed(2); mu0 <- rnorm(K)
nu <- K + 1
S <- diag(K)
set.seed(3); lambda <- runif(1) #Real scalar
set.seed(4); Omega <- as.positive.definite(matrix(rnorm(K^2),K,K))
x <- LaplacesDemon::dnormwishart(mu, mu0, lambda, Omega, S, nu, log=TRUE)
set.seed(5); out <- LaplacesDemon::rnormwishart(n=10, mu0, lambda, S, nu)
joint.density.plot(out$mu[,1], out$mu[,2], color=TRUE)

6.7.8 Normal-Inversa-Wishart

library(LaplacesDemon)
K <- 3
set.seed(1); mu <- rnorm(K)
set.seed(2); mu0 <- rnorm(K)
nu <- K + 1
S <- diag(K)
set.seed(3); lambda <- runif(1) # Real scalar
set.seed(4); Sigma <- as.positive.definite(matrix(rnorm(K^2),K,K))
x <- LaplacesDemon::dnorminvwishart(mu, mu0, lambda, Sigma, S, nu, log=TRUE)
set.seed(5); out <- LaplacesDemon::rnorminvwishart(n=10, mu0, lambda, S, nu)
joint.density.plot(out$mu[,1], out$mu[,2], color=TRUE)

Referências

Box, George EP, and George C Tiao. 1973. Bayesian Inference in Statistical Analysis. John Wiley & Sons.
Kotz, Samuel, N Balakrishnan, and Norman L Johnson. 2000. “Continuous Multivariate Distributions. Vol. 1. Models and Applications.” Wiley-Interscience, New York.
Statisticat, and LLC. 2021. LaplacesDemon: Complete Environment for Bayesian Inference. https://cran.r-project.org/web/packages/LaplacesDemon/LaplacesDemon.pdf.
Wishart, John. 1928. “The Generalised Product Moment Distribution in Samples from a Normal Multivariate Population.” Biometrika, 32–52. https://www.jstor.org/stable/pdf/2331939.pdf.

  1. Documentação da função LaplacesDemon::dist.Wishart.↩︎