Anamika Chaudhuri
2010-Aug-16 21:01 UTC
[R] Specify decimal places for parameters in BUGS output
Hi All: I had a basic question to ask. I am running R2WinBUGS so that I could automate the running of my model using 1000 simulated datasets. Below is the code I am using. The only problem I am having is the bugs output that comes out shows my parameters as nos with 1 decimal place after. I would want to have the parameters with 5 places after decimal. How would I specify that in my code for R2WinBUGS. trial.data <- read.table("trial_data.txt", header=T) bugs.output <- list() for(i in 1:5){ nausea <- as.integer(trial.data[i,]) bugs.output[[i]] <- bugs( data=list(nausea=nausea, N=63), inits=list( list(alpha0=0,tau=1), list(alpha0=0.9, tau=1), list(alpha0=0.8,tau=1) ), model.file="B-LN_model_trial.txt", parameters.to.save = c("sigma", "tau","alpha0","p"), n.chains=3, n.iter=12000, n.burnin=5000, bugs.directory="E:/AChaudhuri/winbugs14/WinBUGS14")} print(bugs.output) The output comes out as Inference for Bugs model at "B-LN_model_trial.txt", fit using WinBUGS, 2 chains, each with 12000 iterations (first 5000 discarded), n.thin = 14 n.sims = 1000 iterations saved mean sd 2.5% 25% 50% 75% 97.5% Rhat n.eff sigma 1.2 0.2 1.0 1.1 1.2 1.3 1.6 1 630 tau 0.7 0.2 0.4 0.6 0.7 0.8 1.0 1 630 alpha0 -2.0 0.2 -2.3 -2.1 -2.0 -1.9 -1.7 1 330 p[1] 0.2 0.0 0.1 0.1 0.2 0.2 0.3 1 1000 p[2] 0.1 0.0 0.0 0.1 0.1 0.1 0.2 1 1000 p[3] 0.0 0.0 0.0 0.0 0.0 0.1 0.1 1 1000 etc> Thanks >Anamika [[alternative HTML version deleted]]
On 16.08.2010 23:01, Anamika Chaudhuri wrote:> Hi All: > > I had a basic question to ask. I am running R2WinBUGS so that I could > automate the running of my model using 1000 simulated datasets. Below is the > code I am using. The only problem I am having is the bugs output that comes > out shows my parameters as nos with 1 decimal place after. I would want to > have the parameters with 5 places after decimal. How would I specify that in > my code for R2WinBUGS. > > trial.data<- read.table("trial_data.txt", header=T) > bugs.output<- list() > for(i in 1:5){ > nausea<- as.integer(trial.data[i,]) > bugs.output[[i]]<- bugs( > data=list(nausea=nausea, N=63), > inits=list( > list(alpha0=0,tau=1), > list(alpha0=0.9, tau=1), > list(alpha0=0.8,tau=1) > ), > model.file="B-LN_model_trial.txt", > parameters.to.save = c("sigma", "tau","alpha0","p"), > n.chains=3, n.iter=12000, n.burnin=5000, > bugs.directory="E:/AChaudhuri/winbugs14/WinBUGS14")} > print(bugs.output) > > The output comes out as > Inference for Bugs model at "B-LN_model_trial.txt", fit using WinBUGS, > 2 chains, each with 12000 iterations (first 5000 discarded), n.thin = 14 > n.sims = 1000 iterations saved > mean sd 2.5% 25% 50% 75% 97.5% Rhat n.eff > sigma 1.2 0.2 1.0 1.1 1.2 1.3 1.6 1 630 > tau 0.7 0.2 0.4 0.6 0.7 0.8 1.0 1 630 > alpha0 -2.0 0.2 -2.3 -2.1 -2.0 -1.9 -1.7 1 330 > p[1] 0.2 0.0 0.1 0.1 0.2 0.2 0.3 1 1000 > p[2] 0.1 0.0 0.0 0.1 0.1 0.1 0.2 1 1000 > p[3] 0.0 0.0 0.0 0.0 0.0 0.1 0.1 1 1000 > etcTo get rounded to 5 decimal places, use print(bugs.output, digits.summary=5) if you want exactly 5 places everywhere, you need to write your own print method. The information is represented as precisely as possible within the original object, bugs.output. Uwe Ligges>> Thanks >> > Anamika > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.