home *** CD-ROM | disk | FTP | other *** search
- (* Multivariate Analysis Package - Partial Correlation Module
- Copyright 1985 Douglas L. Anderton. This program may be freely
- circulated so long as it is not sold for profit and any charge does
- not exceed costs of reproduction *)
-
- Program Partial(Input,Output);
- Type
- R30 = Array [1..30] Of Real;
- M30 = Array [1..30,1..30] Of Real;
- I30 = Array [1..30] Of Integer;
- S8 = Array [1..30] Of String[8];
- Var
- dfile, ofile : Text;
- sel : I30;
- x, y, z: R30;
- varn : S8;
- cor, b, t : M30;
- i, j, j1, k, l, nv, dv, cv, rv, ot, nc: Integer;
- det: real;
-
- Procedure openfiles(Var dfile, ofile:Text; Var nv, dv, cv, ot:Integer);
- Var
- dfl, ofl:String[12];
- Begin
- ClrScr; Writeln(' *** PARTIAL: PARTIAL CORRELATION ***');
- Writeln; Write('Name of the CORREL file? ');
- Readln(dfl); Assign(dfile,dfl); Reset(dfile);
- Write('Name of the output file? ');
- Readln(ofl); Assign(ofile,ofl); Rewrite(ofile);
- ot:= 0;
- If (ofl='CON:') Or (ofl='con:') Then ot:=1;
- If (ofl='LST:') Or (ofl='lst:') Then ot:=2;
- If (ot=2) Then
- Begin
- Writeln(ofile,'Multivariate Analysis Package (1.2) - ',
- 'Program: PARTIAL, Datafile: ',dfl); Writeln(ofile);
- End;
- Write('How many variables in CORREL matrix? ');
- Readln(nv);
- Write('Number of variables to use in PARTIAL? ');
- Readln(dv);
- Write('Number of these to control remaining correlations for? ');
- Readln(cv);
- End; (* Of openfiles *)
-
- Procedure selectvar(Var sel:I30; Var varn:S8; dv, cv:Integer);
- Var
- i:Integer;
- Begin
- Writeln;
- For i:=1 To dv Do
- Begin
- If(i<=cv) Then Write('Column number for controlling variable ',i,'? ');
- If(i>cv) Then Write('Column number for partialled variable ',i-cv,'? ');
- Read(sel[i]); Write(' Name? '); Readln(varn[i]);
- End;
- End; (* Of selectvar *)
-
- Procedure getcor(Var cor:M30; Var mean, stdev:R30; Var nc:Integer;
- sel:I30; nv, dv:Integer; Var dfile:Text);
- Var
- i,j,k,l,z:Integer;
- x,y:Real;
- dum15:String[15];
- dum21:String[21];
- dum8:String[8];
- dum36:String[36];
- Begin
- Readln(dfile); Readln(dfile);
- For i := 1 To nv Do
- Begin
- Readln(dfile,dum15,x,dum21,y,dum8,z);
- If (i=1) Then nc:=z;
- If (nc>z) Then nc:=z;
- For j := 1 To dv Do
- Begin
- If (sel[j]=i) Then
- Begin
- mean[j] := x; stdev[j] := y;
- End;
- End;
- End;
- For i :=1 to 3 Do Readln(dfile);
- For i := 1 To nv-1 Do
- For k := i+1 To nv Do
- Begin
- Readln(dfile,dum36,x,dum15,y);
- For j := 1 To dv Do
- Begin
- cor[j,j] := 1.0;
- If (sel[j]=i) Then
- For l := 1 To dv Do
- If (sel[l]=k) Then
- Begin
- cor[j,l] := y; cor[l,j] := y;
- End;
- End;
- End;
- End; (* Of getcor *)
-
- Procedure minv(Var a:M30; Var d:Real; m:Integer);
- (* matrix inversion in pascal: gauss - reduction method
- inverse returned in a and determinant in d, m is dimension *)
- Var
- j,k,l:Integer;
- pvt,t:Real;
- Begin
- d := 1.0;
- For j:=1 To m Do
- Begin
- pvt := a[j,j]; d := d*pvt; a[j,j] := 1.0;
- If (pvt=0) Then
- Begin
- Writeln; Writeln(' *** Multicollinear Matrix ***'); Writeln;
- End;
- For k:=1 To m Do a[j,k] := a[j,k]/pvt;
- For k:=1 To m Do
- If ((k-j) <> 0) Then
- Begin
- t := a[k,j]; a[k,j] := 0.0;
- For l:=1 To m Do a[k,l] := a[k,l] - (a[j,l]*t);
- End;
- End;
- End; (* of minv *)
-
- Begin (* main *)
- openfiles(dfile, ofile, nv, dv, cv, ot);
- selectvar(sel, varn, dv, cv);
- (* read correlation matrix matrix *)
- getcor(cor, x, y, nc, sel, nv, dv, dfile);
- (* invert left side*)
- minv(cor,det,cv);
- (* multiply for coefficients *)
- rv:=dv-cv;
- For j:=1 To rv Do
- Begin
- j1:=j+cv;
- For k:=1 To cv Do
- Begin
- b[j,k]:=0.0;
- For l:=1 To cv Do b[j,k]:=b[j,k]+(cor[j1,l]*cor[l,k]);
- End;
- End;
- For j:=1 To rv Do
- Begin
- ClrScr;
- Writeln(ofile,'Regression Coefficients of ',varn[j+cv],' on Controls:');
- Writeln(ofile);
- For i:=1 To cv Do Writeln(ofile,' ',varn[i],': ',b[j,i]:10:6);
- Writeln(ofile);
- If ot=1 Then
- Begin
- Write('- Press any key to continue -'); While Not KeyPressed Do;
- ClrScr;
- End;
- End;
- For j:=1 To rv Do
- For k:=1 To rv Do
- Begin
- j1:=k+cv;
- t[j,k]:=0.0;
- For l:=1 To cv Do t[j,k]:=t[j,k]+(b[j,l]*cor[l,j1]);
- End;
- For j:=1 To rv Do
- Begin
- j1:=j+cv;
- For k:=1 To rv Do
- Begin
- l:=k+cv;
- b[j,k]:=cor[j1,l];
- End;
- End;
- For j:=1 To rv Do
- Begin
- x[j]:=t[j,j];
- y[j]:=Sqrt(x[j]);
- z[j]:=(x[j]*(nc-cv-1.0))/((1.0-x[j])*cv);
- End;
- ClrScr;
- Writeln(ofile,'Summary of Regression on Controls:');
- Writeln(ofile);
- Writeln(ofile,'Variable: Mult. R Mult. R-Sq. F-Ratio');
- For j:=1 To rv Do
- Writeln(ofile,varn[j+cv]:8,' ',y[j]:11:5,' ',x[j]:11:5,' ',z[j]:9:3);
- Writeln(ofile); Writeln(ofile,' degrees of freedom: ',cv:3,(nc-cv-1):5);
- Writeln(ofile);
- If ot=1 Then
- Begin
- Write('- Press any key to continue -'); While Not KeyPressed Do;
- ClrScr;
- End;
- For j:=1 To rv Do
- For k:=1 To rv Do b[j,k]:=b[j,k]-t[j,k];
- For j:=1 To rv Do x[j]:=Sqrt(b[j,j]);
- For j:=1 To rv Do
- For k:=1 To rv Do cor[j,k]:=b[j,k]/(x[j]*x[k]);
- Writeln(ofile,'Residual Covariance and Partial Correlations:');
- Writeln(ofile);
- For j:= 1 To rv Do
- Begin
- For i := j+1 To rv Do
- Begin
- Writeln(ofile,varn[j+cv]:8,' with ',varn[i+cv]:8,' Resid Covr: ',
- b[j,i]:13,' Partial Corr:',cor[j,i]:10:6);
- End;
- End;
- Writeln(ofile);
- Close(ofile); Close(dfile);
- End.
- test: ',tt:11:5);
- tt:=SQR((vr[1]/nc[1])/((vr[1]/nc[1])+(vr[2]/nc[2])))/(nc[1]-1);
- tt:=tt+SQR((vr[1]/nc[2])/((vr[2