Learn R Programming

bayesSurv (version 2.6)

sampleCovMat: Compute a sample covariance matrix.

Description

This function computes a sample covariance matrix.

Usage

sampleCovMat(sample)

Arguments

sample
a matrix or data.frame with sampled values in rows. I.e. number of rows of sample determines a sample size, number of columns of sample determines a dimension of the distribution from which it was sampled.

Value

Details

When $y[1], ..., y[n]$ is a sequence of $p$-dimensional vectors $y[i]$ the sample covariance matrix $S$ is equal to $$S = \frac{1}{n-1} \sum_{i=1}^n (y_i - m)(y_i - m)^T$$ where $$m = \frac{1}{n}\sum_{i=1}^n y_i.$$ When $n=1$ the function returns just sum of squares.

Examples

Run this code
  ## Sample some values
  z1 <- rnorm(100, 0, 1)           ## first components of y
  z2 <- rnorm(100, 5, 2)           ## second components of y
  z3 <- rnorm(100, 10, 0.5)        ## third components of y

  ## Put them into a data.frame
  sample <- data.frame(z1, z2, z3)

  ## Compute a sample covariance matrix
  sampleCovMat(sample)

Run the code above in your browser using DataLab