Disclosure: I have just started my career in Analytic and have basic knowledge about statistics.
Hi,
I am trying to execute HB analysis in R using the function rhierMnlRwMixture in the Bayesm Package. I have used the optfederov function in Algdesign package to create choice sets. I then convert those choice sets into a design matrix using excel.When I run rhierMnlRwMixture I get this error:
Error in chol.default(H) :the leading minor of order 3 is not positive definite
I searched and understood that this occurs because of the rank of the design matrix is not enough to execute an algorithm called "Metropolis".
So, I changed the number of attributes, levels and number of runs and found that the code execute if number of attributes and levels is low and number of runs is high . example number of Attributes = 3, Levels = 3 each and number of runs = 9.
The problem is if I increase the number of attributes my code returns the above error. How do I ensure that the rank of my design matrix is big enough ?
install.packages("AlgDesign")
library("AlgDesign", lib.loc="E:/R/R-3.1.2/library")
install.packages("dplyr")
library("dplyr", lib.loc="E:/R/R-3.1.2/library")
# making a full factorial design with 4 attributes each with 3 levels
ffd = gen.factorial(c(3,3,3,3),varNames = c("A","B","C","D"),factors="all")
# making orthogonal factorial design
des = optFederov(~.,ffd,9,crit = "D",nRepeats = 100)
# the criteria Ge = 1 shows the design is orthogonal
des
# passing design to choice 1
ch1 = des$design
# making 3 copies, the design has 3 choice set in each question
ch2 = ch1
ch3 = ch1
# adding a random variable to make three choice sets
ch1 = transform(ch1,r1 = runif(9))
ch2 = transform(ch2,r1 = runif(9))
ch3 = transform(ch3,r1 = runif(9))
#sorting
ch1_sort = arrange(ch1,r1)
ch2_sort = arrange(ch2,r1)
ch3_sort = arrange(ch3,r1)
# output
write.csv(ch1_sort,"ch1_sort.csv")
write.csv(ch2_sort,file = "ch2_sort.csv")
write.csv(ch3_sort,file = "ch3_sort.csv")