Search code examples
combinatoricsspss

How to find which combinations have the most frequency?


I have an SPSS data set with 500+ respondents and 18 symptoms that they could have.

Each symptom has its own variable Symptom01 = 1 means they have the symptom 1 Symptom02 = 0 means they dont have the symptom 2 etc etc

What I want to know is what combination of 3 symptoms is more frequent in my data set. For example how many people have symptom 1, 5 and 6; how many people have symptom 1, 2 and 3, etc.

I doesn't mean that they only have those symptoms. Theey could have others. I just want to know which group of 3 symptoms is more frequent in my dataset. It's a lot of combinations so how would you do this?

Can someone help me?


Solution

  • Please note the macro below uses the variable names Symptom1, Symptom2 etc' instead of "Symptom01", "Symptom02"...

    First creating some sample data to work on:

    data list list/Symptom1 to Symptom18.
    begin data
    1 0 0 1 1 0 0 1 1 0 0 0 0 0 1 1 1 1
    1 1 1 1 0 1 0 0 1 0 1 1 0 0 1 1 0 0
    0 1 1 0 1 1 1 1 1 1 1 0 1 0 0 1 0 0
    1 0 0 1 1 0 1 1 1 0 0 0 0 0 0 0 0 0
    1 0 1 0 0 1 0 1 0 0 0 0 0 1 0 1 0 0
    0 0 0 1 1 1 0 0 0 0 1 0 0 0 1 0 0 1
    1 0 1 1 1 1 1 0 1 1 0 0 0 1 1 1 0 1
    1 0 0 0 1 0 1 1 0 0 0 1 0 1 0 0 1 0
    0 0 1 0 1 0 0 0 0 1 1 0 0 1 0 1 1 1
    1 0 0 1 0 0 0 0 0 0 1 1 0 0 1 0 0 0
    end data.
    

    Now defining a macro with three loops:
    EDIT - this version accounts for repeating combinations of symptoms

    define AllCombsOf3 ()
    !do !vr1=1 !to 18
    !do !vr2=!vr1 !to 18
    !do !vr3=!vr2 !to 18
    !if (!vr2<>!vr1 !and  !vr2<>!vr3) !then
    compute !concat("C_",!vr1,"_",!vr2,"_",!vr3)= !concat("Symptom",!vr1)=1 & !concat("Symptom",!vr2)=1 & !concat("Symptom",!vr3)=1 .
    !ifend
    !doend
    !doend
    !doend
    !enddefine.
    

    Running the macro and displaying wanted results:

    AllCombsOf3.
    means  C_1_2_3 to C_16_17_18.
    

    EDIT 2 - new macro for a four symptom version

    define AllCombsOf4 ()
    !do !vr1=1 !to 18
    !do !vr2=!vr1 !to 18
    !do !vr3=!vr2 !to 18
    !do !vr4=!vr3 !to 18
    !if (!vr2<>!vr1 !and  !vr2<>!vr3  !and  !vr3<>!vr4) !then
    compute !concat("C_",!vr1,"_",!vr2,"_",!vr3,"_",!vr4)=  
        !concat("Symptom",!vr1)=1 & !concat("Symptom",!vr2)=1 &   
        !concat("Symptom",!vr3)=1 & !concat("Symptom",!vr4)=1 .
    !ifend
    !doend  !doend  !doend  !doend
    !enddefine.
    
    AllCombsOf4.
    means  C_1_2_3_4 to C_15_16_17_18.