Hello,
I am looking for a way to customize t-tests in the following way: there are multiple independet samples I want to test against equality with a certain value. This value changes each time I want to do the test as much as the samples could vary. I have accomplished a macro with parameters doing most of the job. But the t-test needs a specific value to test the mean aof the samples in a given variable against. the test value ist in most cases a mean of a variable in the same dataset. The problem is: how can I get SPSS calculating a mean of a variable just for scratch variable and not for each case in the dataset? for better understanding: I did the following in syntax: compute #mean = mean(age). and using #mean as a parameter within the macro call: !t_test value=#mean vars=x1 x2. but that does not work. It shows an error indicating that the value "(age" is not valid. How could I convince SPSS of doing what I want? Thanks in advance Stefan |
To comment on a number of issues, skipping the macro questions. (First
principle: it's wisest not to attempt a macro, until you the corresponding code works when it's NOT in a macro.) At 02:09 PM 10/15/2006, Stefan Lippitsch wrote: >I am looking for a way to customize t-tests in the following way: >There are multiple independent samples I want to test against equality >with a certain value. This value changes each time I want to do the >test as much as the samples could vary. I have accomplished a macro >with parameters doing most of the job. But the t-test needs a specific >value to test the mean of the samples in a given variable against. the >test value is in most cases a mean of a variable in the same dataset. I'll mostly leave this to others, but treating an observed mean from the dataset as a 'constant' value for comparisons, is statistically dubious. If "the same dataset" is the dataset on which you're running the t-test, it's clearly wrong; you should be doing a paired t-test. Now, as a data manipulation question, here's where you get fouled up: >The problem is: how can I get SPSS calculating a mean of a variable >just for scratch variable and not for each case in the dataset? Here, it's not clear what you mean. If you mean the "mean of a [...] scratch variable" over the cases in your dataset, the answer is, you don't. It has to be a regular variable, and you calculate its mean across cases using AGGREGATE. Read up on how to use AGGREGATE, and post again with any questions. >I did the following in syntax: > >compute #mean = mean(age). >and using #mean as a parameter within the macro call: >!t_test value=#mean vars=x1 x2. OK; you have at least two serious misconceptions. . FIRST, you're trying to calculate a mean across cases. The syntax above doesn't do it, macro or not. Read up on MEAN: it calculates a mean across VARIABLES, WITHIN a case. Expression "mean(age)" isn't useful; it's simply the value of variable "age". I've no idea why you got the error that '"(age" is not valid'. It works for me; see draft output, below. (Second principle: If you're asking about an error message, give the *exact* error message, and enough listing that we can see the context where it occurs.) Draft output [To myself: I ran this direct from SPSS. There's no saved syntax file or .RTF file]: LIST. List |-----------------------------|---------------------------| |Output Created |15-OCT-2006 15:01:53 | |-----------------------------|---------------------------| [DataSet0] AGE 47 53 13 97 60 Number of cases read: 5 Number of cases listed: 5 COMPUTE MEAN=MEAN(AGE). LIST. List |-----------------------------|---------------------------| |Output Created |15-OCT-2006 15:03:33 | |-----------------------------|---------------------------| [DataSet0] AGE MEAN 47 47.00 53 53.00 13 13.00 97 97.00 60 60.00 Number of cases read: 5 Number of cases listed: 5 . SECOND, and here's your syntax again: >compute #mean = mean(age). >and using #mean as a parameter within the macro call: >!t_test value=#mean vars=x1 x2. I've no idea what your macro !t_test looks like. (Third principle: Neither we on the List, nor anybody else, can debug your code if you don't show it to us.) Try running this syntax with SET MPRINT ON, and see what code the macro is generating, and what it seems to be doing. (And, fourth principle: always run with SET MPRINT ON, when debugging a macro.) >How could I convince SPSS of doing what I want? First, don't use scratch variables. For you, they have no real purpose, and can easily cause confusion. Second, look at AGGREGATE for calculating your mean value. And third, investigate the statistical validity of what you're trying to do. -Good luck, and post again if you need to, Richard |
Hi Stefan
You wrote: >>I am looking for a way to customize t-tests in the following way: >>There are multiple independent samples I want to test against equality >>with a certain value. This value changes each time I want to do the >>test as much as the samples could vary. I have accomplished a macro >>with parameters doing most of the job. But the t-test needs a specific >>value to test the mean of the samples in a given variable against. the >>test value is in most cases a mean of a variable in the same dataset. Richard answered: RR> I'll mostly leave this to others, but treating an observed mean from RR> the dataset as a 'constant' value for comparisons, is statistically RR> dubious. If "the same dataset" is the dataset on which you're running RR> the t-test, it's clearly wrong; you should be doing a paired t-test. I'd even add: absolutely wrong. The mean from a sample is a STATISTIC, and the reference value for a one-sample t-test should be a PARAMETER (the population mean), never a sample mean. If you want to ompared two sample measn, then you yould use a different test (paired samples t-test, or independent samples t-test, it depends on the design - the way the data were collected). If you insist on using a one-sample t-test, you should, as Richard said, use AGGREGATE to compute the mean across cases and add it to the dataset as a new variable. There is a trick I use for one-sample non-parametric testing (Wilcoxon and sign test) that can be used to get a one-sample t-test using two variables (I developed it for SPSS 6, when one-sample t-test was not available). If you still want it (after what Richard and I have explained), tell me and I'll give you the syntax. It will save you having to use a macro, because you will be able to test a lot of variables against a lot of reference means in one go. -- Regards, Dr. Marta García-Granero,PhD mailto:[hidden email] Statistician --- "It is unwise to use a statistical procedure whose use one does not understand. SPSS syntax guide cannot supply this knowledge, and it is certainly no substitute for the basic understanding of statistics and statistical thinking that is essential for the wise choice of methods and the correct interpretation of their results". (Adapted from WinPepi manual - I'm sure Joe Abrahmson will not mind) |
Hi Stephan
I usually don't answer off-list, because more people might be interested in the answer SL> yes, I know the statistical essentials which say that one SL> should never do what I am about to do. Because I know the SL> statistical background, I think I can keep those limitations in SL> mind and doing the interpretation with that knowledge and just SL> search for a technical solution. But thank you for your advice. I SL> would be very glad if you sent me the "trick" you accomplished. * Sample dataset [to test if x1 TO x6 are equal to mean(age)] Replace by your own *. DATA LIST LIST/age x1 TO x6 (7 F8). BEGIN DATA 47 25 27 31 43 29 33 53 41 17 38 45 41 78 13 73 68 17 47 59 61 97 55 87 21 16 37 39 60 41 43 45 47 21 19 END DATA. * This new variable is needed for aggregating the dataset *. NUMERIC k(F1). COMPUTE k = 1 . * Now you need to compute a new variable (mean1) with the mean values for age *. * Assuming you have SPSS 13 at least (if older SPSS, see below) *. AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK=k /mean1 = MEAN(age). * For older SPSS versions use this syntax instead *. AGGREGATE /OUTFILE='C:\Temp/aggr.sav' /BREAK=k /mean1 = MEAN(age). MATCH FILES /FILE=* /TABLE='C:\temp\aggr.sav' /BY k. EXECUTE. * Now, you run a paired t-test using your variables (x1, x2, x3...) as one element of the pair, and mean1 as the second element (this is exactly the same as running a one-sample t-test using 54 (the value of mean(age) in this sample dataset) as reference value *. T-TEST PAIRS = x1 TO x6 WITH mean1. * Check *. T-TEST /TESTVAL = 54 /VARIABLES = x1 x2 x3 x4 x5 x6. If you have more than one variable the mean of which is going to be used as "parameter", then aggregate all variables (call the new ones mean1, mean2, mean3...) AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK=k /mean1 = MEAN(age) /mean2 = MEAN ("2nd variable") /mean3 = MEAN ("3rd variable") . And run the following afterwards: T-TEST PAIRS = x1 TO x6 WITH mean1 TO mean3. As you can see, you don't need a macro, one simple T-TEST is enough to check every variable against every possible "parameter". -- Regards, Dr. Marta García-Granero,PhD mailto:[hidden email] Statistician --- "It is unwise to use a statistical procedure whose use one does not understand. SPSS syntax guide cannot supply this knowledge, and it is certainly no substitute for the basic understanding of statistics and statistical thinking that is essential for the wise choice of methods and the correct interpretation of their results". (Adapted from WinPepi manual - I'm sure Joe Abrahmson will not mind) |
Free forum by Nabble | Edit this page |