0
$\begingroup$

This is probably a very basic question on statistics, but somehow I can’t understand it in a way that I’m sure that my interpretation of the outcome will be correct. Here goes.

I have data on the visits to two webpages that are part of the same domain. I have daily data on visits for a whole year. I’ve made visualisations of the rolling mean for both pages in one graph. However, people seem to interpret these different. One person sees a strong connection in visits to one and the other, another person does not. I’m now looking for a statically solid way to settle this.

Basically I want to know if an increase/decrease in one is linked to increase/decrease in the other over time. I’ve looked into correlation/covariance but I’m thrown off by that they need to be linear? Since the visits increase and decrease depending on the day, there is no such thing.

I’m using R Studio for my graphs and data cleaning/processing. I have one column with dates (one date for each page), one that identifies the page (page1, page2), one with the number of visits and one with the rolling 7-day mean.

Thanks in advance!

Data:

structure(list(Date = structure(c(18628, 18628, 18627, 18627, 
18626, 18626, 18625, 18625, 18624, 18624, 18623, 18623, 18622, 
18622, 18621, 18621, 18620, 18620, 18619, 18619, 18618, 18618, 
18617, 18617, 18616, 18616, 18615, 18615, 18614, 18614, 18613, 
18613, 18612, 18612, 18611, 18611, 18610, 18610, 18609, 18609, 
18608, 18608, 18607, 18607, 18606, 18606, 18605, 18605, 18604, 
18604, 18603, 18603, 18602, 18602, 18601, 18601, 18600, 18600, 
18599, 18599, 18598, 18598, 18597, 18597, 18596, 18596, 18595, 
18595, 18594, 18594, 18593, 18593, 18592, 18592, 18591, 18591, 
18590, 18590, 18589, 18589, 18588, 18588, 18587, 18587, 18586, 
18586, 18585, 18585, 18584, 18584, 18583, 18583, 18582, 18582, 
18581, 18581, 18580, 18580, 18579, 18579, 18578, 18578, 18577, 
18577, 18576, 18576, 18575, 18575, 18574, 18574, 18573, 18573, 
18572, 18572, 18571, 18571, 18570, 18570, 18569, 18569, 18568, 
18568, 18567, 18567, 18566, 18566, 18565, 18565, 18564, 18564, 
18563, 18563, 18562, 18562, 18561, 18561, 18560, 18560, 18559, 
18559, 18558, 18558, 18557, 18557, 18556, 18556, 18555, 18555, 
18554, 18554, 18553, 18553, 18552, 18552, 18551, 18551, 18550, 
18550, 18549, 18549, 18548, 18548, 18547, 18547, 18546, 18546, 
18545, 18545, 18544, 18544, 18543, 18543, 18542, 18542, 18541, 
18541, 18540, 18540, 18539, 18539, 18538, 18538, 18537, 18537, 
18536, 18536, 18535, 18535, 18534, 18534, 18533, 18533, 18532, 
18532, 18531, 18531, 18530, 18530, 18529, 18529, 18528, 18528, 
18527, 18527, 18526, 18526, 18525, 18525, 18524, 18524, 18523, 
18523, 18522, 18522, 18521, 18521, 18520, 18520, 18519, 18519, 
18518, 18518, 18517, 18517, 18516, 18516, 18515, 18515, 18514, 
18514, 18513, 18513, 18512, 18512, 18511, 18511, 18510, 18510, 
18509, 18509, 18508, 18508, 18507, 18507, 18506, 18506, 18505, 
18505, 18504, 18504, 18503, 18503, 18502, 18502, 18501, 18501, 
18500, 18500, 18499, 18499, 18498, 18498, 18497, 18497, 18496, 
18496, 18495, 18495, 18494, 18494, 18493, 18493, 18492, 18492, 
18491, 18491, 18490, 18490, 18489, 18489, 18488, 18488, 18487, 
18487, 18486, 18486, 18485, 18485, 18484, 18484, 18483, 18483, 
18482, 18482, 18481, 18481, 18480, 18480, 18479, 18479, 18478, 
18478, 18477, 18477, 18476, 18476, 18475, 18475, 18474, 18474, 
18473, 18473, 18472, 18472, 18471, 18471, 18470, 18470, 18469, 
18469, 18468, 18468, 18467, 18467, 18466, 18466, 18465, 18465, 
18464, 18464, 18463, 18463, 18462, 18462, 18461, 18461, 18460, 
18460, 18459, 18459, 18458, 18458, 18457, 18457, 18456, 18456, 
18455, 18455, 18454, 18454, 18453, 18453, 18452, 18452, 18451, 
18451, 18450, 18450, 18449, 18449, 18448, 18448, 18447, 18447, 
18446, 18446, 18445, 18445, 18444, 18444, 18443, 18443, 18442, 
18442, 18441, 18441, 18440, 18440, 18439, 18439, 18438, 18438, 
18437, 18437, 18436, 18436, 18435, 18435, 18434, 18434, 18433, 
18433, 18432, 18432, 18431, 18431, 18430, 18430, 18429, 18429, 
18428, 18428, 18427, 18427, 18426, 18426, 18425, 18425, 18424, 
18424, 18423, 18423, 18422, 18422, 18421, 18421, 18420, 18420, 
18419, 18419, 18418, 18418, 18417, 18417, 18416, 18416, 18415, 
18415, 18414, 18414, 18413, 18413, 18412, 18412, 18411, 18411, 
18410, 18410, 18409, 18409, 18408, 18408, 18407, 18407, 18406, 
18406, 18405, 18405, 18404, 18404, 18403, 18403, 18402, 18402, 
18401, 18401, 18400, 18400, 18399, 18399, 18398, 18398, 18397, 
18397, 18396, 18396, 18395, 18395, 18394, 18394, 18393, 18393, 
18392, 18392, 18391, 18391, 18390, 18390, 18389, 18389, 18388, 
18388, 18387, 18387, 18386, 18386, 18385, 18385, 18384, 18384, 
18383, 18383, 18382, 18382, 18381, 18381, 18380, 18380, 18379, 
18379, 18378, 18378, 18377, 18377, 18376, 18376, 18375, 18375, 
18374, 18374, 18373, 18373, 18372, 18372, 18371, 18371, 18370, 
18370, 18369, 18369, 18368, 18368, 18367, 18367, 18366, 18366, 
18365, 18365, 18364, 18364, 18363, 18363, 18362, 18362, 18361, 
18361, 18360, 18360, 18359, 18359, 18358, 18358, 18357, 18357, 
18356, 18356, 18355, 18355, 18354, 18354, 18353, 18353), class = "Date"), 
    BICOR2 = c("COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", 
    "COR", "REG", "COR", "REG", "COR", "REG", "COR", "REG", "COR", 
    "REG", "COR", "REG", "COR", "REG"), UPV = c(392, 33, 321, 
    43, 537, 71, 743, 86, 613, 93, 592, 75, 670, 66, 532, 40, 
    497, 46, 539, 69, 705, 92, 952, 105, 937, 132, 854, 78, 897, 
    136, 334, 37, 758, 126, 1555, 156, 1503, 135, 1902, 159, 
    1210, 74, 1095, 144, 698, 184, 930, 172, 835, 194, 355, 148, 
    584, 92, 402, 54, 449, 128, 630, 171, 887, 146, 856, 223, 
    876, 234, 617, 79, 597, 64, 602, 132, 732, 219, 884, 196, 
    874, 220, 703, 210, 612, 107, 603, 82, 646, 125, 679, 152, 
    769, 149, 873, 139, 792, 175, 560, 117, 535, 69, 531, 126, 
    572, 135, 740, 117, 811, 170, 823, 155, 651, 76, 499, 79, 
    600, 113, 589, 132, 821, 159, 1518, 215, 1364, 195, 863, 
    110, 766, 112, 956, 150, 1102, 167, 1266, 212, 763, 175, 
    824, 206, 738, 97, 814, 78, 1139, 241, 1198, 221, 1090, 187, 
    1240, 224, 1300, 195, 1034, 120, 1011, 109, 1320, 183, 1740, 
    246, 2004, 260, 1727, 234, 1418, 239, 1167, 171, 981, 92, 
    1285, 195, 1612, 226, 1716, 263, 1894, 251, 2868, 442, 1730, 
    204, 2129, 208, 1693, 242, 1118, 256, 1107, 301, 1745, 310, 
    1696, 323, 846, 152, 732, 115, 872, 212, 1233, 252, 1099, 
    279, 909, 293, 948, 284, 780, 144, 795, 112, 1250, 177, 2213, 
    307, 1809, 305, 619, 160, 562, 186, 605, 125, 554, 94, 600, 
    121, 688, 157, 822, 206, 843, 194, 787, 170, 706, 118, 560, 
    73, 612, 105, 606, 153, 597, 146, 691, 161, 745, 151, 738, 
    81, 753, 90, 918, 138, 897, 128, 804, 129, 961, 168, 1018, 
    166, 935, 87, 1040, 112, 898, 157, 1009, 163, 1061, 137, 
    1311, 190, 1170, 179, 1234, 138, 1219, 128, 1292, 154, 1152, 
    181, 1349, 166, 1264, 148, 1430, 171, 1364, 134, 1354, 128, 
    1784, 157, 2682, 300, 1326, 139, 1581, 167, 1710, 169, 1468, 
    169, 1199, 112, 1107, 142, 1355, 145, 1741, 196, 2147, 269, 
    2127, 234, 1940, 320, 1697, 273, 2019, 324, 2257, 362, 2227, 
    372, 2480, 451, 1925, 313, 2056, 273, 1678, 246, 2025, 286, 
    2148, 290, 1414, 235, 1628, 261, 1652, 76, 1780, 44, 1524, 
    40, 1664, 58, 1641, 60, 1666, 67, 1632, 85, 2020, 110, 2051, 
    52, 1613, 48, 1276, 102, 1442, 86, 1485, 105, 1640, 81, 1490, 
    125, 1604, 64, 1195, 49, 1270, 91, 1576, 111, 2213, 116, 
    2318, 131, 1311, 127, 856, 76, 778, 30, 724, 133, 712, 157, 
    737, 135, 844, 115, 1042, 164, 980, 89, 571, 55, 565, 102, 
    665, 90, 668, 114, 750, 115, 622, 168, 671, 63, 586, 68, 
    577, 122, 687, 134, 805, 170, 584, 115, 647, 100, 608, 71, 
    568, 66, 653, 103, 828, 164, 926, 176, 841, 135, 968, 143, 
    959, 88, 881, 79, 1044, 83, 1466, 60, 1217, 189, 945, 150, 
    1040, 121, 854, 106, 773, 62, 828, 142, 774, 138, 926, 137, 
    941, 156, 1193, 153, 982, 61, 688, 71, 934, 110, 1153, 137, 
    1179, 139, 760, 121, 910, 105, 632, 57, 573, 69, 603, 114, 
    792, 114, 1049, 120, 1058, 109, 808, 44, 647, 46, 567, 45, 
    627, 73, 820, 142, 1135, 118, 1184, 153, 822, 135, 674, 61, 
    581, 48, 694, 122, 830, 139, 1128, 118, 1461, 140, 1129, 
    87, 633, 62, 411, 65, 666, 101, 826, 152, 531, 110, 581, 
    144, 934, 161, 748, 70, 646, 54, 914, 117, 983, 172, 839, 
    151)), row.names = c(NA, -552L), class = c("tbl_df", "tbl", 
"data.frame"))
$\endgroup$
3
  • 1
    $\begingroup$ This can be achieved with cross-correlation. Could you provide the data with dput(data) . Needed are date, number of visits page 1, number of visits site 2 $\endgroup$
    – Waldi
    Apr 23, 2021 at 17:07
  • $\begingroup$ @Waldi I added the data to my post, the pages 1 and 2 are in BICOR2 as REG and COR. Thanks! $\endgroup$
    – Justin
    Apr 24, 2021 at 13:12
  • $\begingroup$ @Justin, see my answer $\endgroup$
    – Waldi
    Apr 24, 2021 at 16:37

