/* This macro tests the typeII error rates (and power) of factor analysis applied to dichotomous manifest variables. The macro can test for as many manifest variables as desired. However there is only one dichotomous latent variables. The probabilities of each manifest variables taking the value 1 can be individually set for both latent variable=1 and latent variable=0. In addition the number of observations in each sample and number of samples can be controlled. When testing more than 30,000 observations one should use more than 1 iteration in order to avoid memory problems. The paramters are set in the macro "controller." */ /* options nonotes nosource; */ %macro powertest(numVar, proportionGroup1, probabilityG1, probabilityG2, totalobs, sizesamples, level); data dataset; %do j=1 %to &totalobs; groupNo = int((&j - .5)/&sizesamples) + 1; %do i=1 %to &numVar + 1; randomNumber&i = uniform(0); %end; output; %end; run; data dataset; set dataset; %do i=2 %to &numVar + 1; if randomNumber1 <= &proportionGroup1 AND randomNumber&i < %sysevalf(%sysevalf(%scan(&probabilityG1,&i - 1))/100) then randomNumber&i=1; else if randomNumber1 <= &proportionGroup1 then randomNumber&i=0; if randomNumber1 > &proportionGroup1 AND randomNumber&i < %sysevalf(%sysevalf(%scan(&probabilityG2,&i - 1))/100) then randomNumber&i=1; else if randomNumber1 > &proportionGroup1 then randomNumber&i=0; %end; run; proc print data=datset; run; data dataset; set dataset; drop randomNumber1; run; proc print data=dataset; run; ods listing close; ods output SignifTests=testSig; proc factor data=dataset method=ml maxiter=100 heywood; by groupNo; run; ods output close; ods listing; data testSig; set testSig; if Test ne "H0: No common factors" then delete; run; data testSig; set testSig; if ProbChiSq <= &level then ProbChiSq = 1; else ProbChiSq = 0; run; proc means data=testSig noprint; var ProbChiSq; output out=out1 mean=mean; run; data results; set results out1; run; %mend powertest; data final; run; %macro controller(numVar, proportionGroup1, probabilityG1, probabilityG2, totalobs, sizesamples, level, iterations); data results; run; %do m=1 %to &iterations; %powertest(&numVar, &proportionGroup1, &probabilityG1, &probabilityG2, &totalobs, &sizesamples, &level); %end; proc means data=results noprint; var mean; output out=results mean=mean; run; data results; set results; numberVariables = &numVar; totalObs = &totalobs * &iterations; #sample = &sizesamples; aLevel = &error; typeIIEst = Mean; powerEst = 1 - Mean; probabilityG1 = "&probabilityG1"; probabilityG2 = "&probabilityG2"; run; data results; set results; drop Mean; run; data final; set final results; run; %mend controller; /* Set parameters here. Make sure to include the probability strings for group1 and group2 are of the form .xx with a space in between each argument. The number of arguments in the group1 and group2 probability strings must equal the number of variables (the first argument in the macro). %macro controller(numVar, proportionGroup1, probabilityG1, probabilityG2, totalobs, sizesamples, level, iterations); */ %controller(4, .5, .50 .50 .50 .50, .50 .50 .50 .50, 300, 30, .05, 5); data final; set final; if _TYPE_=. then delete; run; data final; set final; drop _TYPE_ _FREQ_; run; ods html file="resultsPower3.htm" contents = "contents.htm" frame = "frame.htm"; proc print data=final noobs; var numVariables totalObs #Sample probabilityGroup1 probabilityG1 probabilityG2 aLevel typeIIEst powerEst; run; ods html close;