问题描述
请我出去!我感谢任何帮助!谢谢!
Please me out! I appreciate any helps ! Thanks!
我在重复进行1000次重复采样时遇到麻烦.我尝试使用copy()来做到这一点,但是它不起作用.还有其他方法可以做到吗?有人可以告诉我是否可以通过使用lapply来做到这一点? 以下是我的代码:
I have trouble on repeat doing re-sampling for 1000 times.I tried using replicate() to do that but it's not working. Is there any other method to do that? Can anyone show me if this maybe done by using 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
从上面的代码中,我可以获得1000 betas0& 1通过随机采样数据.我想这样做1000次以获得不同的Beta.除了plicate(),我该怎么办?
From the above code I can get 1000 betas0 & 1 by random sampling the data. And I would like to do that 1000 times to get different betas. How should I do that besides replicate()?
推荐答案
这是扩展注释,在此我证明replicate
应该可以工作.这是CLT的示例.只需替换花括号之间的行即可.
This is more of an extended comment where I demonstrate that replicate
should work. Here's an example of a CLT. Just replace your lines what's between the curly braces.
x <- replicate(1000, {
mm <- runif(10)
mean(mm)
})
hist(x)
这篇关于重复重新采样功能1000次?使用lapply?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!