question about random seed for simulation

9 messages 7 people Latest: Mar 10, 2017

question about random seed for simulation

From: Penny Zhu Date: March 09, 2017 technical
Dear All I have finished a multiple dose simulation for 600 subjects and want to perform a single dose simulation (different sampling time) on the same subjects (same ETA as the first simulation). I used the same seed for the simulation step, it turned out the first subject was the same and the rest of the subjects are not and I am not sure whether this was due to the fact that the two simulation has different number TIME records. If so, I wonder what is the proper way to set the simulation seed so that the ETAs for the second simulation will be identical to the first one. I know that I could output the individual parameter estimate from the first simulation and import them into the second one. But I was thinking if the random seed can be synchronized between the two simulation, it could be an easier solution. Your help is very much appreciated! Thank you very much and best regards! Penny (Peijuan) Zhu, Ph.D. Associate Director Clinical Pharmacology Cell: 862-926-9079 PD Bio-Pharma CDMA Sandoz 1N025, 100 College Road West Princeton, NJ 08540

RE: question about random seed for simulation

From: Magnus Åstrand Date: March 09, 2017 technical
Hi Penny, I suspect you are right in your conclusion that number of records for each id matters in this case. My solution to your problem would be to add columns for IIV to your dataset outside of NONMEM. Quite easily done in R. Use the rmvnorm R function to simulate your etas, 600 rows times as many etas you have require(mvtnorm) sigma<-diag(c(1,2,3)) ## example 3 etas , without block, variances 1,2 and 3 Etas<-rmvnorm(600,sigma=sigma) colnames(Etas)<-paste("ETAr",1:ncol(Etas),sep="") Then load your NONMEM datafile as is now with dosing and observational records, d0<-read.table(.....) Match each of the rows in Etas to ID in your data Etas2<-Etas[as.numeric(factor(d0$ID)),] and then append the simulated etas d1<-cbind(d0,Etas2) and then finaly save the d1 R data.frame as a text file using write.table. In your nonmem code you the just replace eta(1) with ETAR1, and so on. BW Magnus strand Principal Clinical Pharmacometrician, Ph.D. _____________________________________________________________________________________________ AstraZeneca Innovative Medicines | Quantitative Clinical Pharmacology SE-431 83 Mlndal, Sweden T: +46 (0)31 776 23 41 Mob: +46 (0)708 467 667 magnus.astrand_at_astrazeneca.com Please consider the environment before printing this e-mail
Quoted reply history
From: owner-nmusers_at_globomaxnm.com [mailto:owner-nmusers_at_globomaxnm.com] On Behalf Of Zhu, Penny Sent: den 9 mars 2017 19:19 To: nmusers_at_globomaxnm.com Subject: [NMusers] question about random seed for simulation Dear All I have finished a multiple dose simulation for 600 subjects and want to perform a single dose simulation (different sampling time) on the same subjects (same ETA as the first simulation). I used the same seed for the simulation step, it turned out the first subject was the same and the rest of the subjects are not and I am not sure whether this was due to the fact that the two simulation has different number TIME records. If so, I wonder what is the proper way to set the simulation seed so that the ETAs for the second simulation will be identical to the first one. I know that I could output the individual parameter estimate from the first simulation and import them into the second one. But I was thinking if the random seed can be synchronized between the two simulation, it could be an easier solution. Your help is very much appreciated! Thank you very much and best regards! Penny (Peijuan) Zhu, Ph.D. Associate Director Clinical Pharmacology Cell: 862-926-9079 PD Bio-Pharma CDMA Sandoz 1N025, 100 College Road West Princeton, NJ 08540 ________________________________ Confidentiality Notice: This message is private and may contain confidential and proprietary information. If you have received this message in error, please notify us and remove it from your system and note that you must not copy, distribute or take any action in reliance on it. Any unauthorized use or disclosure of the contents of this message is not permitted and may be unlawful.

RE: question about random seed for simulation

