# linear regression with dependent and independent variables as percentages

I would like to test whether the prevalence (in %) of parasite-infected individuals of population A (second host) is correlated with the prevalence of parasite-infected individuals of population B (first host). I have seven stations in total, in each of them I sampled 30 individuals of population A and 40 individuals of population B. So, I have 14 data points in total, 7 belonging to B, 7 belonging to A. In general I want to see if there is any correlation between the presence of parasites in A and the presence of parasites in B. I calculated prevalence in percentages. First, can I apply a linear regression to verify the correlation? If yes, but the data are not meeting the assumptions of linear regression, can I transform percentages (with log, for example)?

• In theory you can regress one against the other by doing a logit transformation.If you want to look at correlation, why don't you just perform a spearman correlation? – StupidWolf Oct 22 '19 at 9:52
• Hi! Actually I did perform a spearman but then my supervisor was not agree with that. He was saying that since we cannot rank them, Spearman correlation cannot be used, or something like that (I'm still a beginner). – Claudia Bommarito Oct 22 '19 at 10:02
• Sorry I am quite confused now. Can you edit your post and give us more information on what your data is like? To do correlation, you should have the same individuals that are parasitised in A or B. I think something is missing between what you are supposed to find out and the nature of your data – StupidWolf Oct 22 '19 at 10:12
• Done. As an example: in one station I have 30% of population B (first host) and 90% of population A (second host) infected with parasite species x. And I would like to see whether the prevalence of parasite x in the second host is correlated with the one of the first host. Thank you so much for further comments – Claudia Bommarito Oct 22 '19 at 10:55
• You have two data points, 1. 30% of B infected with x and 2. 90% of A infected with x. You cannot do correlation between 1 data point and the other. What do you want to know from the statistical test? – StupidWolf Oct 22 '19 at 11:08

I do not have your data, but below i simulate some data according to what you describe, and you can see how correlation works

# number of stations
n=7
# number of individuals sampled per station
# i assume all of them to be 40
x = rep(40,n)
# simulate probability of being infection in A
true_pA = runif(n,max=0.5)
# make the probability in B some function of A, with some error
true_pB = 2*true_pA + runif(n,max=0.1)
# simulate the data under a binomial
A = rbinom(n,size=x,p=true_pA)
B = rbinom(n,size=x,p=true_pB)
# you can see the counts are correlated
plot(A,B)


You should get something like: Because you sampled the same number of individuals per station, you can simply do a pearson correlation between the two values, with 0.5 to handle zeros (as pointed out by AdamO):

 cor.test(log(A+0.5),log(B+0.5))


If however you want to correlate the ratios,let's say if you have different number of individuals sampled between population.

cor.test(log((A+0.5)/x),log((B+0.5)/x))


The correlation is identical to a test of slope in linear regression (this link should be ok), but in this case we just transform the count values using log, which works as a good approximation most of the time.

• 1. test of slope coefficient in OLS is identical to a test of correlation. 2. one could log transform the predictor and response, but to say that doing so tests the ratios specifically is misleading. 3. Using the 0.5 constant to the log transform is done simply to handle 0 values, and does not require 0.5 per se all the while introducing sensitivity as to what constant you do choose to offset the log transform. – AdamO Oct 22 '19 at 15:36
• Hi @AdamO, so what would you suggest? If you read the comments above, the same number of individuals are sampled, so I suggest simply correlating the counts. Yes, I agree if you have ratios or rates, then you transform them differently. – StupidWolf Oct 22 '19 at 15:40
• I agree with 1. and 3. , so I have changed the wording in my answer to be more specific. Thanks you for pointing that out. – StupidWolf Oct 22 '19 at 15:50
• Thank you so much to both of you. I think I will use pearson correlation. By the way, I really did not explain it well at the beginning. The number of individuals sampled differs from the two populations (by 5-10 more in B than A in all seven stations), and so it would may better to correlate the ratios. I guess that if I follow exactly your indication I should use the row dataset, with presence/absence (as 0 or 1) of parasite in each individual and then divide for the total. The other option is to directly use the percentages dataset, right? But I would say that the output should be the same. – Claudia Bommarito Oct 22 '19 at 17:11