Login  Register

Re: saving MATRIX output to SAV file

Posted by David Marso on Feb 21, 2015; 7:03pm
URL: http://spssx-discussion.165.s1.nabble.com/saving-MATRIX-output-to-SAV-file-tp5728761p5728763.html

Assuming the cases are ordered with sample 1 being rows 1-6, sample 2 rows 7-12 etc.
Untested...
may need to fiddle a bit to defray golden monkey residuals... ;-)

MATRIX.
GET data /FILE * /VARIABLES sample corr.
LOOP I=1 TO TRUNC(NROW(data)/6).
COMPUTE R=MAKE(4,4,0).
COMPUTE start=(I-1)*6+1.
COMPUTE R(1,2)=data(start).
COMPUTE R(1,3)=data(start+1).
.....
COMPUTE R(3,4)=data(start+6).
COMPUTE R=R+T(R)+ MDIAG(4,1).
SAVE {I,DET(R)}/OUTFILE "filepath" /VARIABLES sample Det .
END LOOP.
END MATRIX.

Kirill Orlov wrote
Of course. You are looping whole MATRIX sessions, that will not do.
Instead, you may put just SAVE statement inside !DO - !DOEND or (better)
inside regular LOOP - END LOOP.
New cases will be appended in loops to an output sav file.


21.02.2015 19:52, Beckstead, Jason пишет:
> I am using MATRIX/ END MATRIX to calculate the determinant of a
> correlation matrix. In my data file I have 6 variables, each is a
> correlation coefficient from a sample. Each row of the data file is
> from a different sample created as part of a Monte Carlo simulation,
> so the file has about 10,000 rows. I need to select a row (6
> correlations for a sample) pass the values to MATRIX get the
> determinant, and then write the sample id and the value of the
> determinant to an external SAV file that I can then match to the
> original data file.
> I put the MATRIX code into a macro loop which runs, but the SAVE
> command overwrites rather than appends the results.
> My code so far looks like this.
>
> GET FILE='CNTR_SIM3_12CONDS.SAV'
>  /KEEP= rYX1u rYX2u rYpdctu rX1X2u rX1pdctu rX2pdctu SAMPLE_.
> SELECT IF SAMPLE_<=100.
>
> DEFINE !DETS (!POS !TOKENS(1)).
> !DO !I = 1 !TO !1.
>  TEMP.
>  SELECT IF SAMPLE_=!I.
> MATRIX.
> GET VALS.
> COMPUTE R=MAKE(4,4,1).
> COMPUTE R(2,1)=VALS(1).
> COMPUTE R(3,1)=VALS(2).
> COMPUTE R(4,1)=VALS(3).
> COMPUTE R(3,2)=VALS(4).
> COMPUTE R(4,2)=VALS(5).
> COMPUTE R(4,3)=VALS(6).
> COMPUTE R(1,2)=VALS(1).
> COMPUTE R(1,3)=VALS(2).
> COMPUTE R(1,4)=VALS(3).
> COMPUTE R(2,3)=VALS(4).
> COMPUTE R(2,4)=VALS(5).
> COMPUTE R(3,4)=VALS(6).
> COMPUTE SAMPLE_=VALS(7).
> COMPUTE D=DET(R).
> COMPUTE RST={SAMPLE_,D}.
> PRINT RST.
> SAVE RST/OUTFILE='DETS.SAV'
> /VARIABLES=SMP DET.
> END MATRIX.
> !DOEND.
> !ENDDEFINE.
> !DETS 100.
>
> Any help would be much appreciated.
>
> Jason
> _____________________________________________________________
>
>  Jason W. Beckstead, Ph.D.
>
>   Associate Professor/Quantitative Methodologist
>
>   University of South Florida College of Nursing
>
>   12901 Bruce B. Downs Blvd., MDC22, Tampa, FL 33612, USA
>
>   Statistical Editor, International Journal of Nursing Studies
>
>   phone: +1.813.974.7667  fax: +1.813.974.5418
>
>   personal website: http://personal.health.usf.edu/jbeckste/
>
>   International Journal of Nursing Studies http://www.elsevier.com/ijns
>
>
> ===================== To manage your subscription to SPSSX-L, send a
> message to [hidden email] 
> <mailto:[hidden email]> (not to SPSSX-L), with no body text
> except the command. To leave the list, send the command SIGNOFF
> SPSSX-L For a list of commands to manage subscriptions, send the
> command INFO REFCARD



=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"