R:Bayesn包中的分层Bayesn错误

时间:2015-02-08 15:08:16

标签: r bayesian

披露:我刚开始从事分析,并掌握有关统计学的基本知识。

您好,

我正在尝试使用Bayesm Package中的函数rhierMnlRwMixture在R中执行HB分析。我在Algdesign包中使用了optfederov函数来创建选择集。然后我使用excel将这些选择集转换为设计矩阵。当我运行rhierMnlRwMixture时,我收到此错误:

chol.default(H)出错:第3阶段的主要未成年人不是肯定的

我搜索并了解这是因为设计矩阵的等级不足以执行一个名为“Metropolis”的算法。

因此,我更改了属性,级别和运行次数,并发现如果属性和级别数量较少且运行次数较多,则代码会执行。示例的Attributes数= 3,Levels = 3,运行次数= 9.

问题是如果我增加属性数量,我的代码会返回上述错误。如何确保设计矩阵的等级足够大?

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")

0 个答案:

没有答案