简体   繁体   English

重复重采样功能1000次?使用lapply?

[英]Repeat the re-sampling function for 1000 times ? Using lapply?

Please me out! 请我出去! I appreciate any helps ! 我感谢任何帮助! Thanks! 谢谢!

I have trouble on repeat doing re-sampling for 1000 times. 重复进行1000次重复采样我遇到了麻烦。 I tried using replicate() to do that but it's not working. 我尝试使用replicate()来做到这一点,但它不起作用。 Is there any other method to do that? 有没有其他方法可以做到这一点? Can anyone show me if this maybe done by using lapply? 任何人都可以告诉我,如果这可能通过使用lapply完成? Following is my code: 以下是我的代码:

#sampling 1000 betas0 & 1 (coefficients) from the data
get.beta=function(data,indices){ 
  data=data[indices,] #let boot to select sample
  lm.out=lm(y ~ x,data=data)
  return(lm.out$coefficients)
}
n=nrow(data)
get.beta(data,1:n)

bootcoe=boot(data,get.beta,R=1000) #generate 1000 random samples
head(bootcoe$t) #look at the betas

From the above code I can get 1000 betas0 & 1 by random sampling the data. 从上面的代码我可以通过随机抽样数据得到1000 betas0&1。 And I would like to do that 1000 times to get different betas. 我想做1000次以获得不同的测试版。 How should I do that besides replicate()? 除了replicate()之外我该怎么做呢?

This is more of an extended comment where I demonstrate that replicate should work. 这更像是一个扩展注释,我证明replicate应该有效。 Here's an example of a CLT. 这是CLT的一个例子。 Just replace your lines what's between the curly braces. 只需更换花括号之间的线条即可。

x <- replicate(1000, {
  mm <- runif(10)
  mean(mm)
  })
hist(x)

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM