0

In R, when I create a full factorial plan with the fac.design() function from the DoE.base package to reduce the number of necessary runs, the optFederov() function from the AlgDesign package gives a different answer every time the code is executed.

What code should I add to ensure that the optFederov() function gives a consistent answer?

I tried to use set.seed() but it has no effect here.

Here is a dummy code to show you the problem:

library(DoE.base)
library(AlgDesign)

plan <- fac.design(factor.names=list(A=c("A1","A2"), B=c("B1", "B2"), C=c("C1", "C2"), D=c("D1", "D2"), E=c("E1", "E2")), seed = 2000)

optFederov(data = plan, nTrials = 16, approximate = FALSE)

Indy
  • 1

1 Answers1

0

I am late on the answer but this might help others. You need to use set.seed() before every call to optFederov in order to get consistent results.

For example, in the next code, design_1 and design_2 are different:

set.seed(42)
design_1 <- optFederov(data = plan,
                     nTrials = 16,
                     approximate = FALSE)

design_2 <- optFederov(data = plan, nTrials = 16, approximate = FALSE)

print(all(design_1$rows == design_2$rows)) #> FALSE

But if you use set.seed before each call to optFederov, you get consistent results:

set.seed(42)
design_3 <- optFederov(data = plan,
                     nTrials = 16,
                     approximate = FALSE)

set.seed(42) design_4 <- optFederov(data = plan, nTrials = 16, approximate = FALSE)

print(all(design_3$rows == design_4$rows)) #> TRUE

You could also wrap optFederov in a function that sets the seed locally before calling it.

  • Thank you very much. The solution is simple and effective, but I would have never thought that the set.seed() function needed to be re-specified for each iteration of optFederov().

    The work is going to become much easier :)

    – Indy Mar 01 '24 at 14:07