0

I am trying to get a latex table of a condition index table. The minimum working example is below. It prints, but it gives a huge number of digits (whether I write to the screen or to a file, and even if I set the options(digits = 3).

library(perturb)
library(Hmisc)

set.seed(1234)
x1 <- rnorm(1000)
x2 <- x1 + rnorm(1000,0,0.1)
x3 <- x1 + rnorm(1000,0,0.1)
x4 <- x1 + rnorm(1000,0,0.1)
x5 <- x1 + rnorm(1000,0,0.1)

y <- x1 + 2*x2 + 3*x3 + 4*x4 + 5*x5 + rnorm(1000,0, 10)

m1 <- lm(y~x1+x2+x3+x4+x5)

m1
options(digits = 3)
latex(colldiag(m1), file = "")   #c:/writing/nonfiction/glm book/CondIndexEx")

colldiag(m1) by itself gives a table with three significant figures, which seems appropriate.

How can I get latex to do that?

Peter Flom
  • 2,008
  • 4
  • 22
  • 35
  • Could you just use `latex(round(colldiag(m1), 3), file = "")`? – Axeman Jul 04 '19 at 17:35
  • I'm guessing this happens because `latex` converts the actual object, and `options(digits = 3)` only affects printing. – Axeman Jul 04 '19 at 17:36
  • 1
    you can pass `digits=3` to `latex`, but this leaves some fairly horrible scientific formatting. There dosn't seem to be a `scientific` format argument, and using something like `options(scipen = 999)` again is horrible. I think the best option is to go in and format the results of `colldiag(m1)` to how you want and then pass this to `latex` – user20650 Jul 04 '19 at 17:54
  • That gave me an error of "non numeric argument to a mathematical function" – Peter Flom Jul 04 '19 at 17:54
  • 1
    ... okay, quick go ... `co = colldiag(m1); co$condindx[,1] <- formatC(co$condindx[,1], digits=2, format="f"); co$pi <- formatC(co$pi, digits=2, format="f")` – user20650 Jul 04 '19 at 18:00

0 Answers0