Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Recency Weighted cumulative exposures


From   Sergiy Radyakin <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Recency Weighted cumulative exposures
Date   Thu, 14 Nov 2013 08:57:32 -0500

In this case your weight column as shown in the first post does not make sense.
I am still not getting exactly the numbers you want as answers, but
see if this brings you closer:

do http://radyakin.org/statalist/2013111301/recencyw3.do

  +---------------------------------------------------------------------------------------------+
  |
csumstr        csum   result |
  |---------------------------------------------------------------------------------------------|
  |
1*0           0        0 |
  |
1*0+.9859553*0           0        0 |
  |
1*2.6+.9859553*0+.9449936*0   2.5999999      2.6 |
  |
1*2.6+.9859553*2.6+.9449936*0+.8804709*0   5.1634836    5.174 |
  |
1*3.2+.9859553*2.6+.9449936*2.6+.8804709*0+.7974722*0   8.2204671
8.218 |
  |---------------------------------------------------------------------------------------------|
  |
1*0           0        0 |
  |
1*0+.9859553*0           0        0 |
  |
1*.7+.9859553*0+.9449936*0   .69999999       .7 |
  |
1*.7+.9859553*.7+.9449936*0+.8804709*0   1.3901687    1.393 |
  |---------------------------------------------------------------------------------------------|
  |
1*0           0        0 |
  |
1*5+.9859553*0           5    3.511 |
  |
1*8+.9859553*5+.9449936*0   12.929776    9.891 |
  |
1*10+.9859553*8+.9449936*5+.8804709*0    22.61261   18.696 |
  |
1*8+.9859553*10+.9449936*8+.8804709*5+.7974722*0   29.821856   26.256
|
  |
1*5+.9859553*8+.9449936*10+.8804709*8+.7974722*5+.702151*0   33.368706
  31.186 |
  | 1*10+.9859553*5+.9449936*8+.8804709*10+.7974722*8+.702151*5+.6009799*0
  41.184967   41.186 |
  +---------------------------------------------------------------------------------------------+

If this is still not the algorithm you want, send me the spreadsheet.
All your examples start with the first dose equal to zero. it is a bad
illustration (even if it is true in you data) and does not help
communicating what you want to be done.

If you can't send the spreadsheet, run the following patients through it:
A: 5.678
B: 1.234 2.345
C: 9.999 8.888 7.777
Show the results in the form of the csumstr above and without any
letters anymore, so that one could -display- the result:
. display 1*10+.9859553*5+.9449936*8+.8804709*10+.7974722*8+.702151*5+.6009799*0
41.184967

Take the example of 5.174 from your first post. The cumulative dose of
5.174 is w1*2.6+w2*2.6 right? w1 is 1, then w2 is 0.99 (exactly).
Where is 0.99 coming from? is that .9859553 rounded?

Best, Sergiy Radyakin