1 Answer 1

1
$\begingroup$

First plotting the time series:

library(ggplot2)
ggplot(data)+geom_line(aes(x=Date,y=UPV,color=BICOR2))

enter image description here

Then running cross-correlation:

COR <- data[data$BICOR2 == "COR","UPV"]
REG <- data[data$BICOR2 == "REG","UPV"]

result <- ccf(COR, REG, type = 'correlation')

max(result$acf)
[1] 0.5838414

enter image description here

Best cross-correlation is achieved at 0 lag, with a significant correlation coefficient of 0.58.
As there is no lag, this suggests both pages visits depend on the same outside factors.

$\endgroup$
4
  • $\begingroup$ Since I expect the effect to be visible on the same day, the lag of 0 is what I’m most interested in, correct? In theory lag would be more interesting if I would be looking at data on rainfall and plant growth, where a change in one would cause a delayed reaction in the other. And what would be an insignificant correlations coefficient? $\endgroup$
    – Justin
    Apr 24, 2021 at 16:48
  • $\begingroup$ significance limit is the blue dashed line. Below this line : no correlation at all. For lag, this is indeed to show delayed reaction, but if you are only interested in the same day you could simply use cor(COR,REG). $\endgroup$
    – Waldi
    Apr 24, 2021 at 16:54
  • $\begingroup$ Great! Last questions: 1. The lack of negative correlation coefficients means there is no inverse relationship between the two? 2. What do the cc at different lags tell me? I don’t necessarily expect a relationship with a lag, so can these just occur at random? Since I presume the correlation occurs on the same date, I can discard them? $\endgroup$
    – Justin
    Apr 24, 2021 at 17:03
  • $\begingroup$ negative values would be anticorrelation : the first series goes up when the second one goes down. For the lagged values you see that correlation decreases, and this can be random. Try ccf(cos(2*pi*seq(1,360*3,by=15)/360),cos(2*pi*(30+seq(1,360*3,by=15))/360)) to better understand what is going on. $\endgroup$
    – Waldi
    Apr 24, 2021 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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