From: Magnus Åstrand Date: March 09, 2017 technical
Hi Penny, I suspect you are right in your conclusion that number of records for each id matters in this case. My solution to your problem would be to add columns for IIV to your dataset outside of NONMEM. Quite easily done in R. Use the rmvnorm R function to simulate your etas, 600 rows times as many etas you have require(mvtnorm) sigma<-diag(c(1,2,3)) ## example 3 etas , without block, variances 1,2 and 3 Etas<-rmvnorm(600,sigma=sigma) colnames(Etas)<-paste("ETAr",1:ncol(Etas),sep="") Then load your NONMEM datafile as is now with dosing and observational records, d0<-read.table(.....) Match each of the rows in Etas to ID in your data Etas2<-Etas[as.numeric(factor(d0$ID)),] and then append the simulated etas d1<-cbind(d0,Etas2) and then finaly save the d1 R data.frame as a text file using write.table. In your nonmem code you the just replace eta(1) with ETAR1, and so on. BW Magnus Åstrand Principal Clinical Pharmacometrician, Ph.D. _____________________________________________________________________________________________ AstraZeneca Innovative Medicines | Quantitative Clinical Pharmacology SE-431 83 Mölndal, Sweden T: +46 (0)31 776 23 41 Mob: +46 (0)708 467 667 [email protected] Please consider the environment before printing this e-mail
Quoted reply history
From: [email protected] [mailto:[email protected]] On Behalf Of Zhu, Penny Sent: den 9 mars 2017 19:19 To: [email protected] Subject: [NMusers] question about random seed for simulation Dear All I have finished a multiple dose simulation for 600 subjects and want to perform a single dose simulation (different sampling time) on the same subjects (same ETA as the first simulation). I used the same seed for the simulation step, it turned out the first subject was the same and the rest of the subjects are not and I am not sure whether this was due to the fact that the two simulation has different number TIME records. If so, I wonder what is the proper way to set the simulation seed so that the ETAs for the second simulation will be identical to the first one. I know that I could output the individual parameter estimate from the first simulation and import them into the second one. But I was thinking if the random seed can be synchronized between the two simulation, it could be an easier solution. Your help is very much appreciated! Thank you very much and best regards! Penny (Peijuan) Zhu, Ph.D. Associate Director Clinical Pharmacology Cell: 862-926-9079 PD Bio-Pharma CDMA Sandoz 1N025, 100 College Road West Princeton, NJ 08540 ________________________________ Confidentiality Notice: This message is private and may contain confidential and proprietary information. If you have received this message in error, please notify us and remove it from your system and note that you must not copy, distribute or take any action in reliance on it. Any unauthorized use or disclosure of the contents of this message is not permitted and may be unlawful.

RE: question about random seed for simulation

