Dear All:
When I apply sample()in S-plus to do for example, bootstrapping, let's say we have four patients(patient ID is 1,2,3,4), one of the results can be 4,4,4,4, how can I do to make NONMEM treat this result as four patients, not just one patient. Do I need do something with data arrangement or some other functions in S-plus can deal with this. Any instructions will be highly appreciated.
Zheng
S-plus code and data arrangement
3 messages
3 people
Latest: Aug 23, 2007
Hi Zheng,
You should modify your code to prevent it.
A hint :
try to test if the current sampled individual is different from the previous
one or not : if yes modify it...
sample code follows :
temp.id<- sample(unique(tab$ID), replace=T) # c(1,2,3,4,6,5,6) #
temp.data<-NULL
while(length(temp.id)>0) {
if (temp.id[length(temp.id)]==temp.id[1]) temp.id[length(temp.id)]<-
temp.id[length(temp.id)]+1000
temp.data<-rbind(temp.data,tab[tab$ID%in%temp.id,])
temp.id<-temp.id[duplicated(temp.id)]
}})
Cheers.
Samer
Quoted reply history
-----Original Message-----
From: [EMAIL PROTECTED] on behalf of Zheng Lu
Sent: Thu 23/08/2007 11:50
To: [email protected]
Subject: [NMusers] S-plus code and data arrangement
Dear All:
When I apply sample()in S-plus to do for example, bootstrapping, let's
say we have four patients(patient ID is 1,2,3,4), one of the results
can be 4,4,4,4, how can I do to make NONMEM treat this result as four
patients, not just one patient. Do I need do something with data
arrangement or some other functions in S-plus can deal with this. Any
instructions will be highly appreciated.
Zheng
Hi Zheng,
One option is to grab records with TIME=0, or any condition that should mark
the beginning of each subject, from the bootstrap dataset (say, bootdata is
your bootstrap dataset),
### 1. perform rle using the condition that should mark the beginning of
### each subject
a<-rle(bootdata$TIME==0)
### 2. function updateNewID(a,b) defined: it uses the rle output and the
### bootstrap dataset as input arguments
updateNewID<-function(a,b,colname="newID") {
asum <- cumsum(a$lengths)
endindx <- asum[a$values==F]
startindx <- c(1,endindx[-length(endindx)]+1)
for(i in 1:length(endindx)) {
b[startindx[i]:endindx[i],colname] <- i
}
invisible(b)
}
### 3. run the function: b2 will be the updated dataset in this case.
b2 <- updateNewID(a,bootdata)
### 'newID' column contains 1 through n #(n=number of subjects in the
### bootstrap dataset).
### You can use the newID column as the ID for the NONMEM run. You may keep
### the original ID column, just with different column name.
### or you can specify any name eg. 'ID2' as column name instead of 'newID'
### default
b2 <- updateNewID(a,bootdata,"ID2")
Livia
Quoted reply history
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Mouksassi Mohamad-Samer
Sent: Thursday, August 23, 2007 11:20 AM
To: Zheng Lu; [email protected]
Subject: RE: [NMusers] S-plus code and data arrangement
Hi Zheng,
You should modify your code to prevent it.
A hint :
try to test if the current sampled individual is different from the previous
one or not : if yes modify it...
sample code follows :
temp.id<- sample(unique(tab$ID), replace=T) # c(1,2,3,4,6,5,6) #
temp.data<-NULL
while(length(temp.id)>0) {
if (temp.id[length(temp.id)]==temp.id[1]) temp.id[length(temp.id)]<-
temp.id[length(temp.id)]+1000
temp.data<-rbind(temp.data,tab[tab$ID%in%temp.id,])
temp.id<-temp.id[duplicated(temp.id)]
}})
Cheers.
Samer
-----Original Message-----
From: [EMAIL PROTECTED] on behalf of Zheng Lu
Sent: Thu 23/08/2007 11:50
To: [email protected]
Subject: [NMusers] S-plus code and data arrangement
Dear All:
When I apply sample()in S-plus to do for example, bootstrapping, let's
say we have four patients(patient ID is 1,2,3,4), one of the results
can be 4,4,4,4, how can I do to make NONMEM treat this result as four
patients, not just one patient. Do I need do something with data
arrangement or some other functions in S-plus can deal with this. Any
instructions will be highly appreciated.
Zheng