RE: S-plus multivariate normal distribution
Nick,
Here is a snippet of code that should get you started.
#
# Set seed and define number of draws desired
#
set.seed(111)
simnum <- 5
#
# Define final parameter estimates from NONMEM output
#
theta <- c(402,-1.11,-11.2,-0.00842, 0.118)
#
# Define variance-covariance matrix of fixed effects estimates
#
varcov <- matrix(NA,length(theta),length(theta))
varcov[,1] <- c(1.34, -1.11E-01, -1.29, -1.83E-04, -1.62E-03)
varcov[,2] <- c(-1.11E-01, 2.50E-01, 2.27E-02, 3.35E-05, 6.37E-04)
varcov[,3] <- c(-1.29, 2.27E-02, 2.10, 8.27E-05, 1.27E-03)
varcov[,4] <- c(-1.83E-04, 3.35E-05, 8.27E-05, 8.69E-07, -4.81E-06)
varcov[,5] <- c(-1.62E-03, 6.37E-04, 1.27E-03, -4.81E-06, 4.00E-04)
varcov <- round(varcov,8)
#
# Generate random draws from MVN for theta values
#
sim.theta <- matrix(NA, nrow = simnum, ncol = length(theta))
sim.theta[,1:length(theta)] <- rmvnorm(simnum,mean = theta, cov =
varcov)
Please let me know if you have other questions.
Steve
Quoted reply history
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Nick Holford
Sent: Thursday, September 13, 2007 6:31 AM
To: nmusers
Subject: [NMusers] S-plus multivariate normal distribution
Hi,
Can someone give me some clues on how to sample from a multivariate
normal distribution using S-plus?
Some working code examples would be very helpful.
Thanks,
Nick
--
Nick Holford, Dept Pharmacology & Clinical Pharmacology
University of Auckland, 85 Park Rd, Private Bag 92019, Auckland, New
Zealand
[EMAIL PROTECTED] tel:+64(9)373-7599x86730 fax:+64(9)373-7090
www.health.auckland.ac.nz/pharmacology/staff/nholford