how to do correlation with unequal sizes?

To find the difference in ages of patient under 2 different groups (drug 1 and drug 2).

age_drug1
[1] 34 34 34 37 40 43 46 47 51 60 62 25 28 30 34 36 38 50 50 50 53 56 60 63

age_drug2
[1] 28 30 34 34 36 39 39 41 43 47 58 68 22 24 36 40 45 55 61


I have tried the Pearson correlation, since the distribution of the age in both groups were normal under Shapiro's test. However, when i try to do the correlation using Pearson's method, corr.test(), it shows error

Error in cor.test.default(age_drug1, age_drug2, method = "pearson") :
'x' and 'y' must have the same length


Is there another way to check the association? I did try Student's t test unpaired, but I am not sure if that is the right option.

• Correlation does not make much sense here since we don't have paired observations. The samples each seem bimodal and you might want to investigate that. In R, plot(density(age_drug2)); lines(density(age_drug1), col = "blue") Feb 28, 2020 at 16:29
• Since it is impossible to apply the usual concept of "correlation" to this situation, please explain to us what you mean by "correlation," "association," or "difference in ages."
– whuber
Feb 28, 2020 at 16:54

It doesn't seem like you are looking for a correlation. First of all, your samples are not paired. Second of all, a correlation won't tell you anything about the absolute difference in ages. For example 1,2,3,5,7 and 98,99,100,102,104 have a perfect correlation of 1 - because they increase in the same increments, but are very far apart.

A two sample Student t-test, like you mentioned, is actually a good way to compare the means of two groups. You can also have a look at the Wilcoxon test.

A $$t$$ test will show that the difference in means is not convincing. It's as or more important for most purposes to look at all the data.

This display shows

• the ages in order (quantile plots; the modality mentioned in a comment does not seem notable to me, but some repeated ages do show up as steps)

• box plots with percentile whiskers out to 5% and 95% (for the smaller group, these are reported as the extremes)

• horizontal reference lines showing the means.

The slightly higher mean and median ages for drug 1 are combined with a bigger range for drug 2, but these are small samples, and such features should not be over-interpreted, and much hinges on how they were produced.