1

I'm running a Hierarchical Lin Regr model using bayesm package in R. I have a data set with one dependent and 6 predictors. There are 207 unique respondents with 35 observations for each.

I began by using

print(out$betadraw)

Then I read about the sink function to output the out$betadraw to a file. I thought that sink function would capture all the draws. Instead the draws were truncated after certain number of draws.

I need to capture all the draws. In addition, is it possible to pass objects from bayesm package to coda package for convergence diagnostics? Any help would be greatly appreciated.

Henrik
  • 65,555
  • 14
  • 143
  • 159
sree
  • 33
  • 4

1 Answers1

0

Without a reproducible example, it's hard to know for sure what is going on.

You should be able to open a text connection using ?file with the open argument set to write. Then, you can capture output and write it to your file using ?write with the append argument set to TRUE. The following worked fine on my machine:

> zz <- file(description="some name.txt", open="w")
> isOpen(zz)
[1] TRUE
> for(i in 1:100000){
+   x <- rbeta(1000, shape1=10, shape2=10)
+   write(x, file=zz, append=TRUE)
+ }
> close(zz)

(Note, I wouldn't try running that; it took nearly a half an hour and created a 962 MB file that could only be opened with EditPad.)

Community
  • 1
  • 1
gung - Reinstate Monica
  • 11,583
  • 7
  • 60
  • 79
  • Thanks for getting back. I will share the data set and my code later today. In the mean time I will also try your solution and see what happens. – sree Oct 28 '13 at 19:45
  • You're welcome, @SriKowtha. If this does resolve your issue you may want to *accept* it by clicking the check mark to the left under the vote total. – gung - Reinstate Monica Oct 28 '13 at 19:49
  • I have tried your suggestion and it worked. I did accept your sulution as an answer too. Thank you! – sree Nov 03 '13 at 04:24