楼主: dhb19900703
2789 3

[问答] 新人求助关于R的bayesm库里面的bayesBLP example的运行 [推广有奖]

  • 0关注
  • 0粉丝

等待验证会员

小学生

0%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
36 点
帖子
3
精华
0
在线时间
4 小时
注册时间
2015-6-7
最后登录
2015-11-16

楼主
dhb19900703 发表于 2015-11-16 07:46:52 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
老师把pdf给我叫我用R运行一次bayesblp,我菜鸟,复制到R里面运行没反应啊
Examples
if(nchar(Sys.getenv("LONG_TEST")) != 0) {
###
### Simulate aggregate level data
###
simulData <- function(para, others, Hbatch){
#
# Keunwoo Kim, UCLA Anderson
#
### parameters
theta_bar <- para$theta_bar
Sigma <- para$Sigma
tau_sq <- para$tau_sq
T <- others$T
J <- others$J
p <- others$p
H <- others$H
K <- J + p
# Hbatch does the integration for computing market shares in batches of
# size Hbatch
### build X
X <- matrix(runif(T*J*p), T*J, p)
inter <- NULL
for (t in 1:T){
inter <- rbind(inter, diag(J))
}
X <- cbind(inter, X)
### draw eta ~ N(0, tau_sq)
eta <- rnorm(T*J)*sqrt(tau_sq)
X <- cbind(X, eta)
share <- rep(0, J*T)
for (HH in 1:(H/Hbatch)){
### draw theta ~ N(theta_bar, Sigma)
cho <- chol(Sigma)
theta <- matrix(rnorm(K*Hbatch), nrow=K, ncol=Hbatch)
theta <- t(cho)%*%theta + theta_bar
### utility
V <- X%*%rbind(theta, 1)
expV <- exp(V)
expSum <- matrix(colSums(matrix(expV, J, T*Hbatch)), T, Hbatch)
expSum <- expSum %x% matrix(1, J, 1)
choiceProb <- expV / (1 + expSum)
share <- share + rowSums(choiceProb) / H
}
### the last K+1'th column is eta, which is unobservable.
X <- X[,c(1:K)]
return (list(X=X, share=share))
}
### true parameter
theta_bar_true <- c(-2, -3, -4, -5)
Sigma_true <- rbind(c(3,2,1.5,1),c(2,4,-1,1.5),c(1.5,-1,4,-0.5),c(1,1.5,-0.5,3))
cho <- chol(Sigma_true)
r_true <- c(log(diag(cho)),cho[1,2:4],cho[2,3:4],cho[3,4])
tau_sq_true <- 1
### simulate data
set.seed(66)
T <- 300;J <- 3;p <- 1;K <- 4;H <- 1000000;Hbatch <- 5000
dat <- simulData(para=list(theta_bar=theta_bar_true, Sigma=Sigma_true, tau_sq=tau_sq_true),
others=list(T=T, J=J, p=p, H=H), Hbatch)
X <- dat$X
share <- dat$share
### Mcmc run
R <- 2000;H <- 50
Data1 <- list(X=X, share=share, J=J)
Mcmc1 <- list(R=R, H=H, nprint=0)
set.seed(66)
out <- rbayesBLP(Data=Data1, Mcmc=Mcmc1)
### acceptance rate
out$acceptrate
### summary of draws
summary(out$thetabardraw)
summary(out$Sigmadraw)
summary(out$tausqdraw)
### plotting draws
plot(out$thetabardraw)
plot(out$Sigmadraw)
plot(out$tausqdraw)
}
以上是R的代码,if(nchar(Sys.getenv("LONG_TEST")) != 0) 这一句什么意思我不懂,simulData <- function(para, others, Hbatch){ 这一句大概知道是用function函数去模拟一个数据组,但是代码这样写没法运行啊,我太菜了,hbatch是什么意思也不知道
谁愿意试着运行一次这个,看哪些地方有问题啊。为什么我的R完全不运行这个。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:example Bayes ExamP baye Exam example

沙发
dhb19900703 发表于 2015-11-16 07:48:23
https://cran.r-project.org/web/packages/bayesm/bayesm.pdf

好像复制代码过来显示错乱了
这个pdf的50页下面example部分开始52页上面为止的部分啊

藤椅
dhb19900703 发表于 2015-11-16 07:51:01
https://cran.r-project.org/web/packages/bayesm/bayesm.pdf
这个pdf的50页到52页的example部分,bayes BLP的
谁比较懂的帮我看下能运行不

板凳
代码小白 发表于 2021-6-27 17:16:17 来自手机
dhb19900703 发表于 2015-11-16 07:46
老师把pdf给我叫我用R运行一次bayesblp,我菜鸟,复制到R里面运行没反应啊
Examples
if(nchar(Sys.getenv ...
你好,我想请问下您关于berry论文中的一些问题可以吗?

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-27 07:45