Question

I'm running Jags/ Winbugs in R, which works fine, but I can't save the output to a text or csv file (either would work)

TEST.sim<- jags(data=jags.data, 
                parameters.to.save=jags.params, 
                n.iter=200000,jags.seed=123, 
                model.file="~/Documents/ARRModel.txt")

What I need is a way to save the output that comes up when I enter:

print(TEST.sim)

When I try write.table it gives the following error: cannot coerce class '"bugs"' into a data.frame

Was it helpful?

Solution

If you are using library R2jags and function jags() then function print() makes table of statistics that are stored in list element BUGSoutput and sublist summary. You can access those data directly and store as other object (or just use directly in function write.table()) and then write to text file.

jag.sum<-TEST.sim$BUGSoutput$summary
jag.sum

                mean         sd        2.5%         25%         50%          75%        97.5%     Rhat n.eff
alpha     19.6399640 1.22982919  17.1888046  18.8401629  19.6391880  20.45108889  22.03860486 1.001312  4100
beta1     -0.1063905 0.01755548  -0.1409861  -0.1180097  -0.1064871  -0.09469226  -0.07198614 1.001028 18000
beta2     -0.1857631 0.03667742  -0.2573464  -0.2103279  -0.1860142  -0.16155874  -0.11304929 1.001138  7700
deviance 192.6742580 3.02780455 188.9038177 190.4371154 192.0046398 194.13875526 200.28772929 1.001252  4800

write.table(x=jag.sum,file="out.txt",sep="\t")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top