1 / 5

Sampling With Replacement

Sampling With Replacement. How the program works a54p10.sas. The Simulation part of SRSWR N=3, n=2. %LET total=6; *Total number of elements in population; %LET tsamp=3; *Total number of elements in the sample;

colt-reid
Download Presentation

Sampling With Replacement

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Sampling With Replacement How the program works a54p10.sas

  2. The Simulation part of SRSWRN=3, n=2 • %LET total=6; *Total number of elements in population; • %LET tsamp=3; *Total number of elements in the sample; • %LET nsamp=40; *Number of samples to Select ; DATA d (KEEP=sample sid1-sid3 s1-s3 ); SET pop1; ARRAY x{&total} ; *Original values; ARRAY id{&total}; *Original ids; ARRAY s{&tsamp}; *Sample; ARRAY sid{&tsamp}; DO sample=1 to &nsamp; DO j=1 TO &tsamp; *Randomly select permutations; rn=INT(&total*RANUNI(54231))+1; s{j}=x{rn}; sid{j}=rn; END; OUTPUT; END; RUN;

  3. The Simulation part of SRSWRN=3, n=2 (without macro vars) DATA d (KEEP=sample sid1-sid3 s1-s3 ); SET pop1; ARRAY x{6} ; *Original values of response; ARRAY id{6}; *Original subject ids; ARRAY s{2}; *Sample values; ARRAY sid{2}; *Sample subject ids; DO sample=1 to 40; * Number of samples to select; DO j=1 TO 2; * Randomly select a subject; rn=INT(6*RANUNI(54231))+1; s{j}=x{rn}; sid{j}=rn; END; OUTPUT; END; RUN;

  4. Uniform random number generator • RANUNI(54231) • A function in SAS • It picks at random a number between 0 and 1 • Example: x=RANUNI(3242); • x=0.321234 • Problem: Write a SAS program to generate 10 uniform random numbers between 0 and 1, and list the numbers.

  5. Uniform random number generator Example: x=RANUNI(3242); x=0.321234 Goal: To randomly select a subject in a population of N=6 subjects. Strategy: Multiply random number by (N): x1=6*RANUNI (3242); Example: x1=1.9274 The random number now ranges from 0 to 6. Take the integer part: x2=INT(6*RANUNI(3242)); Example: x2=1 Add 1 to make it go from 1 to N: x3=INT(6*RANUNI(3242))+1; Example: x3=2;

More Related