3

I received a comment from a reviewer who wanted to have all the p-values for each line of specific variables levels in a demographic characteristic table (Table 1). Even though the request appears quite strange (and inexact) to me, I would like to agree with his suggestion.

    library(tableone)
## Load data
library(survival); data(pbc)

# drop ID from variable list
vars <- names(pbc)[-1]

## Create Table 1 stratified by trt (can add more stratifying variables)
tableOne <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc, factorVars = c("status","edema","stage"))

print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), exact = c("status","stage"),  smd = TRUE)

the output: enter image description here

I need to have the p-values for each level of the variables status, edema and stage, with Bonferroni correction. I went through the documentation without success. In addition, is it correct to use chi-squared to compare sample sizes across rows?

UPDATE:

I'm not sure if my approach is correct, however I would like to share it with you. I generated for the variable status a dummy variable for each strata, than I calculated the chisq .

    library(tableone)
    ## Load data
    library(survival); data(pbc)

    d <- pbc[,c("status", "trt")]

    # Convert dummy variables
    d$status.0 <- ifelse(d$status==0, 1,0)
    d$status.1 <- ifelse(d$status==1, 1,0)
    d$status.2 <- ifelse(d$status==2, 1,0)

t <- rbind(    
    chisq.test(d$status.0, d$trt),
    # p-value = 0.7202

    chisq.test(d$status.1, d$trt),
    # p-value = 1

    chisq.test(d$status.2, d$trt)
    #p-value = 0.7818
)
t

BONFERRONI ADJ FOR MULTIPLE COMPARISONS:

p <- t[,"p.value"]

p.adjust(p, method = "bonferroni")
Borexino
  • 802
  • 8
  • 26

1 Answers1

2

This question was posted some time ago, so I supose you already answered the reviewer.

I don't really understand why computing adjusted p values for just three varibles. In fact, adjusting p values depends on the number of comparisons made. If you use p.adjust() with a vector of 3 p values, results will not really be "adjusted" by the amount of comparison made (you really did more than a dozen and a half!)

I show how to extract all p-values so you can compute the adjusted ones. To extract pValues from package tableOne there is a way calling object attributes (explained first), and two quick and dirty ways (at the bottom part).

To extract them, first I copy your code to create your tableOne:

library(tableone)
## Load data
library(survival); data(pbc)

# drop ID from variable list
vars <- names(pbc)[-1]

## Create Table 1 stratified by trt (can add more stratifying variables)
tableOne <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc, factorVars = c("status","edema","stage"))

You can see what your "tableOne" object has via attributes()

attributes(tableOne)

You can see a tableOne usually has a table for continuous and categorical variables. You can use attributes() in them too

attributes(tableOne$CatTable)
# you can notice $pValues

Now you know "where" the pValues are, you can extract them with attr()

attr(tableOne$CatTable, "pValues")

Something similar with numerical variables:

attributes(tableOne$ContTable)
# $pValues are there
attr(tableOne$ContTable, "pValues")

You have pValues for Normal and NonNormal variables. As you set them before, you can extract both

mypCont <- attr(tableOne$ContTable, "pValues") # put them in an object
nonnormal = c("bili","chol","copper","alk.phos","trig") # copied from your code

mypCont[rownames(mypCont) %in% c(nonnormal), "pNonNormal"] # extract NonNormal

"%!in%" <- Negate("%in%")
mypCont[rownames(mypCont) %!in% c(nonnormal), "pNonNormal"] # extract Normal

All that said, and your pValues extracted, I think there are two much more convenient quick and dirty ways to accomplish the same:

Quick and dirty way A: using dput() with your printed tableOne. Then search in the console where the pValues are and copy-paste them to the script, to store them in an object

Quick and dirty way B: If you look in tableOne vignette there is an "Exporting" section, you can use print(tableOne, quote = TRUE) and then just copy and paste to a spreadsheet (like LibreOffice, Excel...). Then I would select the column with pValue, transpose it, and get it back to R, to compute adjusted p values with p.adjust() and copy them back to the spreadsheet for journal submission