Just when I am about to convert myself into a Linux user, I found this. Running R in the command mode in the Window system is much faster. Here is a simple test:
in the Window interface:
> system.time(rnorm(1000000)%*%rnorm(1000000))
user system elapsed
1.06 0.05 1.14
in the command mode
> system.time(rnorm(1000000)%*%rnorm(1000000))
user system elapsed
0.70 0.01 0.72
So it is two times faster to run the above test in the command mode than to run it in the Window interface. Then I go on to run R2jags with 8 schools example with 10000 iteration. It finishes the whole updating quick. It is almost as quick as I would have run it under the Linux system. Hum, maybe I will do my statistical analysis with R in the command mode from now on!!
4 hours ago
4 comments:
So how exactly can I do this?
In Window XP, Start --> Run, and type cmd.
In Window Vista, Start --> in the search bar, type cmd.
Hi, Yu sung,
I am running some codes in openbugs. The code can be run in the winbugs but not in the openbugs.
Here is the error message:
model is syntactically correct
data loaded
model compiled
model is initialized
model is updating
****** Sorry something went wrong in procedure Updater.Derivatives in module UpdaterDFreeHybrid ******
Here is my code:
model {
for (i in 1:N) {
for (n in 1:n.inteval) {
labda1[i,n] <-inprod(G0[n], I0[i,n]);
G0T[i,n] <- inprod(G0[n],dt1[i,n]);
labda2[i,n] <-inprod(G1[n], I1[i,n]);
G0T1[i,n] <- inprod(G1[n],dt2[i,n]);
}
logit(pi[i]) <- beta[1] + beta[2] *x1[i]+beta[3]*x2[i]+beta[4]*x3[i];
pi.comp[i] <- 1-pi[i];
# the exponential of the X*\beta
exp.cov1[i] <- exp(beta1[1]*x1[i]+beta1[2]*x4[i]+B[i]);
exp.cov2[i] <- exp(beta2[1]*x5[i]+beta2[2]*x4[i]+B[i]);
# haz1N: hazard functions
haz1N[i] <- exp.cov1[i]*sum(labda1[i,]);
haz1T[i] <- haz1N[i]*exp(gamma1);
# S1N, S1T: survival functions for TR and NP of t1
S1N[i]<- exp(-exp.cov1[i]*sum(G0T[i,]));
S1T[i] <- exp(-exp.cov1[i]*exp(gamma1)*sum(G0T[i,]));
# haz2N, haz2T: hazard functions for TR and NP of t2
haz2N[i] <- exp.cov2[i]*sum(labda2[i,]);
haz2T[i] <- haz2N[i]*exp(gamma2);
# S2N, S2T: survival functions for TR and NP of t2
S2N[i]<- exp(-exp.cov2[i]*sum(G0T1[i,]));
S2T[i] <- exp(-exp.cov2[i]*exp(gamma2)*sum(G0T1[i,]));
# L1N, L1T: likelihood functions for TR and NP of t1
L1N[i] <- haz1N[i]*S1N[i];
L1T[i] <- haz1T[i]*S1T[i];
# L2N, L2T: likelihood functions for TR and NP of t2
L2N[i] <- pow(haz2N[i], delta[i])*S2N[i];
L2T[i] <- pow(haz2T[i], delta[i])*S2T[i];
L1L2N[i] <- L1N[i] * L2N[i];
L1L2T[i] <- L1T[i] * L2T[i];
p1[i] <- pi[i]*SN1*L1L2N[i] + pi.comp[i]*SP1.comp*L1L2T[i] ; # pr(y1=1 & y2=1)
p2[i] <- pi[i]*SN1.comp*SNg*L1L2N[i] + pi.comp[i]*SP1*SPg.comp*L1L2T[i]; # pr(y1=0 & y2=1)
p4[i] <- pi[i]*SN1.comp*SNg.comp*L1L2N[i] + pi.comp[i]*SP1*SPg*L1L2T[i] ;
l[i] <- pow(p1[i], myY1[i]*myY2[i]) * pow(p2[i], myY1.comp[i]*myY2[i])* pow(p4[i],myY1.comp[i]*myY2.comp[i]) /1.0E+06;
zeros[i] <- 0.0;
phi[i] <- -log(l[i]);
zeros[i] ~ dpois(phi[i]);
# shared frailty
B[i] ~ dnorm(0, tau.b);
}
for (i in 1:n.inteval) {
G0[i] ~ dgamma(1, 0.1);
G1[i] ~ dgamma(1, 0.1);
}
SN1 ~ dunif(0.5, 1); # the priors are specified for Se and Sp
SP1 ~ dunif(0.5, 1);
SNg ~ dunif(0.0, 0.5) ;# the priors are specified for Se and Sp
lowerBound <- 0.5/SP1;
SPg ~ dunif(lowerBound, 1);
SN1.comp <- 1-SN1;
SP1.comp <- 1-SP1;
SNg.comp <- 1-SNg;
SPg.comp <- 1-SPg;
SN2 <- SN1 + SN1.comp*SNg;
SP2 <- SP1*SPg;
# prior for the variance of the frailty
tau.b ~ dgamma(0.01, 0.01);
sigma.b <- 1/tau.b;
# priors for beta's in logistic regression
beta[1] ~ dnorm(beta.hat[1], 0.1);
beta[2] ~ dnorm(beta.hat[2], 0.1) ;
beta[3] ~ dnorm(beta.hat[3], 0.1) ;
beta[4] ~ dnorm(beta.hat[4], 0.1) ;
# priors for beta's in t1
beta1[1] ~ dnorm(beta1.hat[1], 0.1) ;
beta1[2] ~ dnorm(beta1.hat[2], 0.1) ;
# priors for beta's in t2
beta2[1] ~ dnorm(beta2.hat[1], 0.1) ;
beta2[2] ~ dnorm(beta2.hat[2], 0.1) ;
# priors for gamma1 and gamma2
gamma1 ~ dnorm(0, 0.1);
gamma2 ~ dnorm(0, 0.1) ;
}
If you could give me some help in how to find the problem, I am really appreciate.
Thank you so much!
Min
I am running into the same problem with OpenBUGS, but WinBUGS runs ok, can't find solution.
Post a Comment