• We are pleased to announce that the winner of our Feedback Prize Draw for the Winter 2024-25 session and winning £150 of gift vouchers is Zhao Liang Tay. Congratulations to Zhao Liang. If you fancy winning £150 worth of gift vouchers (from a major UK store) for the Summer 2025 exam sitting for just a few minutes of your time throughout the session, please see our website at https://www.acted.co.uk/further-info.html?pat=feedback#feedback-prize for more information on how you can make sure your name is included in the draw at the end of the session.
  • Please be advised that the SP1, SP5 and SP7 X1 deadline is the 14th July and not the 17th June as first stated. Please accept out apologies for any confusion caused.

Simulations (Risk models 2)

B

Brett Kim

Member
This question is in regard to Chapter 20: Risk models 2, section 3.3, example question (ii), page 25.
I understand what the R code is trying to do, but for some reason, when I create a vector of length 10,000 for lambda outside of the for-loop I get a slightly different mean and standard deviation to what is produced if I create a single lambda every time in the first for-loop.
To demonstrate what I mean, if I do:
Code:
set.seed(123)
sims = 10000
policy = 100
R = matrix(0, nrow = sims, ncol = policy)
lambda = sample(c(0.1, 0.3), sims, prob = c(0.5, 0.5), replace = T)
for(i in 1:sims){
  N = rpois(policy, lambda[i])
  S = numeric(policy)
  for(j in 1:policy){
    S[j] = sum(rgamma(N[j], 750, 0.25))
  }
  R[i,] = S
}
mean(rowSums(R)); sd(rowSums(R))
The result I get for the sample mean and standard deviation are 60189.14 and 32835.25 respectively.
I'm guessing it's probably because the 10,000 lambda values that get created in one go produces a slightly different result to creating a single lambda value 10,000 times.
But would such an answer in an exam setting be considered incorrect?
 
Hi Brett

You are correct that the reason for the different results is that you have produced the simulated values in a different way. Specifically, if you want to recreate a result exactly, not only must you specify the seed, but you also have to call the randomly generated numbers in exactly the same order. What you have done is changed the ordering.

Your solution is valid, and would be worth full marks in the exam. However, in most cases for compound distribution questions this won't be a problem. It's only because we have a randomly simulated lambda that the two possibilities emerge here.

Dave
 
Back
Top