v <- 1:100
v <- v[v %% 2 != 0]
v
[1] 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63
[33] 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99
v <- v[v > 60]
v <- v[v < 80]
v
[1] 61 63 65 67 69 71 73 75 77 79
variance <- var(v)
variance
[1] 36.66667
2*1:5
[1] 2 4 6 8 10
(2*1):5
[1] 2 3 4 5
The first command is having a scalar be multiplied by a vector, which is 1:5. The second command is a vector with the left value being the product of 2*1, which is 2. The parentheses affected the order of operations.
x <- 2*(1:10)-1
x
[1] 1 3 5 7 9 11 13 15 17 19
y <- c(-1, 2, -3, 4, -5)
z <- y[y > 0]
z
[1] 2 4
qchisq(0.95, 10)
[1] 18.30704
x = rnorm(1000)
summary(x)
Min. 1st Qu. Median Mean 3rd Qu. Max.
-3.54719 -0.71405 -0.08119 -0.02399 0.65335 3.08018
var(x)
[1] 0.993529
The mean is -0.02399 and the variance is 0.993529.
hist(x)
For Stock B: 6% return with prob. 0.7; −8% return with prob. 0.3. Calculate its mean value and sample standard deviation.
s_mean <- 0.06*0.7 + -0.08* 0.3
s_variance <- (0.06**2)*0.7 + ((-0.08)**2)*0.3
s_mean
[1] 0.018
s_std <- sqrt(s_variance)
s_std
[1] 0.06663332
s_mean <- 0.4542*0.7 + -1* 0.3
s_variance <- (0.4542**2)*0.7 + ((-1)**2)*0.3
s_mean
[1] 0.01794
s_std <- sqrt(s_variance)
s_std
[1] 0.6666396
The expected value of a Bernoulli random variable is p. The variance of a Bernoulli random variable is p(1-p).
Cov(4X, 6X + 1000) is the same as Cov(4X, 6X), which is the same as 24*Cov(X, X), which is 24*Var(X), which is 24p*(1-p).
std_x <- sqrt(5)
std_y <- sqrt(10)
corr <- 1 / (std_x * std_y)
corr
[1] 0.1414214
Variance(X + Y) = 5 + 10 + 2*1 = 17
Var(X + Y) = 5 + 10 = 15