29 Aug 2011 14:56
Re: Area Under Curve
David L Lorenz <lorenz <at> usgs.gov>
2011-08-29 12:56:52 GMT
2011-08-29 12:56:52 GMT
Matt,
Probably the easiest way to get 0.5*(E1 + E2) is
0.5*(E[-length(E)] + E[-1])
The easiest way to get the delta Ts is using the function diff().
Dave
| From: | Matthew Peng <matthewpeng80 <at> gmail.com> |
| To: | s-news <at> lists.biostat.wustl.edu |
| Date: | 08/26/2011 04:58 PM |
| Subject: | [S] Area Under Curve |
| Sent by: | s-news-owner <at> lists.biostat.wustl.edu |
Dear All,
I was wondering if someone could help me implement the following in S-Plus.
I need to calculate the AUC (Area Under Curve) using the trapezoidal method (0.5*(E1+E2)*T) and it goes as follows:
Time Exposure
1 10
2 20
3 30
4 40
5 50
I need to do the following in S-Plus:
ID Time E Time1 E1 T E AUC (0.5*T*E)
1 1 10 0 0 1 10 5
1 2 20 1 10 1 30 15
1 3 30 2 20 1 50 25
1 4 40 3 30 1 70 35
1 5 50 4 40 1 90 45
2 1 10 0 0 1 10 5
2 2 20 1 10 1 30 15
2 3 30 2 20 1 50 25
2 4 40 3 30 1 70 35
2 5 50 4 40 1 90 45
where;
T=Time1-Time
E=E+E1
Mainly I am having trouble implementing the "lag" columns (Time1 and E1).
Appreciate any inputs I can get.
Best Regards,
Matt
RSS Feed