/* This macro tests the type I error rates of factor analysis applied to dichotomous manifest variables. The macro can test for as many manifest variables as desired. The probabilities of each manifest variable taking the value 1 can be individually for each manifest variable. 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 "control." */ /* options nonotes nosource; */ ods trace off; ods listing; %macro typeIerror(numVar, probability, totalobs, sizesamples, error); data dataset; %do j=1 %to &totalobs; groupNo = int((&j - .5)/&sizesamples) + 1; %do i=1 %to &numVar; randomNumber&i = uniform(0); if randomNumber&i < %sysevalf(%sysevalf(%scan(&probability,&i))/100) then randomNumber&i=1; else randomNumber&i=0; %end; output; %end; 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 <= &error 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 typeIerror; data final; run; /* %macro typeIerror(numVar, probability, totalobs, sizesamples, error); */ %macro control(numVar, probability, totalobs, sizesamples, error, iterations); data results; run; %do m=1 %to &iterations; %typeIerror(&numVar, &probability, &totalobs, &sizesamples, &error); %end; proc means data=results noprint; var mean; output out=results mean=mean; run; data results; set results; numberVariables = &numVar; totalObs = &totalobs * &iterations; sampleSize = &sizesamples; aValueTested = &error; aValueEstimate = Mean; probabilities = "&probability"; run; data results; set results; drop Mean; run; data final; set final results; run; %mend control; /* probabilities must be specified with 2 digits */ %control(5, .80 .10 .40 .50 .99, 300, 30, .05, 1); /* %control(5, .50 .50 .50 .50 .50, 30000, 30, .05, 20); %control(5, .30 .40 .50 .60 .70, 30000, 30, .05, 20); %control(5, .65 .65 .65 .65 .65, 30000, 30, .05, 20); %control(6, .50 .50 .50 .50 .50 .50, 30000, 30, .05, 20); %control(6, .30 .40 .40 .50 .60 .70, 30000, 30, .05, 20); %control(6, .65 .65 .65 .65 .65 .65, 30000, 30, .05, 20); %control(7, .50 .50 .50 .50 .50 .50 .50, 30000, 30, .05, 20); %control(7, .30 .40 .50 .50 .60 .60 .70, 30000, 30, .05, 20); %control(7, .65 .65 .65 .65 .65 .65 .65, 30000, 30, .05, 20); %control(8, .50 .50 .50 .50 .50 .50 .50 .50, 30000, 30, .05, 20); %control(8, .30 .40 .40 .50 .50 .60 .60 .70, 30000, 30, .05, 20); %control(8, .65 .65 .65 .65 .65 .65 .65 .65, 30000, 30, .05, 20); */ data final; set final; if _TYPE_=. then delete; run; data final; set final; drop _TYPE_ _FREQ_; run; ods html file="resultsTypeIError.htm" contents = "contents.htm" frame = "frame.htm"; proc print data=final noobs; var numberVariables probabilities totalObs sampleSize aValueTested aValueEstimate; run; ods html close;