# Limited Experience with coding, how to do longitudinal statistical analysis on two variables

Hello,

Please forgive me as I do not have much experience with statistical analysis or using R, but I am attempting to correlate two variables seeing if X predicts Y and their relationship. I am doing this for multiple patients at multiple time points. In other words, the data looks like this (1st, 2nd, 3rd being different timepoints):

Patient X Y

a(1st) a01 a02

a(2nd) a11 a12

a(3rd) a21 a22

b(1st) b01 b02

b(2nd) b11 b12

b(3rd) b21 b22

I heard I could use the geeglm or glm function but I really do not know how to start, if anyone could help out by giving steps or explaining the process I would greatly appreciate it. Thank you in advance!

Hi Bhima,
and welcome to the R Community!

You need to create a reprex (REProducible EXample) to help us

what you might want, and created a simple reprex below.

``````library(tidyverse)
library(corrr)

data <- data.frame(
patient_id = rep(c(1:5),4),
sbp = c(145, 138, 127, 124, 122,
142, 135, 124, 121, 118,
146, 137, 128, 126, 124,
143, 136, 123, 127, 132),
dbp = c(93, 88, 82, 77, 72,
95, 91, 85, 79, 76,
91, 85, 80, 73, 68,
96, 89, 88, 74, 79),
time = rep(c(1,2,3,4,5),4)
)

print(data)
#>    patient_id sbp dbp time
#> 1           1 145  93    1
#> 2           2 138  88    2
#> 3           3 127  82    3
#> 4           4 124  77    4
#> 5           5 122  72    5
#> 6           1 142  95    1
#> 7           2 135  91    2
#> 8           3 124  85    3
#> 9           4 121  79    4
#> 10          5 118  76    5
#> 11          1 146  91    1
#> 12          2 137  85    2
#> 13          3 128  80    3
#> 14          4 126  73    4
#> 15          5 124  68    5
#> 16          1 143  96    1
#> 17          2 136  89    2
#> 18          3 123  88    3
#> 19          4 127  74    4
#> 20          5 132  79    5

corr <- data %>%
correlate() %>%
focus(-patient_id, mirror = TRUE) %>%
rearrange()
#>
#> Correlation method: 'pearson'
#> Missing treated using: 'pairwise.complete.obs'
#> Registered S3 method overwritten by 'seriation':
#>   method         from
#>   reorder.hclust gclus

fashion(corr)
#>   rowname  dbp  sbp time
#> 1     dbp       .79 -.92
#> 2     sbp  .79      -.87
#> 3    time -.92 -.87

rplot(corr)
#> Don't know how to automatically pick scale for object of type noquote. Defaulting to continuous.
``````

Created on 2019-11-03 by the reprex package (v0.3.0)