1

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

Julius Vainora
  • 47,421
  • 9
  • 90
  • 102
adkane
  • 1,429
  • 14
  • 29
  • Which package is function `expo` from? – Jonny Phelps Dec 06 '18 at 11:47
  • that was a typo, I've fixed it now. I'm just using the exponential function – adkane Dec 06 '18 at 11:50
  • If it's just the calculations for weighted mean & sd, then this may be enough? https://stackoverflow.com/questions/10049402/calculating-weighted-mean-and-standard-deviation. If its the methodology behind weighting families of distributions, then try moving the question to https://stats.stackexchange.com/ maybe – Jonny Phelps Dec 06 '18 at 11:51

1 Answers1

1

Given n Bernoulli random variables X1, ..., X20 with the same parameter p and weights w1, ..., w20, the expectation of their sum is

E[sumin wiXi] = p sumin wi

and the variance is

Var[sumin wiXi] = sumin wi2Var[Xi] = p(1-p) sumin wi2

This gives

p <- 0.5
n <- 20

# No weights
2 * n * p # Mean
# [1] 20
2 * n * p * (1 - p) # Variance
# [1] 10

# Weights
2 * sum(y) * p # Mean
# [1] 5
2 * p * (1 - p) * sum(y^2) # Variance
# [1] 1.172048

# Unweighted case again
y <- rep(1, n)
2 * sum(y) * p # Mean
# [1] 20
2 * p * (1 - p) * sum(y^2) # Variance
# [1] 10
Julius Vainora
  • 47,421
  • 9
  • 90
  • 102