在R中访问列表中的双元素的问题 [英] Problems with accessing double elements in a list in R
问题描述
我使用李·卡特模型的2000个重采样进行了自举,以进行死亡率预测。
这个问题并非专门针对死亡率研究,而是在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.
执行引导程序后,我得到了一个包含2000个元素的列表,每个元素对应于2000个元素-模型的估计。对于每个模型,我的3个变量都有一个估计值:a_x,b_x和k_t。
a_x和b_x都是特定年龄的,因此 x表示表示在[0:95]间隔内的年龄。
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].
我现在想绘制x = 70的所有b_x值的直方图。
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]]
我尝试了多种选择,但无法使其正常工作。
触发我的是,我正在列表的列表中使用double。
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:
有人对此有解决方案吗?
Does anybody have a solution to this?
推荐答案
您似乎需要 apply
函数族。您的数据不可重现,因此无法确认是否可以,但是如果您这样做:
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.
这篇关于在R中访问列表中的双元素的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!