# EXAMPLE 4 (d) - MODULE 3 ########################################################### n = 20 # number of chips k = 5 # number of drawn chips y = seq(k,n,1);print(y) r = length(y);print(r) F = choose(y,k)/choose(n,k);print(F) F = round(F,4);print(F) f = rep(0,r);print(f) f[1] = F[1] # This is the probability that Y=5 f[2:r] = F[2:r] -F[1:r-1] print(f) cbind(y,f,F) mu = sum(y*f); print(mu) # to calculate mu = E(Y) mu2 = sum(y^2*f); print(mu2) # to calculate mu2 = E(Y^2) s2 =mu2 - mu^2; print(s2) # to calculate Var(Y) = mu2 - mu^2 s =sqrt(s2); print(s) # to calculate SD(Y) = (mu2 - mu^2)^1/2 print(paste('mean = ',round(mu,3)),quote = FALSE) print(paste('Variance = ',round(s2,3)),quote = FALSE) print(paste('SD = ',round(s,3)),quote = FALSE)