Kod 6.1. Test permutacyjny dla porównania średnich zmian
t=1:10
y1=c(20,25,32,36,42,48,53,60,68,64)
y2=c(30,33,35,38,41,43,46,49,52,55)
i1=y1[-1]/y1[-10];i2=y2[-1]/y2[-10]
i12=c(i1,i2)
id=c(rep(0,9),rep(1,9))
T0=prod(i1)-prod(i2)
N=1000
T=c()
for (i in 1:N)
{
ids=sample(id)
i1s= ids*i12; i2s=(1-ids)*i12
T=c(T,prod(i1s[i1s>0])-prod(i2s[i2s>0]))
}
sum(T>=T0)/N