rparallel-processingsnowfall

Using snowfall package in R to do some simulation


I am staring work with snowfall package in that way:

library(snowfall)
sfInit(parallel=TRUE, cpus=6, type="SOCK")
#loading packages
sfLibrary(package = lars)
sfLibrary(package=covTest) 

Function that I want to compute multiple times using sfLapply:

funkcja <- function(i,k=5)
{
  beta <- c(k,k,0,k,k,rep(0,35))
  X <- matrix(rnorm(100*40),100,40)
  Y <- X%*%beta+rnorm(100)
  lasso.lars <- lars(X,Y,intercept=FALSE,use.Gram=FALSE)
  test <- covTest(lasso.lars,X,Y,sigma.est=1)
  test
}

But when I try this

sfLapply(1:100,funkcja)

I get error: "Error in checkForRemoteErrors(val): 6 nodes produced errors; first error: object 'Y' not found". But when I hide the last but one line and change test for lasso.lars then there is no longer trobule about vector Y:

funkcja <- function(i,k=5)
{
  beta <- c(k,k,0,k,k,rep(0,35))
  X <- matrix(rnorm(100*40),100,40)
  Y <- X%*%beta+rnorm(100)
  lasso.lars <- lars(X,Y,intercept=FALSE,use.Gram=FALSE)
  #test <- covTest(lasso.lars,X,Y,sigma.est=1)
  lasso.lars
}

I dont understand this because the line

test <- covTest(lasso.lars,X,Y,sigma.est=1)

should work since

lars(X,Y,intercept=FALSE,use.Gram=FALSE)

can work. I will be grateful for your help.


Solution

  • My guess is that Y is hiding and internal variable. The following function works (changed the case of "Y" to "y")

    funkcja <- function(i,k=5)
    {
      beta <- c(k,k,0,k,k,rep(0,35))
      X <- matrix(rnorm(100*40),100,40)
      y <- X %*% beta + rnorm(100)
    
      lasso.lars <- lars(X,y,intercept=FALSE,use.Gram=FALSE)
      test <- covTest(lasso.lars,X,y,sigma.est=1)
      test
    }