clear all
clc
% load 'LawSchoolData.m';

X = [622 3.23;
    542 2.83;
    579 3.24;
    653 3.12;
    606 3.09;
    576 3.39;
    620 3.10;
    615 3.40;
    553 2.97;
    607 2.91;
    558 3.11;
    596 3.24;
    635 3.30;
    581 3.22;
    661 3.43;
    547 2.91;
    599 3.23;
    646 3.47;
    622 3.15;
    611 3.33;
    546 2.99;
    614 3.19;
    628 3.03;
    575 3.01;
    662 3.39;
    627 3.41;
    608 3.04;
    632 3.29;
    587 3.16;
    581 3.17;
    605 3.13;
    704 3.36;
    477 2.57;
    591 3.02;
    578 3.03;
    572 2.88;
    615 3.37;
    606 3.20;
    603 3.23;
    535 2.98;
    595 3.11;
    575 2.92;
    573 2.85;
    644 3.38;
    545 2.76;
    645 3.27;
    651 3.36;
    562 3.19;
    609 3.17;
    555 3.00;
    586 3.11;
    580 3.07;
    594 2.96;
    594 3.05;
    560 2.93;
    641 3.28;
    512 3.01;
    631 3.21;
    597 3.32;
    621 3.24;
    617 3.03;
    637 3.33;
    572 3.08;
    610 3.13;
    562 3.01;
    635 3.30;
    614 3.15;
    546 2.82;
    598 3.20;
    666 3.44;
    570 3.01;
    570 2.92;
    605 3.45;
    565 3.15;
    686 3.50;
    608 3.16;
    595 3.19;
    590 3.15;
    558 2.81;
    611 3.16;
    564 3.03;
    575 2.74];




[m,n] = size(X);

n1=15;
num = ceil(rand*5);

for i=num:num:n1*num;
	x1(ceil(i/num),:) = X(i,:);
end;
% part a
mean_x = mean(x1(:,1))
mean_y = mean(x1(:,2))

rou = corr(x1(:,1),x1(:,2))

sd_x = std(x1(:,1));
sd_y = std(x1(:,2));



% part and c

B= [25 50 100 500 1000 2000 5000];
m=size(B);
for i=1:m;
	for j=1:B(i);
		u1 = randint(1,n1,[1,n1]);	
		for k=1:n1;
			x2(k,:) = x1(u1(k),:);
        end;
		sd_m1x(j)=std(x2(:,1));
		sd_m1y(j)=std(x2(:,2));
		rou_m1(j)=corr(x2(:,1),x2(:,2));
    end;
	sd_m2_x=mean(sd_m1x);
	sd_m2_y=mean(sd_m1y);
	rou_m2=mean(rou_m1);

	for j2=1:B(i);
		u2 = randint(1,n1,[1,n1]);	
		for k2=1:n1;
			x3(k2,:) = x1(u2(k2),:);
        end;
		sd_m2x(j2)=std(x3(:,1));
		sd_m2y(j2)=std(x3(:,2));
		rou_m2(j2)=corr(x3(:,1),x3(:,2));
			
    end;
    sd_m2x(end)
    sd_m2y(end)

if B(i)==2000
figure(1)
hist(rou_m1);
title('Bootstrap Method for B=2000');

figure(2)
hist(rou_m2);
title('Random Sample for B=2000');
end;
end;