User:Trettels:Session 23 - 01APR

From Computational Statistics (CSE383M and CS395T)
Jump to navigation Jump to search

Pre-Class

Matlab code for the pre-class activity:

Code

n_data=100;
x_init=betarnd(2.5,5,1,n_data);
nresamp=100000;
out_val=zeros(1,nresamp);
for aa=1:nresamp
    xx=x_init(randsample(n_data,n_data,true));
    [y,x] =hist(xx,100);
    out_val(aa) =  x(find(cumsum(y)/sum(y) >=.75,1)) - x(find(cumsum(y)/sum(y) >=0.25,1));
end
hist(out_val,50);
mu=mean(out_val)
sigma=std(out_val)

n_data=100;
x_init=betarnd(2.5,5,1,n_data);
nresamp=100000;
out_val=zeros(1,nresamp);
for aa=1:nresamp
    xx=betarnd(3,2,1,n_data);
    [y,x] =hist(xx,100);
    out_val(aa) =x(find(cumsum(y)/sum(y) >=.75,1)) - x(find(cumsum(y)/sum(y) >=0.25,1));
end
figure
hist(out_val,50);
mu=mean(out_val)
sigma=std(out_val)

act_val = betainv(0.75,2.5,5) - betainv(0.25,2.5,5)

Output

For the bootstrap estimation: Histogram

mu =

   0.210450100797775


sigma =

   0.028586856472617

and for the resampled estimate: Histogram

mu =

   0.299897695902584


sigma =

   0.033799773359941

The actual value is:


act_val =

   0.232952354263591


In Class

Done with Dan

Matlab Code

n_data=100;
x_init=betarnd(3,2,1,n_data);
nresamp=100000;
out_val=zeros(1,nresamp);
xrng=linspace(0,1,1000);
for aa=1:nresamp
    xx=x_init(randsample(n_data,n_data,true));
    out_val(aa) =  sum(exp(-1.*xrng).*(hist(xx,xrng)/sum(hist(xx,xrng)))); 
end
S=sum(exp(-1.*xrng).*hist(x_init,xrng)/sum(hist(x_init,xrng)))
hist(out_val,50);
mu=mean(out_val)
sigma=std(out_val)

n_data=100;
x_init=betarnd(3,2,1,n_data);
S=sum(exp(-1.*xrng).*hist(x_init,xrng)/sum(hist(x_init,xrng)))
nresamp=100000;
out_val=zeros(1,nresamp);
for aa=1:nresamp
    xx=betarnd(3,2,1,n_data);
    out_val(aa) = sum(exp(-1*xrng).*(hist(xx,xrng)/sum(hist(xx,xrng))));
end
figure
hist(out_val,50);
mu=mean(out_val)
sigma=std(out_val)

Results

For the bootstrap estimation: Histogram

mu =

   0.558731122219118


sigma =

   0.0110396392531490

and for the resampled estimate: Histogram

mu =

   0.560064580617217


sigma =

   0.011525181525111

Back to TrettelS Index