본문 바로가기

Bootstrap estimate of bias 본문

Applied/Statistical Computing

Bootstrap estimate of bias

TaeTrix 2022. 11. 13. 02:12

#Motivation :  small sample로 population parameter를 추정하고 싶다 - bootstrap

 

2. Consider patch data in “patch.csv” file. The data contains measurements of a certain hormone in the bloodstream of eight subjects after wearing a medical patch. The parameter of interest is

 

θ= (E(new)E(old)) / (E(old)  E(placebo))

 

If |θ| ≤ 0.20, this indicates bioequivalence of the old and new patches. The statistic is Y ̄/Z ̄. Compute a bootstrap estimate of bias and three 95% confidence intervals in the bioequivalence ratio statistic.

 

#Directory 설정
getwd()
setwd("/Users/kimtaestu/Downloads")

#data 불러오기
dat <- read.csv("patch.csv", stringsAsFactors = T);dat 
#내가 가진샘플이 8개 밖에 없음 - small sample

theta.hat <- mean(dat$y)/mean(dat$z)
theta.hat

B <- 20000 #replicate
n <- nrow(dat);n #bootsamp
theta.hat_star <- numeric(B) #empty vector

for(b in 1:B){
  i <- sample(1:n, size = n, replace = T) #1부터 n까지 n개 복원해서 뽑겠다
  y_star <- dat$y[i]
  z_star <- dat$z[i]
  theta.hat_star[b] <- mean(y_star)/mean(z_star)
}

bias_hat <- mean(theta.hat_star) - theta.hat
bias_hat

sd(theta.hat_star)
sqrt(sum((mean(theta.hat_star) - theta.hat_star)^2)/(B-1))
Comments