Repaso Algebra Lineal

Daniel Camacho

Introducción

En el siguiente notebook se encuentran ejercicios de Álgebra Lineal del libro Methods of Multivariate Analysis de Alvin C Rencher, y del libro Multivariate Statistical Inference and Applications de Alvin C Rencher.

Ejercicio 2.12

Let

\[A = \begin{pmatrix} 1&2&3\\ 4&5&6\\ 7&8&9 \end{pmatrix} \;\;\;\; ,\;\;\; D = \begin{pmatrix} a&0&0\\ 0&b&0\\ 0&0&c \end{pmatrix}\]

find \(DA\), \(AD\), \(DAD\)

Solución

DA

\[DA=\begin{pmatrix} a&0&0\\ 0&b&0\\ 0&0&c \end{pmatrix} \begin{pmatrix} 1&2&3\\ 4&5&6\\ 7&8&9 \end{pmatrix}\]

\[= \begin{pmatrix} a*1+0*4+0*7 & a*2+0*5+0*8 & a*3+0*6+0*9\\ 0*1+b*4+0*7 & 0*2+b*5+0*8 & 0*3+b*6+0*9\\ 0*1+0*4+c*7 & 0*2+0*5+c*8 & 0*3+0*6+c*9 \end{pmatrix}\]

\[DA = \begin{pmatrix} a & 2a & 3a \\ 4b&5b&6b\\ 7c&8c&9c \end{pmatrix}\]

DAD

\[DAD =\begin{pmatrix} a&0&0\\ 0&b&0\\ 0&0&c \end{pmatrix} \begin{pmatrix} 1&2&3\\ 4&5&6\\ 7&8&9 \end{pmatrix} \begin{pmatrix} a&0&0\\ 0&b&0\\ 0&0&c \end{pmatrix}\]

\[DAD = \begin{pmatrix} a & 2a & 3a \\ 4b&5b&6b\\ 7c&8c&9c \end{pmatrix} \begin{pmatrix} a&0&0\\ 0&b&0\\ 0&0&c \end{pmatrix}\]

\[DAD = \begin{pmatrix} a^2+2a*0+3a*0 & a*0+5*b+3a*0 & 3a*0+2a*0+3ac\\ 4ba+5b*0+6b*0 & 4b*0+5b^2+6b*0 & 4b*0 +5b*0+6bc\\ 7ca+8c*0+9c*0 & 7c*0+ 8cb + 9*c & 7c*0+8c*0+9c^2 \end{pmatrix}\]

\[DAD = \begin{pmatrix} a^2 & 5ab & 3ac \\ 4ba & 5b^2 & 6bc \\ 7ca & 8cb & 9c^2 \end{pmatrix}\]

Ejercicio 2.13

Let \(A\) and \(B\) be partitioned as follows

\[ A=\left( \begin{array}{c|c} 2 \;\;\;\; 1 & 2 \\ 3 \;\;\;\; 2 & 0 \\ \hline 1 \;\;\;\; 0 & 1 \end{array} \right) \]

\[B=\left( \begin{array}{c|c} 1 \;\;\;\; 1 \;\;\;\; 1 & 0 \\ 2 \;\;\;\; 1 \;\;\;\; 1 & 2 \\ \hline 2 \;\;\;\; 3 \;\;\;\; 1 & 1 \end{array} \right)\]

(a) Find \(AB\) as in (2.65) using the indicated partitioning.

(b) Check by finding \(AB\) in the usual way, ignoring the partitioning.

Solución

a

(a)

Donde (2.65) es igual a

\[AB = \begin{pmatrix} A_{11} & A_{12} \\ A_{21} & A_{22} \end{pmatrix} \begin{pmatrix} B_{11} & B_{12} \\ B_{21} & B_{22} \end{pmatrix} = \begin{pmatrix} A_{11}B_{11} + A_{12}B_{21} & A_{11}B_{21} + A_{12}B_{22}\\ A_{21}B_{11} + A_{22}B_{22} & A_{21}B_{12} + A_{22}B_{22} \end{pmatrix}\]

Con

\[A_{11} = \begin{pmatrix} 2&1\\ 3&2 \end{pmatrix} \;\;\;\; A_{12}= \begin{pmatrix} 2\\ 0 \end{pmatrix}\]

\[A_{21} = \begin{pmatrix} 1&0 \end{pmatrix} \;\;\;\; A_{22}= \begin{pmatrix} 1 \end{pmatrix}\]

\[B_{11} = \begin{pmatrix} 1&1&1\\ 2&1&1 \end{pmatrix} \;\;\;\; B_{12}= \begin{pmatrix} 0\\ 2 \end{pmatrix}\]

\[B_{21} = \begin{pmatrix} 2&3&1 \end{pmatrix} \;\;\;\; B_{22}= \begin{pmatrix} 2 \end{pmatrix}\]

Así

\[A_{11}B_{11} = \begin{pmatrix} 2&1\\ 3&2 \end{pmatrix} \begin{pmatrix} 1&1&1\\ 2&1&1 \end{pmatrix} =\begin{pmatrix} 4&3&3\\ 7&5&5 \end{pmatrix}\]

\[A_{12}B_{21} = \begin{pmatrix} 2\\ 0 \end{pmatrix} \begin{pmatrix} 2&3&1 \end{pmatrix} = \begin{pmatrix} 4&6&2\\ 0&0&0 \end{pmatrix}\]

\[A_{11}B_{12} = \begin{pmatrix} 2&1\\ 3&2 \end{pmatrix} \begin{pmatrix} 0\\ 2 \end{pmatrix} = \begin{pmatrix} 2\\ 4 \end{pmatrix}\]

\[A_{12}B_{22} = \begin{pmatrix} 2\\ 0 \end{pmatrix} \begin{pmatrix} 2 \end{pmatrix} = \begin{pmatrix} 4\\ 0 \end{pmatrix}\]

\[A_{21}B_{11} = \begin{pmatrix} 1 & 0 \end{pmatrix} \begin{pmatrix} 1 & 1 & 1\\ 2 & 1 & 1 \end{pmatrix} = \begin{pmatrix} 1&1&1 \end{pmatrix}\]

\[A_{22}B_{21} = \begin{pmatrix} 1 \end{pmatrix} \begin{pmatrix} 2&3&1 \end{pmatrix}= \begin{pmatrix} 2&3&1 \end{pmatrix}\]

\[A_{21}B_{12} = \begin{pmatrix} 1&0 \end{pmatrix} \begin{pmatrix} 0\\ 2 \end{pmatrix} = \begin{pmatrix} 0 \end{pmatrix}\]

\[A_{22}B_{22} = \begin{pmatrix} 1 \end{pmatrix} \begin{pmatrix} 2 \end{pmatrix}= \begin{pmatrix} 2 \end{pmatrix}\]

Así \(AB\)

