cov4gappy | R Documentation |
This function calculates a covoriance matrix for data that contain missing values ('gappy data').
cov4gappy(F1, F2 = NULL)
F1 |
A data field. |
F2 |
An optional 2nd data field. |
This function gives comparable results to cov(F1, y=F2, use="pairwise.complete.obs")
whereby each covariance value is divided by n number of shared values (as opposed
to n-1 in the case of cov()
. Futhermore, the function will return a 0 (zero) in
cases where no shared values exist between columns; the advantage being that a
covariance matrix will still be calculated in cases of very gappy data, or when
spatial locations have accidentally been included without observations (i.e. land
in fields of aquatic-related parameters).
A matrix with covariances between columns of F1
.
If both F1
and F2
are provided, then the covariances
between columns of F1
and the columns of F2
are returned.
# Create synthetic data set.seed(1) mat <- matrix(rnorm(500, sd=10), nrow=50, ncol=10) matg <- mat matg[sample(length(mat), 0.5*length(mat))] <- NaN # Makes 50% missing values matg # gappy matrix # Calculate covariance matrix and compare to 'cov' function output c1 <- cov4gappy(matg) c2 <- cov(matg, use="pairwise.complete.obs") plot(c1,c2, main="covariance comparison", xlab="cov4gappy", ylab="cov") abline(0,1,col=8)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.