I am trying to create a factorial design in R for a conjoint analysis experiment (like SPSS orthoplan).
Searching among past Stackoverflow questions, I have found this previous answer:
How to create a fractional factorial design in R?
It is indeed an useful answer but only in the case you have factors with numeric levels.
That's unfortunately not my case, because the factors I want to use are nominal variable, i.e. their levels are not numeric type but factor type: for example I have to deal with a factor indicating the color of a product which can be green, yellow or red.
I've tried modifying the code proposed as an answer to the question How to create a fractional factorial design in R? in such a way:
f.design <- gen.factorial(levels.design,factors="all")
but the result is nor balanced, nor orthogonal. Moreover, you have to define the exact number of trials in the optFederov function. In that answer the suggested number of trials was :
nTrials=sum(levels.design)
but in order to have a balanced solution in a design with nominal factors, I expect it should at least be :
nTrials=prod(unique(levels.design))
There's a package anyway that could deal with such an issue, it is the package FrF2
by Prof. Ulrike Groemping, but it handles only dichotomous variables and I cannot figure out how to use it to solve my problem.
After having been for a while researching an answer by myself, I can share here what I have found:
yes, you can build orthogonal designs in R, in a similar fashion as it happens in SPSS orthoplan.
Just define the variable nlevels
as a vector containing the levels of your variables.
Then you have to call:
library(DoE.base)
fract.design <- oa.design(nlevels=levels.design)
The function will look up into a library of orthogonal designs (exactly Kuhfeld W., 2009, Orthogonal arrays)
If there isn't a suitable available orthogonal design, the function will just return the full factorial design (and therefore you'll have no other choice in R but to call the optFederov function, as explained above in my question).
As an example try:
oa.design(nlevels=c(2,2,3))
oa.design(nlevels=c(2,2,4))
The first doesn't have a solution (so you'll get back the full factorial), but the second one does have a solution, an 8 cards, orthogonal and balanced design.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With