how to implement the jaccknife method if two terms are removed (in R)

Asked

Viewed 44 times

2

I created the following code to calculate the variance using the jackknife method. However, instead of taking one term at a time, I now need to take it out two by two. I know it’s something basic, but I couldn’t think of a way to do it, someone could give me some idea?

A<- numeric(1000)


var1<- numeric(1000)

x<- data.frame(numeric(9))

amostra<- rnorm(10,100,10) #gerando amostra

for(i in 1:10){

x[i]<-c(amostra[-i]) #tirando um termo da amostra

}

var2<- numeric(10) #calculando as variancias dos vetores n-1

for(i in 1:10){

  var2[i]<- var(x[,i])
}

Tn<- sum(var2) #soma das variancias de 3 termos

var1[j] <- var(amostra)# variancia da amstra de tamanho n


A[j]<-10*var1[j]-((9/10)*Tn) #  variancia Jackknife

2 answers

0


I’ll help you find var2 and Tn. From then on I didn’t understand what you did.

#Todas as combinações de índices de 10 elementos tomados 8 a 8.
idx <- t(combn(10, 8))
#Todas as sub-amostras de 8 elementos
x <- apply(idx, 2, function(x){amostra[x]})
#Variancia de cada sub-amostra
var2 <- apply(x, 1, var)
# soma das variancias
Tn <- sum(var2)

Check it all out, because it wasn’t clear to me what the content of x.

  • It helped a lot, from there I can develop the rest! Thank you!

0

I tried the following:

As you want to remove two by two, the dataframe should have 8 lines, otherwise the reallocation of the data will be incompatible, as it is taking 2 values at a time:

x<- data.frame(numeric(8))

amostra<- rnorm(10,100,10) #gerando amostra

amostra

[1] 108.27618  99.33371 122.50547 105.59071  89.95836 108.99908 101.51803  96.98692 100.51190 102.91556

for(i in 1:8){
  x[i]<- c(amostra[-c(i,i+1)]) # retira dois termos por iteração
}

x

numeric.8.        V2        V3        V4        V5        V6        V7        V8
1  122.50547 108.27618 108.27618 108.27618 108.27618 108.27618 108.27618 108.27618
2  105.59071 105.59071  99.33371  99.33371  99.33371  99.33371  99.33371  99.33371
3   89.95836  89.95836  89.95836 122.50547 122.50547 122.50547 122.50547 122.50547
4  108.99908 108.99908 108.99908 108.99908 105.59071 105.59071 105.59071 105.59071
5  101.51803 101.51803 101.51803 101.51803 101.51803  89.95836  89.95836  89.95836
6   96.98692  96.98692  96.98692  96.98692  96.98692  96.98692 108.99908 108.99908
7  100.51190 100.51190 100.51190 100.51190 100.51190 100.51190 100.51190 101.51803
8  102.91556 102.91556 102.91556 102.91556 102.91556 102.91556 102.91556 102.91556

Browser other questions tagged

You are not signed in. Login or sign up in order to post.