1
$\begingroup$

In R I have a dataset promotion and another dataset new_users for each hours in a day. dim(promotion)=193 24 and dim(new_users)=193 24

So head(promotion) gives

      V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21
1  1  2  2  0  0  1  1  5  3   3   3   4   4   4   3   3   2   1   2   6   5
2  2  0  0  0  1  1  2  3  3   1   2   2   5   3   3   1   3   1   2   3   6
3  2  1  2  2  4  2  3  6  6   4   9   7   7   9   8   6   5   5   6   4   7
4  6  3  2  0  2  1  0  1  2   1   1   2   1   2   0   0   0   0   0   0   0
5  1  0  0  0  0  0  1  0  4   1   1   1   1   1   0   0   0   0   1   1   3
6  1  0  0  0  0  0  0  0  2   2   1   2   1   0   1   1   1   0   1   0   0
  V22 V23 V24
1   5   6   2
2   1   2   7
3   4  11   7
4   1   0   1
5   1   1   1
6   0   0   0

whereas head(new_users) gives

  V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21
1  1  0  1  0  0  0  0  0  2   1   1   3   9   5  12  11   7  11   5  14  14
2  7  1  3  2  0  1  1  3  2   6   9   6   5   8  12   7  14  16  11  14  19
3  7  1  1  1  1  1  3  3  4   6   7   8  22  10  19  18  16  16  13  20  10
4  1  2  2  0  0  1  0  4  7   2   6   6   7   9   3   4   6   5  13   3   6
5  1  0  0  1  1  0  1  2  4   6   4   3   2   7   1   4   5  11   3  13  10
6  0  0  1  0  0  1  1  4  2   6   4   7   3   2   4   5   4   8  14   7   9
  V22 V23 V24
1  10   0   2
2  11  11   7
3   8  11   6
4   2   0   2
5   3   2   3
6   5   2   1

Now for each hours I want to calculate the correlation between promotion and new_users. In R I do this

corr=c()
for(j in 1:24)  {
h=cbind(promotion[,j],new_users[,j])
corr[j] = cor.test(h[,1],h[,2], alternative="greater",method="pearson" )$estimate
 }

where the hypothesis is, that there is not positive correlation against the alternative hypothesis that there is a positive correlation.

I get these correlations-value for each hour

[1] -0.004365943  0.057143049  0.019965735 -0.009082763  0.024618575
 [6] -0.076012180  0.015401301 -0.053603118  0.170855851 -0.005217288
[11]  0.005104891  0.253814298  0.252274772  0.154165103  0.341692734
[16]  0.141843370  0.070887960  0.051190216  0.106422766  0.078130045
[21]  0.167922398  0.105443213  0.095502165  0.188213970

Now I want to calculate the quotient , ie new_users for each promotion.

col=c()
for(j in 1:24)  {
col[j] <- sum(new_users[,j])/sum(promotion[,j])
}

This gives me this output

 [1] 0.8021978 1.7894737 1.7714286 3.8125000 1.0845070 1.2842105 1.1685393
 [8] 1.1000000 0.9393258 1.0870536 1.1233184 1.6129032 1.6222760 1.3982684
[15] 1.7456359 2.9314516 1.9717514 2.6331361 2.5803815 2.0771144 1.9431525
[22] 1.4424084 0.7556008 0.5657568

and this is very strange, because entry 4 has the highest value at 3.81 but the correlation-value is very low, namely -0.009. Intuitively if an entry has a high quotient then it should also have a high correlation-value.

What am I missing ?

My main goal is to find which hours has strongest correlation; so which hours I should chose to improve the promotion to get more new_users.

$\endgroup$
  • $\begingroup$ Is it correct that the correlation test inside the for-loop is independent of the loop-variable $j$? Are you intending to calculate the same thing 24 times? $\endgroup$ – dimpol Oct 28 '16 at 11:07
  • $\begingroup$ And how do you get a 1 bij 24 matrix/vector when dividing new_users by promotions? Isn't it element-wise division which wouldn't change the dimensions? $\endgroup$ – dimpol Oct 28 '16 at 11:10
  • $\begingroup$ I have made the change. $\endgroup$ – Ole Petersen Oct 28 '16 at 11:28
2
$\begingroup$

I'm not sure what you're trying to find do, but a high quotient between the sum of x and the sum of y does not say anything about the correlation:

x1 <- seq(1:10)
y1 <- seq(1:10)
cor(x1,y1)

[1] 1

sum(x1)/sum(y1)

[1] 1

Correlation is 1 and the quotient is 1.

y2 <- y1 + 10
cor(x1,y2)

[1] 1

sum(x1)/sum(y2)

[1] 0.3548387

Correlation is still 1, but quotient is 0.35.

y3 <- y1 - 10
cor(x1,y3)

[1] 1

sum(x1)/sum(y3)

[1] -1.222222

Correlation is again 1, but now the quotient is negative.

set.seed(1)
x2 <- sample(1000:2000, 10)
cor(x2,y1)

[1] 0.0666171

sum(x2)/sum(y1)

[1] 281.6364

Correlation is nearly 0, but the quotient is very high.

As you can see, you shouldn't at all expect a linear relationship between correlation and your quotient of the sums. This can of course be explained mathematically as well, but I think these examples are sufficient.

$\endgroup$
  • $\begingroup$ Ok, I understand that now. If one would ask: which hours has strongest correlation, ie improve promotion will improve new_users. How should one approach this ? $\endgroup$ – Ole Petersen Oct 28 '16 at 12:20
  • 1
    $\begingroup$ I'm note sure I understand what promotion and new users mean. Can you tell us a bit more about the design of the study? $\endgroup$ – JonB Oct 28 '16 at 12:45
  • $\begingroup$ Promotion is an commercial in television. When people see it some of them will be new_user (signing up). So I want to investigate which hours a day these commercial have the highest effect on people, so they can signed up. $\endgroup$ – Ole Petersen Oct 28 '16 at 14:18
  • 1
    $\begingroup$ Ok, I get it! I'll edit my answer to provide a possible solution next week unless somebody beats me to it. Just one question: what does the rows represent? Are they different days or different commercials? $\endgroup$ – JonB Oct 28 '16 at 14:32
  • 1
    $\begingroup$ I think you should do a Poisson regression model. I don't have the time to formulate a good answer right now. Perhaps you could post a new question about how to analyze your data in order to answer your research question. $\endgroup$ – JonB Nov 2 '16 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.