Randomly select covariate values

I have a PK/PD model that I would like to use for some simulations. The model has a variety of covariates and I want to explore the response across that range. For argument sake, let’s say I have the following covariates: PK covariate: Body weight (BW), Age (AGE) PD covariate: Baseline Response (BResp) I would like to run a simulation where BW, AGE, and BResp are randomly selected from a distribution for each covariate (for example BW values between 55 and 100). My model is a text model in Phoenix NLME. I suspect I would need to input a data file with the timepoints of interest and dosing profiles of interest. But how do I randomly select the set of covariates? I’m guessing it is a line of code in the model text … Thanks in advance for the guidance! Nathan

You just need to define these continuous covariate as structural parameters and then the program will simulate BW, age, etc.. for example stparm(BW=tvBW*exp(nBW) fixef(tvBW=c(,70,)) ranef(diag(nBW)=c(0.1)) 0;.1 is about 30% variability from which you can know the range of BW you will get. best Serge

in addition to what Serge mentioned you can try a transformation that will truncate the values into the range you want. another idea would be to use a sequence statement and initialize the “covariate” values when the subject begins but we need to do some tests

One way of truncating would be to use for example if BW must be between 40 and 90 BW=40+50*iogit(para) para is a model parameter for example normally distributed where you give the mean and variance. ilogit (para) is between 0 and 1 and therefore BW will be between 40 and 90. You can check with different means and variances for para to see how the BW distribution looks like. Best Serge

Serge, I’m getting the following error in the Compiler Output: undefined reference to `logit’ Here are snippets of my code: test(){ PK MODEL IS HERE C = A1 / V DMWEIGHT = 15+70logit(para1) E0 = 20 + 35logit(para2) PD MODEL IS HERE stparm(para1 = tvpara1exp(npara1)) stparm(para2 = tvpara2exp(npara2)) fixef(tvbwpara = c(0,0.5,1)) fixef(tvskamppara = c(0,0.5,1)) ranef(diag(nbwpara)=c(0.1)) ranef(diag(nskamppara)=c(0.1)) OTHER PARAMETERS DEFINED HERE } I also tried the function “iogit” with the same results. I must be defining the logit function incorrectly. Thanks in advance. Nathan

Problem solved … I misspelled the function … it is “ilogit” Nathan

Yes ilogit or you can try also iprobit. It will change the look of the distribution. Best Serge

I also got a response from our main developer Mike: " You can have a sequence block, and make up a random number in there. For a truncated uniform: double(u) sequence { u = low_limit + unif()*(high_limit - low_limit); } For a truncated normal, the code below samples from a standard normal, where the limits are in standard normal units. (When there’s a mean and sd, they can transform the limits.) The user can transform it as needed. This is the rejection method. It uses a “while” statement to keep drawing numbers until it gets one that falls within the limits. (Note this can produce an inifinite loop.) double(u) double(x) sequence { x = low_limit - 1 while(x < low_limit || x > high_limit){ x = norm() } } Another way to get a truncated normal is to use iprobit to transform the limits to a uniform scale, then draw a uniform, and then transform it back to normal with the probit function. double(u) double(ulow) double(uhigh) double(x) sequence { ulow = iprobit(low_limit) uhigh = iprobit(high_limit) u = ulow + unif() * (uhigh - ulow) x = probit(u) } note that I did not test the above and it will be good if you can test it and report back to us note this require the latest 1.3 NLME that is not yet officially released but it is about to be very soon !

The truncated uniform method (1st one presented) worked well. I did not try the exclusion method (2nd one presented) … I don’t like to risk infinite loops :slight_smile: The third method didn’t work for me. I may have coded it wrong, but since the first method appeared to work, I didn’t troubleshoot it any further. Thanks for the suggestions. Nathan