{"id":37,"date":"2013-05-29T13:48:04","date_gmt":"2013-05-29T11:48:04","guid":{"rendered":"http:\/\/candrea.ch\/blog\/?p=37"},"modified":"2013-05-29T14:23:09","modified_gmt":"2013-05-29T12:23:09","slug":"parallel-computing-unidimtest-in-irt","status":"publish","type":"post","link":"https:\/\/candrea.ch\/blog\/parallel-computing-unidimtest-in-irt\/","title":{"rendered":"Parallel computing unidimTest in IRT"},"content":{"rendered":"<p>In the <a href=\"http:\/\/cran.r-project.org\" target=\"_blank\">R<\/a> package <a href=\"http:\/\/cran.r-project.org\/web\/packages\/ltm\/index.html\" target=\"_blank\">ltm<\/a>\u00a0by\u00a0Dimitris Rizopoulos there is a function called <a href=\"http:\/\/www.inside-r.org\/node\/64979\" target=\"_blank\">unidimTest()<\/a>. Computations of this function are very power consuming due the\u00a0Monte Carlo procedure used inside. Without parallelizing only one core of your (surely) multicore computer is used for this computation. A simple modification of <a href=\"http:\/\/www.inside-r.org\/node\/64979\" target=\"_blank\">unidimTest()<\/a> makes it possible to use the quite easy to use <a href=\"http:\/\/cran.r-project.org\" target=\"_blank\">R<\/a>\u00a0package <a href=\"http:\/\/cran.r-project.org\/web\/packages\/foreach\/index.html\" target=\"_blank\">foreach<\/a> for parallel computing using the <a href=\"http:\/\/cran.r-project.org\" target=\"_blank\">R<\/a>\u00a0packages <a href=\"http:\/\/stat.ethz.ch\/R-manual\/R-patched\/library\/parallel\/html\/parallel-package.html\" target=\"_blank\">parallel<\/a> and <a href=\"http:\/\/cran.r-project.org\/web\/packages\/doParallel\/index.html\" target=\"_blank\">doParallel<\/a>. See also <a href=\"http:\/\/viksalgorithms.blogspot.ch\/2012\/01\/parallel-r-loops-for-windows-and-linux.html\" target=\"_blank\">parallel-r-loops-for-windows-and-linux<\/a>\u00a0by Vik Paruchuri.<\/p>\n<p>I have changed the lines\u00a0of\u00a0<a href=\"http:\/\/www.inside-r.org\/node\/64979\" target=\"_blank\">unidimTest()<\/a><\/p>\n<pre class=\"lang:r decode:true\">for (b in 1:B) {\r\n  if (!missing(object)) \r\n    z.vals &lt;- rnorm(n, ablts, se.ablts)\r\n  data.new &lt;- rmvlogis(n, parms, IRT = IRT, z.vals = z.vals)\r\n  T.boot[b, ] &lt;- eigenRho(data.new)$ev\r\n}<\/pre>\n<p>to<\/p>\n<pre class=\"lang:r decode:true\">T.boot[,] &lt;- foreach(b=1:B, .combine=\"rbind\", .errorhandling=\"pass\") %dopar%\r\n{\r\n  #if (!missing(object)) \r\n  z.vals &lt;- rnorm(n, ablts, se.ablts)\r\n  data.new &lt;- rmvlogis(n, parms, IRT = IRT, z.vals = z.vals)\r\n  eigenRho(data.new)$ev   \t\r\n}<\/pre>\n<p>and named the function unidimTest.p().<\/p>\n<p>The function is called as<\/p>\n<pre class=\"lang:r decode:true\">library(foreach)\r\nlibrary(parallel)\r\nlibrary(doParallel)\r\n\r\nregisterDoParallel(cores=4) # put in here how many cores you want to be used\r\n\r\nset.seed(666)\r\nproc &lt;- proc.time()\r\nuni.p &lt;- unidimTest.p(fit.rasch.u, B=100)\r\nproc.time() - proc<\/pre>\n<p>and works at least on an Mac OS X (10.8.3) environment with\u00a0<a href=\"http:\/\/cran.r-project.org\" target=\"_blank\">R<\/a>\u00a0version 3.0.1.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the R package ltm\u00a0by\u00a0Dimitris Rizopoulos there is a function called unidimTest(). Computations of this function are very power consuming due the\u00a0Monte Carlo procedure used inside. Without parallelizing only one core of your (surely) multicore computer is used for this computation. A simple modification of unidimTest() makes it possible to use the quite easy to &hellip; <a href=\"https:\/\/candrea.ch\/blog\/parallel-computing-unidimtest-in-irt\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Parallel computing unidimTest in IRT<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-37","post","type-post","status-publish","format-standard","hentry","category-r"],"_links":{"self":[{"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/posts\/37"}],"collection":[{"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/comments?post=37"}],"version-history":[{"count":8,"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/posts\/37\/revisions"}],"predecessor-version":[{"id":45,"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/posts\/37\/revisions\/45"}],"wp:attachment":[{"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/media?parent=37"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/categories?post=37"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/tags?post=37"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}