# Is it possible to do this in R?

I have a big clinical data file with 96 columns like age, gender, BMI, etc

I want to see which of these clinical characteristics respond to chemotherapy. Response to chemotherapy divides patients to two groups as yes and no. Among these clinical characteristics, some are based on continuous data and some reflect categorical data. Is it possible to write a function to loop over these characteristics and test for relationship between response to chemotherapy? Something like Wilcox test for continuous values and chi square for categorical characteristics. By hand, it takes too much to do for all one by one !

This is my data

ID  response_to_chemo   BMI Chemo   Predictor   DJANGO  gender
AH/155  no  50  1   1   0   M
RS/022  no  67  1   1   0   M
RS/027  no  80  1   1   1   F
ST/023  no  65  1   1   0   M
SH/051  yes 47  1   1   0   M
AH/075  yes 90  0   1   0   M
RS/047  no  67  0   1   0   F
ST/029  no  61  1   1   0   F


For instance

myTable <- table(clin$$gender, clin$$response_to_chemo)

chisq.test(myTable)


Gives p-value for testing the relationship of gender (CATEGORICAL) in response to chemotherapy

And

t.test(clin$$BMI ~ clin$$response_to_chemo)


is for BMI

I meant a function calculating these p-values for clinical characteristics one by one

• Did you triy anything yet ? Commented Jan 31, 2020 at 15:53
• Actually in my mind I think about some for i in colnames of my data but can not go further as I am unable to tailor a function :( Commented Jan 31, 2020 at 15:56
• Try to include some code that you would run on the data example you provided. Taking the time to make a good reproducible example often gives you the answer to the original question. Commented Jan 31, 2020 at 16:05
• Don't forget to correct for multiple hypothesis testing at the end, too. With 20 completely random variables, you'd expect 1 of them to show a spurious association at p<0.05. Commented Mar 10, 2020 at 15:35

R supports logistic regression, which would seem to be the most efficient method for tackling this question. Assuming the "Chemo" variable is the type of chemo the code would be something like:

glm( (response_to_chemo == "yes") ~  BMI + Chemo  + Predictor +  DJANGO + gender,
family="binomial")


EDIT: Corrected a typo (added a missing double quote)

The general approach would be to loop through every column starting at column 2. You can use numeric indexes to do that.

For each column, check its type. If it is a factor, use your chisq.test method. If it is of numeric type, use your t.test` approach. Write the results to a list so you can parse them later.

You have category-based variables as well as variables based on continuous data. The best-option could be linear Mixed- effects model for your research purpose. Chi-square test and t-test may be used to cross-validate or re-examine the outcome of LME model.

• Hi @subhash what mixed model would you consider?
– M__
Commented Mar 9, 2020 at 18:30
• When using such a model, how do you decide which effects to be "fixed" and which to be "random"?
– haci
Commented Mar 10, 2020 at 15:48
• These are assumptions that pervade hierarchical modelling.Saying "which effects" here seems to reflect the variables! Please clarify. Commented Mar 12, 2020 at 2:58