开始使用免费开始使用

复现实证自助法(bootstrap)

您在一家网络证券经纪公司工作。公司正在开发一款 Android 应用,用于提供公司所售股票的一般价格区间。已经为您提供了一个自助法函数 boot_price(),用于计算每月的价格区间。

为了在并行环境中测试该函数的可复现性,您决定将此函数应用于列表 ls_micro 的每个元素。该列表的每个元素都是某个月份 Microsoft 股票的平均日收盘价向量。

已为您加载 parallel 包。

本练习是课程的一部分

R 并行编程

查看课程

练习说明

  • 为集群 cl1 设置种子值 321,执行第一次运行。
  • 为集群 cl2 设置相同的种子值,执行第二次运行。
  • 测试输出 result1result2 是否相同。

交互式实操练习

通过完成这段示例代码来试试这个练习。

cl1 <- makeCluster(4)
# Set 321 as the seed value for the first run
___(___, ___)
result1 <- parLapply(cl1, ls_micro, boot_price)
stopCluster(cl1)

cl2 <- makeCluster(4)
# Set the same seed value for the second run
___(___, ___)
result2 <- parLapply(cl2, ls_micro, boot_price)
stopCluster(cl2)

# Test if outputs are the same
___(___, ___)
编辑并运行代码