Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sampling Distribution of the Mean in IML

Similar presentations


Presentation on theme: "Sampling Distribution of the Mean in IML"— Presentation transcript:

1 Sampling Distribution of the Mean in IML

2 Complete code for data step version
%let obs = 10; %let reps = 1000; data uniforms; call streaminit(54321); do rep = 1 to &reps; do i = 1 to &obs; x = rand("Uniform"); output; end; run; proc means data=uniforms noprint; by rep; var x; output out=MeansUni mean=Meanx; proc univariate data=meansuni; label meanx = "Sample Mean of U(0,1) Data"; histogram Meanx / normal; ods select Histogram moments;

3 In the IML version, each sample is stored as a row in a matrix and we use the mean function to calculate the sample means. There are no loops Three statements: Randseed, J, and Randgen generate the samples. Randgen can fill an entire matrix with random values.

4 %let obs = 10; %let reps = 1000; proc iml; call randseed(123); x = j(&reps,&obs); /* many samples (rows), each of size N */ call randgen(x, "Uniform"); /* 1. Simulate data */ s = x[,:]; /* 2. Compute statistic for each row */ Mean = mean(s); /* 3. Summarize and analyze ASD */ StdDev = std(s); call qntl(q, s, { }); print Mean StdDev (q`)[colname={"5th Pctl" "95th Pctl"}]; /* compute proportion of statistics greater than 0.7 */ Prob = mean(s > 0.7); print Prob[format=percent7.2]; quit;

5 Create a data set in wide format
%let obs = 10; %let reps = 1000; proc iml; call randseed(123); x = j(&reps,&obs); /* many samples (rows), each of size N */ call randgen(x, "Uniform"); /* 1. Simulate data*/ c="x1":"x&obs"; show c; create unif from x [colname=c]; append from x; close unif; quit; proc contents data=unif; run;

6 Summarize data set in wide format
%let obs=10; data stats (keep=mean std max); set unif; mean=mean(of x1-x10); std=std(of x1-x10); max=max(of x:); run; proc means data=stats; proc univariate data=stats; var mean std max; ods select qqplot; qqplot mean std max;

7 Restructure data into long format using IML

8 %let obs=3; %let reps=5; %let seed=54321; proc iml; reset print; call randseed(54321); x = j(&reps,&obs); call randgen(x, "Uniform"); print x; rep = repeat( T(1:&reps), 1, &obs); rep = shape(rep, 0, 1); z = shape(x, 0, 1); create Long var{rep z}; append; close Long; create Long2 var{rep x}; append; close Long2; quit; proc print data=long(obs=5);run; proc print data=long2(obs=5);run;

9 /**********************/
/* Answer to exercise 4.8*/ proc iml; call randseed(123); x = j(10000, 10); call randgen(x, "Uniform"); * 1. Simulate data; s = x[,<>]; * 2. Compute statistic for each row; Mean = mean(s); * 3. Summarize and analyze ASD; StdDev = std(s); call qntl(q, s, { }); print Mean StdDev (q`)[colname={"5th Pctl" "95th Pctl"}]; create MaxDist var {s}; append; close MaxDist; /*Sampling Normal Means, IML*/ %let N = 31; /* size of each sample */ %let NumSamples = 10000; /* number of samples */ samples=j(&numsamples,&n,.); call randgen(samples,"Normal"); samplemeans=samples[,:]; create means var {samplemean}; append from samplemeans; close means; quit;


Download ppt "Sampling Distribution of the Mean in IML"

Similar presentations


Ads by Google