\[\begin{bmatrix} \begin{pmatrix} 4 & 3 & 3\\ 7 & 5 & 5 \end{pmatrix} + \begin{pmatrix} 4 & 6 & 2\\ 0 & 0 & 0 \end{pmatrix} \;\;\; \begin{pmatrix} 2\\ 4 \end{pmatrix} + \begin{pmatrix} 4\\ 0 \end{pmatrix} \\ \begin{pmatrix} 1&1&1 \end{pmatrix} + \begin{pmatrix} 2&3&1 \end{pmatrix} \;\;\;\; \begin{pmatrix} 0 \end{pmatrix} \begin{pmatrix} 2 \end{pmatrix} \end{bmatrix}\]

\[AB = \begin{bmatrix} \begin{pmatrix} 8&9&5\\ 7&5&5 \end{pmatrix} \begin{pmatrix} 6\\ 4 \end{pmatrix} \\ \begin{pmatrix} 3&4&2 \end{pmatrix} \;\;\; \begin{pmatrix} 2 \end{pmatrix} \end{bmatrix}\]

b

(b)

Check by finding \(AB\) in the usual way, ignoring the partitioning.

\[AB = \begin{pmatrix} 2&1&2\\ 3&2&0\\ 1&0&1 \end{pmatrix} \begin{pmatrix} 1&1&1&0\\ 2&1&1&2\\ 2&3&1&2 \end{pmatrix}\]

\[AB = \begin{pmatrix} 2+2+4 & 2+1+6 & 2+1+2 & 0+2+4 \\ 3+4+0 & 3+2+0 & 3+2+0 & 0+4+0 \\ 1+0+2 & 1+0+3 & 1+0+1 & 0+0+2 \end{pmatrix}\]

\[AB=\begin{pmatrix} 8&9&5&6\\ 7&5&5&4\\ 3&4&2&4 \end{pmatrix}\]

Con lo cual se comprueba de manera numérica.

Ejercicio 2.16

Let

\[A = \begin{pmatrix} 3&4&3\\ 4&8&6\\ 3&6&9 \end{pmatrix}\]

(a) Show that \(|A|>0\).

