4.1 Vetores e matrizes aleatórios

Definição 4.1 Seja \(\varepsilon\) um experimento associado ao espaço amostral \(\Omega\). Sejam \(X_1(\omega), \ldots, X_p(\omega)\) funções associando um número real a cada resultado \(\omega \in \Omega\). Será denominada \((X_1,\ldots,X_p)\) variável aleatória p-dimensional.

Um vetor aleatório é portanto um vetor \(1 \times n\) ou \(n \times 1\) composto por variáveis aleatórias. De maneira análoga uma matriz aleatória é uma matriz \(n \times p\) formada por variáveis aleatórias. Tais matrizes são usualmente representadas por \(X\), formada por \(n\) observações e \(p\) variáveis. \[\begin{equation} X = X_{n \times p} = \begin{bmatrix} x_{11} & x_{12} & \cdots & x_{1p} \\ x_{21} & x_{22} & \cdots & x_{2p} \\ \vdots & \ddots & \cdots & \vdots \\ x_{n1} & x_{n2} & \cdots & x_{np} \end{bmatrix} \tag{4.1} \end{equation}\]

Cada linha é um vetor \(p\)-variado de observações do elemento \(i \in \{1,2,\ldots,n\}\).

Cada coluna corresponde a uma variável \(X_j\) \(n\)-variada, \(j \in \{1,2,\ldots,p\}\).

Exemplo 4.1 Considere experimento aleatório \(\varepsilon\): ‘lançar um dado duas vezes’. Seu espaço amostral é definido por \[ \Omega = \left\lbrace \begin{array}{cccccc} (1,1) & (1,2) & (1,3) & (1,4) & (1,5) & (1,6) \\ (2,1) & (2,2) & (2,3) & (2,4) & (2,5) & (2,6) \\ (3,1) & (3,2) & (3,3) & (3,4) & (3,5) & (3,6) \\ (4,1) & (4,2) & (4,3) & (4,4) & (4,5) & (4,6) \\ (5,1) & (5,2) & (5,3) & (5,4) & (5,5) & (5,6) \\ (6,1) & (6,2) & (6,3) & (6,4) & (6,5) & (6,6) \\ \end{array} \right\rbrace \]

Sejam as variáveis aleatórias \(X_1\): ‘soma dos pontos’, \(X_2\): ‘diferença dos pontos’, \(X_3\): ‘produto dos pontos’ e \(X_4\): ‘quociente dos pontos’. Seus contradomínios são dados por \[R_{X_1} = \{ 2,3,4,5,6,7,8,9,10,11,12 \}\] \[R_{X_2} = \{ -5,-4,-3,-2,-1,0,1,2,3,4,5 \}\] \[R_{X_3} = \{ 1,2,3,4,5,6,8,9,10,12,15,16,18,20,24,25,30,36 \}\] \[R_{X_4} = \left\{ \frac{1}{6},\frac{1}{5},\frac{1}{4},\frac{1}{3},\frac{2}{5},\frac{1}{2},\frac{3}{5},\frac{2}{3},\frac{3}{4},\frac{4}{5},\frac{5}{6},1,\frac{6}{5},\frac{5}{4},\frac{4}{3},\frac{3}{2},\frac{5}{3},2,\frac{5}{2},3,4,5,6 \right\}\]

A matriz \(X\) pode ser calculada, tal que \(n=36\) e \(p=4\).

rn <- expand.grid(1:6,1:6)
X <- matrix(nrow = nrow(rn), ncol = 4)
rownames(X) <- paste0('(', rn[,2], ',', rn[,1], ')') 
colnames(X) <- paste0('X', 1:4)
X[,1] <- rn[,2]+rn[,1] # Soma
X[,2] <- rn[,2]-rn[,1] # Diferença
X[,3] <- rn[,2]*rn[,1] # Produto
X[,4] <- rn[,2]/rn[,1] # Quociente
MASS::fractions(X)
##       X1  X2  X3  X4 
## (1,1)   2   0   1   1
## (1,2)   3  -1   2 1/2
## (1,3)   4  -2   3 1/3
## (1,4)   5  -3   4 1/4
## (1,5)   6  -4   5 1/5
## (1,6)   7  -5   6 1/6
## (2,1)   3   1   2   2
## (2,2)   4   0   4   1
## (2,3)   5  -1   6 2/3
## (2,4)   6  -2   8 1/2
## (2,5)   7  -3  10 2/5
## (2,6)   8  -4  12 1/3
## (3,1)   4   2   3   3
## (3,2)   5   1   6 3/2
## (3,3)   6   0   9   1
## (3,4)   7  -1  12 3/4
## (3,5)   8  -2  15 3/5
## (3,6)   9  -3  18 1/2
## (4,1)   5   3   4   4
## (4,2)   6   2   8   2
## (4,3)   7   1  12 4/3
## (4,4)   8   0  16   1
## (4,5)   9  -1  20 4/5
## (4,6)  10  -2  24 2/3
## (5,1)   6   4   5   5
## (5,2)   7   3  10 5/2
## (5,3)   8   2  15 5/3
## (5,4)   9   1  20 5/4
## (5,5)  10   0  25   1
## (5,6)  11  -1  30 5/6
## (6,1)   7   5   6   6
## (6,2)   8   4  12   3
## (6,3)   9   3  18   2
## (6,4)  10   2  24 3/2
## (6,5)  11   1  30 6/5
## (6,6)  12   0  36   1

