Skip to content

Instantly share code, notes, and snippets.

@ramiroluz
Last active October 3, 2017 20:18
Show Gist options
  • Save ramiroluz/ab6cd965a49355b3d6f051be7a1e27bb to your computer and use it in GitHub Desktop.
Save ramiroluz/ab6cd965a49355b3d6f051be7a1e27bb to your computer and use it in GitHub Desktop.
import numpy
from rpy2 import robjects
import rpy2.robjects.numpy2ri
rpy2.robjects.numpy2ri.activate()
mirtCAT = robjects.r('library(mirtCAT)')
simdata = robjects.r('simdata')
mirt = robjects.r('mirt')
nitems = 50
itemnames = ['Item.{}'.format(n) for n in range(1, nitems+1)]
numpy.random.seed(1234)
a = numpy.matrix(numpy.random.lognormal(0.2, 0.3, nitems))
d = numpy.matrix(numpy.random.normal(size=nitems))
# FIXED: it must be a matrix with an array.
# Not working: rpy2.rinterface.RRuntimeError: Error in d[i, ] : número incorreto de dimensões
dat = simdata(a, d, 1000, itemtype = 'dich')
@ramiroluz
Copy link
Author

In [7]: d
Out[7]:
array([-0.46930528, 0.67555409, -1.81702723, -0.18310854, 1.05896919,
-0.39784023, 0.33743765, 1.04757857, 1.04593826, 0.86371729,
-0.12209157, 0.12471295, -0.32279481, 0.84167471, 2.39096052,
0.07619959, -0.56644593, 0.03614194, -2.0749776 , 0.2477922 ,
-0.89715678, -0.13679483, 0.01828919, 0.75541398, 0.21526858])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment