-1

I'm trying to calculate the covariance of a matrix which has two colinear vectors. I have read that it was impossible with the "cov" function from R.

Does a different function exist on R to calculate the covariance of a matrix which has two colinear vectors (since it works on Matlab and Excel).

Thank you in advance for your answers

4

1 回答 1

2

请考虑提供一个可重现的示例,其中包含您的数据样本和相应的代码。从广义上讲,可以使用以下代码创建协方差矩阵:

# Vectors
V1 <- c(1:4)
V2 <- c(4:8)
V3 <- runif(n = 4)
V4 <- runif(n = 4)

#create matrix
M <- cbind(V1,V2, V3, V4)

# Covariance
cov(M)

我猜你可能会收到以下错误:

number of rows of result is not a multiple of vector length (arg 1)

您可以先尝试使用此处cov讨论的功能。

于 2015-11-23T11:17:07.523 回答