Definição 4.2 Seja \((X_1, \ldots, X_p)\) uma variável aleatória p-dimensional discreta. Para cada ponto de \(R_{X}\) associa-se uma função (massa) de probabilidade (fmp) \(p(x_1,\ldots,x_p)\), satisfazendo

\[\begin{equation} p(x_1,\ldots,x_p) \ge 0, \forall \; x_j, \; j \in \{1,2,\ldots,p\} \tag{4.2} \end{equation}\]

\[\begin{equation} \sum_{x_1} \cdots \sum_{x_p} p(x_1,\ldots,x_p) = 1 \tag{4.3} \end{equation}\]

Exemplo 4.2 Podem-se calcular probabilidades associadas à variável aleatória 4-dimensional discreta \(X\) do Exemplo 4.1.
\[Pr(X_1 \le 3) = Pr(\{(1,1),(1,2),(2,1)\}) = \frac{3}{36} = \frac{1}{12}\] \[Pr(X_2 = 0) = Pr(\{(1,1),(2,2),(3,3),(4,4),(5,5),(6,6)\}) = \frac{6}{36} = \frac{1}{6}\] \[Pr(X_1 \le 3, X_2 = 0) = Pr(\{(1,1)\}) = \frac{1}{36}\] \[Pr(X_1 > 4, X_2 < 0, X_3 > 2, X_4 < 1/2) = Pr(\{(1,4),(1,5),(1,6),(2,5),(2,6)\}) = \frac{5}{36}\]

sum(X[,1] <= 3)
## [1] 3
sum(X[,2] == 0)
## [1] 6
sum(X[,1] <= 3 & X[,2] == 0)
## [1] 1
sum(X[,1] > 4 & X[,2] < 0 & X[,3] > 2 & X[,4] < 1/2) 
## [1] 5

Note que \[Pr(X_1 = 2, X_2 = 0, X_3 = 1, X_4 = 1) = \cdots = Pr(X_1 = 12, X_2 = 0, X_3 = 36, X_4 = 1) = \frac{1}{36} > 0\] \[Pr(X_1 = 2, X_2 = 0, X_3 = 1, X_4 = 1) + \cdots + Pr(X_1 = 12, X_2 = 0, X_3 = 36, X_4 = 1) = 1\]

Exercício 4.1 Considere o Exemplo 4.1.
a. Amplie a matriz \(X\) considerando as variáveis \(X_5\): ‘média dos pontos’ e \(X_6\): ‘norma dos pontos’ conforme Eq. (3.9). Indique \(n\) e \(p\).
b. No Exemplo 4.2 substitua sum por which e interprete a saída.
c. Calcule \(Pr(X_1 > 2, X_2 < 0, X_3 > 1, X_4 < 1, X_5 \ge 1, X_6 > 1)\).

Definição 4.3 Seja \((X_1, \ldots, X_p)\) uma variável aleatória p-dimensional contínua. Para cada ponto de \(R_{X}\) associa-se uma (função) densidade (de probabilidade) (fdp) \(f(x_1,\ldots,x_p)\), satisfazendo

\[\begin{equation} f(x_1,\ldots,x_p) \ge 0, \forall \; x_j, \; j \in \{1,2,\ldots,p\} \tag{4.4} \end{equation}\]

\[\begin{equation} \int_{x_1} \cdots \int_{x_p} f(x_1,\ldots,x_p)\;dx_p \cdots dx_1 = 1 \tag{4.5} \end{equation}\]

A fda, (função de) distribuição (acumulada) \(F\) de uma variável aleatória multivariada é definida como

