Calculate combined exposure days

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

Calculate combined exposure days

Koen
I have a datafile with a couple of start days and end days for exposure to a specific agent. Some of these agents belong to the same category. Sometimes individuals use only one agent at a time, sometimes multiple I want to calulate some incidence ratios, so I have to calculate the total amout of patientyears of exposure.

Is there a way to let SPSS calculate the time of exposure to the categories of these agents?

DATA LIST FREE /A1_start_days  A1_end_days A2_start_days A2_end_days B1_start_days B1_end_days (6F5.0).
BEGIN DATA
0 250 0 0 0 0
10 250 200 250 0 0
0 400 0 0 400 500
END DATA.

I obviously can calculate the amount of days of exposure for A1, A2 and B2. But what if I want to calculate the amount of days a patients uses any agent from the A-category. I can't add A1+A2, because the second case uses 2 agents at the same time. For the first case, it should be 250, for the second 240 (and not 290!) and for the third 400.

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Calculate combined exposure days

Andy W
Interesting problem, here is one solution I could think of that is somewhat general, although needs two pieces of information that shouldn't be too problematic; the minimum start day and maximum end day. What I do is loop through those min and max days and use a DO IF and the RANGE function to evaluate if the day is within at least one of date ranges. Using a DO IF allows you to not double count dates.

FYI the dates for this are 251, 241 and 401 (i.e. inclusive dates). If you don't want inclusive dates just initialize "exp" to -1 instead of 0.

**************************************.
DATA LIST FREE /A1_start_days  A1_end_days A2_start_days A2_end_days B1_start_days B1_end_days (6F5.0).
BEGIN DATA
0 250 0 0 0 0
10 250 200 250 0 0
0 400 0 0 400 500
END DATA.

COMPUTE exp = 0.
LOOP #i = 0 to 500.
DO IF RANGE(#i,A1_start_days,A1_end_days).
  compute exp = exp +1.
ELSE IF RANGE(#i,A2_start_days,A2_end_days).
  compute exp = exp + 1.
END IF.
END LOOP.
EXE.
**************************************.

I'm sure there are other ways, this is just what I dreamed up first without having to worry about ordering of the date ranges. If you have alot of potential ranges though this would be annoying to code up all those ELSE IF statements.
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: Calculate combined exposure days

Andy W
Thinking about it some more it will be more efficient to use the MIN and MAX functions to code the loop (presuming days are calculated as integers). I still can't think of a flexible way that doesn't involve all the ELSE IF statements though if you have many date ranges.

***************************************.
DATA LIST FREE /A1_start_days  A1_end_days A2_start_days A2_end_days B1_start_days B1_end_days (6F5.0).
BEGIN DATA
0 250 0 0 0 0
10 250 200 250 0 0
0 400 0 0 400 500
0 1 0 0 400 500
200 250 10 250 0 0
END DATA.

*Updated.
COMPUTE exp = 0.
LOOP #i = MIN(A1_start_days,A2_start_days) to MAX(A1_end_days,A2_end_days).
DO IF RANGE(#i,A1_start_days,A1_end_days).
  compute exp = exp +1.
ELSE IF RANGE(#i,A2_start_days,A2_end_days).
  compute exp = exp + 1.
END IF.
END LOOP.
EXE.
***************************************.
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: Calculate combined exposure days

Jon K Peck
In reply to this post by Koen
What you really want to compute here is the set union of these intervals.  Here is a way to do that using the SPSSINC TRANS extension command that makes that clear.

DATA LIST FREE /A1_start_days  A1_end_days A2_start_days A2_end_days
B1_start_days B1_end_days (6F5.0).
BEGIN DATA
0 250 0 0 0 0
10 250 200 250 0 0
0 400 0 0 400 500
END DATA.
dataset name sets.

begin program.
def getsize(a1start, a1end,a2start, a2end, b1start, b1end):
    s1 = set(range(int(a1start), int(a1end)))
    s2 = set(range(int(a2start), int(a2end)))
    s3 = set(range(int(b1start), int(b1end)))
    return len(s1.union(s2).union(s3))
end program.

spssinc trans result = exposure
/formula "getsize(A1_start_days, A1_end_days, A2_start_days, A2_end_days, B1_start_days, B1_end_days)".


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:        Koen <[hidden email]>
To:        [hidden email],
Date:        09/17/2013 08:15 AM
Subject:        [SPSSX-L] Calculate combined exposure days
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




I have a datafile with a couple of start days and end days for exposure to a
specific agent. Some of these agents belong to the same category. Sometimes
individuals use only one agent at a time, sometimes multiple I want to
calulate some incidence ratios, so I have to calculate the total amout of
patientyears of exposure.

Is there a way to let SPSS calculate the time of exposure to the categories
of these agents?

DATA LIST FREE /A1_start_days  A1_end_days A2_start_days A2_end_days
B1_start_days B1_end_days (6F5.0).
BEGIN DATA
0 250 0 0 0 0
10 250 200 250 0 0
0 400 0 0 400 500
END DATA.

I obviously can calculate the amount of days of exposure for A1, A2 and B2.
But what if I want to calculate the amount of days a patients uses any agent
from the A-category. I can't add A1+A2, because the second case uses 2
agents at the same time. For the first case, it should be 250, for the
second 240 (and not 290!) and for the third 400.

Thanks!



--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Calculate-combined-exposure-days-tp5722060.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