library(dsample)
Please run demo(mix2)
and demo(mix3)
.
Data are taken from Dalal, Fowlkes, and Hoadley (1989). Details are described in Dezfuli et al. (2009) on pages 144–146.
<- str2expression("
expr lp <- 0
for(i in 1:len) lp <- lp +
y[i] * log(exp(alpha + beta*temp[i])/(1+exp(alpha + beta*temp[i])))
for(i in 1:len) lp <- lp +
(1-y[i])*log(1/(1+exp(alpha + beta*temp[i])))
lp <- lp + alpha - exp(alpha)/b
lp <- exp(lp)
")
<- list(
sets alpha=runif(n=nd, min=10, max=20),
beta=runif(n=nd, min=-0.3, max=-0.15)
)
<- dsample(expr=expr, rpmat=sets, nk=1e3, n=1e3)
smp <- summary(smp)
op $means
op#> alpha beta
#> 15.1416129 -0.2345963
$stdevs
op#> alpha beta
#> 1.18252018 0.01836517
Data are taken from Prentice (1976). Details are described in OpenBUGS Examples Vol 2. Beetles.
<- str2expression("
expr sigma <- exp(log.sigma)
m1 <- exp(log.m1)
lp <- 0
for(i in 1:len) lp <- lp +
yi[i]*m1*log((exp((wi[i]-mu)/sigma)/(1+exp((wi[i]-mu)/sigma))))
for(i in 1:len) lp <- lp +
(ni[i]-yi[i])*log(( 1- (exp((wi[i]-mu)/sigma)/(1+exp((wi[i]-mu)/sigma)))^m1 ))
lp <- lp + (a-1)*log.m1 - 2*(e+1)*log.sigma
lp <- lp - 0.5*((mu-c1)/d)^2
lp <- lp - m1/b - 1/(f*sigma^2)
lp <- exp(lp)
")
<- list(
sets mu=runif(nd, min=1.75, max=1.85),
log.sigma=runif(nd, min=-5, max=-3),
log.m1=runif(nd, min=-2, max=0.1)
)
<- dsample(expr=expr, rpmat=sets, nk=1e3, n=1e3)
smp <- summary(smp)
op $means
op#> mu log.sigma log.m1
#> 1.813845 -4.082532 -1.174099
$stdevs
op#> mu log.sigma log.m1
#> 0.0154026 0.2642583 0.3701782
Data are taken from Ratkowsky (1986). Details are described in OpenBUGS Examples Vol 2.Dugongs.
<- str2expression("
expr lp <- (len/2 + k - 1)*log(tau)
for(i in 1:len) lp <- lp -
tau*0.5*(y.length[i] - alpha+beta*gamma^x.age[i])^2
lp <- lp - tau*k - tau.alpha*alpha^2*0.5 - tau.beta*beta^2*0.5
lp <- exp(lp)
")
<- list(
sets alpha=runif(nd, min=2, max=3),
beta=runif(nd, min=0.5, max=1.5),
gamma=runif(nd, min=0.5, max=1.5),
tau=runif(nd, min=0.2, max=200)
)
<- dsample(expr=expr, rpmat=sets, nk=1e3, n=1e3)
smp <- summary(smp)
op $means
op#> alpha beta gamma tau
#> 2.5921814 0.9837057 0.8154180 122.4837366
$stdevs
op#> alpha beta gamma tau
#> 0.1859048 0.1783082 0.1047462 51.0445042
Data are taken from Diggle and Marron (1988).
<- str2expression("
expr ll <- 0
ll <- ll + (cum.x.until.k[kappa]-0.5)*log(theta) +
(cum.x.after.k[kappa]-0.5)*log(lambda) -
kappa*theta - (len-kappa)*lambda
lp <- ll + 1.5*log(alpha) + 1.5*log(beta) -
(theta+1)*alpha - (lambda+1)*beta
lp <- exp(lp)
")
<- list(
sets kappa=sample(x=30:50, size=nd, replace=TRUE),
theta=runif(nd, min=2.2, max=4),
lambda=runif(nd, min=0.6, max=1.4),
alpha=runif(nd, min=0, max=2),
beta=runif(nd, min=0, max=4)
)
<- dsample(expr=expr, rpmat=sets, nk=1e3, n=1e3)
smp <- summary(smp)
op $means
op#> kappa theta lambda alpha beta
#> 40.1420000 3.0530883 0.9149556 0.6408854 1.3262175
$stdevs
op#> kappa theta lambda alpha beta
#> 2.6150860 0.3075382 0.1258025 0.3889245 0.7792260
Data are taken from Gaver and O’Muircheartaigh (1987). Details are described in OpenBUGS Examples Vol 2..
<- str2expression("
expr ll <- 0
for(i in 1:len){
sum.cmd <- gsub(' ', '', paste('ll <- ll +(failure[', i,']+alpha-1)*log(lambda', i,')'))
eval(parse(text=sum.cmd))
}
for(i in 1:len){
sum.cmd <- gsub(' ', '', paste('ll <- ll - (time[', i,']+bb)*lambda', i))
eval(parse(text=sum.cmd))
}
lp <- ll + (10*alpha+gg-1)*log(bb) - delta*bb
lp <- exp(lp)
")
<- list(
sets bb=runif(nd, 0, 4),
lambda1=runif(nd, 0, 0.2),
lambda2=runif(nd, 0, 0.4),
lambda3=runif(nd, 0, 0.25),
lambda4=runif(nd, 0, 0.25),
lambda5=runif(nd, 0, 2),
lambda6=runif(nd, 0, 1.5),
lambda7=runif(nd, 0, 2),
lambda8=runif(nd, 0, 2),
lambda9=runif(nd, 0, 4),
lambda10=runif(nd, 0, 3.5)
)
<- dsample(expr=expr, rpmat=sets, nk=5e4, n=3e3)
smp <- summary(smp)
op $means
op#> bb lambda1 lambda2 lambda3 lambda4 lambda5 lambda6
#> 1.10946266 0.06747204 0.10239138 0.09436450 0.11230018 0.57639415 0.61232911
#> lambda7 lambda8 lambda9 lambda10
#> 0.78275520 0.78171333 1.40242048 1.93788664
$stdevs
op#> bb lambda1 lambda2 lambda3 lambda4 lambda5 lambda6
#> 0.65214851 0.03357516 0.08561880 0.04104042 0.03711780 0.34884930 0.20068897
#> lambda7 lambda8 lambda9 lambda10
#> 0.43586702 0.47294621 0.84314819 0.52456361