Hello R friends,

This last year I became awere of some modern strategies of varible selection
for regression analisys, such as bootstrap, bayesian approaches and others.
Nevertheless, most analysts (that Im awere of) find it usefull to compare
crude measures with adjusted ones to have an idea of direction and magnitude
of confounding. In a recent report, I had some work to make a table with
several crude risk ratios, then I made a function to invoke riskratio
function and display the riskratio of several exposures for the same
outcome. It was inspired in epicalc::tableStack. Unfortunately, I could not
avoid the many for(), but I guess it would not be much a problem with small
datasets. It assumes that both the exposures and the outcome are binary
variables. But I guess that with little improvementes could work with more
categories too. Similar to tableStack, its output may be easily be exported
to a spreadsheet with write.table or other export function.

I hope it is usefull to others too.

rrStack <- function(outcome, exposure, data=.data,
                    method = "wald",
                    conf.level = 0.95,
                    rev = "neither",
                    correction = FALSE,
                    verbose = FALSE,
                    replicates = 5000,
                    digits=2){
  ret <-
lapply(1:length(exposure),function(i)riskratio(table(data[,exposure[i]],data[,outcome]),
                                              method = method,
                                              conf.level = conf.level,
                                              rev = rev,
                                              correction = correction,
                                              verbose = verbose,
                                              replicates = replicates))
  variables <- c(exposure[1],NA)
  for(i in 2:length(exposure)){temp <- c(exposure[i],NA); variables <-
c(variables,temp)}
  categories <- rownames(ret[[1]]$measure)
  for(i in 2:length(exposure)){temp <- rownames(ret[[i]]$measure);
categories <- c(categories,temp)}
  N <- unname(ret[[1]]$data[1:2,3])
  for(i in 2:length(exposure)){temp <- unname(ret[[i]]$data[1:2,3]); N <-
c(N,temp)}
  risk <- unname(ret[[1]]$data[1:2,2]) / unname(ret[[1]]$data[1:2,3])
  for(i in 2:length(exposure)){temp <- unname(ret[[i]]$data[1:2,2]) /
unname(ret[[i]]$data[1:2,3]); risk <- c(risk,temp)}
  lower <- binom.exact(ret[[1]]$data[1:2,2], ret[[1]]$data[1:2,3],
conf.level = conf.level)$lower
  for(i in 2:length(exposure)){temp <- binom.exact(ret[[i]]$data[1:2,2],
ret[[i]]$data[1:2,3], conf.level = conf.level)$lower; lower <-
c(lower,temp)}
  upper <- binom.exact(ret[[1]]$data[1:2,2], ret[[1]]$data[1:2,3],
conf.level = conf.level)$upper
  for(i in 2:length(exposure)){temp <- binom.exact(ret[[i]]$data[1:2,2],
ret[[i]]$data[1:2,3], conf.level = conf.level)$upper; upper <-
c(upper,temp)}
  RR <-  unname(ret[[1]]$measure)
  colnames(RR) <- c('RR','lower','upper')
  for(i in 2:length(exposure)){temp <- unname(ret[[i]]$measure); RR <-
rbind(RR,temp)}
  pvalue <-  unname(ret[[1]]$p.value)
  colnames(pvalue) <- c('midp.exact','fisher.exact','chi.square')
  for(i in 2:length(exposure)){temp <- unname(ret[[i]]$p.value); pvalue <-
rbind(pvalue,temp)}
  table <-
as.data.frame(cbind(cbind(variables,categories),round(cbind(N,risk,lower,upper,RR,pvalue),digits=digits)))
  print(table,quote = FALSE,na.print='')
  invisible(table)
}

> output <- rrStack('HEPATOTO',c('SEXO','HIV','HCV'),data=b)
  variables categories   N risk lower upper   RR lower upper midp.exact
fisher.exact chi.square
1      SEXO       Male  99 0.22  0.14  0.32
1
2               Female  55 0.15  0.06  0.27 0.65  0.31  1.37
0.26         0.29       0.25
3       HIV   Positive  60 0.32   0.2  0.45
1
4             Negative  94 0.12  0.06   0.2 0.37  0.19  0.72
0            0          0
5       HCV   Positive   9 0.11     0  0.48
1
6             Negative 145  0.2  0.14  0.27  1.8  0.28 11.75
0.58            1       0.51
Warning message:
In chisq.test(xx, correct = correction) :
  Chi-squared approximation may be incorrect

Kind regards,

Abraço forte e que a força esteja com você,

Dr. Pedro Emmanuel A. A. do Brasil
Instituto de Pesquisa Clínica Evandro Chagas
Fundação Oswaldo Cruz
Rio de Janeiro - Brasil
Av. Brasil 4365
Tel 55 21 3865-9648
email: pedro.brasil@ipec.fiocruz.br
email: emmanuel.brasil@gmail.com

---Apoio aos softwares livres
www.zotero.org - gerenciamento de referências bibliográficas.
www.broffice.org ou www.openoffice.org - textos, planilhas ou apresentações.
www.epidata.dk - entrada de dados.
www.r-project.org - análise de dados.
www.ubuntu.com - sistema operacional

	[[alternative HTML version deleted]]

