-1

How can I change the number of decimal places my PSRF is outputted as in the gelman.diag function?

enter image description here

  • 1
    The gelman.diag function seems not to have a parameter controlling the number of decimal places. Perhaps setting global options as above could help. Except it says "The gelman.diag class has its own print method." https://www.rdocumentation.org/packages/coda/versions/0.19-2/topics/gelman.diag – NelsonGon Jan 25 '19 at 11:25
  • Might help: https://stackoverflow.com/questions/10938427/example-needed-change-the-default-print-method-of-an-object – NelsonGon Jan 25 '19 at 11:27
  • Format decimals: https://stackoverflow.com/questions/3443687/formatting-decimal-places-in-r – NelsonGon Jan 25 '19 at 11:34

1 Answers1

2

The output of gelman.diag by default formats data such that it shows 2 decimal places. You can however store the output of gelman.diag in an object, and access the data more directly like in the following minimal & reproducible example:

library(coda)       
data(line)
ret <- gelman.diag(line)

# The output of gelman.diag automatically formats data to show 2 decimal places
ret
#Potential scale reduction factors:
#
#      Point est. Upper C.I.
#alpha       1.02       1.02
#beta        1.00       1.00
#sigma       1.04       1.12
#
#Multivariate psrf
#
#1.01

# ret$psrf contains the full data
ret$psrf
#      Point est. Upper C.I.
#alpha   1.019377   1.019838
#beta    1.000695   1.002321
#sigma   1.037599   1.115930

More generally, for more flexibility to format floating point numbers, see the link provided by @NelsonGon in the comments above.

Maurits Evers
  • 49,617
  • 4
  • 47
  • 68
  • Thank you so much! I'm a fairly new user and I had tried changing my default options but couldn't work out how to influence what was happening inside the function. – Stephanie Jan 25 '19 at 11:34
  • @Stephanie You're very welcome, glad it helped. In general, it's often useful to take a look at the output object of a new function/method with `str`. So in this case `str(ret)` would tell you that `ret` is in fact just a `list` with two elements, one of them containing the `numeric` matrix that you're after. – Maurits Evers Jan 25 '19 at 11:36
  • @Stephanie PS. Please consider closing the question by setting the green check mark next to the answer. That way you help keeping SO tidy, and make it easier for others to identify relevant posts. Thanks. – Maurits Evers Jan 25 '19 at 13:03