1

I have an operation I am running in R, and want to know if there is any set of rules that can help me determine if I want the operation to be performed over rows or columns, given that transposing a matrix is a matter of programming preference otherwise.

The only regular advice I have so far is: Test it on a subsample every time. Can we do better than that in any way, say: Division is best longer than wider? If we can't do better than that, why not?

I have programmed my specific operation of interest to be as follows, but keep in mind I am more interested in this in general than in specific:

support_n: Some matrix I'm investigating. It is, (N) x (K choose N). K is >50, N>4

fz(): A bland function of several variables, polynomials, max, and min.

fz<-function(z,vec_l){ 
  if(z%in%vec_l){ #find if z is eqivilant to any number, return 0
    out<-0
  } else if(z>max(vec_l)){
    out<-z^2*max(vec_l)^2
  } else {
    out<-z^2+min(vec_l)^2
  }
  out
}

registerDoParallel(cl)
system.time(
payoff<-foreach(y=1:n, .combine='cbind') %:%  
  foreach(x=1:ncol(support_n), .combine='c')  %dopar% {
    fz(support_n[y,x],support_n[-y,x])
  }
)

So should I run this over y's or x's first, in general? Why?

RegressForward
  • 280
  • 1
  • 15

0 Answers0