From: Ruben Faelens Date: March 09, 2017 technical
Hi Penny, Nonmem indeed calculates each subject one after the other. The random values will therefore change. Maybe you can set the random seed every time you simulate t=0, based on the subject ID? This may also depend on your data file; have you tried ordering on time (so the first 50 rows are all t=0 for subject 1 to 50) ? This largely depends on the simulation software and its design: As an example: Simulo samples all subjects together at simulation start, after which it runs the trial design; so the same subjects are sampled independent of subsequent trial design. I do not know about other tools (TS.2, simulx, mrgsolve), maybe the authors of these tools can specify? Kind regards, Ruben Faelens
Quoted reply history
From: [email protected] [mailto:[email protected]] On Behalf Of Zhu, Penny Sent: donderdag 9 maart 2017 19:19 To: [email protected] Subject: [NMusers] question about random seed for simulation Dear All I have finished a multiple dose simulation for 600 subjects and want to perform a single dose simulation (different sampling time) on the same subjects (same ETA as the first simulation). I used the same seed for the simulation step, it turned out the first subject was the same and the rest of the subjects are not and I am not sure whether this was due to the fact that the two simulation has different number TIME records. If so, I wonder what is the proper way to set the simulation seed so that the ETAs for the second simulation will be identical to the first one. I know that I could output the individual parameter estimate from the first simulation and import them into the second one. But I was thinking if the random seed can be synchronized between the two simulation, it could be an easier solution. Your help is very much appreciated! Thank you very much and best regards! Penny (Peijuan) Zhu, Ph.D. Associate Director Clinical Pharmacology Cell: 862-926-9079 PD Bio-Pharma CDMA Sandoz 1N025, 100 College Road West Princeton, NJ 08540 Information in this email and any attachments is confidential and intended solely for the use of the individual(s) to whom it is addressed or otherwise directed. Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the Company. Finally, the recipient should check this email and any attachments for the presence of viruses. The Company accepts no liability for any damage caused by any virus transmitted by this email. All SGS services are rendered in accordance with the applicable SGS conditions of service available on request and accessible at http://www.sgs.com/en/Terms-and-Conditions.aspx
One simple option is to stack simulation data files together, with EVID=4 for the first (or the only) dose of the second file. Leonid
Quoted reply history
On 3/9/2017 6:11 PM, Faelens, Ruben (Belgium) wrote: > Hi Penny, > > Nonmem indeed calculates each subject one after the other. The random > values will therefore change. Maybe you can set the random seed every > time you simulate t=0, based on the subject ID? > > This may also depend on your data file; have you tried ordering on time > (so the first 50 rows are all t=0 for subject 1 to 50) ? > > This largely depends on the simulation software and its design: > > As an example: Simulo samples all subjects together at simulation start, > after which it runs the trial design; so the same subjects are sampled > independent of subsequent trial design. > > I do not know about other tools (TS.2, simulx, mrgsolve), maybe the > authors of these tools can specify? > > Kind regards, > > Ruben Faelens > > *From:*[email protected] > [mailto:[email protected]] *On Behalf Of *Zhu, Penny > *Sent:* donderdag 9 maart 2017 19:19 > *To:* [email protected] > *Subject:* [NMusers] question about random seed for simulation > > Dear All > > I have finished a multiple dose simulation for 600 subjects and want to > perform a single dose simulation (different sampling time) on the same > subjects (same ETA as the first simulation). I used the same seed for > the simulation step, it turned out the first subject was the same and > the rest of the subjects are not and I am not sure whether this was due > to the fact that the two simulation has different number TIME records. > If so, I wonder what is the proper way to set the simulation seed so > that the ETAs for the second simulation will be identical to the first > one. > > I know that I could output the individual parameter estimate from the > first simulation and import them into the second one. But I was > thinking if the random seed can be synchronized between the two > simulation, it could be an easier solution. > > Your help is very much appreciated! > > Thank you very much and best regards! > > * * > > *Penny (Peijuan) Zhu, Ph.D.* > > Associate Director Clinical Pharmacology > > Cell: 862-926-9079 > > PD Bio-Pharma CDMA > > Sandoz > > 1N025, 100 College Road West > > Princeton, NJ 08540 > > Information in this email and any attachments is confidential and > intended solely for the use of the individual(s) to whom it is addressed > or otherwise directed. Please note that any views or opinions presented > in this email are solely those of the author and do not necessarily > represent those of the Company. Finally, the recipient should check this > email and any attachments for the presence of viruses. The Company > accepts no liability for any damage caused by any virus transmitted by > this email. All SGS services are rendered in accordance with the > applicable SGS conditions of service available on request and accessible > at http://www.sgs.com/en/Terms-and-Conditions.aspx

Re: RE: question about random seed for simulation

