[R] Help on vectorizing

From: Vidyut (Yahoo) <vidyut.vidyut_at_gmail.com>
Date: Thu, 17 Apr 2008 16:54:43 -0400


Hi,

I am a newbie at R and was thinking of ways to vectorize this loop but can't quite figure out if anything more can be done :

Here the dimensions of the arrays are (N=2000, K=2, D=1000): responsibilities : N * K
pi: K
corp: N*D
theta: K*D

    for (n in 1:N)

        {
            for (k in 1:K)
            {
                responsibilities[n, k] <- (pi[k]) +
(log1p(dmultinom(x=corp[n, ], prob=exp(theta[k, ]))))
            }
            denom <- log.sum(responsibilities[n, ])
            responsibilities[n,] <- responsibilities[n, ] - denom
        }


Any help is much appreciated!

thanks.

        [[alternative HTML version deleted]]



R-help_at_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. Received on Thu 17 Apr 2008 - 20:57:49 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 17 Apr 2008 - 22:30:29 GMT.

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

list of date sections of archive