One can quite easily obtain odds ratios and their associated confidence intervals from a Bayesian GLM. Your code, exp(cbind(Odds_Ratio_RedvBlue=coef(fit), confint(result)))
, however, is incorrect. The confint()
function accepts a model; so, you should have fit
there.
Here is a completely reproducible example:
create random data
I create 2 random data matrices and then rbind them - this helps to make both of these different, as they will be generated using different seeds. One will represent cases; the other, controls.
mat <- rbind(
matrix(rexp(10000, rate=.1), ncol=20),
matrix(rexp(10000, rate=.1), ncol=20))
rownames(mat) <- paste0('sample', 1:nrow(mat))
colnames(mat) <- paste0('gene', 1:ncol(mat))
add a casecontrol
binary categorical variable
casecontrol <- factor(c(rep('case', nrow(mat)/2), rep('control', nrow(mat)/2)),
levels = c('control', 'case'))
mat <- data.frame(casecontrol, mat)
mat[1:5,1:5]
casecontrol gene1 gene2 gene3 gene4
sample1 case 12.587667 5.273483 4.622787060 16.4662629
sample2 case 4.299452 16.972602 24.363363216 1.1530915
sample3 case 1.445478 4.427493 0.911904015 15.9480892
sample4 case 2.795976 15.170870 0.005618626 0.4279287
sample5 case 9.031451 14.965446 3.215852608 0.1271495
create a formula that includes all genes
f <- as.formula(paste0('casecontrol ~ ',
paste(colnames(mat)[2:ncol(mat)], collapse = ' + ')))
f
casecontrol ~ gene1 + gene2 + gene3 + gene4 + gene5 + gene6 +
gene7 + gene8 + gene9 + gene10 + gene11 + gene12 + gene13 +
gene14 + gene15 + gene16 + gene17 + gene18 + gene19 + gene20
fit the formula to the data
require(arm)
model <- bayesglm(f, data = mat, family = binomial(link = 'logit'))
calculate ORs with default confidence intervals
exp(cbind(OR = coef(model), confint(model)))
Waiting for profiling to be done...
OR 2.5 % 97.5 %
(Intercept) 1.7419832 0.9776763 3.1350934
gene1 0.9890273 0.9759172 1.0020303
gene2 0.9940674 0.9811322 1.0070403
gene3 1.0076251 0.9948488 1.0208389
gene4 0.9863225 0.9735852 0.9987108
gene5 0.9980863 0.9851915 1.0110568
gene6 0.9912441 0.9786471 1.0036911
gene7 0.9993135 0.9868953 1.0118432
gene8 1.0071035 0.9944845 1.0201311
gene9 0.9998519 0.9872245 1.0126304
gene10 0.9984163 0.9847696 1.0121882
gene11 0.9896538 0.9763643 1.0028173
gene12 0.9956987 0.9831751 1.0082592
gene13 1.0048972 0.9935748 1.0165546
gene14 0.9923246 0.9793540 1.0052122
gene15 1.0112406 0.9979852 1.0249532
gene16 0.9895135 0.9765408 1.0023046
gene17 0.9897853 0.9763983 1.0030825
gene18 0.9959242 0.9832540 1.0086531
gene19 1.0029393 0.9904289 1.0156923
gene20 1.0011999 0.9893800 1.0132243
Oh!Kevin thank you so much ! i have a last question can add to p-value? some paper add to odd ratio table including p value so i wanna try
Sure, you just need to cbind the odds ratio output to this:
thank u for ur kindness!