I did a multivariate multiple linear regression in R. So I have a set of predictors (let's call them x1, x2, x3 and x4) that I used to estimate a set of responses (let's call them y1, y2 and y3). I have one fit stored for each response (fit1, fit2, fit3). Now I want to create a latex table with the predictors as rows and the responses as columns. In each cell, I report the effect estimate (rounded to two digits) as well as the corresponding 95%CI (format: [lower, upper], also rounded to two digits) of the corresponding combination of x and y. In the table, I want the 95%CIs to be right-aligned, but also the estimates to be right-aligned (which is not the case per default, as there are both positive as well as negative values), and I also want them to be displayed in math mode.
Currently I'm using the following code:
tab <- matrix(NA, ncol = 4, nrow = 3)
colnames(tab) <- c("y1", "y2", "y3")
rownames(tab) <- c("x1", "x2", "x3", "x4")
tab[,"y1"] <- paste(round(coef(fit1), 2), formatCI(confint(fit1)))
tab[,"y2"] <- paste(round(coef(fit2), 2), formatCI(confint(fit2)))
tab[,"y3"] <- paste(round(coef(fit3), 2), formatCI(confint(fit3)))
xtab <- xtable(tab,
align = "|l|r|r|r|")
formatCI() is a function from a package of our institute, that formats the 95%CI as follows: [lower, upper], rounded to two digits.
Since some estimates and lower/upper bounds are positive and others are negative, the resulting table does not produce perfectly aligned results. What I want is that all CIs are right-aligned (this is fulfilled), but also that all estimates are right-aligned (this isn't fulfilled). On top of that, I want the estimates and 95%CI to be displayed in math mode. Does anyone know how this can be done? If possible, I would like to do it using xtable() and not write the whole table manually with \begin{table} etc. But if there's no other way, ofc, I'd also do that.
Thank you in advance for your help!