Primary exercises

Extra exercises

  1. Correlated vectors.
    Let’s define a parameter size <- 12. Later this will be the number of rows of the matrix.
    From normal distribution let’s create a random vector x <- rnorm( size ).
    Now let’s create another vector x1 by adding (on average 10 times smaller) noise to x: x1 <- x + rnorm( size )/10.
    Correlation coefficient of x and x1 should be close to 1.0: check this with function cor.
    Finally, create similarly vectors x2 and x3 by adding (other) noise to x.

  2. Matrix from vectors; matrix heatmap.
    Let’s merge x1, x2 and x3 column-wise into a matrix using m <- cbind( x1, x2, x3 ).
    Check class of m.
    Show the first few rows of m.
    Try a simple heatmap visualisation of the matrix: heatmap( m, Colv = NA, Rowv = NA, scale = "none" ).
    Which colors correspond to lowest/highest matrix values?
    Do the vectos appear correlated?

  3. Matrix of correlated and uncorrelated vectors.
    Repeat the first exercise and create several additional correlated vectors y1y4 (but not correlated with x), of the same length size.
    Now build again m from columns x1x3,y1y4 in some random order.
    Show again the heatmap; you should see similarity between some columns.

  4. Matrix of correlations.
    Use cc <- cor( m ) to build the matrix of correlation coefficients between columns of m.
    Use round( cc, 3 ) to show this matrix with 3 digits precision.
    Can you interpret the values?



Copyright © 2023 Biomedical Data Sciences (BDS) | LUMC