stcov {classicaltest}R Documentation

Population and sample (co)variance

Description

Estimates the weighted and unweighted population and sample covariance for a vector, a matrix or a data frame. Missing values are omitted.

Usage

stcov(x, wt = NULL, sample = TRUE)

Arguments

x

a numeric vector, matrix or data frame.

wt

a vector with total weights. Default is NULL.

sample

a logical value indicating if the sample variance should be used. Default is TRUE. If TRUE, the unbiased estimate (n-1) is used; if FALSE, the maximum likelihood estimate is used.

Value

a numeric value or a numeric matrix.

Examples


# Variance ----

## Sample variance with no weights
stcov(x = iris$Sepal.Length, sample = TRUE)

## Population variance with no weights
stcov(x = iris$Sepal.Length, sample = TRUE)

## Sample variance with no weights
wt = c(100, rep(1,nrow(iris)-1)) # Unbalanced weights
stcov(x = iris$Sepal.Length, sample = FALSE, wt = wt)

## Population variance with no weights
wt = c(100, rep(1,nrow(iris)-1)) # Unbalanced weights
stcov(x = iris$Sepal.Length, sample = FALSE)


# Covariance ----

## Sample covariance with no weights
stcov(x = iris[,1:4], sample = TRUE)

## Population covariance with no weights
stcov(x = iris[,1:4], sample = TRUE)

## Sample covariance with no weights
wt = c(100, rep(1,nrow(iris)-1)) # Unbalanced weights
stcov(x = iris[,1:4], sample = FALSE, wt = wt)

## Population covariance with no weights
wt = c(100, rep(1,nrow(iris)-1)) # Unbalanced weights
stcov(x = iris[,1:4], sample = FALSE)




[Package classicaltest version 0.7.5 Index]