Reputation: 51
I have to implement this summation in R:
I have tried to implement the first exponential in the following way:
f <- rep(0,48)
for(i in 1:48) {
f[i] <- exp(-sum(lambda[which(lambda<lambda[i])])-(i-1))}
where 48 is the length of lambda. I think this expression looks ok, but my problem now is..How can I add the second summation? I don't have any idea because of the double indeces. Do you have any suggestion? Thank you.
Upvotes: 1
Views: 705
Reputation: 4002
I am not sure about a few parenthesis in your formula, but something like that should do the trick:
exp(-sum(lambda[20:j]) + (j-20)) * sum(unlist(lapply(20:j, function(i) lambda[i] * exp(sum(lambda[20:i]) + i-20) )))
In R, it is easier to use vectorisation than loop.
Upvotes: 1