{"action":"created","issue":{"url":"https://api.github.com/repos/gitter-lab/LPWC/issues/24","repository_url":"https://api.github.com/repos/gitter-lab/LPWC","labels_url":"https://api.github.com/repos/gitter-lab/LPWC/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/gitter-lab/LPWC/issues/24/comments","events_url":"https://api.github.com/repos/gitter-lab/LPWC/issues/24/events","html_url":"https://github.com/gitter-lab/LPWC/issues/24","id":326768908,"number":24,"title":"Different correlation value generated from comp.corr() vs. comp.bestlag() with same input","user":{"login":"leungi","id":30273868,"avatar_url":"https://avatars0.githubusercontent.com/u/30273868?v=4","gravatar_id":"","url":"https://api.github.com/users/leungi","html_url":"https://github.com/leungi","followers_url":"https://api.github.com/users/leungi/followers","following_url":"https://api.github.com/users/leungi/following{/other_user}","gists_url":"https://api.github.com/users/leungi/gists{/gist_id}","starred_url":"https://api.github.com/users/leungi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leungi/subscriptions","organizations_url":"https://api.github.com/users/leungi/orgs","repos_url":"https://api.github.com/users/leungi/repos","events_url":"https://api.github.com/users/leungi/events{/privacy}","received_events_url":"https://api.github.com/users/leungi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-05-26T21:36:30Z","updated_at":"2018-05-27T22:47:33Z","closed_at":null,"author_association":"NONE","body":"Below is a sample dataset to illustrate the issue.\r\n\r\nIn the dataset, `b` lags `a` by 1 timestep, and `comp.bestlag()` picks this up, but `comp.corr()` doesn't seem to. As per documentation, `comp.corr()`  is supposed to pick the best lag and adjust the data for lags.\r\n\r\nLook forward to your insights. \r\n\r\n``` r\r\nlibrary(LPWC)\r\nlibrary(dplyr)\r\n\r\n# create data\r\na = c(0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4)\r\nb = c(1, 2, 3, 3, 0, 1, 2, 3, 4, 0, 1, 1, 4, 4, 0, 1, 2, 3, 4, 0)\r\n\r\nmydata <- data.frame(a = a, b = b) %>% t() %>% as.data.frame()\r\n\r\ntimepoints <- seq(ncol(mydata))\r\n\r\nbest.lag(as.matrix(mydata), timepoints, max.lag = NULL, C = 10)\r\n#> [1] -1  1\r\n\r\ncomp.corr(as.matrix(mydata), matrix(rep(1:20), nrow = 2, ncol = 20, byrow = TRUE), \r\n  C = 10)\r\n#>               1\r\n#> 2 -4.500519e-18\r\n\r\ncorr.bestlag(as.matrix(mydata), max.lag = NULL, timepoints = timepoints, C = 10, \r\n  penalty = \"high\")\r\n#> $corr\r\n#>           1\r\n#> 2 0.8682825\r\n#> \r\n#> $lags\r\n#> [1] -1  1\r\n#> \r\n#> $C\r\n#> [1] 10\r\n```"},"comment":{"url":"https://api.github.com/repos/gitter-lab/LPWC/issues/comments/392382614","html_url":"https://github.com/gitter-lab/LPWC/issues/24#issuecomment-392382614","issue_url":"https://api.github.com/repos/gitter-lab/LPWC/issues/24","id":392382614,"user":{"login":"thevaachandereng","id":13036494,"avatar_url":"https://avatars3.githubusercontent.com/u/13036494?v=4","gravatar_id":"","url":"https://api.github.com/users/thevaachandereng","html_url":"https://github.com/thevaachandereng","followers_url":"https://api.github.com/users/thevaachandereng/followers","following_url":"https://api.github.com/users/thevaachandereng/following{/other_user}","gists_url":"https://api.github.com/users/thevaachandereng/gists{/gist_id}","starred_url":"https://api.github.com/users/thevaachandereng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thevaachandereng/subscriptions","organizations_url":"https://api.github.com/users/thevaachandereng/orgs","repos_url":"https://api.github.com/users/thevaachandereng/repos","events_url":"https://api.github.com/users/thevaachandereng/events{/privacy}","received_events_url":"https://api.github.com/users/thevaachandereng/received_events","type":"User","site_admin":false},"created_at":"2018-05-27T22:47:33Z","updated_at":"2018-05-27T22:47:33Z","author_association":"MEMBER","body":"@leungi I think it was not your fault but the documentation might be slightly misleading. We will fix it soon. \r\n\r\nIn corr.best lag with large multiple time series, we assume most entities would have a lag of 0 and a lag of 0 would be the reference point. However, you can create a dataset with an equal number of positive and negative lags with a small dataset and this affects the reference point. \r\n\r\nThese are really good questions. Please let me know if that addresses the problem you had.  I'll close this issue in 1 week if there is no further discussion.\r\n"}}
{"actor":{"display_login":"thevaachandereng"}}