1

My data looks like this

structure(list(Outcome1 = c(3L, 4L, 5L, 7L, 2L, 8L, 9L, 6L, 10L, 
1L), Outcome2 = c(13L, 12L, 16L, 20L, 15L, 17L, 18L, 14L, 11L, 
19L), Outcome3 = c(30L, 22L, 26L, 21L, 29L, 28L, 27L, 25L, 23L, 
24L), Response1 = c(35L, 36L, 34L, 32L, 40L, 38L, 39L, 31L, 37L, 
33L), Response2 = c(49L, 46L, 47L, 44L, 48L, 50L, 41L, 42L, 43L, 
45L), Response3 = c(55L, 58L, 54L, 52L, 51L, 56L, 57L, 59L, 53L, 
60L)), class = "data.frame", row.names = c(NA, -10L))

I would like to carry out a series of linear regressions between the outcomes and responses. For example Outcome1 ~ Response1, Outcome1 ~ Response2, Outcome1 ~ Response3, Outcome2 ~ Response1 and so on. I would then like to extract the p-values of these regressions in a tabular format and have them listed next to their respective regression models. Could this also be done to extract correlation coefficients?

For example

Model                 p-value   Correlation Coefficient

Outcome1 ~ Response1  0.041     0.43

Thanks for taking the time to read this post.

DiscoR
  • 247
  • 2
  • 11
  • Your title said linear regression, but your desired output want correlation coefficient. That is strange. – www Sep 28 '18 at 17:33
  • @www, I will clarify. I would like to see regression p-values and in a separate column correlation coefficients. – DiscoR Sep 28 '18 at 17:38
  • @李哲源 That solution worked very well. Thanks! I have some na's in my columns. And the function is returning all NA for all the simple linear regression outcomes. How do I exclude na's from my analysis. Thanks. – DiscoR Sep 28 '18 at 18:57
  • @DiscoR I created that Q & A because I realized that there are many people trying to do this kind of thing. If you like that thread, please consider voting up the question and answer. Regarding `NA`, there are more than one ways to deal with it. You can apply `na.omit` on your data frame to drop all `NA`. But this is different from removing NA pairwise. – Zheyuan Li Sep 28 '18 at 19:02
  • @李哲源 Thanks, that was helpful. I tried with na.omit and that worked. Do you recommend removing NA pairwise? I have voted your question and answer. – DiscoR Sep 28 '18 at 19:06
  • @DiscoR Pairwise removal requires some changes to my functions. As I mentioned somewhere in the answer, I did not use `cov` to compute covariance but chose to use `crossprod` for speed. Pairwise removal of NA is supported by `cov` (see `?cov`), but `crossprod` can not do it. Joint removal and pairwise removal would in principle give different results, because the sample size for different pairs can be different. But if you don't have many NA, the difference is unlikely to be big. – Zheyuan Li Sep 28 '18 at 19:09
  • @李哲源 okay, I don't have a lot of NA's. Thanks for the detailed answer. I will be sure to reference the original code. – DiscoR Sep 28 '18 at 20:28

0 Answers0