希望你一切都好。我正在使用 ChoiceModelR 估计分层贝叶斯选择模型。这是一个很长的代码,除了这个块之外,它可以完美地工作。每次我运行这个块时,我都会收到错误:“choicemodel()”中的错误:!缺少参数“目录”,没有默认值。准确的说,问题出在hb.post。那条线会产生混乱!请帮助我。
choice <- rep(0, nrow(cbc.df))
choice[cbc.df[,"alt"]==1] <- cbc.df[cbc.df[,"choice"]==1,"alt"]
head(choice)
cbc.coded <- model.matrix(~ cereal_label + bill + quantity + price, data = cbc.df)
cbc.coded <- cbc.coded[, -1] # remove the intercept
choicemodelr.data <- cbind(cbc.df[,1:3], cbc.coded, choice)
head(choicemodelr.data)
cerealpool <- cbc.df$cerealpool[cbc.df$ques==1 & cbc.df$alt==1]=="yes"
cerealpool <- as.numeric(cerealpool)
choicemodelr.demos <- as.matrix(cerealpool, nrow=length(cerealpool))
str(choicemodelr.demos)
library(ChoiceModelR)
hb.post <- choicemodelr(data=choicemodelr.data, xcoding=rep(1, 7),
demos=choicemodelr.demos,
mcmc=list(R=20000, use=10000),
options=list(save=TRUE))
names(hb.post)
Error in `choicemodelr()`:
! argument "directory" is missing, with no default
Backtrace:
1. ChoiceModelR::choicemodelr(...)
3. base::paste(directory, "/", "RLog.txt", sep = "")
Execution halted
Warning message:
In sink() : no sink to remove
请尝试一下
hb.post <- choicemodelr(data=choicemodelr.data, xcoding=rep(1, 7),
demos=choicemodelr.demos,
mcmc=list(R=20000, use=10000),
options=list(save=TRUE),
directory=getwd())