On Wed, Aug 8, 2012 at 10:37 AM, alijk1989 [via R] <ml-node+s789695n4639622...@n4.nabble.com> wrote: > > > Hi Michael, > > Thanks for your response. Here is a simple example of what I am trying to > do: > > w=rep(0.02,10) > Q=rep(0.02,10) > rho=matrix(0.5,nrow=10,ncol=10) > m=10 > LGD=0.45 > > M1=sum(sapply(1:m, > function(k){sum(sapply(1:m,function(j){w[k]*w[j]*LGD^2*(pmnorm(c(qnorm(Q[k]),qnorm(Q[j])),c(0,0),equicorr(2,rho[k,j]))-Q[k]*Q[j])}))})) > > It uses the mnormt and QRM packages. > > I am trying to reproduce the following sum: > > \sum\limits_{j=1}^M \sum\limits_{k=1}^M w_j w_k > LGD^2[N_2(N^{-1}[Q(j)],N^{-1}[Q(k)],\rho_{jk})-Q(j)Q(k)]
Hi Alijk, The problem ultimately comes from the fact that equicorr() is not nicely vectorized so you'll need to home-brew something to replace it, but that's not hard. However, I don't think that pmnorm is vectorized in the varcov argument: we can probably work out the double sapply() loop if you can assume rho is constant, otherwise I think you're stuck. Michael > > > > _______________________________________________ > If you reply to this email, your message will be added to the discussion > below: > http://r.789695.n4.nabble.com/sapply-and-matrix-command-tp4637769p4639622.html > > To unsubscribe from sapply and matrix command, visit > http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4637769&code=ci1oZWxwQHItcHJvamVjdC5vcmd8NDYzNzc2OXwtNzg0MjM1NTA4 > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.