Skip to content

Instantly share code, notes, and snippets.

@Planeshifter
Created May 26, 2014 00:55
Show Gist options
  • Save Planeshifter/00a3aa94f6d2083f4d89 to your computer and use it in GitHub Desktop.
Save Planeshifter/00a3aa94f6d2083f4d89 to your computer and use it in GitHub Desktop.
R.parseEvalQ('Beta = matrix(rnorm(50),nrow=5,ncol=10);' +
'Beta[5,] = 1;' +
'prob = apply(X,1,function(x){exp(Beta %*% x)});' +
'prob = sweep(prob, 2, colSums(prob), FUN="/");' +
'y = t(apply(prob,2,FUN=function(p) rmultinom(1,1,p)))');
y = R.get('y')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment