TTT flawed in case of a lagtime… [🇷 for BE/BA]

posted by ElMaestro  – Denmark, 2013-07-24 00:35 (4706 d 06:03 ago) – Posting: # 11043
Views: 10,411

Hi Helmut,

❝ Does anybody have a clever idea how I can find the lagtime in R without a loop? Essentially I would search backwards from tmax until I find the first NA.


Not thoroughly tested, but if I get your drift, then here's something to consider:
time=c(1,2,3,4,5,6,7,8,9,10)
conc=c(NA,NA,NA,5,19,56, 53,46,40, NA)
data=data.frame(time, conc)

d1=subset(data, !(is.na(conc))) ##d1 now holds everything not NA
Tmax=subset(d1,  conc==max(d1[,2]))[1,1] ##records Tmax
d4=subset(data, (is.na(conc)) &(time<Tmax) ) ##takes all NA's observed until Tmax
Tlag=(subset(data, (is.na(conc))&&(time<Tmax)))[nrow(d4),1] ##Time of last observed NA before Tmax


Not thoroughly tested though :PCchaos:

Pass or fail!
ElMaestro

Complete thread:

UA Flag
Activity
 Admin contact
23,653 posts in 4,991 threads, 1,570 registered users;
137 visitors (0 registered, 137 guests [including 20 identified bots]).
Forum time: 06:38 CEST (Europe/Vienna)

Outside his own ever-narrowing field of specialization,
a scientist is a layman.
What members of an academy of science have in common
is a certain form of semiparasitic living.    Erwin Chargaff

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5