0

I have a dataset (con) divided in 2 groups (A and B) and for each sample from group A (1-5), group B has a correspondent sample (1-5), each sample has different measures (zinc, iron, cadmium) pertaining to it.

My intended goal is making a correlation test between A1-B1;A2-B2;A3-B3,...measures. My question is, is there a way to make such a individual correlation and then trace a linear model graph or if I can just separate the groups and do a cor.test() between the two subsets?

I have created two different subsets (conA, conB), using:

cor.test(conA$Zinc,conB$Zinc, method="spearman",exact=FALSE)

to get the overall correlation for each measure but I wanted to make each pair wise correlation which I don't think it's been done this way.

L Tyrone
  • 1,268
  • 3
  • 15
  • 24
Tig
  • 1
  • 1
    Welcome to stackoverflow. Can you please give us some toy (dummy) data where we can experiment? This would be quite helpful for us to understand and answer your question. – Eva Jun 03 '23 at 14:48
  • "2 different subsets" can have correlation so long as they have the same length and they are tied together logically (such as: date, person, sequence of event, etc). While the logical-tying thing is an "analytical" thing (meaning without it you can still get a number, whether or not it is meaningful or just a statistical _fabrication/lie_), but the former is a requirement. If you look at `stats:::cor.test.default`, one of the first checks if `if (length(x) != length(y))`. – r2evans Jun 03 '23 at 14:48
  • As Eva hinted: the solution might involve a bit of reshaping of your original dataframe `con`. Please provide this data by pasting the output of `dput(con)` or a sufficient subset, say, five paired observations per group for, say, two outcomes. – I_O Jun 03 '23 at 16:05
  • @Eva here you go, sorry for this format but i dont know how to put it in a table Type Samples Zinc Iron Cadmium A 1 40.4182538494163 4.14246558453983 5.06275257049576 B 1 8.226684025 4.142465585 0.057200545 A 2 40.0059157351504 4.14246558453983 2.49802561608657 B 2 21.89781394 4.142465585 0.057200545 A 3 52.8162770923082 4.14246558453983 9.51114173008322 B 3 3.215615851 4.142465585 0.197002949 A 4 37.2108767466964 8.18085608926247 10.7597595838906 B 4 1.816150512 75.46619229 0.158789084 A 5 52.068752120785 4.14246558453983 5.52795315325597 B 5 13.29312173 35.02115892 0.057200545 – Tig Jun 04 '23 at 15:55

0 Answers0