Search code examples
rdimensionsstatistics-bootstrap

Problems with accessing double elements in a list in R


I have performed a bootstrapping with 2.000 resamples of the Lee Carter model for mortality projection. The question is not specific for mortality studies, but on more general dimensions in R.

After performing the bootstrapping I get a list with 2000 elements, each for every of 2.000 re-estimations of the model. For each model, there are estimates of my 3 variables: a_x, b_x and k_t. Both a_x and b_x are age-specific, so the "x" denotes an age in the interval [0:95].

I would now like to plot a histogram of all the b_x values for age x = 70.

### Performing the bootstrap:
JA_lc_fitM_boot1 <- bootstrap(LCfit_JA_M, nBoot = 2000, type = "semiparametric")

### Plotting the histogram with all b_x for x = 70:
JA_lc_fitM_boot1[["bootParameters"]][1:2000][["bx"]][[70]]

I have tried multiple options, but I cannot make it work. The thing that triggers me, is that I am working with a double within a list of a list.

I have added a picture of the data below:

enter image description here

Does anybody have a solution to this?


Solution

  • It looks like you need the apply family of functions. Your data is not reproducible, so I can't confirm this will work, but if you do:

    result <- sapply(JA_lc_fitM_boot1[["bootParameters"]], function(var) var[["bx"]][[70]])
    

    You should get what you're looking for.