Obtenha IC via bootstrap para a média e para a mediana com os dados dos exercícios 1 e 2

Exercício 1

od<-c(1.2, 1.4, 1.4, 1.3, 1.2, 1.35, 1.4, 2.0, 1.95, 1.1, 1.75, 1.05, 1.05, 1.4)
xbar= c()
for (i in 1:1999) {
  amostras = sample(od, size = length(od), replace = TRUE) 
  xbar[i] = mean(amostras)
  }
hist(xbar)

quantile (xbar, c(.050, .950))
##       5%      95% 
## 1.271429 1.525000

IC Para Média do Bootstrap

library(boot)
# Dados Exercício 1
od = c(1.2, 1.4, 1.4, 1.3, 1.2, 1.35, 1.4, 2.0, 1.95, 1.1, 1.75, 1.05, 1.05, 1.4)
mean(od)
## [1] 1.396429
# IC Média Exercício 01
fmedia = function(od, i) {mean(od[i])}
boot.res1 = boot(data = od, statistic = fmedia, R = 1999)
boot.ci(boot.res1, conf = 0.95, type = c("all"))
## Warning in boot.ci(boot.res1, conf = 0.95, type = c("all")): bootstrap
## variances needed for studentized intervals
## BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
## Based on 1999 bootstrap replicates
## 
## CALL : 
## boot.ci(boot.out = boot.res1, conf = 0.95, type = c("all"))
## 
## Intervals : 
## Level      Normal              Basic         
## 95%   ( 1.242,  1.554 )   ( 1.232,  1.539 )  
## 
## Level     Percentile            BCa          
## 95%   ( 1.254,  1.561 )   ( 1.261,  1.586 )  
## Calculations and Intervals on Original Scale

Exercício 2

library(boot)
#Dados Exercicio 2

cod<-c(57, 60, 49, 50, 51, 60, 49, 53, 49, 56, 64, 60, 49, 52, 69, 40, 44, 38, 53, 66)
xbar= c()
for (i in 1:1999) {
  amostras = sample(cod, size = length(od), replace = TRUE) 
  xbar[i] = mean(amostras)
  }
hist(xbar)

quantile (xbar, c(.050, .950))
##       5%      95% 
## 49.92857 57.00714
library(boot)
# Dados Exercício 1
cod = c(57, 60, 49, 50, 51, 60, 49, 53, 49, 56, 64, 60, 49, 52, 69, 40, 44, 38, 53, 66)
mean(cod)
## [1] 53.45
# IC Média Exercício 01
fmedia = function(cod, i) {mean(cod[i])}
boot.res1 = boot(data = cod, statistic = fmedia, R = 1999)
boot.ci(boot.res1, conf = 0.95, type = c("all"))
## Warning in boot.ci(boot.res1, conf = 0.95, type = c("all")): bootstrap
## variances needed for studentized intervals
## BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
## Based on 1999 bootstrap replicates
## 
## CALL : 
## boot.ci(boot.out = boot.res1, conf = 0.95, type = c("all"))
## 
## Intervals : 
## Level      Normal              Basic         
## 95%   (49.96, 56.91 )   (50.05, 56.95 )  
## 
## Level     Percentile            BCa          
## 95%   (49.95, 56.85 )   (49.98, 56.85 )  
## Calculations and Intervals on Original Scale