I'm working on a genetics problem where I have 20 genes which each have two alleles. This results in 40 values that can be 1 or 0.
For this distribution I get an expected value of 20 (np) and a variance of 10 (np(1-p)) because n=40 and p=0.5 (see here).
But I weight the contribution of each of these genes. The weights are calculated as follows:
res <- optimize(function(lambda) (sum(exp(-lambda * (1:20))) -5)^2, 0:1, tol = .Machine$double.eps)
res
x <- c(1:20)
lambda <- res$minimum
y<-exp(-lambda*x)
Note that because each of the genes has 2 alleles, each weight is used twice.
gene1.1 * weight1 + gene1.2 * weight 1 + gene2.1 * weight2 + gene2.2 * weight2...
I want to calculate the expected value and variance of this new distribution but I'm not sure how to do this in R. Indeed I don't know the mathematical form of this at all.
Hope you can help