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   Wed, 13 Nov 2013 23:42:56 -0500

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/


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