Need for Permutation Code to Run Partial Correlations Multiple Times

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Need for Permutation Code to Run Partial Correlations Multiple Times

Zachary Feinstein
The following code is very simple to run in SPSS:
 
PARTIAL CORR /VARIABLES = cmpi7 cta_1 BY cta_2 ctb_1 ctc_1.
 
However, I need code or a macro to do the first variable (cmpi7) by every possible combination of the other variables.  So the next one might be cmpi7 cta_1 BY ctb_1 ctc_1.  And another one could be cmpi7 ctb_1 BY ctc_1.
 
I would think some sort of a macro would best help here but I do not think I have found the perfect macro for doing permutations within a command in SPSS.
 
Please help!  Thank you very much in advance.
 
Zachary
 

Reply | Threaded
Open this post in threaded view
|

Re: Need for Permutation Code to Run Partial Correlations Multiple Times

Spousta Jan
Hi Zachary,
 
try this macro (and of course change the directory in the call in the last row of the macro if needed):
 

define permut (outfile = !charend('|') / statvars = !charend('|') / byvars = !cmdend ).

* creates PARTIAL CORR commands with all permutations of byvars on left & right side of BY.

* statvars are on the left side of BY only

* the output is saved in outfile .

 

* count byvars and create quoted variables.

!let !countstr = ""

!let !kv = ""

!do !i !in (!byvars)

!let !countstr = !concat(!countstr, "x")

!let !kv = !concat(!kv ," ", !quote(!i))

!doend

!let !cnt = !length(!countstr) .

 

* create a SPSS data file with the permutations in rows.

input program.

- vector r (!cnt, f1).

- loop #n = 1 to 2**!cnt .

  loop #i = 1 to !cnt .

  compute r(#i) = rnd((-1)**(trunc((#n-1)/(2**(#i-1)) )) + 1) / 2.

- end loop.

- end case.

- end loop.

- end file.

end input program.

!let !rmax = !concat("r",!cnt )

compute #s = sum(r1 to !rmax ).

select if #s > 0 and #s < !cnt .

* because the 0000 and 1111 permutations do not give sense here.

exe.

* create the needed commands.

vector r = r1 to !rmax .

string command (a250).

compute command = concat("PARTIAL CORR /VARIABLES = ", !quote(!statvars)).

do repe i = 1 to !cnt / v = !kv .

- if r(i) = 0 command = concat(rtrim(command), " ", v).

end repe.

compute command = concat(rtrim(command), " BY").

do repe i = 1 to !cnt / v = !kv .

- if r(i) = 1 command = concat(rtrim(command), " ", v).

end repe.

compute command = concat(rtrim(command), ".").

WRITE OUTFILE = !quote(!outfile) /command .

exe.

!enddefine.

 

permut outfile = c:/temp/partcorr.sps | statvars = cmpi7 | byvars = cta_1 cta_2 ctb_1 ctc_1 .

 

Best,

Jan



From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Zachary Feinstein
Sent: Monday, October 04, 2010 11:26 PM
To: [hidden email]
Subject: Need for Permutation Code to Run Partial Correlations Multiple Times

The following code is very simple to run in SPSS:
 
PARTIAL CORR /VARIABLES = cmpi7 cta_1 BY cta_2 ctb_1 ctc_1.
 
However, I need code or a macro to do the first variable (cmpi7) by every possible combination of the other variables.  So the next one might be cmpi7 cta_1 BY ctb_1 ctc_1.  And another one could be cmpi7 ctb_1 BY ctc_1.
 
I would think some sort of a macro would best help here but I do not think I have found the perfect macro for doing permutations within a command in SPSS.
 
Please help!  Thank you very much in advance.
 
Zachary
 

 

_____________

Tato zpráva a všechny připojené soubory jsou důvěrné a určené výlučně adresátovi(-ům). Jestliže nejste oprávněným adresátem, je zakázáno jakékoliv zveřejňování, zprostředkování nebo jiné použití těchto informací. Jestliže jste tento mail dostali neoprávněně, prosím, uvědomte odesilatele a smažte zprávu i přiložené soubory. Odesilatel nezodpovídá za jakékoliv chyby nebo opomenutí způsobené tímto přenosem.

P Jste si jisti, že opravdu potřebujete vytisknout tuto zprávu a/nebo její přílohy? Myslete na přírodu.

 


This message and any attached files are confidential and intended solely for the addressee(s). Any publication, transmission or other use of the information by a person or entity other than the intended addressee is prohibited. If you receive this in error please contact the sender and delete the message as well as all attached documents. The sender does not accept liability for any errors or omissions as a result of the transmission.

 

P Are you sure that you really need a print version of this message and/or its attachments? Think about nature.

-.- --