From: Kyle Baron Date: March 09, 2017 technical
To Ruben's question: mrgsolve simulates the subjects up front as well. The subjects are identical across runs if the seed and number of subjects does not change. An illustration: http://mrgsolve.github.io/2017/03/09/reproducible-results-with-set.seed/ Best regards, Kyle
Quoted reply history
On Thu, Mar 9, 2017 at 5:11 PM, Faelens, Ruben (Belgium) < Ruben.Faelens_at_sgs.com> wrote: > Hi Penny, > > > > Nonmem indeed calculates each subject one after the other. The random > values will therefore change. Maybe you can set the random seed every time > you simulate t=0, based on the subject ID? > > This may also depend on your data file; have you tried ordering on time > (so the first 50 rows are all t=0 for subject 1 to 50) ? > > > > This largely depends on the simulation software and its design: > > As an example: Simulo samples all subjects together at simulation start, > after which it runs the trial design; so the same subjects are sampled > independent of subsequent trial design. > > > > I do not know about other tools (TS.2, simulx, mrgsolve), maybe the > authors of these tools can specify? > > > > Kind regards, > > Ruben Faelens > > > > *From:* owner-nmusers_at_globomaxnm.com [mailto:owner-nmusers_at_globomaxnm.com] > *On Behalf Of *Zhu, Penny > *Sent:* donderdag 9 maart 2017 19:19 > *To:* nmusers_at_globomaxnm.com > *Subject:* [NMusers] question about random seed for simulation > > > > Dear All > > I have finished a multiple dose simulation for 600 subjects and want to > perform a single dose simulation (different sampling time) on the same > subjects (same ETA as the first simulation). I used the same seed for the > simulation step, it turned out the first subject was the same and the rest > of the subjects are not and I am not sure whether this was due to the fact > that the two simulation has different number TIME records. If so, I wonder > what is the proper way to set the simulation seed so that the ETAs for the > second simulation will be identical to the first one. > > > > I know that I could output the individual parameter estimate from the > first simulation and import them into the second one. But I was thinking > if the random seed can be synchronized between the two simulation, it could > be an easier solution. > > > > Your help is very much appreciated! > > > > Thank you very much and best regards! > > > > *Penny (Peijuan) Zhu, Ph.D.* > > Associate Director Clinical Pharmacology > > > > Cell: 862-926-9079 <(862)%20926-9079> > > > > PD Bio-Pharma CDMA > > Sandoz > > 1N025, 100 College Road West > > Princeton, NJ 08540 > > > > > > > Information in this email and any attachments is confidential and intended > solely for the use of the individual(s) to whom it is addressed or > otherwise directed. Please note that any views or opinions presented in > this email are solely those of the author and do not necessarily represent > those of the Company. Finally, the recipient should check this email and > any attachments for the presence of viruses. The Company accepts no > liability for any damage caused by any virus transmitted by this email. All > SGS services are rendered in accordance with the applicable SGS conditions > of service available on request and accessible at > http://www.sgs.com/en/Terms-and-Conditions.aspx > -- Kyle Baron, PharmD, PhD Senior Scientist Metrum Research Group

Re: RE: question about random seed for simulation

From: Kyle Baron Date: March 10, 2017 technical
To Ruben's question: mrgsolve simulates the subjects up front as well. The subjects are identical across runs if the seed and number of subjects does not change. An illustration: http://mrgsolve.github.io/2017/03/09/reproducible-results-with-set.seed/ Best regards, Kyle
Quoted reply history
On Thu, Mar 9, 2017 at 5:11 PM, Faelens, Ruben (Belgium) < [email protected]> wrote: > Hi Penny, > > > > Nonmem indeed calculates each subject one after the other. The random > values will therefore change. Maybe you can set the random seed every time > you simulate t=0, based on the subject ID? > > This may also depend on your data file; have you tried ordering on time > (so the first 50 rows are all t=0 for subject 1 to 50) ? > > > > This largely depends on the simulation software and its design: > > As an example: Simulo samples all subjects together at simulation start, > after which it runs the trial design; so the same subjects are sampled > independent of subsequent trial design. > > > > I do not know about other tools (TS.2, simulx, mrgsolve), maybe the > authors of these tools can specify? > > > > Kind regards, > > Ruben Faelens > > > > *From:* [email protected] [mailto:[email protected]] > *On Behalf Of *Zhu, Penny > *Sent:* donderdag 9 maart 2017 19:19 > *To:* [email protected] > *Subject:* [NMusers] question about random seed for simulation > > > > Dear All > > I have finished a multiple dose simulation for 600 subjects and want to > perform a single dose simulation (different sampling time) on the same > subjects (same ETA as the first simulation). I used the same seed for the > simulation step, it turned out the first subject was the same and the rest > of the subjects are not and I am not sure whether this was due to the fact > that the two simulation has different number TIME records. If so, I wonder > what is the proper way to set the simulation seed so that the ETAs for the > second simulation will be identical to the first one. > > > > I know that I could output the individual parameter estimate from the > first simulation and import them into the second one. But I was thinking > if the random seed can be synchronized between the two simulation, it could > be an easier solution. > > > > Your help is very much appreciated! > > > > Thank you very much and best regards! > > > > *Penny (Peijuan) Zhu, Ph.D.* > > Associate Director Clinical Pharmacology > > > > Cell: 862-926-9079 <(862)%20926-9079> > > > > PD Bio-Pharma CDMA > > Sandoz > > 1N025, 100 College Road West > > Princeton, NJ 08540 > > > > > > > Information in this email and any attachments is confidential and intended > solely for the use of the individual(s) to whom it is addressed or > otherwise directed. Please note that any views or opinions presented in > this email are solely those of the author and do not necessarily represent > those of the Company. Finally, the recipient should check this email and > any attachments for the presence of viruses. The Company accepts no > liability for any damage caused by any virus transmitted by this email. All > SGS services are rendered in accordance with the applicable SGS conditions > of service available on request and accessible at > http://www.sgs.com/en/Terms-and-Conditions.aspx > -- Kyle Baron, PharmD, PhD Senior Scientist Metrum Research Group

