From: RAVI VARADHAN <rvaradhan_at_jhmi.edu>

Date: Mon 17 Jul 2006 - 08:11:34 EST

n <- 120

sigerr <- 5

covmat <- diag(c(8,6,3.5))

mu <- c(105,12,10)

mcsamp <- 10000

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Jul 17 08:16:04 2006

Date: Mon 17 Jul 2006 - 08:11:34 EST

Hi,

I have the following piece of code that is part of a larger function. This piece is the most time consuming part of the function, and I would like to make this a bit more efficient. Could anyone suggest a way to do this faster?

##########################

n <- 120

sigerr <- 5

covmat <- diag(c(8,6,3.5))

mu <- c(105,12,10)

mcsamp <- 10000

Tbar <- array(0, dim=c(3,3,n))

# theta is a mcsamp x 3 matrix

theta <- mvrnorm(mcsamp, mu = mu, Sigma = covmat)

wt <- matrix(runif(n*mcsamp),n,mcsamp) wti <- apply(wt,1,sum)

tarray <- array(apply(theta,1,function(x)outer(x,x)),dim=c(3,3,mcsamp))

for (i in 1:n) {

for (k in 1:mcsamp) {

Tbar[,,i] <- Tbar[,,i] + wt[i,k] * tarray[,,k]

* }
*

Tbar[,,i] <- Tbar[,,i] / wti[i]

* }
*

###############################################

Thanks very much,

Ravi.

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Jul 17 08:16:04 2006

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.1.8, at Mon 17 Jul 2006 - 10:20:01 EST.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*