나는 각각 100 개의 행을 갖는 n 개의 변수가 있습니다. 1에서 nrows로 다시 샘플링하려면 다음 코드를 사용하여 예상 결과를 얻지 만, 지루하고 비실용적입니다.R : 루프를 사용하여 1에서 n을 리샘플링 (y)
y<-rnorm(n=5, mean=10, sd=2)
R=1000 #number of resamplings
boot.means = numeric(R)
for (i in 1:R) { boot.sample = sample(y, 1, replace=T)
boot.means[i] = mean(boot.sample) }
m1<-mean(boot.means)
d1<-sd(boot.means)
cv1 =(d1*100)/m1
R=1000 #number of resamplings
boot.means = numeric(R)
for (i in 1:R) { boot.sample = sample(y, 2, replace=T)
boot.means[i] = mean(boot.sample) }
m2<-mean(boot.means)
d2<-sd(boot.means)
cv2 =(d2*100)/m2
R=1000 #number of resamplings
boot.means = numeric(R)
for (i in 1:R) { boot.sample = sample(y, 3, replace=T)
boot.means[i] = mean(boot.sample) }
m3<-mean(boot.means)
d3<-sd(boot.means)
cv3 =(d3*100)/m3
R=1000 #number of resamplings
boot.means = numeric(R)
for (i in 1:R) { boot.sample = sample(y, 4, replace=T)
boot.means[i] = mean(boot.sample) }
m4<-mean(boot.means)
d4<-sd(boot.means)
cv4 =(d4*100)/m4
R=1000 #number of resamplings
boot.means = numeric(R)
for (i in 1:R) { boot.sample = sample(y, 5, replace=T)
boot.means[i] = mean(boot.sample) }
m5<-mean(boot.means)
d5<-sd(boot.means)
cv5 =(d5*100)/m5
CV.OK<-(c(cv1,cv2,cv3,cv4,cv5))
plot(CV.OK)
나는 다음과 같은 코드를 사용하고자하는
하지만주는 예상치 못한 결과 : 상황을 재현하려면 y는 5 개 행이 suposse을 할 수 있습니다. 제발, 누군가 도울 수있어. 감사.
R = 1000 #number of resamplings
boot.sample=seq(1,5, by=1)
boot.means = numeric(R)
boot.sd = numeric(R)
m = 5
d = 5
for (i in 1:5) {
for (j in 1:R) {
boot.sample[i] = sample(y, i, replace=T)
boot.means[j] = mean(boot.sample[i])
boot.sd[j] = sd(boot.sample[i])
m[i]=mean(boot.means[j])
d[i]=mean(boot.sd[j])
}
}
CV.Fail<-(d*100)/m
네, 예상대로 작동합니다. 하지만 남아있는 질문은 부트 스트랩 횟수를 지정해야합니다. 즉, 'sample_vect'변수를 통해 지정해야하는 1000. –
입니다. 따라서'sample_vect = c (1 : 100)'로 간다면 결국에는 최대 100 개의 샘플을 취하여 요약 통계를 계산하게됩니다. – sluedtke