Re: RE: question about random seed for simulation

From: Ron Keizer Date: March 10, 2017 technical
Same for PKPDsim (when `seed` argument specified): all subjects sampled up front, so inserting / removing observations has no effect on sampled parameters. Ron
Quoted reply history
On Thu, Mar 9, 2017 at 3:56 PM, Kyle Baron <[email protected]> wrote: > > To Ruben's question: mrgsolve simulates the subjects up front as well. > The subjects are identical across runs if the seed and number of subjects > does not change. > > An illustration: > http://mrgsolve.github.io/2017/03/09/reproducible-results-with-set.seed/ > > Best regards, > Kyle > > > On Thu, Mar 9, 2017 at 5:11 PM, Faelens, Ruben (Belgium) < > [email protected]> wrote: > >> Hi Penny, >> >> >> >> Nonmem indeed calculates each subject one after the other. The random >> values will therefore change. Maybe you can set the random seed every time >> you simulate t=0, based on the subject ID? >> >> This may also depend on your data file; have you tried ordering on time >> (so the first 50 rows are all t=0 for subject 1 to 50) ? >> >> >> >> This largely depends on the simulation software and its design: >> >> As an example: Simulo samples all subjects together at simulation start, >> after which it runs the trial design; so the same subjects are sampled >> independent of subsequent trial design. >> >> >> >> I do not know about other tools (TS.2, simulx, mrgsolve), maybe the >> authors of these tools can specify? >> >> >> >> Kind regards, >> >> Ruben Faelens >> >> >> >> *From:* [email protected] [mailto:[email protected]] >> *On Behalf Of *Zhu, Penny >> *Sent:* donderdag 9 maart 2017 19:19 >> *To:* [email protected] >> *Subject:* [NMusers] question about random seed for simulation >> >> >> >> Dear All >> >> I have finished a multiple dose simulation for 600 subjects and want to >> perform a single dose simulation (different sampling time) on the same >> subjects (same ETA as the first simulation). I used the same seed for the >> simulation step, it turned out the first subject was the same and the rest >> of the subjects are not and I am not sure whether this was due to the fact >> that the two simulation has different number TIME records. If so, I wonder >> what is the proper way to set the simulation seed so that the ETAs for the >> second simulation will be identical to the first one. >> >> >> >> I know that I could output the individual parameter estimate from the >> first simulation and import them into the second one. But I was thinking >> if the random seed can be synchronized between the two simulation, it could >> be an easier solution. >> >> >> >> Your help is very much appreciated! >> >> >> >> Thank you very much and best regards! >> >> >> >> *Penny (Peijuan) Zhu, Ph.D.* >> >> Associate Director Clinical Pharmacology >> >> >> >> Cell: 862-926-9079 <(862)%20926-9079> >> >> >> >> PD Bio-Pharma CDMA >> >> Sandoz >> >> 1N025, 100 College Road West >> >> Princeton, NJ 08540 >> >> >> >> >> >> >> Information in this email and any attachments is confidential and >> intended solely for the use of the individual(s) to whom it is addressed or >> otherwise directed. Please note that any views or opinions presented in >> this email are solely those of the author and do not necessarily represent >> those of the Company. Finally, the recipient should check this email and >> any attachments for the presence of viruses. The Company accepts no >> liability for any damage caused by any virus transmitted by this email. All >> SGS services are rendered in accordance with the applicable SGS conditions >> of service available on request and accessible at >> http://www.sgs.com/en/Terms-and-Conditions.aspx >> > > > > -- > Kyle Baron, PharmD, PhD > Senior Scientist > Metrum Research Group > >
Hi Penny, I would highly encourage you to check out mrgsolve. It will be the fastest (and IMO easiest) to do flexible designs. That said, given that you seem to just be changing the sampling, per your email, why don't you just simulate the richest design you need, then in post processing filter out various sub-designs as needed? That means no need to mess with multiple simulations and normalizing seeds. For example, on scenario at 2 and 11 hrs post dose, one 1.5, 12, etc, you'd simulate 1.5, 2, 11, 12. This would also allow you easily handle many more scenarios in a single simulation. Furthermore, you can even flexibly control the sampling times on a patient-by-patient level (eg if you were to recommend a sampling window) by dynamically filtering. You could use code, in R approximately like: library(dplyr) library(PKPDmisc) peak_time <- function(.nsamples = 1) { # sample .nsamples values from the provided vector sample(c(1.5, 2), .nsamples) } peak_time <- function(.nsamples = 1) { # sample .nsamples values from the provided vector sample(c(11, 12), .nsamples) } # data from nonmem saved to output_df <- read_nonmem("outputtable") # for fixed times output_from_design <- output_df %>% filter(TIME %in% c(2, 12)) # for flexible sampling per id output_from_design <- output_df %>% group_by(ID) %>% filter(TIME %in% c(peak_time(), trough_time()) # do what you want with output_from_design, which will have random samples from peak and trough for each individual) This post-processing is not specific to nonmem, and can be used with any of the simulation softwares. Devin
Quoted reply history
On Thu, Mar 9, 2017 at 7:01 PM Kyle Baron <[email protected]> wrote: > > To Ruben's question: mrgsolve simulates the subjects up front as well. > The subjects are identical across runs if the seed and number of subjects > does not change. > > An illustration: > http://mrgsolve.github.io/2017/03/09/reproducible-results-with-set.seed/ > > Best regards, > Kyle > > > On Thu, Mar 9, 2017 at 5:11 PM, Faelens, Ruben (Belgium) < > [email protected]> wrote: > > Hi Penny, > > > > Nonmem indeed calculates each subject one after the other. The random > values will therefore change. Maybe you can set the random seed every time > you simulate t=0, based on the subject ID? > > This may also depend on your data file; have you tried ordering on time > (so the first 50 rows are all t=0 for subject 1 to 50) ? > > > > This largely depends on the simulation software and its design: > > As an example: Simulo samples all subjects together at simulation start, > after which it runs the trial design; so the same subjects are sampled > independent of subsequent trial design. > > > > I do not know about other tools (TS.2, simulx, mrgsolve), maybe the > authors of these tools can specify? > > > > Kind regards, > > Ruben Faelens > > > > *From:* [email protected] [mailto:[email protected]] > *On Behalf Of *Zhu, Penny > *Sent:* donderdag 9 maart 2017 19:19 > *To:* [email protected] > *Subject:* [NMusers] question about random seed for simulation > > > > Dear All > > I have finished a multiple dose simulation for 600 subjects and want to > perform a single dose simulation (different sampling time) on the same > subjects (same ETA as the first simulation). I used the same seed for the > simulation step, it turned out the first subject was the same and the rest > of the subjects are not and I am not sure whether this was due to the fact > that the two simulation has different number TIME records. If so, I wonder > what is the proper way to set the simulation seed so that the ETAs for the > second simulation will be identical to the first one. > > > > I know that I could output the individual parameter estimate from the > first simulation and import them into the second one. But I was thinking > if the random seed can be synchronized between the two simulation, it could > be an easier solution. > > > > Your help is very much appreciated! > > > > Thank you very much and best regards! > > > > *Penny (Peijuan) Zhu, Ph.D.* > > Associate Director Clinical Pharmacology > > > > Cell: 862-926-9079 <(862)%20926-9079> > > > > PD Bio-Pharma CDMA > > Sandoz > > 1N025, 100 College Road West > > Princeton, NJ 08540 > > > > > > > Information in this email and any attachments is confidential and intended > solely for the use of the individual(s) to whom it is addressed or > otherwise directed. Please note that any views or opinions presented in > this email are solely those of the author and do not necessarily represent > those of the Company. Finally, the recipient should check this email and > any attachments for the presence of viruses. The Company accepts no > liability for any damage caused by any virus transmitted by this email. All > SGS services are rendered in accordance with the applicable SGS conditions > of service available on request and accessible at > http://www.sgs.com/en/Terms-and-Conditions.aspx > > > > > -- > Kyle Baron, PharmD, PhD > Senior Scientist > Metrum Research Group > >