\[\begin{equation} F(\boldsymbol{x}) = Pr(X_1 \leq x_1, \ldots, X_p \leq x_p) \tag{4.6} \end{equation}\]

Note que \[f(x_1,\ldots,x_p)=F'(x_1,\ldots,x_p),\] \[Pr(X_1=x_1, \ldots, X_p=x_p)=0\] e \[Pr(X_1 \le x_1, \ldots, X_p \le x_p) = Pr(X_1 < x_1, \ldots, X_p < x_p).\]

4.1.1 Vetor de médias

Geralmente um conjunto de dados é caracterizado pelo vetor de médias e pela matriz de variâncias e covariâncias. A notação referente aos parâmetros (populacionais) e às estatísticas (amostrais) é distinta, conforme definido a seguir.

Universal/populacional

\[\begin{equation} \boldsymbol{\mu} = \begin{bmatrix} \mu_{1} \\ \mu_{2} \\ \vdots \\ \mu_{p} \end{bmatrix} \tag{4.7} \end{equation}\]

\[\begin{equation} E(X_j) = \mu_j = \frac{\sum_{i=1}^N x_{ji}}{N} \tag{4.8} \end{equation}\]

Amostral

\[\begin{equation} \bar{\boldsymbol{x}} = \begin{bmatrix} \bar{x}_{1} \\ \bar{x}_{2} \\ \vdots \\ \bar{x}_{p} \end{bmatrix} \tag{4.9} \end{equation}\]

\[\begin{equation} \bar{x}_{j} = \frac{\sum_{i=1}^n x_{ji}}{n} \tag{4.10} \end{equation}\]

4.1.2 Matriz de variâncias e covariâncias

A notação da matriz de variâncias e covariâncias (ou simplesmente matriz (de) covariância) também é diferenciada para parâmetros e estatísticas, sendo que a partir de \(S\) estima-se \(\Sigma\). Note que \(\sigma_{ij} = \sigma_{ji}\), portanto será utilizada a notação \(\sigma_{ij}\) para as covariâncias e \(\sigma_{ii} = \sigma_{i}^2\) para as variâncias. O mesmo vale para a matriz \(S\).

Universal/populacional

\[\begin{equation} \Sigma = Cov(X) = \begin{bmatrix} \sigma_{1}^2 & \sigma_{12} & \cdots & \sigma_{1p} \\ \sigma_{12} & \sigma_{2}^2 & \cdots & \sigma_{2p} \\ \vdots & \vdots & \ddots & \vdots \\ \sigma_{1p} & \sigma_{2p} & \cdots & \sigma_{p}^2 \end{bmatrix} = \begin{bmatrix} \sigma_{1}^2 & \rho_{12} \sigma_1 \sigma_2 & \cdots & \rho_{1p} \sigma_1 \sigma_p \\ \rho_{12} \sigma_1 \sigma_2 & \sigma_{2}^2 & \cdots & \rho_{2p} \sigma_2 \sigma_p \\ \vdots & \vdots & \ddots & \vdots \\ \rho_{1p} \sigma_1 \sigma_p & \rho_{2p} \sigma_2 \sigma_p & \cdots & \sigma_{p}^2 \end{bmatrix} \tag{4.11} \end{equation}\]

\[\begin{equation} Var(X_j) = \sigma_{X_j}^2 = \sigma_{j}^2 = \sigma_{X_j X_j} = \sigma_{jj} = \frac{\sum_{i=1}^N (x_{ji} - \mu_{j})^2}{N} \tag{4.12} \end{equation}\]

\[\begin{equation} Cov(X_j,X_k) = \sigma_{X_j X_k} = \sigma_{jk} = \frac{\sum_{i=1}^N (x_{ji} - \mu_{j})(x_{ki} - \mu_{k})}{N} \tag{4.13} \end{equation}\]

\(\rho_{jk}\) é dado conforme Eq. (4.21). No caso bivariado a inversa de \(\Sigma\) só existe se \(|\rho|<1\) pois \[\begin{equation} |\Sigma| = \sigma_1^2 \sigma_2^2 (1-\rho^2) \tag{4.14} \end{equation}\]

Amostral

\[\begin{equation} S = cov(X) = \begin{bmatrix} s_{1}^2 & s_{12} & \cdots & s_{1p} \\ s_{12} & s_{2}^2 & \cdots & s_{2p} \\ \vdots & \vdots & \ddots & \vdots \\ s_{1p} & s_{2p} & \cdots & s_{p}^2 \end{bmatrix} \tag{4.15} \end{equation}\]

\[\begin{equation} var(X_j) = s_{X_j}^2 = s_{j}^2 = s_{X_j X_j} = s_{jj} = \frac{\sum_{i=1}^n (x_{ji} - \bar{x}_{j})^2}{n-1} \tag{4.16} \end{equation}\]

\[\begin{equation} cov(X_j,X_k) = s_{X_j X_k} = s_{jk} = \frac{\sum_{i=1}^n (x_{ji} - \bar{x}_{j})(x_{ki} - \bar{x}_{k})}{n-1} \tag{4.17} \end{equation}\]

4.1.2.1 Simulando

A matriz de covariâncias \(\Sigma\) possui as seguintes propriedades:

  1. Simétrica, i.e., \(\Sigma = \Sigma^T\).
  2. Positiva definida, i.e., \(z^T \Sigma z > 0, \forall z \ne 0.\)

Teoremas
1. Uma matriz simétrica é positiva definida se e somente se todos seus autovalores são positivos.
2. Uma matriz simétrica é positiva definida se e somente se a decomposição \(M=B^TB\) existe com \(B\) inversível.

Considerando o Teorema 2, pode-se simular uma matriz de covariâncias gerando uma matriz qualquer \(B\) e multiplicando pela sua transposta.

dm <- 3 # dimensão desejada
# set.seed(777)
seed <- rnorm(dm^2)
B <- matrix(seed, nrow = dm, ncol = dm)
(Sigma <- crossprod(B, B))
##            [,1]      [,2]      [,3]
## [1,]  2.5307221 -2.719875 0.3571942
## [2,] -2.7198752  6.556305 1.1255217
## [3,]  0.3571942  1.125522 0.8931079
isSymmetric(Sigma)
## [1] TRUE
matrixcalc::is.positive.definite(Sigma)
## [1] TRUE

Exercício 4.2 Mostre que a matriz de covariâncias amostral \(S\) possui as mesmas propriedades de \(\Sigma\).

4.1.3 Matriz de desvios padrão

\[\begin{equation} \boldsymbol{V}^{1/2} = \begin{bmatrix} \sigma_{1} & 0 & \cdots & 0 \\ 0 & \sigma_{2} & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & \sigma_{p} \end{bmatrix} \tag{4.18} \end{equation}\]

\[\begin{equation} \sigma_j = \sqrt{\sigma_j^2} \tag{4.19} \end{equation}\]

4.1.4 Matriz de correlação

A correlação é obtida dividindo-se a covariância pelo produto dos desvios padrão.

Universal/populacional

\[\begin{equation} \boldsymbol{\rho} = Cor(X) = \begin{bmatrix} 1 & \rho_{12} & \cdots & \rho_{1p} \\ \rho_{12} & 1 & \cdots & \rho_{2p} \\ \vdots & \vdots & \ddots & \vdots \\ \rho_{1p} & \rho_{2p} & \cdots & 1 \end{bmatrix} \tag{4.20} \end{equation}\]

\[\begin{equation} \rho_{jk} = \dfrac{\sigma_{jk}}{\sigma_{j}\sigma_{k}} \tag{4.21} \end{equation}\]

Amostral

\[\begin{equation} R = cor(X) = \begin{bmatrix} 1 & r_{12} & \cdots & r_{1p} \\ r_{12} & 1 & \cdots & r_{2p} \\ \vdots & \vdots & \ddots & \vdots \\ r_{1p} & r_{2p} & \cdots & 1 \end{bmatrix} \tag{4.22} \end{equation}\]

\[\begin{equation} r_{jk} = \dfrac{s_{jk}}{s_{j}s_{k}} \tag{4.23} \end{equation}\]

4.1.5 Propriedades

\[\begin{equation} V^{1/2} \boldsymbol{\rho} V^{1/2} = \Sigma \tag{4.24} \end{equation}\]

\[\begin{equation} \boldsymbol{\rho} = (V^{1/2})^{-1} \Sigma (V^{1/2})^{-1} \tag{4.25} \end{equation}\]

Exemplo 4.3 \(\\\)

# matriz X com 2 variáveis
(X <- matrix(c(10,5,11,4,12,7,13,9,14,10), nrow = 5, byrow = T))
##      [,1] [,2]
## [1,]   10    5
## [2,]   11    4
## [3,]   12    7
## [4,]   13    9
## [5,]   14   10
colnames(X) <- c('X1','X2') # nomeando as colunas
(m <- colMeans(X)) # vetor de médias
## X1 X2 
## 12  7
(S <- cov(X)) # matriz de covariâncias (amostrais)
##      X1   X2
## X1 2.50 3.75
## X2 3.75 6.50
(R <- cor(X)) # matriz de correlações (amostrais)
##           X1        X2
## X1 1.0000000 0.9302605
## X2 0.9302605 1.0000000

Exercício 4.3 Considere o Exemplo 4.3.
a. Calcule os elementos da matriz S a partir das Equações (4.16) e (4.17).
b. Calcule os elementos da matriz R a partir da Equação (4.23).

4.1.6 Medidas-resumo

Exemplo 4.4 Considere o banco de dados mtcars extraído da revista Motor Trend US de 1974, que abrange o consumo de combustível e 10 aspectos/variáveis do desenho e desempenho de 32 automóveis (modelos de 1973 a 1974).

DT::datatable(mtcars)

As variáveis são as seguintes:

  • mpg Milhas/galão (EUA) (1 gal EUA \(\approx\) 3.78541L)
  • cyl Número de cilindros
  • disp Cilindrada (polegada cúbica)
  • hp Potência bruta (cavalos de força)
  • drat Relação do eixo traseiro
  • wt Peso (1000 libras) (1lb \(\approx\) 0.453592kg)
  • qseg Tempo de 1/4 de milha (1mi \(\approx\) 1.60934km)
  • vs Motor (0 = em forma de V, 1 = reto)
  • am Transmissão (0 = automático, 1 = manual)
  • gear Número de marchas para frente
  • carb Número de carburadores
str(mtcars) # verificando a classificação dos dados
## 'data.frame':    32 obs. of  11 variables:
##  $ mpg : num  21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...
##  $ cyl : num  6 6 4 6 8 6 8 4 4 6 ...
##  $ disp: num  160 160 108 258 360 ...
##  $ hp  : num  110 110 93 110 175 105 245 62 95 123 ...
##  $ drat: num  3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...
##  $ wt  : num  2.62 2.88 2.32 3.21 3.44 ...
##  $ qsec: num  16.5 17 18.6 19.4 17 ...
##  $ vs  : num  0 0 1 1 0 1 0 1 1 1 ...
##  $ am  : num  1 1 1 0 0 0 0 0 0 0 ...
##  $ gear: num  4 4 4 3 3 3 3 4 4 4 ...
##  $ carb: num  4 4 1 1 2 1 4 2 2 4 ...
mtcars$cyl <- as.integer(mtcars$cyl) # tratado cyl como integer
mtcars$vs <- as.character(mtcars$vs) # tratado vs como character
mtcars$am <- as.character(mtcars$am) # tratado am como character
mtcars$gear <- as.integer(mtcars$gear) # tratado gear como integer
mtcars$carb <- as.integer(mtcars$carb) # tratado carb como integer
str(mtcars) # verificando novamente
## 'data.frame':    32 obs. of  11 variables:
##  $ mpg : num  21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...
##  $ cyl : int  6 6 4 6 8 6 8 4 4 6 ...
##  $ disp: num  160 160 108 258 360 ...
##  $ hp  : num  110 110 93 110 175 105 245 62 95 123 ...
##  $ drat: num  3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...
##  $ wt  : num  2.62 2.88 2.32 3.21 3.44 ...
##  $ qsec: num  16.5 17 18.6 19.4 17 ...
##  $ vs  : chr  "0" "0" "1" "1" ...
##  $ am  : chr  "1" "1" "1" "0" ...
##  $ gear: int  4 4 4 3 3 3 3 4 4 4 ...
##  $ carb: int  4 4 1 1 2 1 4 2 2 4 ...
summary(mtcars) # medidas de posição
##       mpg             cyl             disp             hp             drat             wt       
##  Min.   :10.40   Min.   :4.000   Min.   : 71.1   Min.   : 52.0   Min.   :2.760   Min.   :1.513  
##  1st Qu.:15.43   1st Qu.:4.000   1st Qu.:120.8   1st Qu.: 96.5   1st Qu.:3.080   1st Qu.:2.581  
##  Median :19.20   Median :6.000   Median :196.3   Median :123.0   Median :3.695   Median :3.325  
##  Mean   :20.09   Mean   :6.188   Mean   :230.7   Mean   :146.7   Mean   :3.597   Mean   :3.217  
##  3rd Qu.:22.80   3rd Qu.:8.000   3rd Qu.:326.0   3rd Qu.:180.0   3rd Qu.:3.920   3rd Qu.:3.610  
##  Max.   :33.90   Max.   :8.000   Max.   :472.0   Max.   :335.0   Max.   :4.930   Max.   :5.424  
##       qsec            vs                 am                 gear            carb      
##  Min.   :14.50   Length:32          Length:32          Min.   :3.000   Min.   :1.000  
##  1st Qu.:16.89   Class :character   Class :character   1st Qu.:3.000   1st Qu.:2.000  
##  Median :17.71   Mode  :character   Mode  :character   Median :4.000   Median :2.000  
##  Mean   :17.85                                         Mean   :3.688   Mean   :2.812  
##  3rd Qu.:18.90                                         3rd Qu.:4.000   3rd Qu.:4.000  
##  Max.   :22.90                                         Max.   :5.000   Max.   :8.000
sapply(mtcars[,c(8,9)], table) # tabela das variáveis character
##   vs am
## 0 18 19
## 1 14 13
round(sapply(mtcars[,-c(8,9)], sd), 3) # desvios padrão, desconsiderando vs e am
##     mpg     cyl    disp      hp    drat      wt    qsec    gear    carb 
##   6.027   1.786 123.939  68.563   0.535   0.978   1.787   0.738   1.615
cv <- function(x) {sd(x)/mean(x)} # coeficiente de variação, cv
round(sapply(mtcars[,-c(8,9)], cv), 3) # cv, desconsiderando vs e am
##   mpg   cyl  disp    hp  drat    wt  qsec  gear  carb 
## 0.300 0.289 0.537 0.467 0.149 0.304 0.100 0.200 0.574
round(cov(mtcars[,-c(8,9)]), 3) # matriz de covariâncias
##           mpg     cyl      disp       hp    drat      wt    qsec    gear   carb
## mpg    36.324  -9.172  -633.097 -320.732   2.195  -5.117   4.509   2.136 -5.363
## cyl    -9.172   3.190   199.660  101.931  -0.668   1.367  -1.887  -0.649  1.520
## disp -633.097 199.660 15360.800 6721.159 -47.064 107.684 -96.052 -50.803 79.069
## hp   -320.732 101.931  6721.159 4700.867 -16.451  44.193 -86.770  -6.359 83.036
## drat    2.195  -0.668   -47.064  -16.451   0.286  -0.373   0.087   0.276 -0.078
## wt     -5.117   1.367   107.684   44.193  -0.373   0.957  -0.305  -0.421  0.676
## qsec    4.509  -1.887   -96.052  -86.770   0.087  -0.305   3.193  -0.280 -1.894
## gear    2.136  -0.649   -50.803   -6.359   0.276  -0.421  -0.280   0.544  0.327
## carb   -5.363   1.520    79.069   83.036  -0.078   0.676  -1.894   0.327  2.609
round(cor(mtcars[,-c(8,9)]), 3) # matriz de correlação
##         mpg    cyl   disp     hp   drat     wt   qsec   gear   carb
## mpg   1.000 -0.852 -0.848 -0.776  0.681 -0.868  0.419  0.480 -0.551
## cyl  -0.852  1.000  0.902  0.832 -0.700  0.782 -0.591 -0.493  0.527
## disp -0.848  0.902  1.000  0.791 -0.710  0.888 -0.434 -0.556  0.395
## hp   -0.776  0.832  0.791  1.000 -0.449  0.659 -0.708 -0.126  0.750
## drat  0.681 -0.700 -0.710 -0.449  1.000 -0.712  0.091  0.700 -0.091
## wt   -0.868  0.782  0.888  0.659 -0.712  1.000 -0.175 -0.583  0.428
## qsec  0.419 -0.591 -0.434 -0.708  0.091 -0.175  1.000 -0.213 -0.656
## gear  0.480 -0.493 -0.556 -0.126  0.700 -0.583 -0.213  1.000  0.274
## carb -0.551  0.527  0.395  0.750 -0.091  0.428 -0.656  0.274  1.000
symnum(cor(mtcars[,-c(8,9)])) # matriz de correlação simbólica
##      m cy ds h dr w q g cr
## mpg  1                    
## cyl  + 1                  
## disp + *  1               
## hp   , +  ,  1            
## drat , ,  ,  . 1          
## wt   + ,  +  , ,  1       
## qsec . .  .  ,      1     
## gear . .  .    ,  .   1   
## carb . .  .  ,    . ,   1 
## attr(,"legend")
## [1] 0 ' ' 0.3 '.' 0.6 ',' 0.8 '+' 0.9 '*' 0.95 'B' 1