1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
Subject: Re: Area Under the curve > Here is a solution that I wrote for a similar problem. The area is > calculated for each case by trapezoidal integration. If your time points > are evenly spaced, then the commands could be simplified somewhat, but you could > still use thes same structure if you wished, only changing variable names > and times. > I hope this helps. > > David Matheson > SPSS Technical Support > > Q. > How can I use SPSS to calculate the area under a curve for each cas= e > in the data file? I have measurements of drug levels in the blood f= or > each case at 9 time points. These time points are unevenly spaced b= ut > identical for all cases. Suppose that I plotted drug level as a > function of time for each case. I would like SPSS to calculate the > area under this curve, using trapezoidal integration, and store it > in a new variable. I would also like to calculate and store the > maximum drug level for each case and the time point at which that > maximum level first appeared for that case. INPUT PROGRAM. LOOP id=1 TO 50. DO REPEAT v=TH00,TH05,TH10,TH15,TH20,TH30,TH40,TH60,TH80. COMPUTE v=UNIFORM(25). END REPEAT. END CASE. END LOOP. END FILE. END INPUT PROGRAM. EXECUTE. DO REPEAT h = h00 h05 h10 h15 h20 h30 h40 h60 h80 / t = 0 .5 1 1.5 2 3 4 6 8 . COMPUTE h = t. END REPEAT. EXECUTE. * trapezoidal integration of drug = f(time) curve . VECTOR time = h00 to h80. VECTOR drug = th00 to th80. COMPUTE cmax = MAX(th00 to th80). COMPUTE tmax = $sysmis. COMPUTE lagdrug = $sysmis. COMPUTE lagtime = $sysmis. COMPUTE auc = 0. LOOP #k = 1 to 9. DO IF (NOT(MISSING(drug(#k)))). IF (NOT(MISSING(lagdrug))) auc = auc + (time(#k) - lagtime)*(lagdrug + drug(#k))/2 . IF (drug(#k) = cmax and missing(tmax)) tmax = time(#k) . COMPUTE lagdrug = drug(#k). COMPUTE lagtime = time(#k). END IF. END LOOP. EXECUTE. * Save file with CMAX, TMAX, and AUC added, dropping the * intermediate variables created for their calculation . save outfile drugauc.sav / drop = h00 to h80 lagdrug lagtime.