[ScaleR] How to calculate the Variance of a Variable?

• Question

• So, I've read the whole thing on Diving into Data Analysis (https://msdn.microsoft.com/en-us/microsoft-r/data-analysis-in-microsoft-r) and I'm aware of rxGetInfo, rxSummary and rxCovCor.

However, I can't seem to find what I'm looking for, which is how to calculate the variance in a ScaleR manner.

Min/Max/Mean/StdDev/Obs/MissingValues/Covariance/Correlation and so many things are readily available - how do you go about calculating the variance of a variable (in a ScaleR manner)?

• Edited by Sunday, February 12, 2017 12:08 PM
Sunday, February 12, 2017 12:07 PM

• The covariance of a random variable with itself is by definition the variance of that variable. Hopefully the example below can help show how you can get var to match rxCov.

```# https://en.wikipedia.org/wiki/Covariance
#
var(iris\$Petal.Width)
# [1] 0.5810063

rxCov(~ Petal.Width, data=iris)
# Petal.Width   0.5810063

```

• Marked as answer by Wednesday, February 15, 2017 1:10 PM
Monday, February 13, 2017 8:52 PM

All replies

• The covariance of a random variable with itself is by definition the variance of that variable. Hopefully the example below can help show how you can get var to match rxCov.

```# https://en.wikipedia.org/wiki/Covariance
#
var(iris\$Petal.Width)
# [1] 0.5810063

rxCov(~ Petal.Width, data=iris)
# Petal.Width   0.5810063

```

• Marked as answer by Wednesday, February 15, 2017 1:10 PM
Monday, February 13, 2017 8:52 PM
• You're going to want to look at the diagonal of the output matrix if you put more than one variable into this formula, as it produces the covariance matrix.
Wednesday, February 15, 2017 1:08 PM
• So I can just put 1 variable there and it'll calculate the co-variance with itself? That's cool ^^ Didn't realise that.

That's what I'll do.

Thank you both very much.

Wednesday, February 15, 2017 1:13 PM