# 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

• Sorry why unvoting? Please allow knowledgeable people to help if they don't mind – Exhausted Jan 31 '20 at 15:32
• Did you triy anything yet ? – Paul Endymion Jan 31 '20 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 :( – Exhausted Jan 31 '20 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. – Paul Endymion Jan 31 '20 at 16:05
• No one is going to help you by doing your work for you. Try to do it yourself. If you have problems, work on narrowing the problem down as much as you can, and then you can post your code and people will try to figure out what you did wrong. But coming here with nothing at all, and no evidence of having tried anything is not going to get a good response. – swbarnes2 Jan 31 '20 at 22:27

## 3 Answers

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.

This will be a good exercise for you in trying to automate analyses. Please do not expect people to do your job for you - that is why your posts receive downvotes.

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__ Mar 9 '20 at 18:30
• When using such a model, how do you decide which effects to be "fixed" and which to be "random"? – haci Mar 10 '20 at 15:48
• These are assumptions that pervade hierarchical modelling.Saying "which effects" here seems to reflect the variables! Please clarify. – Subhash C. Davar Mar 12 '20 at 2:58