5.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}\)

5.7.2 Gama inversa

library(LaplacesDemon)
dinvgamma(4.3, 1.1)
## [1] 0.03893829
set.seed(1234); rinvgamma(10, 3.3)
##  [1] 0.8737863 0.2984410 0.2912499 0.5844254 0.2694825 0.5206008 0.2133415 0.5389982 0.4858066 1.5705256
# 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"))

5.7.3 Qui-quadrado inversa padronizada

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 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"))

5.7.4 Normal-Gama

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

5.7.6 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 (Box and Tiao 1973, 427) e [Statisticat and LLC. (2021)]6, 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 é qui-quadrado.

library(LaplacesDemon)
Omega <- matrix(c(2,-.3,-.3,4),2,2)
dwishart(Omega, 3, matrix(c(1,.1,.1,1),2,2))
## [1] 0.003785585
set.seed(9876); 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)
dwishartc(U, 3, matrix(c(1,.1,.1,1),2,2))
## [1] 0.003785585
set.seed(9876); rwishartc(3, matrix(c(1,.1,.1,1),2,2))
##          [,1]       [,2]
## [1,] 2.137119 -0.3732020
## [2,] 0.000000  0.1821115

5.7.7 Wishart inversa

library(LaplacesDemon)
Sigma <- matrix(c(2,-.3,-.3,4),2,2)
dinvwishart(Sigma, 3, matrix(c(1,.1,.1,1),2,2))
## [1] 0.0001079824
set.seed(1); 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)
dinvwishartc(U, 3, matrix(c(1,.1,.1,1),2,2))
## [1] 0.0001079824
set.seed(1); rinvwishartc(3, matrix(c(1,.1,.1,1),2,2))
##          [,1]       [,2]
## [1,] 1.197597 -0.2669354
## [2,] 0.000000  0.4408669

5.7.8 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 <- dnormwishart(mu, mu0, lambda, Omega, S, nu, log=TRUE)
set.seed(5); out <- rnormwishart(n=10, mu0, lambda, S, nu)
joint.density.plot(out$mu[,1], out$mu[,2], color=TRUE)

5.7.9 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 <- dnorminvwishart(mu, mu0, lambda, Sigma, S, nu, log=TRUE)
set.seed(5); out <- 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. Bayesian-Inference.com. vignette("BayesianInference").
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.↩︎