(b) Using Cholesky decomposition in section 2.7, find and upper triangular matrix such that \(A=T'T\)

Solución

a

(a)

Usando la expresión (2.82)

\[|A| = a_{11}a_{22}a_{33} + a_{12}a_{23}a_{31} + a_{13}a_{32}a_{21} - a_{31}a_{22}a_{13} - a_{32}a_{23}a_{11} - a_{33}a_{12}a_{21}\]

\[|A| = 3*8*9 + 4*6*3 + 3*6*4 - 3*8*3 - 6*6*3 - 9*4*4\]

\[|A| = 216 + 72 + 72 -72 -108-144\] \[|A| = 36\]

Donde efectivamente \(|A|>0\)

b

(b)

Donde si \(A = (a_{ij})\) y \(T=(t_{ij})\) son \(n\times n\) entonces los elementos de \(T\) se encuentran de la siguiente manera.

\[t_{11} = \sqrt{a_{11}}\] \[t_{1j} = \frac{a1j}{t_{11}} , \; 2\le j \le n\] \[t_{ii} = \sqrt{a_{11} - \sum^{i-2}_{k=1} t^2_{ki}} ,\; 2\le i \le n\] \[t_{ij} = \frac{a_{ij}- \sum_{k=1}^{i-1} t_{ki}t_{kj}}{t_{ii}},\; 2\le i < j \le n\] \[t_{ij} = 0\]

Aplicado a la matriz \(A\) del ejercicio 2.16

\[t_{11} = \sqrt{3}=1.7321\] \[t_{12}=\frac{4}{\sqrt{3}}=2.309\] \[t_{13}=\frac{3}{\sqrt{3}}=1.71321\] \[t_{22} = \sqrt{8-(2.309)^2}=1.633\] \[t_{23}= \frac{6-2.309*1.7321}{1.633}=1.2247\] \[t_{33}=\sqrt{9-(1.7321)^2-(1.2247)^2}=2.1213\]

Así

\[T = \begin{pmatrix} 1.7321 & 2.309 & 1.7321\\ 0 & 1.633 & 1.2247 \\ 0 & 0 & 2.1213 \end{pmatrix}\]

Así

\[A = \begin{pmatrix} 1.7321 & 0 & 0 \\ 2.309 & 1.633 & 0 \\ 1.7321 & 1.2247 & 2.1213 \end{pmatrix} \begin{pmatrix} 1.7321 & 2.309 & 1.7321\\ 0 & 1.633 & 1.2247 \\ 0 & 0 & 2.1213 \end{pmatrix}\]

Verificando con código

Se escribe la matriz

A = matrix(data = c(3, 4, 3,
                    4, 8, 6,
                    3, 6, 9),
           nrow = 3, ncol = 3, byrow = TRUE)

Se hace la descomposición de Cholesky.

cholesky = chol(A)
cholesky
##          [,1]     [,2]     [,3]
## [1,] 1.732051 2.309401 1.732051
## [2,] 0.000000 1.632993 1.224745
## [3,] 0.000000 0.000000 2.121320

Siendo esta nuestra matriz \(T\).

Ejercicio 2.19

Let

\[A = \begin{pmatrix} 1&1&-2\\ -1&2&1\\ 0&1&-1 \end{pmatrix}\]

(a) Find the eigenvalues and associated normalized eigenvectors

(b) Find \(tr(A)\) and show that \(tr(A)=\sum^{3}_{i=1} \lambda_i\) and \(|A| = \Pi^{3}_{i=1} \lambda_i\)

Solución

a

Si se parte de la ecuación característica tenemos que

\[|A-\lambda I|\] \[|A-\lambda I| = \begin{pmatrix} 1-\lambda & 1 & -2 \\ -1 & 2-\lambda & 1 \\ 0 & 1 & -\lambda-1 \end{pmatrix}\]

Ahora calculando el determinante, usando la expresión 2.82 del ejercicio 8.16

\[|A-\lambda I| = (1-\lambda)(2-\lambda)(-\lambda-1)+0+2-0-(1-\lambda)-(\lambda+1)\] \[|A-\lambda I| = (1-\lambda)(2-\lambda)(-\lambda-1)\] \[|A-\lambda I| = -(\lambda+1)(\lambda+2)(\lambda+1)\] Si se resuelve la ecuación

\[-(\lambda-2)(\lambda-1)(\lambda+1)=0\]

Obtenemos

\[\lambda_{1}=2,\; \lambda_{2}=1,\; \lambda_{3}=-1\]

Siendo estos los eigenvalores

Para los eigenvectores resolvemos

\[(A-\lambda I)x = 0\]

Para \(\lambda_1 = 2\)

\[\begin{pmatrix} 1-2 & 1 & -2 \\ -1 & 2-2 & 1 \\ 0 & 1 & -2-1 \end{pmatrix} \begin{pmatrix} x_1\\ x_2\\ x_3 \end{pmatrix} =\begin{pmatrix} 0\\ 0\\ 0 \end{pmatrix}\]

Lo cual es

\[\begin{pmatrix} -1 & 1 & -2 \\ -1 & 0 & 1 \\ 0 & 1 & -3 \end{pmatrix} \begin{pmatrix} x_1\\ x_2\\ x_3 \end{pmatrix} =\begin{pmatrix} 0\\ 0\\ 0 \end{pmatrix}\]

\[-x_1+x_2-2x_3=0\\ -x_1 + x_3 = 0\\ x_2-3x_3 = 0\]

Sí de la ecuación dos tomamos

\[x_1=x_3=1\]

\[-1+x_2-2(1)=0\\ x_2=3\]

Así con un eigenvalor de \(\lambda_1=2\) con multiplicidad \(c=1\) obtenemos un eigenvector de

\[\vec{x_1} = \begin{Bmatrix} 1\\ 3\\ 1 \end{Bmatrix}\]

Donde normalizamos de la siguiente manera

\[\vec{x_1}=\frac{x_1}{||x_{1}||}\]

Así \(||x_{1}||=\sqrt{1^2+3^2+1^2}=\sqrt{11}\)

Así el vector normalizado es

\[\vec{x_1} = \begin{Bmatrix} \frac{1}{\sqrt{11}}\\ \frac{3}{\sqrt{11}}\\ \frac{1}{\sqrt{11}} \end{Bmatrix}\]

Lo cual es

\[\vec{x_1} = \begin{Bmatrix} 0.3015\\ 0.9045\\ 0.3015 \end{Bmatrix}\]

Para \(\lambda_2 = 1\)

\[\begin{pmatrix} 1-1 & 1 & -2 \\ -1 & 2-1 & 1 \\ 0 & 1 & -1-1 \end{pmatrix} \begin{pmatrix} x_1\\ x_2\\ x_3 \end{pmatrix} =\begin{pmatrix} 0\\ 0\\ 0 \end{pmatrix}\]

Lo cual es

\[\begin{pmatrix} 0 & 1 & -2 \\ -1 & 1 & 1 \\ 0 & 1 & -2 \end{pmatrix} \begin{pmatrix} x_1\\ x_2\\ x_3 \end{pmatrix} =\begin{pmatrix} 0\\ 0\\ 0 \end{pmatrix}\]

Movemos filas y multiplicamos por (-1)

\[\begin{pmatrix} 0 & 1 & -2 \\ -1 & 1 & 1 \\ 0 & 1 & -2 \end{pmatrix} = \begin{pmatrix} 1&-1&-1\\ 0&1&-2\\ 0&1&-2 \end{pmatrix}\]

Aplicamos reducción Gauss-Jordan obtenemos

\[\begin{pmatrix} 1&-1&-1\\ 0&1&-2\\ 0&0&0 \end{pmatrix}=>\begin{pmatrix} 1&0&-3\\ 0&1&-2\\ 0&0&0 \end{pmatrix}\]

Así

\[\vec{x}=\begin{pmatrix} 3c\\ 2c\\ c \end{pmatrix}= \begin{pmatrix} 3\\ 2\\ 1 \end{pmatrix}c\]

Así si \(c=1\)

Para el eigenvalue \(\lambda_2 =1\) tenemos el eigenvector

\[\vec{x_2}= \begin{Bmatrix} 3\\ 2\\ 1 \end{Bmatrix}\]

Donde normalizamos de la siguiente manera

\[\vec{x_2}=\frac{x_2}{||x_{2}||}\]

Así \(||x_{2}||=\sqrt{3^2+2^2+1^2}=\sqrt{14}\)

Así el vector normalizado es

\[\vec{x_2} = \begin{Bmatrix} \frac{3}{\sqrt{14}}\\ \frac{2}{\sqrt{14}}\\ \frac{1}{\sqrt{14}} \end{Bmatrix}\]

Lo cual es

\[\vec{x_2} = \begin{Bmatrix} 0.8017\\ 0.5345\\ 0.2672 \end{Bmatrix}\]

Por ultimo para el eigenvalue \(\lambda_3 = -1\)

\[\begin{pmatrix} 1+1 & 1 & -2 \\ -1 & 2+1 & 1 \\ 0 & 1 & 1-1 \end{pmatrix} \begin{pmatrix} x_1\\ x_2\\ x_3 \end{pmatrix} =\begin{pmatrix} 0\\ 0\\ 0 \end{pmatrix}\]

Lo cual es

\[\begin{pmatrix} 2 & 1 & -2 \\ -1 & 3 & 1 \\ 0 & 1 & 0 \end{pmatrix} \begin{pmatrix} x_1\\ x_2\\ x_3 \end{pmatrix} =\begin{pmatrix} 0\\ 0\\ 0 \end{pmatrix}\]

\[2x_1+x_2-2x_3=0\\ -x_1+3x_2-x_3=0\\ x_2=0\]

\(x_2=0\)

\[2x_1-2x_3=0\\ -x_1-x_3=0\]

Así sí \(x_1=x_3\) entonces para el eigenvalor \(\lambda_3=-1\)

Se tiene el eigenvector

\[\vec{x_3} = \begin{Bmatrix} 1\\ 0\\ 1 \end{Bmatrix}\]

Con multiplicidad 1.

Donde normalizamos de la siguiente manera

\[\vec{x_3}=\frac{x_3}{||x_{3}||}\]

Así \(||x_{3}||=\sqrt{1^2+0^2+1^2}=\sqrt{2}\)

Así el vector normalizado es

\[\vec{x_3} = \begin{Bmatrix} \frac{1}{\sqrt{2}}\\ \frac{0}{\sqrt{2}}\\ \frac{1}{\sqrt{2}} \end{Bmatrix}\]

Lo cual es

\[\vec{x_3} = \begin{Bmatrix} 0.7071\\ 0.0000\\ 0.7071 \end{Bmatrix}\]

Calculo con R

#Matriz
B = matrix(data = c(1, 1, -2,
                    -1, 2, 1,
                    0, 1, -1),
           nrow = 3, ncol = 3, byrow = TRUE)

Eigenvalues

eg = eigen(B)
# Eigenvalues
eg$values
## [1]  2  1 -1

Eigenvectors

# Eigenvectos
eg$vectors
##           [,1]       [,2]          [,3]
## [1,] 0.3015113 -0.8017837  7.071068e-01
## [2,] 0.9045340 -0.5345225 -1.922963e-16
## [3,] 0.3015113 -0.2672612  7.071068e-01

b

(b)

\[A = \begin{pmatrix} 1&1&-2\\ -1&2&1\\ 0&1&-1 \end{pmatrix}\]

Para \(tr(A)\)

Claramente

\[tr(A)=1+2-1=2\]

Y

\[tr(A)=\sum^{3}_{i=1}\lambda_i\]

\[tr(A)=\lambda_1 + \lambda_2 +\lambda_3= 2+1-1=2\]

Lo cual se comprueba

Y ademas

\[|A| = \Pi^{3}_{i=1} \lambda_i\]

El determinante de la matriz es

determinante = det(B)
determinante
## [1] -2

Y el producto de los eigenvalues es

\[|A| = (2)(1)(-1)=-2\]

Lo cual también se comprueba.

Ejercicio 2.20

\[A = \begin{pmatrix} 3 & 1 & 1 \\ 1 & 0 & 2 \\ 1 & 2 & 0 \end{pmatrix}\]

(a) The eigenvalues of \(A\) are 1,4,-2, find the normalized eigenvectors, and use them as columns in an orthogonal matrix \(C\)

(b) Show that \(C'AC=D\) as in (2.111), where \(D\) is diagonal with the eigenvalues of \(A\) in the diagonal.

(c) Show that \(A=CDC'\) as in (2.109)

Solución

a

Para \(\lambda = 1\)

\[A = \begin{pmatrix} 3-\lambda & 1 & 1 \\ 1 & -\lambda & 2 \\ 1 & 2 & -\lambda \end{pmatrix} = \begin{pmatrix} 2 & 1 & 1 \\ 1 & -1 & 2 \\ 1 & 2 & -1 \end{pmatrix} \begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \\ 0 \end{pmatrix}\]

Con reducción Gaussiana

\[A =F_1 \frac{1}{2} \begin{pmatrix} 1 & 1/2 & 1/2 \\ 1 & -1 & 2 \\ 1 & 2 & -1 \end{pmatrix} => \begin{pmatrix} 1 & 1/2 & 1/2 \\ 0 & -3/2 & 3/2 \\ 0 & 3/2 & -3/2 \end{pmatrix} => F_2\frac{-2}{3} \begin{pmatrix} 1 & 1/2 & 1/2 \\ 0 & 1 & -1 \\ 0 & 3/2 & -3/2 \end{pmatrix}\]

\[=> \begin{pmatrix} 1 & 0 & 1 \\ 0 & 1 & -1 \\ 0 & 0 & 0 \end{pmatrix}\]

\[x_1+x_2=0\\ x_2-x_3=0\]

\[x_1=-x_2 \\ x_2=x_3\]

Así \(x_1 = -1\), \(x_2 = 1\), \(x_3=1\)

\[\vec{x} = \begin{Bmatrix} -1\\ 1\\ 1 \end{Bmatrix}\]

Normalizado

\[\vec{x} = \begin{Bmatrix} -1/\sqrt{3}\\ 1/\sqrt{3}\\ 1/\sqrt{3} \end{Bmatrix}\]

Para \(\lambda = 4\)

\[A = \begin{pmatrix} 3-\lambda & 1 & 1 \\ 1 & -\lambda & 2 \\ 1 & 2 & -\lambda \end{pmatrix} = \begin{pmatrix} -1 & 1 & 1 \\ 1 & -4 & 2 \\ 1 & 2 & -4 \end{pmatrix} \begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \\ 0 \end{pmatrix}\]

Con reducción Gaussiana

\[A = -1*F_1 \begin{pmatrix} 1 & -1 & -1 \\ 1 & -4 & 2 \\ 1 & 2 & -4 \end{pmatrix} => \begin{pmatrix} 1 & -1 & -1 \\ 0 & -3 & 3/2 \\ 0 & 3 & -3 \end{pmatrix} => F_2\frac{-1}{3} \begin{pmatrix} 1 & -1 & -1 \\ 0 & 1 & -1 \\ 0 & 3 & -3 \end{pmatrix}\]

\[=> \begin{pmatrix} 1 & 0 & -2 \\ 0 & 1 & -1 \\ 0 & 0 & 0 \end{pmatrix}\]

\[x_1-2x_2=0\\ x_2-x_3=0\]

\[x_1=2x_2 \\ x_2=x_3\]

Así \(x_1 = 2\), \(x_2 = 1\), \(x_3=1\)

\[\vec{x} = \begin{Bmatrix} 2\\ 1\\ 1 \end{Bmatrix}\]

Normalizado

\[\vec{x} = \begin{Bmatrix} 1/\sqrt{6}\\ 1/\sqrt{6}\\ 1/\sqrt{6} \end{Bmatrix}\]

Para \(\lambda = -2\)

\[A = \begin{pmatrix} 3-\lambda & 1 & 1 \\ 1 & -\lambda & 2 \\ 1 & 2 & -\lambda \end{pmatrix} = \begin{pmatrix} -5 & 1 & 1 \\ 1 & 2 & 2 \\ 1 & 2 & 2 \end{pmatrix} \begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \\ 0 \end{pmatrix}\]

Con reducción Gaussiana

\[A = F_1\frac{1}{5} \begin{pmatrix} 1 & 1/5 & 1/5 \\ 1 & 2 & 2 \\ 1 & 2 & 2 \end{pmatrix} => \begin{pmatrix} 1 & 1/5 & 1/5 \\ 0 & 9/5 & 9/5 \\ 0 & 9/5 & 9/5 \end{pmatrix} => F_2\frac{5}{9} \begin{pmatrix} 1 & 1/5 & 1/5 \\ 0 & 1 & 1 \\ 0 & 9/5 & 9/5 \end{pmatrix}\]

\[=> \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 1 \\ 0 & 0 & 0 \end{pmatrix}\]

\[x_1=0\\ x_2+x_3=0\]

\[x_1=0 \\ x_2=-x_3\]

Así \(x_1 = 1\), \(x_2 = 1\), \(x_3=1\)

\[\vec{x} = \begin{Bmatrix} 0\\ -1\\ 1 \end{Bmatrix}\]

Normalizado

\[\vec{x} = \begin{Bmatrix} 0\\ -1/\sqrt{2}\\ 1/\sqrt{2} \end{Bmatrix}\]

Así para una matriz \(C\) ortogonal con las columnas de los eigenvectores normalizados obtenemos

Para \(\lambda_1 = 4\), \(\lambda_2 = 1\), \(\lambda_3=-2\)

\[C = \begin{pmatrix} -2/\sqrt{6} & -1/\sqrt{3} & 0 \\ 1/\sqrt{6} & 1/\sqrt{3} & -1/\sqrt{2} \\ 1/\sqrt{6} & 1/\sqrt{3} & 1/\sqrt{2} \end{pmatrix}\]

Verificación con R

A = matrix(data = c(3,1,1,
                    1,0,2,
                    1,2,0),
           nrow = 3, ncol = 3)
A
##      [,1] [,2] [,3]
## [1,]    3    1    1
## [2,]    1    0    2
## [3,]    1    2    0

La Matriz \(C\)

C = eigen(A)$vectors
C
##           [,1]       [,2]          [,3]
## [1,] 0.8164966  0.5773503 -3.489094e-17
## [2,] 0.4082483 -0.5773503 -7.071068e-01
## [3,] 0.4082483 -0.5773503  7.071068e-01

b

(b)

con \(C\)

C
##           [,1]       [,2]          [,3]
## [1,] 0.8164966  0.5773503 -3.489094e-17
## [2,] 0.4082483 -0.5773503 -7.071068e-01
## [3,] 0.4082483 -0.5773503  7.071068e-01

La matriz \(C'\)

C_t=t(C)
C_t
##               [,1]       [,2]       [,3]
## [1,]  8.164966e-01  0.4082483  0.4082483
## [2,]  5.773503e-01 -0.5773503 -0.5773503
## [3,] -3.489094e-17 -0.7071068  0.7071068

Así

\[C'AC=D\]

D_g = C_t%*%A%*%C
D_g
##               [,1]          [,2]          [,3]
## [1,]  4.000000e+00 -3.330669e-16  2.220446e-16
## [2,] -1.387779e-16  1.000000e+00  1.110223e-16
## [3,]  4.440892e-16  0.000000e+00 -2.000000e+00

Y la matriz \(D\)

D = diag(eigen(A)$values)
D
##      [,1] [,2] [,3]
## [1,]    4    0    0
## [2,]    0    1    0
## [3,]    0    0   -2

Donde con ciertas aproximaciones se observa como se cumple la propiedad al obtener la misma matriz.

c

(c)

Ahora se pide encontrar que

\[A=CDC'\]

A_g = C%*%D%*%C_t
A_g
##      [,1]          [,2]         [,3]
## [1,]    3  1.000000e+00  1.00000e+00
## [2,]    1 -8.881784e-16  2.00000e+00
## [3,]    1  2.000000e+00 -1.44329e-15

Comparando con \(A\)

A
##      [,1] [,2] [,3]
## [1,]    3    1    1
## [2,]    1    0    2
## [3,]    1    2    0

Se observa también que la propiedad se cumple.

Ejercicio 2.21

Let

\[A = \begin{pmatrix} 2 & -1 \\ -1 & 2 \end{pmatrix}\]

Calculate the eigenvalues and eigenvectors and find the square root matrix \(A^2\) as in (2.112). Check by showing that \((A^{1/2})^{2} = A\)

Solución

Empezamos con la ecuación característica

\[|A-\lambda I| = \begin{pmatrix} 2-\lambda & -1 \\ -1 & 2-\lambda \end{pmatrix}\]

Se procede a calcular el determinante

\[|A-\lambda I| = \begin{pmatrix} 2-\lambda & -1 \\ -1 & 2-\lambda \end{pmatrix} =(2-\lambda)(2-\lambda) - (-1)(-1)=0\]

\[(2-\lambda)(2-\lambda) - 1=0\\ 4-2\lambda -2\lambda + \lambda^2 - 1 = 0 \\ \lambda^2-4\lambda+3=0 \\ (\lambda-3)(\lambda-1)=0\]

Sus eigenvalues son \(\lambda=3\) y \(\lambda=1\)

Para los eigenvectores

Para \(\lambda = 3\)

\[|A-3 I| = \begin{pmatrix} 2-3 & -1 \\ -1 & 2-3 \end{pmatrix} = \begin{pmatrix} -1 & -1 \\ -1 & -1 \end{pmatrix}\]

Así

\[-x_1-x_2=0\\-x_1-x_2=0\] \[-x_1=x_2\\-x_1=x_2\]

Así

\[\vec{x}=\begin{Bmatrix} -1\\ 1 \end{Bmatrix}\]

Normalizados

\[\vec{x}=\begin{Bmatrix} -1/\sqrt{2}\\ 1/\sqrt{2} \end{Bmatrix}\]

Para \(\lambda = 1\)

\[|A-1 I| = \begin{pmatrix} 2-1 & -1 \\ -1 & 2-1 \end{pmatrix} = \begin{pmatrix} 1 & -1 \\ -1 & 1 \end{pmatrix}\]

Así

\[x_1-x_2=0\\-x_1+x_2=0\] \[x_1=x_2\\x_1=x_2\]

Así

\[\vec{x}=\begin{Bmatrix} 1\\ 1 \end{Bmatrix}\]

Normalizados

\[\vec{x}=\begin{Bmatrix} 1/\sqrt{2}\\ 1/\sqrt{2} \end{Bmatrix}\]

Verificando con R

A = matrix(data = c(2, -1, 
                    -1, 2),
           nrow = 2, ncol = 2)
A
##      [,1] [,2]
## [1,]    2   -1
## [2,]   -1    2
eg = eigen(A)

# Eigenvalues
eg$values
## [1] 3 1
#Eigenvectors
eg$vectors
##            [,1]       [,2]
## [1,] -0.7071068 -0.7071068
## [2,]  0.7071068 -0.7071068
# Matriz diagonal de eigenvalues
diag(eg$values)
##      [,1] [,2]
## [1,]    3    0
## [2,]    0    1

Donde se verifican los resultados.

Ahora procedemos a calcular \(A^{1/2}\)

Usando

\[A^{1/2} = CD^{1/2}C'\]

Se vería de la forma

\[A^{1/2} = \begin{pmatrix}-\frac{1}{\sqrt{2}}&\frac{1}{\sqrt{2}}\\ \:\frac{1}{\sqrt{2}}&\frac{1}{\sqrt{2}}\end{pmatrix}\begin{pmatrix}\sqrt{3}&0\\ \:0&\sqrt{1}\end{pmatrix}\begin{pmatrix}-\frac{1}{\sqrt{2}}&\frac{1}{\sqrt{2}}\\ \:\:\frac{1}{\sqrt{2}}&\frac{1}{\sqrt{2}}\end{pmatrix}\]

\[A^{1/2} = \begin{pmatrix} -\frac{\sqrt{3}}{\sqrt{2}} & \frac{\sqrt{1}}{\sqrt{2}} \\ \frac{\sqrt{3}}{\sqrt{2}} & \frac{\sqrt{1}}{\sqrt{2}} \end{pmatrix} \begin{pmatrix} -\frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\ \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \end{pmatrix}\]

\[A^{1/2} = \begin{pmatrix} \frac{\sqrt{3}+1}{2} & \frac{-\sqrt{3}+1}{2} \\ \frac{-\sqrt{3}+1}{2} & \frac{\sqrt{3}+1}{2} \end{pmatrix}\]

A_sqrt = eg$vectors%*%(diag(eg$values))^0.5%*%t(eg$vectors)
A_sqrt
##            [,1]       [,2]
## [1,]  1.3660254 -0.3660254
## [2,] -0.3660254  1.3660254

Donde al evaluar aritméticamente \(A^{1/2}\) obtenemos los mismos resultados.

Por ultimo nos pide otra verificación por medio de la expresión \((A^{1/2})^2=A\)

\[(A^{1/2})^2 = \begin{pmatrix} \frac{\sqrt{3}+1}{2} & \frac{-\sqrt{3}+1}{2} \\ \frac{-\sqrt{3}+1}{2} & \frac{\sqrt{3}+1}{2} \end{pmatrix} \begin{pmatrix} \frac{\sqrt{3}+1}{2} & \frac{-\sqrt{3}+1}{2} \\ \frac{-\sqrt{3}+1}{2} & \frac{\sqrt{3}+1}{2} \end{pmatrix} \]

Esto es igual a

\[(A^{1/2})^2 = \begin{pmatrix} 1.3660254 & -0.3660254 \\ -0.3660254 & 1.3660254 \end{pmatrix} \begin{pmatrix} 1.3660254 & -0.3660254 \\ -0.3660254 & 1.3660254 \end{pmatrix}\]

\[(A^{1/2})^2 = \begin{pmatrix} 1.366*1.366 + -0.366*-0.366 & 1.366*0.366+1.366*1.366\\ -0.366*1.366 + 1.366*-0.366 & -0.366*-0.366+1.366*1.366 \end{pmatrix}\]

\[(A^{1/2})^2 = \begin{pmatrix} 2 & -1 \\ -1 & 2 \end{pmatrix} = A\]

Siendo esta la matriz \(A\) original

Verificando con R

A_orig = A_sqrt%*%A_sqrt
A_orig
##      [,1] [,2]
## [1,]    2   -1
## [2,]   -1    2

Ejercicio 2.22

Let

\[A = \begin{pmatrix} 3 & 6 & -1 \\ 6 & 9 & 4 \\ -1 & 4 & 3 \end{pmatrix}\]

(a) Find the spectral decomposition of \(A\) as in (2.019).

(b) Find the spectral decomposition of \(A^2\) and show that the diagonal matrix of eigenvalues is equal to the square of the matrix \(D\) found in part (a), thus illustrating (2.115).

(c) Find the spectral decomposition of \(A^{-1}\) and show that the diagonal matrix of eigenvalues is equal to the inverse of the matrix \(D\) found in part (a), thus illustrating (2.116).

Solución

a

La descomposición espectral definida como

\[A=CDC'\]

Donde \(C\), contiene los eigenvectores normalizados, y \(D\) es una matriz diagonal de eigenvalues.

Primero escribiremos la matriz

A = matrix(data = c(3,6,-1,
                    6,9,4,
                    -1,4,3),
           nrow = 3, byrow = TRUE) 
A
##      [,1] [,2] [,3]
## [1,]    3    6   -1
## [2,]    6    9    4
## [3,]   -1    4    3

Calculamos sus eigenvalores y eigenvectores.

spec_decomp = eigen(A)

La matriz \(C\)

C = spec_decomp$vectors
C
##            [,1]        [,2]       [,3]
## [1,] -0.4551422 -0.58020965  0.6754275
## [2,] -0.8459671  0.04509354 -0.5313250
## [3,] -0.2778225  0.81321789  0.5113622

La matriz \(C'\)

C_t = t(C)
C_t
##            [,1]        [,2]       [,3]
## [1,] -0.4551422 -0.84596706 -0.2778225
## [2,] -0.5802096  0.04509354  0.8132179
## [3,]  0.6754275 -0.53132504  0.5113622

La matriz \(D\)

D = diag(spec_decomp$values)
D
##          [,1]     [,2]      [,3]
## [1,] 13.54172 0.000000  0.000000
## [2,]  0.00000 3.935277  0.000000
## [3,]  0.00000 0.000000 -2.476994

Así se tiene a \(A=CDC'\)

verificacion = C%*%D%*%C_t
verificacion
##      [,1] [,2] [,3]
## [1,]    3    6   -1
## [2,]    6    9    4
## [3,]   -1    4    3

b

La descomposición espectral de \(A^2\)

\(A\) es

\[A = \begin{pmatrix} 3 & 6 & -1 \\ 6 & 9 & 4 \\ -1 & 4 & 3 \end{pmatrix}\]

A = matrix(data = c(3,6,-1,
                    6,9,4,
                    -1,4,3),
           nrow = 3, byrow = TRUE) 
A
##      [,1] [,2] [,3]
## [1,]    3    6   -1
## [2,]    6    9    4
## [3,]   -1    4    3

Donde \(A^2\) es

A2 = A%*%A
A2
##      [,1] [,2] [,3]
## [1,]   46   68   18
## [2,]   68  133   42
## [3,]   18   42   26

Así su descomposición espectral es:

spec_decompA2 = eigen(A2)

La matriz \(C\)

C2 = spec_decompA2$vectors
C2
##            [,1]        [,2]       [,3]
## [1,] -0.4551422 -0.58020965  0.6754275
## [2,] -0.8459671  0.04509354 -0.5313250
## [3,] -0.2778225  0.81321789  0.5113622

La matriz \(C'\)

C2_t = t(C2)
C2_t
##            [,1]        [,2]       [,3]
## [1,] -0.4551422 -0.84596706 -0.2778225
## [2,] -0.5802096  0.04509354  0.8132179
## [3,]  0.6754275 -0.53132504  0.5113622

La matriz \(D\)

D2 = diag(spec_decompA2$values) 
D2
##          [,1]    [,2]     [,3]
## [1,] 183.3781  0.0000 0.000000
## [2,]   0.0000 15.4864 0.000000
## [3,]   0.0000  0.0000 6.135498

Donde como dice el enunciado es el mismo resultado que el de elevar al cuadrado la matriz \(D\) del apartado (a)

Como observamos, si verificamos usando D

D2_verificado = D%*%D
D2_verificado
##          [,1]    [,2]     [,3]
## [1,] 183.3781  0.0000 0.000000
## [2,]   0.0000 15.4864 0.000000
## [3,]   0.0000  0.0000 6.135498

Así verificamos la descomposición espectral de \(A^2\)

verificacion_2 = C2%*%D2%*%C2_t
verificacion_2
##      [,1] [,2] [,3]
## [1,]   46   68   18
## [2,]   68  133   42
## [3,]   18   42   26

Siendo la matriz \(A^2\)

Con lo que se verifica (2.115) esto es

\[A^2 = CD^2C'\]

c

Para \(A^{-1}\) calculamos \(A^{-1}\)

De

\[A = \begin{pmatrix} 3 & 6 & -1 \\ 6 & 9 & 4 \\ -1 & 4 & 3 \end{pmatrix}\]

A = matrix(data = c(3,6,-1,
                    6,9,4,
                    -1,4,3),
           nrow = 3, byrow = TRUE) 
A
##      [,1] [,2] [,3]
## [1,]    3    6   -1
## [2,]    6    9    4
## [3,]   -1    4    3

Así \(A^{-1}\)

inversa = solve(A)
inversa
##             [,1]        [,2]        [,3]
## [1,] -0.08333333  0.16666667 -0.25000000
## [2,]  0.16666667 -0.06060606  0.13636364
## [3,] -0.25000000  0.13636364  0.06818182

Así

spec_decomp_inv = eigen(inversa)

La matriz \(C\)

C_inv = spec_decomp_inv$vectors
C_inv
##             [,1]      [,2]       [,3]
## [1,] -0.58020965 0.4551422  0.6754275
## [2,]  0.04509354 0.8459671 -0.5313250
## [3,]  0.81321789 0.2778225  0.5113622

La matriz \(C'\)

C_inv_t = t(spec_decomp_inv$vectors)
C_inv_t
##            [,1]        [,2]      [,3]
## [1,] -0.5802096  0.04509354 0.8132179
## [2,]  0.4551422  0.84596706 0.2778225
## [3,]  0.6754275 -0.53132504 0.5113622

Y la matriz \(D\)

D_inv = diag(spec_decomp_inv$values)
D_inv
##           [,1]       [,2]       [,3]
## [1,] 0.2541117 0.00000000  0.0000000
## [2,] 0.0000000 0.07384588  0.0000000
## [3,] 0.0000000 0.00000000 -0.4037152

El cual se observa que es la inversa \(\frac{1}{\lambda_i}\) de los eigenvalues de la matriz \(D\) del apartado (a), solo que el orden de estos es distinto.

Así verificamos la descomposición espectral de \(A^{-1}\)

verificiacion_inv = C_inv%*%D_inv%*%C_inv_t
verificiacion_inv
##             [,1]        [,2]        [,3]
## [1,] -0.08333333  0.16666667 -0.25000000
## [2,]  0.16666667 -0.06060606  0.13636364
## [3,] -0.25000000  0.13636364  0.06818182

Observamos que tenemos la matriz \(A^{-1}\)

Ejercicio 2.23

Find the singular value decomposition of \(A\) as in (2.117), where

\[A = \begin{pmatrix} 4 & -5 & -1 \\ 7 & -2 & 3 \\ -1 & 4 & -3 \\ 8 & 2 & 6 \end{pmatrix}\]

Solución

De la forma

\[A_{m\times n} = U_{m\times n}D_{n\times n}V'_{n\times n}\]

Primero escribimos la matriz

A =  matrix(data = c(4,-5,-1,
                     7,-2,3,
                     -1,4,6,
                     8,2,6),
            nrow = 4, byrow = TRUE)
A
##      [,1] [,2] [,3]
## [1,]    4   -5   -1
## [2,]    7   -2    3
## [3,]   -1    4    6
## [4,]    8    2    6

En R existe una forma directa de obtenerla con la función svd()

sv_decomp = svd(A)

Observamos la matriz \(U_{4\times 3}\)

U = sv_decomp$u
U
##            [,1]       [,2]       [,3]
## [1,] -0.2063863  0.6196357 -0.5632763
## [2,] -0.5720687  0.2697116 -0.1722794
## [3,] -0.1987154 -0.7141407 -0.6694711
## [4,] -0.7685403 -0.1825110  0.4526014

La cual es los eigenvectores normalizados de \(AA'\)

Los eigenvalues

sv_decomp$d
## [1] 13.027277  9.332598  2.047600

Y en una matriz \(D_{3\times 3}\)

D = diag(sv_decomp$d)
D
##          [,1]     [,2]   [,3]
## [1,] 13.02728 0.000000 0.0000
## [2,]  0.00000 9.332598 0.0000
## [3,]  0.00000 0.000000 2.0476

Siendo la matriz diagonal de los eigenvalues de \(D\)

Y la matriz \(V_{3 \times 3}\)

V = sv_decomp$v
V
##             [,1]       [,2]       [,3]
## [1,] -0.82746636  0.3879494  0.4059491
## [2,] -0.01196515 -0.7349708  0.6779932
## [3,] -0.56138780 -0.5561593 -0.6128054

Resultante de los eigenvectores de \(A'A\)

Así \(V'\)

V_t = t(V)
V_t
##            [,1]        [,2]       [,3]
## [1,] -0.8274664 -0.01196515 -0.5613878
## [2,]  0.3879494 -0.73497075 -0.5561593
## [3,]  0.4059491  0.67799323 -0.6128054

Verificamos la descomposición de valores singulares

\[A_{4\times 3} = U_{4\times 3}D_{3\times 3}V_{3\times 3}'\]

verificacion_sv = U%*%D%*%V_t
verificacion_sv
##      [,1] [,2] [,3]
## [1,]    4   -5   -1
## [2,]    7   -2    3
## [3,]   -1    4    6
## [4,]    8    2    6

Donde obtenemos la matriz \(A\) de este apartado.

Ejercicio 2.38

Show that the eigenvalues of \(AB\) are the same as those of \(BA\), as noted in Section 2.11.5

Solución

Partiendo de la definición

\[Ax=\lambda x\]

Donde \(\lambda\) es el eigenvalor de \(A\), y \(x\) el eigenvector de \(A\)

Ahora si partimos de

\[ABx=\lambda x\]

Ahora \(\lambda\) es el eigenvalor de \(AB\), y \(x\) su eigenvector

Ahora si multiplicamos \(B\) por ambos lados

\[BABx=B\lambda x\]

Así

\[(BA)(Bx)=\lambda (Bx)\]

Ahora, \(\lambda\) es el eigenvalor de \(BA\) y \(Bx\) es su eigenvector

Donde \(Bx\) es no cero por definición.

De esa forma se encuentra que \(\lambda\) es el eigenvalor de \(AB\) como de \(BA\).

Aunque no se puede decir lo mismo de sus eigenvectores.

Ejercicio 2.39

If \(A^{1/2}\) is the square root matrix defined in (2.112), show that

(a) \((A^{1/2})^2=A\) as in (2.114)

(b) \(|A^{1/2}|^2=|A|\)

(c) \(|A^{1/2}|=|A|\)

Solución

a

(a)

Para \((A^{1/2})^2=A\)

\[A^{1/2}=CD^{1/2}C' \;\;\; (2.112)\]

\[=> \; (A^{1/2})^2=A\\ A^{1/2}A^{1/2}=A\\ CD^{1/2}C'CD^{1/2}C'=A \;\;\; (2.112)\\\]

Donde \(C\) es ortogonal

\[CD^{1/2}\underbrace{C'C}_{I}D^{1/2}C'=A\]

\[CD^{1/2}D^{1/2}C'=A \\ C\begin{bmatrix} \lambda^{1/2}_1 & 0 & ...&0 \\ 0 & \lambda^{1/2}_2 &... &0 \\ 0 & 0 & . & 0 \\ 0 & 0 & 0 & \lambda^{1/2}_n \end{bmatrix}\begin{bmatrix} \lambda^{1/2}_1 & 0 & ...&0 \\ 0 & \lambda^{1/2}_2 &... &0 \\ 0 & 0 & . & 0 \\ 0 & 0 & 0 & \lambda^{1/2}_n \end{bmatrix}C'=A \\ C\begin{bmatrix} \lambda_1 & 0 & ...&0 \\ 0 & \lambda_2 &... &0 \\ 0 & 0 & . & 0 \\ 0 & 0 & 0 & \lambda_n \end{bmatrix}C'=A \\ \]

Así

\[CDC'=A\]

Que es la descomposición espectral

Entonces

\[CDC'=A \\ A=A\]

b

(b)

Para \(|A^{1/2}|^2=|A|\)

\[|A^{1/2}|^2=|A|\\ |A^{1/2}||A^{1/2}|=|A|\\ |A^{1/2}A^{1/2}|=|A| \;\; (2.89)\\ |CD^{1/2}C'CD^{1/2}C'|=|A| \;\; (2.112) \\\]

Tomando de la demostración del apartado (a)

\[|CD^{1/2}D^{1/2}C'|=|A|\\ |CDC'|=|A|\]

Siendo la descomposición espectral

\[|CDC'|=|A|\\ |A|=|A|\]

c

(c)

Para \(|A^{1/2}|= |A|^{1/2}\)

Si sabemos que

\[|AB|=|A||B|\]

Y tambien

\[|A^n|=|\underbrace{AAAA...A}_{\text{n terminos}}|\\ |A^n|=|A||A||A||A|...|A|\\ |A^{n}|=|A|^{n}\]

Esto es comprensible dado que el determinante es un escalar así que permite que se realicen dichas operaciones.

Sabiendo eso es trivial el resultado de que

\[|A^{1/2}|=|A|^{1/2}\]

Dado que es un escalar y permite que dichas operaciones se efectúen.

Ejercicio 1.6.1

Del libro Multivariate Statistical Inference and Applications, el ejemplo 1.6.1.

Son datos de Reaven and Miller, 5 variables de pacientes normales y de pacientes con diabetes.

Los datos son un dataset incluido en el paquete rrcov, donde estan incluidos todas las observaciones (145)

En el libro Multivariate Statistical Inference and Applications, muestran solo 25 observaciones y en el libro Methods of multivariate Analysis hay 46.

Así que yo los usare todos.

Los baje del repositorio de GitHub donde se encuentra el paquete

https://github.com/cran/rrcov

En la carpeta de data

https://github.com/cran/rrcov/tree/master/data

Se encuentran los datos

https://github.com/cran/rrcov/blob/master/data/diabetes.rda

Se que estos son los datos dado que el CRAN oficial de R lo dice

https://search.r-project.org/CRAN/refmans/rrcov/html/diabetes.html

Y de que verifique varias de las entradas con las de los libros

# Importamos los datos
data_diabetes = read.csv("diabetes.csv", 
                         header = TRUE, 
                         stringsAsFactors = FALSE)
DT::datatable(data = data_diabetes,
              extensions = c('Buttons'),
              options = list(dom = 'Bfrtip',
                             buttons = c('csv','excel')),
              escape = TRUE)

Donde

  • \(rw=\) Relative Weight
  • \(fpg=\) Fasting Plasma Glucose
  • \(glucose=\) Glucose intolerance
  • \(insulin=\) Insulin responce to oral glucose
  • \(sspg=\) Insulin resistance

Donde inicialmente el objetivo es calcular la matriz de covarianza

# Tomando solo las variables cuantitativas.
data_diabetes_1 = subset(data_diabetes,
                         select = -c(group))

Donde se presenta la matriz de covarianza de todas las variables.

cov_t = cov(data_diabetes_1)
cov_t
##                  rw           fpg       glucose       insulin         sspg
## rw       0.01670174 -7.281513e-02  9.824262e-01      3.473373     5.266255
## fpg     -0.07281513  4.087097e+03  1.954606e+04  -3063.463649  4849.905651
## glucose  0.98242625  1.954606e+04  1.004578e+05 -12918.162739 25908.490182
## insulin  3.47337308 -3.063464e+03 -1.291816e+04  14625.312548   101.482519
## sspg     5.26625479  4.849906e+03  2.590849e+04    101.482519 11242.331897

Donde se observa que en su mayoría son positivas.

Y la matriz de correlación de entre todas las variables

cor_t = GGally::ggpairs(data_diabetes_1,
                        title = "Correlaciones")
cor_t

Donde las que mas sobresalen son la correlación entre la intolerancia a la glucosa y glucosa plasmática en ayunas, así cada aumento en la glucosa plasmática en ayunas también se relaciona en un aumento a la intolerancia a la glucosa.

De igual manera la resistencia a la insulina y la glucosa plasmática en ayunas tienen una correlación de 0.715, a parte la glucosa y la resistencia a la insulina tienen correlación de 0.77, las cuales se pueden considerar como altas, lo que implica que a mayor resistencia a la insulina mayor sera la glucosa común y la plasmática en ayunas.

Usando solo las primeras 25 observaciones como en el libro de Inferencia Estadística de Rencher.

data_diabetes_1_remove = data_diabetes_1[1:25,]
cov_t_r = cov(data_diabetes_1_remove)
cov_t_r
##                  rw          fpg    glucose    insulin       sspg
## rw       0.01284433   0.04373333    0.27405   -0.19970    1.06880
## fpg      0.04373333  42.47666667    6.54500   16.96167  -16.80500
## glucose  0.27405000   6.54500000 1122.44000  512.69000  -16.80167
## insulin -0.19970000  16.96166667  512.69000 1853.19000  305.03167
## sspg     1.06880000 -16.80500000  -16.80167  305.03167 1129.45667

Donde se muestra como al cambiar el tamaño de muestra inclusive cambia el signo de estas, (la resistencia a la insulina y los niveles de glucosa por ejemplo) y como se refleja en la correlación como se explicara mas adelante.

Y sus respectivas correlaciones.

cor_t_r = GGally::ggpairs(data_diabetes_1_remove,
                        title = "Correlaciones")
cor_t_r

Donde se observa como el tamaño de muestra afecta a las correlaciones, por ejemplo la glucosa y la glucosa plasmática en ayunas paso de tener una correlación de 0.96 a 0.030, y la resistencia la insulina con respecto a los niveles de glucosa pasaron de 0.71 y 0.77 para la glucosa común y la plasmática en ayunas respectivamente a -0.07 y -0.015, inclusive cambiando la orientación de esta.

Conclusión

Con ello se culmina el repaso de álgebra lineal parte del repaso en el estudio de teoría estadística, donde se repaso y reflexiono sobre la importancia de estas operaciones y conceptos en la estadística.