SPSS Statistics

 View Only
Expand all | Collapse all

Nearest neighbor analysis to create new variable

  • 1.  Nearest neighbor analysis to create new variable

    Posted Tue May 18, 2021 12:21 PM
      |   view attached
    Hey there,

    I was wondering if you could help me with a problem I have with finding a nearest neighbor in SPSS.

    So this is the data (in the attachment): 
    - On a certain moment (date with hh:mm:ss.ss configuration) TimeOfSCP happens
    - This moment either happens when the Metronome is ON or OFF. By default it is OFF until someone switches it ON
    - Moments on which it is switched ON or OFF are noted (date with hh:mm:ss.ss configuration), on random moments in time, with no consecutive order (it could be ON, ON, OFF, ON)

    What I want is to create a new variable where the TimeOfSCP is labeled as a moment during which the metronome is ON or OFF. For example, SCP_ONOFF in which the outcome is ON or OFF. 

    Technically, this would be possible if SPSS would find the nearest neighbor of the TimeOfSCP that lies just before SCP happens, and then label the outcome as the variable itself (i.e. MetronomeOFF1). I can't seem to find a way to make this possible, so your help is much required! 
    *nice to know: this would help us improve CPR in cardiac arrest!

    Kind regards, Lotte

    ------------------------------
    Lotte Doeleman
    ------------------------------

    #SPSSStatistics

    Attachment(s)



  • 2.  RE: Nearest neighbor analysis to create new variable

    Posted Tue May 18, 2021 12:34 PM
    Edited by System Fri January 20, 2023 04:27 PM
    Hi. It looks to me like the DATEDIFF function (see the Command Syntax Reference pp 64-65) may be something worth looking into. For example:

    COMPUTE DateDiff1=DATEDIFF(TimeOfSCP1, MetronomeON1, "seconds").
    LIST DateDiff1 TimeOfSCP1 MetronomeON1.

    You could create an array of these differences and choose the one that best suits your criteria.

    ------------------------------
    Rick Marcantonio
    Quality Assurance
    IBM
    ------------------------------