1

I'm using a 4 parameter log logistic curve to model a time series. Since some time trends were not converging fast enough, and so were producing errors, I used TryCatch so that the loop wouldn't break and I could still get the results for the remaining rows. Here's the function I wrote up:

sig_reg <- function(vec)
{
  df_tst <- data.frame(y=vec, x = 1:29)
  
  tmp_vec <- tryCatch({
    llm4 <- drm(y ~ x, fct = LL.4(names = c("Slope", "Lower Limit", "Upper Limit", "ED50")), data = df_tst)
    return(c(coef(summary(llm4))[1], coef(summary(llm4))[2], coef(summary(llm4))[3], coef(summary(llm4))[4]))
  }, 
  
  error=function(e){
    return(c(0,0,0,0))
  })
  
  return(tmp_vec)
}

Now when I call this function with apply (as so: apply(tmp_clsm, 1, sig_reg)), it runs as expected and gives me the output I want, i.e, the coefficients of the log-logistic curve. To make things clear tmp_clsm looks like this:

FCNT_92 FCNT_93 FCNT_94 FCNT_95 FCNT_96 FCNT_97 FCNT_98 FCNT_99 FCNT_00 FCNT_01
1  0.6409  0.6409  0.6409  0.6409  0.6409  0.6409  0.6409  0.6409  0.6409  0.6409
2  1.9597  1.9597  1.9597  1.9597  1.9597  1.9597  1.9597  1.9597  1.9597  1.9597

Note: I have shortened the time series to show only 10 columns for each row. In fact it contains 29 columns.

Now, since I have to perform the same operation for close to 3 million rows, I thought of using sfApply from within the snowfall package. This is the command I use:

sfApply(tmp_clsm, 1, sig_reg)

However, the output just produces rows of 0's.

What am I doing wrong? And how can I make my function work with sfApply?

lomoshome
  • 11
  • 1
  • Not exactly what you've asked for, but you could try to use [`future.apply::future_apply()`](https://future.apply.futureverse.org/). It's designed, implemented, and tested to give identical results as `base::apply()`, including how errors are produced, but with the option to run in parallel. – HenrikB Mar 10 '23 at 18:00

0 Answers0