I have 2 random variables, all independant, discrete and uniform
I want to compute standard deviation for Z = X - Y
Here is the R code:
#create X and Y
X = rep(0:1, c(733-41,41))
Y = rep(0:1, c(742-60,60))
#create Z as Y - X
Z = c()
for (i in X) {Z = c(Z,c(Y-i))}
Means are equal:
mean(Z)
[1] 0.02492802
mean(Y) - mean(X)
[1] 0.02492802
Then I count standard deviation and variance of Z using the formula:
sd(Y) + sd(X)
[1] 0.5027599
var(Y) + var(X)
[1] 0.1273021
Ann then, using sd() and var() functions:
sd(Z)
[1] 0.3565528
var(Z)
[1] 0.1271299
Where is my mistake and why sd(Y) + sd(X) != sd(Z) and var(Z) != var(Y) + var(X)?
Thanks!