IAI CS2B Nov 2019 Q8

Discussion in 'CS2' started by Srijana Raghunath, Mar 3, 2020.

  1. KaustavSen

    KaustavSen Member

    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
     
  2. Thank you very much for a prompt and elaborate reply.
     
    KaustavSen likes this.

Share This Page