Markov chain Paper B

Discussion in 'CS2' started by Kanishka, Feb 27, 2021.

Tags:
  1. Kanishka

    Kanishka Active Member

    Can someone please help me understand the solution of bit (iv) of question 2.2 in Markov chain pbor? I am unable to understand the code.
     
  2. Andrew Martin

    Andrew Martin ActEd Tutor Staff Member

    Hello

    Is this in the 2020 version of the questions? Do you mean the function in part (iv)(a)?

    The idea behind the code is to calculate the expected income for each year and add them up. The function takes 4 inputs:
    1. The probability transition matrix
    2. The number of years that we want to calculate the premium income for minus 1
    3. The starting distribution across the states
    4. The percentage of the premium paid by drivers in each state.

    The first line of the function calculates the premium for the first year by first multiplying the starting distribution vector by the vector containing the percentage of the premium paid by drivers in each state. When multiplying vectors together in R in this way, it returns a vector where each element is the product of the corresponding elements from the vectors being multiplied. The sum of the elements in this returned vector is then taken to give the overall average proportion of the full premium paid by all drivers. This sum is then multiplied by the full premium to get the monetary amount of the premium paid in the first year.

    In the loop, for each subsequent year, the function first finds the expected distribution after the relevant number of transitions using the follow.driver function. Then the same calculation as above is performed but using the current expected distribution, rather than the starting distribution. Finally, each time this is done, we add the resulting premium income for that year to the overall running total.

    Finally, the function returns the total calculated.

    Hope this helps

    Andy
     

Share This Page