【发布时间】:2019-07-14 15:28:02
【问题描述】:
我有一个包含不同 20 个样本 ID 的数据表。现在我想用固定的 ID 分布随机减少样本量,这意味着我想随机抽取 7 个值来自 'A' 和 5 个值来自 'B' 所以我的 data.table 有 12 行而不是20,而不是建立我生成的列的平均值。现在我想通过引导重复 100 次,看看平均值是否不同,所以我想做一些统计数据,比如 sd、mean 等。
背景是我有一个小样本集和一个更大的样本集。我想减少较大的样本集以评估较小样本集的准确性。我对 R 相当陌生,并感谢任何帮助。谢谢
data <- data.table(Sample = c('A','A','A','A','A','A','A','A','A','A','A','B','B','B','B','B','B','B','B','B','B','B'),
weight=rnorm(1:22),
height=rnorm(1:22))
# I want to draw randomly 7 values out of A and 5 values out of B and than get the mean of this new df and do that whole step 100 times
#to again build the mean over all 100 replicates
set.seed(4561)
new_df <- data %>%
group_by(Sample) %>%
nest() %>%
mutate(n = c(7,5)) %>%
mutate(samp = map2(data, n, sample_n)) %>%
select(Sample, samp) %>%
unnest() %>%
mutate(diff.height.weight = height-weight) %>%
mutate(means = mean(diff.height.weight))%>%
bootstraps(means, times=100)
【问题讨论】:
标签: r random statistics-bootstrap