Maxima – 232 – descriptive – 9

D0SX

Continuo da qui, copio dal Reference Manual, PDF scaricabile da qui, sono a p.729.

list_correlations (matrix)
list_correlations (matrix, options ...)
Function list_correlations returns a list of correlation measures:

  • precision matrix: the inverse of the covariance matrix S1,
    232-0
  • multiple correlation vector: (R12, R22, ..., Rp2), with
    232-1
    being an indicator of the goodness of fit of the linear multivariate regression model on Xi when the rest of variables are used as regressors.
  • partial correlation matrix: with element (i, j) being
    232-2

Option: 'data, default 'true, indicates whether the input matrix contains the sample data, in which case the covariance matrix cov1 must be calculated, or not, and then the covariance matrix (symmetric) must be given, instead of the data.

(%i1) load ("descriptive")$

(%i2) s2 : read_matrix (file_search ("wind.data"))$

(%i3) z : list_correlations (s2)$

(%i4) fpprintprec : 5$ /* for pretty output */
(%i5) z[1]; /* precision matrix */
         [  0.38485   - 0.13856   - 0.15626   - 0.10239    0.031179  ]
         [                                                           ]
         [ - 0.13856   0.34107    - 0.15233    0.038447   - 0.052842 ]
         [                                                           ]
(%o5)    [ - 0.15626  - 0.15233    0.47295    - 0.024815  - 0.10053  ]
         [                                                           ]
         [ - 0.10239   0.038447   - 0.024815   0.10936    - 0.034032 ]
         [                                                           ]
         [ 0.031179   - 0.052842  - 0.10053   - 0.034032   0.14834   ]
(%i6) z[2]; /* multiple correlation vector */
(%o6)            [0.85063, 0.80633, 0.86474, 0.71867, 0.72674]
(%i7) z[3]; /* partial correlation matrix */
            [   - 1.0     0.38244   0.36626   0.49908   - 0.13049 ]
            [                                                     ]
            [  0.38244   - 0.99999  0.37927  - 0.19906   0.23492  ]
            [                                                     ]
(%o7)       [  0.36626    0.37927    - 1.0    0.10911    0.37956  ]
            [                                                     ]
            [  0.49908   - 0.19906  0.10911    - 1.0     0.26719  ]
            [                                                     ]
            [ - 0.13049   0.23492   0.37956   0.26719     - 1.0   ]

See also cov and cov1.

principal_components (matrix)
principal_components (matrix, options ...)
Calculates the principal componentes of a multivariate sample. Principal components are used in multivariate statistical analysis to reduce the dimensionality of the sample.

Option: 'data, default 'true, indicates whether the input matrix contains the sample data, in which case the covariance matrix cov1 must be calculated, or not, and then the covariance matrix (symmetric) must be given, instead of the data.

The output of function principal_components is a list with the following results:

  • variances of the principal components,
  • percentage of total variance explained by each principal component,
  • rotation matrix.
(%i8) s2 : read_matrix (file_search ("wind.data"))$

(%i9) fpprintprec:4 $

(%i10) res: principal_components(s2);
(%o10) [[87.56, 8.753, 5.514, 1.888, 1.612],
[83.13, 8.309, 5.235, 1.792, 1.53],
[ 0.4149  0.03378   - 0.4756   - 0.581   - 0.5126 ]
[                                                 ]
[ 0.369   - 0.3656  - 0.4297   0.7237    - 0.1469 ]
[                                                 ]
[ 0.3959  - 0.2178  - 0.2181  - 0.2749    0.8201  ]]
[                                                 ]
[ 0.5547   0.7744    0.1857    0.2318    0.06498  ]
[                                                 ]
[ 0.4765  - 0.4668   0.712    - 0.09604  - 0.1968 ]
(%i11) /* accumulated percentages */
      block([ap: copy(res[2])],
        for k:2 thru length(ap) do ap[k]: ap[k]+ap[k-1],
      ap);
(%o11)                [83.13, 91.44, 96.67, 98.46, 100.0]
(%i12) /* sample dimension */
      p: length(first(res));
(%o12)                                 5
(%i13) /* plot percentages to select number of
      principal components for further work */
      draw2d(
          fill_density = 0.2,
          apply(bars, makelist([k, res[2][k], 1/2], k, p)),
          points_joined = true,
          point_type
          = filled_circle,
          point_size
          = 3,
          points(makelist([k, res[2][k]], k, p)),
          xlabel = "Variances",
          ylabel = "Percentages",
          xtics = setify(makelist([concat("PC",k),k], k, p))) $

232-3

In case de covariance matrix is known, it can be passed to the function, but option data=false must be used.

(%i14) S: matrix([1,-2,0],[-2,5,0],[0,0,2]);
                                [  1   - 2  0 ]
                                [             ]
(%o14)                          [ - 2   5   0 ]
                                [             ]
                                [  0    0   2 ]
(%i15) /* the argumment is a covariance matrix */
res: principal_components(S, data=false);
                                                    [ - 0.3826  0.0  0.9238 ]
                                                    [                       ]
(%o15) [[5.828, 2.0, 0.1715], [72.85, 25.0, 2.144], [  0.9238   0.0  0.3826 ]]
                                                    [                       ]
                                                    [   0.0     1.0   0.0   ]
(%i16) /* transformation to get the principal components from original records */
      matrix([a1,b2,c3],[a2,b2,c2]).last(res);
           [ 0.9238 b2 - 0.3826 a1  1.0 c3  0.3826 b2 + 0.9238 a1 ]
(%o16)     [                                                      ]
           [ 0.9238 b2 - 0.3826 a2  1.0 c2  0.3826 b2 + 0.9238 a2 ]

Posta un commento o usa questo indirizzo per il trackback.

Trackback

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d blogger hanno fatto clic su Mi Piace per questo: