Macro to run TTEST

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

Macro to run TTEST

Ray Haraf
I worked around 30 t-tests by cutting and pasting the first SPSS syntax.
However, I am curious to know an efficient way to cut and paste. I
modified a macro posted by Bruce Weaver in October 2009 to run logistic
regression (thanks, Bruce!). The following modified macro fails to run. No
results, no error message.

DEFINE MyTTEST (XLIST !CMDEND/YLIST !CMDEND)

!do !X !in(!XLIST)
!do !Y !in(!YLIST)

T-TEST GROUPS =!X(0 1)
  /MISSING=ANALYSIS
  /VARIABLE=!Y.

!doend
!doend
!ENDDEFINE.

MyTTEST xlist=A B C D /ylist =E F G H.

I also tried

MyTTEST xlist=A(0 1) B(0 1) C(0 1) D(0 1)/ylist =E F G H. replacing !X(0
1) with !X

Modifying lirdoall (Do All Univariate Linear Regression MACRO by Marta
http://www.spsstools.net/Syntax/RegressionRepeatedMeasure/DoAllUnivariateLi
nearAndLogisticRegressions.txt) gives me results in the xlist/ylist format
for A/E F G H; B/E F G H; C/E F G H and D/E F G H. This is not what I
want. I would like to obtain results for A/E; B/F; C/G and D/H

Thanks for your care,
Ray

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Macro to run TTEST

David Marso
Administrator
RTFM regarding DEFINE !ENDDEFINE.

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?"
Reply | Threaded
Open this post in threaded view
|

Re: Macro to run TTEST

Bruce Weaver
Administrator
In reply to this post by Ray Haraf
While following David's advice re the manual, pay attention to the difference between !CHAREND and !CMDEND.  

Also note that your lines

!do !X !in(!XLIST)
!do !Y !in(!YLIST)

T-TEST GROUPS =!X(0 1)
  /MISSING=ANALYSIS
  /VARIABLE=!Y.

!doend
!doend

will result in one t-test for every combination of variables in the two lists, which is not what you want.  To get what you want (A/E; B/F; C/G; D/H), you'll need to walk through the two lists in parallel. Here's an example of how to do that using !HEAD and !TAIL (courtesy of David a few years ago).

!LET !XCOPY=!XLIST
**PARALLEL PROCESS VARIABLE LISTS **
!DO !Y !IN (!YLIST)
!LET !X = !HEAD(!XCOPY)
!LET l!XCOPY=!TAIL(!XCOPY)
T-TEST GROUPS=!X(0,1) /VARIABLES=!Y.
!doend

HTH.

Ray Haraf wrote
I worked around 30 t-tests by cutting and pasting the first SPSS syntax.
However, I am curious to know an efficient way to cut and paste. I
modified a macro posted by Bruce Weaver in October 2009 to run logistic
regression (thanks, Bruce!). The following modified macro fails to run. No
results, no error message.

DEFINE MyTTEST (XLIST !CMDEND/YLIST !CMDEND)

!do !X !in(!XLIST)
!do !Y !in(!YLIST)

T-TEST GROUPS =!X(0 1)
  /MISSING=ANALYSIS
  /VARIABLE=!Y.

!doend
!doend
!ENDDEFINE.

MyTTEST xlist=A B C D /ylist =E F G H.

I also tried

MyTTEST xlist=A(0 1) B(0 1) C(0 1) D(0 1)/ylist =E F G H. replacing !X(0
1) with !X

Modifying lirdoall (Do All Univariate Linear Regression MACRO by Marta
http://www.spsstools.net/Syntax/RegressionRepeatedMeasure/DoAllUnivariateLi
nearAndLogisticRegressions.txt) gives me results in the xlist/ylist format
for A/E F G H; B/E F G H; C/E F G H and D/E F G H. This is not what I
want. I would like to obtain results for A/E; B/F; C/G and D/H

Thanks for your care,
Ray

=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Macro to run TTEST

Ray Haraf
In reply to this post by Ray Haraf
On Sat, 11 Dec 2010 06:16:26 -0800, Bruce Weaver
<[hidden email]> wrote:

>While following David's advice re the manual, pay attention to the
difference

>between !CHAREND and !CMDEND.
>
>Also note that your lines
>
>!do !X !in(!XLIST)
>!do !Y !in(!YLIST)
>
>T-TEST GROUPS =!X(0 1)
>  /MISSING=ANALYSIS
>  /VARIABLE=!Y.
>
>!doend
>!doend
>
>will result in one t-test for every combination of variables in the two
>lists, which is not what you want.  To get what you want (A/E; B/F; C/G;
>D/H), you'll need to walk through the two lists in parallel. Here's an
>example of how to do that using !HEAD and !TAIL (courtesy of David a few
>years ago).
>
>!LET !XCOPY=!XLIST
>**PARALLEL PROCESS VARIABLE LISTS **
>!DO !Y !IN (!YLIST)
>!LET !X = !HEAD(!XCOPY)
>!LET l!XCOPY=!TAIL(!XCOPY)
>T-TEST GROUPS=!X(0,1) /VARIABLES=!Y.
>!doend
>
>HTH.
>
>
>Ray Haraf wrote:
>>
>> I worked around 30 t-tests by cutting and pasting the first SPSS syntax.
>> However, I am curious to know an efficient way to cut and paste. I
>> modified a macro posted by Bruce Weaver in October 2009 to run logistic
>> regression (thanks, Bruce!). The following modified macro fails to run.
No

>> results, no error message.
>>
>> DEFINE MyTTEST (XLIST !CMDEND/YLIST !CMDEND)
>>
>> !do !X !in(!XLIST)
>> !do !Y !in(!YLIST)
>>
>> T-TEST GROUPS =!X(0 1)
>>   /MISSING=ANALYSIS
>>   /VARIABLE=!Y.
>>
>> !doend
>> !doend
>> !ENDDEFINE.
>>
>> MyTTEST xlist=A B C D /ylist =E F G H.
>>
>> I also tried
>>
>> MyTTEST xlist=A(0 1) B(0 1) C(0 1) D(0 1)/ylist =E F G H. replacing !X(0
>> 1) with !X
>>
>> Modifying lirdoall (Do All Univariate Linear Regression MACRO by Marta
>>
http://www.spsstools.net/Syntax/RegressionRepeatedMeasure/DoAllUnivariateLi
>> nearAndLogisticRegressions.txt) gives me results in the xlist/ylist
format

>> for A/E F G H; B/E F G H; C/E F G H and D/E F G H. This is not what I
>> want. I would like to obtain results for A/E; B/F; C/G and D/H
>>
>> Thanks for your care,
>> Ray
>>
>> =====================
>> 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
>>
>>
>
>
>-----
>--
>Bruce Weaver
>[hidden email]
>http://sites.google.com/a/lakeheadu.ca/bweaver/
>
>"When all else fails, RTFM."
>
>NOTE: My Hotmail account is not monitored regularly.
>To send me an e-mail, please use the address shown above.
>
>--
>View this message in context: http://spssx-
discussion.1045642.n5.nabble.com/Macro-to-run-TTEST-tp3300721p3301520.html
>Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
>=====================
>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

Hi Bruce,

Thanks for your kind and quick reply. This time I am less lucky than with
the case of repeated logistic regression. I tried to fix errors as pointed
out in the output but the parallel process is above my reach!

Kindest regards,

DEFINE MyTTEST(XLIST !CMDEND/YLIST !CMDEND).

!do !X !in(!XLIST)
!do !Y !in(!YLIST)

!LET !XCOPY=!XLIST
**PARALLEL PROCESS VARIABLE LISTS **
!DO !Y !IN (!YLIST)
!LET !X = !HEAD(!XCOPY)
!LET l!XCOPY=!TAIL(!XCOPY)
T-TEST GROUPS=!X(0,1) /VARIABLES=!Y.

>Error # 6863 in column 5.  Text: !Y
>The variable following !DO is already in use in an outer !DO.  It is
invalid
>to attempt to alter the value of a !DO variable.
>Execution of this command stops.

>Error # 6873 in column 6.  Text: !X
>On the DEFINE command, the variable following !LET is the control
variable for
>a !DO which has not been closed, i.e.  for which the matching !DOEND has
not
>yet occurred.  The value of a !DO variable cannot be altered inside the
loop.

>Error # 6871 in column 6.  Text: l
>On the DEFINE command, the symbol following !LET is not a valid macro
variable
>name.  The name must begin with "!" followed by a letter.

>Error # 6876 in column 7.  Text: !XCOPY
>On the DEFINE command, there is no equals sign (=) following the name of
the
>variable to be altered.
!doend

!ENDDEFINE.

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Macro to run TTEST

David Marso
Administrator
Maybe you should just stick with COPY Paste, or read the fine manual (RTFM) as previously indicated.
You are not paying attention to what the error messages are telling you or the advice which Bruce and myself have offered. Read up on what CMDEND does.  Look at your !DO loops (get rid of the first 2).
Pay attention!
Here is working code, but definitely read the manual on MACROS if you plan to use them.

DEFINE MyTTEST (XLIST !CHAREND ("/")
                          /YLIST !CMDEND)
!LET !XCOPY=!XLIST
**PARALLEL PROCESS VARIABLE LISTS **.
!DO !Y !IN (!YLIST)  
!LET !X = !HEAD(!XCOPY)
!LET !XCOPY=!TAIL(!XCOPY)
T-TEST GROUPS=!X(0,1) /VARIABLES=!Y.
!DOEND
!ENDDEFINE
MyTTEST XLIST A B C D / YLIST E F G H .
--------------

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?"
Reply | Threaded
Open this post in threaded view
|

Re: Macro to run TTEST

Bruce Weaver
Administrator
I would add a command terminator (i.e., a period) after !ENDDEFINE.  The "fine manual" is a bit unclear about whether it is actually required, oddly enough.  Here's what it says under "Syntax Rules" for DEFINE-!ENDDEFINE (v18 of the CSRM):

* The macro !ENDDEFINE statement should end with a period. A period as the last character on
a line is interpreted as a command terminator in interactive mode.  [Notice that it says "should", not "must".  I always include it to be safe.]

* Other macro statements (for example, !IF, !LOOP, !LET) should not end with a period.

* Text within the body of the macro that represent commands that will be generated when the
macro is expanded should include the period at the end of each command, and each command
should start on a new line.


David Marso wrote
Maybe you should just stick with COPY Paste, or read the fine manual (RTFM) as previously indicated.
You are not paying attention to what the error messages are telling you or the advice which Bruce and myself have offered. Read up on what CMDEND does.  Look at your !DO loops (get rid of the first 2).
Pay attention!
Here is working code, but definitely read the manual on MACROS if you plan to use them.

DEFINE MyTTEST (XLIST !CHAREND ("/")
                          /YLIST !CMDEND)
!LET !XCOPY=!XLIST
**PARALLEL PROCESS VARIABLE LISTS **.
!DO !Y !IN (!YLIST)  
!LET !X = !HEAD(!XCOPY)
!LET !XCOPY=!TAIL(!XCOPY)
T-TEST GROUPS=!X(0,1) /VARIABLES=!Y.
!DOEND
!ENDDEFINE
MyTTEST XLIST A B C D / YLIST E F G H .
--------------
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Macro to run TTEST

David Futrell
Another option you might consider is using the MEANS procedure instead of T-Test. You can specify multiple X and Y variables, and if you request the /Statistics=ANOVA option, the p-value is equivalent to the two-tailed T-Test, equal variances assumed (this, of course, assumes that your X values have exactly two levels). 

I find the output formatting of MEANS is usually closer to what I need. 





--- On Tue, 12/14/10, Bruce Weaver <[hidden email]> wrote:

From: Bruce Weaver <[hidden email]>
Subject: Re: Macro to run TTEST
To: [hidden email]
Date: Tuesday, December 14, 2010, 10:52 AM

I would add a command terminator (i.e., a period) after !ENDDEFINE.  The
"fine manual" is a bit unclear about whether it is actually required, oddly
enough.  Here's what it says under "Syntax Rules" for DEFINE-!ENDDEFINE (v18
of the CSRM):

* The macro !ENDDEFINE statement should end with a period. A period as the
last character on
a line is interpreted as a command terminator in interactive mode.  [Notice
that it says "should", not "must".  I always include it to be safe.]

* Other macro statements (for example, !IF, !LOOP, !LET) should not end with
a period.

* Text within the body of the macro that represent commands that will be
generated when the
macro is expanded should include the period at the end of each command, and
each command
should start on a new line.



David Marso wrote:

>
> Maybe you should just stick with COPY Paste, or read the fine manual
> (RTFM) as previously indicated.
> You are not paying attention to what the error messages are telling you or
> the advice which Bruce and myself have offered. Read up on what CMDEND
> does.  Look at your !DO loops (get rid of the first 2).
> Pay attention!
> Here is working code, but definitely read the manual on MACROS if you plan
> to use them.
>
> DEFINE MyTTEST (XLIST !CHAREND ("/")
>                           /YLIST !CMDEND)
> !LET !XCOPY=!XLIST
> **PARALLEL PROCESS VARIABLE LISTS **.
> !DO !Y !IN (!YLIST)
> !LET !X = !HEAD(!XCOPY)
> !LET !XCOPY=!TAIL(!XCOPY)
> T-TEST GROUPS=!X(0,1) /VARIABLES=!Y.
> !DOEND
> !ENDDEFINE
> MyTTEST XLIST A B C D / YLIST E F G H .
> --------------
>
>
>


-----
--
Bruce Weaver
bweaver@...
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Macro-to-run-TTEST-tp3300721p3304791.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@... (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

Reply | Threaded
Open this post in threaded view
|

Re: Macro to run TTEST

Bruce Weaver
Administrator
David Futrell wrote
Another option you might consider is using the MEANS procedure instead of T-Test. You can specify multiple X and Y variables, and if you request the /Statistics=ANOVA option, the p-value is equivalent to the two-tailed T-Test, equal variances assumed (this, of course, assumes that your X values have exactly two levels). 
I find the output formatting of MEANS is usually closer to what I need. 
Good catch David.  Given that the OP wants to walk through two lists of variables in parallel, he would have to use multiple TABLES sub-commands, one for each pair of variables.  Like this (using the variable names from the original example):

means
 e by a /
 f by b /
 g by c /
 h by d /
 stat = anova
.

This assumes that there are only two possible values for the Group variables, though.  The T-TEST method inside the macro allowed the user to specify 0 and 1 as the values for the two groups, so only cases with those values would be used, even if other values were present.

--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).