Question: http://www.actuariesindia.org/downloads/exampapers/november2019/Q_CS2B.pdf Solution: http://www.actuariesindia.org/downloads/exampapers/november2019/CS2 - Paper B.pdf Can someone pls explain me the solution given? especially.. i) Why the random number generated is multiplied by 2? ii) Why n=11, 101 and 1001 used instead of 10, 100 and 1000 as given in the question? iii) Why subtract 1? iv) Why use filter function to create equation yt?
Code: rbinom(n, 1, .5) will generate numbers 0 or 1. However, as per the question we need the random numbers to be -1 or 1. Hence, multiplying the 0 or 1 observation generated by 2 and then subtracted by 1 gives us the required sample. y_t depends on x_t and x_(t-1). So to generate y_1 we need x_1 and x_0; y_2 we need x_2 and x_1 and so on... Thus to generate 10 samples of y_t, we need x_0, x_1,..., x_10 and hence 11 observations. This logic should generalize to the case when n = 100 and n = 1000. See response to (i) above. Personally, I have never used the filter function from the stats package. So, not entirely sure of how this works. Although, you can go over the help documentation here: https://stat.ethz.ch/R-manual/R-devel/library/stats/html/filter.html However, in the present case, I think using the lag function from dplyr should also solve you needs: https://dplyr.tidyverse.org/reference/lead-lag.html