On Thu, Nov 14, 2013 at 5:17 AM, Carmine Rossi, Mr
<[email protected]> wrote:
> Thank you again Mr. Radyakin and all STATA listers for your time.
>
> I will provide one more (fresh) numerical example, perhaps it would be more clear. It is for one id with 7 visits. "Result" is the variable I am looking to create. It is correct and follows the methods outlined in Abrahamowicz et al, and I am a student of his (2006, JCE, http://www.ncbi.nlm.nih.gov/pubmed/16549262). I used an excel spreadsheet to calculate the "result" variable, as I still am unable to program it in STATA, but this hand calculation method is tedious and impossible for large datasets (see all my calculations below).
>
> id time dose result
> 1   1   0     0
> 1   2   5     5
> 1   3   8    12.930
> 1   4   10   22.613
> 1   5   8    29.822
> 1   6   5    33.369
> 1   7   10   41.186
>
> To calculate the "result", which is a recency-weighted cumulative sum, the following calculations are made at every time point.
>
> The weight function, selected a priori is: exp((-((delta_t)^2))/(70.7))
>
>
> -------Hand Calculations begin---------
>
> For time=1:
>
> id time dose delta_t weight dose*weight cumulat_sum(dose*weight)
> 1   1    0    0        1        0           0 [this is result shown at time==1]
>
>
> For time=2:
>
> id time dose delta_t weight dose*weight cumulat_sum(dose*weight)
> 1   1    0    1     0.98595        0           0
> 1   2    5    0        1           5           5 [this is result shown at time==2]
>
> For time=3:
>
> id time dose delta_t weight dose*weight cumulat_sum(dose*weight)
> 1   1    0    2     0.9450        0           0
> 1   2    5    1     0.98595     4.930       4.930
> 1   3    8    0        1          8         12.930 [this is result shown at time==3]
>
> For time=4:
>
> id time dose delta_t weight dose*weight cumulat_sum(dose*weight)
> 1   1    0    3     0.8805        0           0
> 1   2    5    2     0.9450     4.725       4.725
> 1   3    8    1     0.98595    7.888       12.613
> 1   4    10   0        1         10        22.613 [this is result shown at time==4]
>
> For time=5:
>
> id time dose delta_t weight dose*weight cumulat_sum(dose*weight)
> 1   1    0    4     0.7975        0           0
> 1   2    5    3     0.8805      4.402       4.402
> 1   3    8    2     0.9450      7.560      11.962
> 1   4    10   1     0.98595     9.860      21.822
> 1   5    8    0        1          8        29.822 [this is result shown at time==5]
>
> For time=6:
>
> id time dose delta_t weight dose*weight cumulat_sum(dose*weight)
> 1   1    0    5     0.7022        0           0
> 1   2    5    4     0.7975      3.987       3.987
> 1   3    8    3     0.8805      7.044      11.031
> 1   4    10   2     0.9450      9.450      20.481
> 1   5    8    1     0.98595     7.888      28.369
> 1   6    5    0        1          5        33.369  [this is result shown at time==6]
>
>
> For time=7:
>
> id time dose delta_t weight dose*weight cumulat_sum(dose*weight)
> 1   1    0    6     0.6010        0           0
> 1   2    5    5     0.7022      3.511       3.511
> 1   3    8    4     0.7975      6.380       9.891
> 1   4    10   3     0.8805      8.805      18.696
> 1   5    8    2     0.9450      7.560      26.256
> 1   6    5    1     0.98595     4.930      31.186
> 1   7    10   0        1         10        41.186 [this is result shown at time==7]
>
>
> -------Hand Calculations end---------
>
> Notice how the weights are not fixed. They change depending on which time point you are calculating the recent cumulative sum. This is why I initially thought I needed to use a for values loop or something similar.
> This is what I am trying to program, and so far, it has been very difficult.
>
> I want to thank you again for looking at this and giving it a shot. I appreciate it very much!
>
> Have a great day,
>
> Carmine Rossi
> PhD Candidate, Epidemiology
> [email protected]
>
> On 2013-11-13, at 11:42 PM, Sergiy Radyakin <[email protected]>
>  wrote:
>
>> On Wed, Nov 13, 2013 at 7:42 PM, Carmine Rossi, Mr
>> <[email protected]> wrote:
>>> Hi Mr. Radyakin,
>>>
>>> Thank you very much for your email and help. However, the code is not correct.
>>
>> Well it is pretty close to what you are looking for. The main
>> difference is that 'delta time' was not defined in your formula, so I
>> took absolute time, and you now describe relative time. That is also
>> easily fixable:
>>
>> do http://radyakin.org/statalist/2013111301/recencyw2.do
>>
>> I am still NOT getting your exact numeric values, but it might be due
>> to the rounding. Is your magic number 70 shown exactly? Is it same for
>> all IDs? Are there any digits not shown for dosage? You may want to
>> share your spreadsheet to reduce the traffic.
>>
>> Now I expect this modification to take care of both issues you
>> mentioned since they essentially appear the same to me. Except I can't
>> agree that the weights depend on the sum. I'd insist that the sum
>> depends on the weights. The weights depend on the time.
>>
>> Best, Sergiy
>>
>>>
>>> There are two issues: 1) The number of observations per ID is not constant, so for the macro `mt', it would need to be specific per id. For example, ID==1 has 5 time points, and ID==2 has 4 time points.
>>>
>>> 2) The weights are not fixed. This is more difficult for me to explain, but I will try.
>>>
>>> To get the "result" for ID==1 and time==5, I used the spreadsheet calculations shown in the previous email.
>>> However, if I was to calculate the "result" at time==4, I would use the following weights:
>>>
>>> id time  dose delta_t       w(t)      dose(t)*weight(t)        cumulative_sum
>>> 1     1      0        3               0.88              0                 0
>>> 1   2        0        2               0.94              0                 0
>>> 1  3        2.6      1                0.99               2.574        2.574
>>> 1  4       2.6       0                1                 2.6           5.174
>>>
>>> Notice how, now the weight, w(t), at time==4 is equal to 1, when I want to calculate the cumulative sum at time==4.
>>>
>>> For this reason, I thought I would need loops, and this is why I am asking the STATA community for help. My major issue is that the weight’s are not fixed and they change depending on the cumulative sum that I want to calculate at each time point.
>>>
>>> Thank you again for trying to help,
>>> -Carmine Rossi
>>> PhD Candidate, Epidemiology
>>> [email protected]
>>>
>>> On 2013-11-13, at 5:23 PM, Sergiy Radyakin <[email protected]> wrote:
>>>
>>>> Carmine, no loops are really necessary:
>>>>
>>>> do http://radyakin.org/statalist/2013111301/recencyw.do
>>>>
>>>> Hope this helps, Sergiy Radyakin
>>>>
>>>>
>>>> On Wed, Nov 13, 2013 at 5:08 PM, Carmine Rossi, Mr
>>>> <[email protected]> wrote:
>>>>> Dear STATA listers,
>>>>>
>>>>> I have the following repeated measures data on two subjects with a dose exposure variable. I am interested in creating a variable called “result” that is a recency-weighted cumulative sum.
>>>>>
>>>>> id   time   dose         result
>>>>> 1     1    0              0
>>>>> 1     2    0              0
>>>>> 1     3    2.6            2.6
>>>>> 1     4    2.6            5.174
>>>>> 1     5    3.2            8.218
>>>>> 2     1    0              0
>>>>> 2     2    0              0
>>>>> 2     3    0.7            0.7
>>>>> 2     4    0.7            1.393
>>>>>
>>>>> The “result” variable is obtained as a cumulative sum using a weight function:
>>>>> Summation of (Dose(i)  x weight(t)), where the weight function is:
>>>>>
>>>>> W(t) = exp((-(delta time)2)/70.70)
>>>>>
>>>>> So to get the weighted cumulative sum value of 8.218 (for subject 1 at time 5), rather than 8.4, which would have been the un-weighted cumulative sum, I did the following in a spreadsheet.
>>>>>
>>>>>
>>>>> Id time     dose     delta_t       w(t)      dose(t)*weight(t)        cumulative_sum
>>>>> 1   1        0         4           0.80                0                                             0
>>>>> 1   2        0         3           0.88                0                                             0
>>>>> 1   3       2.6        2           0.94              2.444                                 2.444
>>>>> 1   4       2.6        1           0.99              2.574                                 5.018
>>>>> 1   5       3.2        0            1                 3.2                                       8.218
>>>>>
>>>>> Is there a way to do this in STATA with loops? Can anyone provide any suggestions?
>>>>>
>>>>>
>>>>> Carmine Rossi
>>>>> PhD Candidate, Epidemiology
>>>>> McGill University
>>>>> [email protected]
>>
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/faqs/resources/statalist-faq/
>> *   http://www.ats.ucla.edu/stat/stata/
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index