500 patients had an operation to remove stomach cancer. There exists a clinical guideline that suggests that a minimum of ten lymph nodes should be removed during the operation. I am therefore interested in the proportion of patients who had at least ten nodes removed. The variable Fewer_or_more_than_ten contains this information. I am using R.

# Example data
study_data <- data.frame(
              Gender = sample(c("Male","Female"),500,T),
              Fewer_or_more_than_ten = sample(c("Fewer","More"),500,T))

I can tabulate these data to see how many people got an adequate lymph node dissection (i.e., had more than ten nodes removed).

# Tabulate data

I want to know whether this varies with gender, so I can type:

# Stratify by gender
table(study_data$Gender, study_data$Fewer_or_more_than_ten)

What I want to do is to report the percentage of women and men who got an adequate lymph node dissection. So for that I would report the percentage shown under the "More" column in the below table.

# Calculate frequencies
prop.table(table(study_data$Gender, study_data$Fewer_or_more_than_ten), 1) * 100

My question is:

I would also like to report a p value with these numbers to show whether or not there appears to be a significant difference between the proportion of men versus women who got an adequate dissection. How should I do this?

I wasn't sure whether I should try to calculate confidence intervals for the percentages and then compare them to see if they overlap, or if I should apply a Chi-square test or Fisher's exact test to the tabulated data, etc.

I am also curious, if gender could take on three values rather than two (e.g., Male, Female, and Unknown), and I wanted to extend my hypothesis test to these three groups, how would that change my approach?


1 Answer 1


You probably want a chi-square test.

chisq.test( table(study_data) )

This is a test of the interaction between sex and whether there were more than 10.

(as an aside, if you just want tables of all of the columns of a data.frame there's no need to pass each column like you are, just pass the whole data.frame to the table command)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.