0

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?

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
  • 2
    Please provide a subsample of the data using `dput(yourdata)`. That increases the chance of getting help significantly – MKR Apr 07 '20 at 11:23

2 Answers2

1

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.

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
0

You may want to have a look at the purrr package and the family of map functions, or tidyr and the hoist funtion.

(If you want code that works, you indeed need to provide some data!)

Arthur
  • 1,208
  • 13
  • 25