correlate | R Documentation |
Compute correlation matrix for multiple variables and/or multiple groups.
correlate(
formula,
data,
repetition,
use = "everything",
method = "pearson",
collapse.value = ".",
collapse.var = ".",
na.rm
)
formula |
[formula] on the left hand side the outcome(s) and on the right hand side the grouping variables. E.g. Y1+Y2 ~ Gender will compute for each gender the correlation matrix for Y1 and the correaltion matrix for Y2. |
data |
[data.frame] dataset containing the observations. |
repetition |
[formula] Specify the structure of the data: the time/repetition variable and the grouping variable, e.g. ~ time|id. |
use |
[character] method for computing correlation in the presence of missing values: |
method |
[character] type of correlation coefficient: |
collapse.value |
[character] symbol used to combine covariate values when using multiple grouping variables. |
collapse.var |
[character] symbol used to combine variable names to be pasted left of the covariate values when using multiple grouping variables.
Can be disabled setting it to |
na.rm |
[logical] not used. The user may expect this argument though so it is added to help the user with a message pointing toward the argument |
as.array
to convert the output to an array or as.matrix
to convert the output to a matrix (when a single outcome and no grouping variable).
summarize
for other summary statistics (e.g. mean, standard deviation, ...).
#### simulate data (wide format) ####
data(gastricbypassL, package = "LMMstar")
## compute correlations (composite time variable)
e.S <- correlate(weight ~ 1, data = gastricbypassL, repetition = ~time|id)
e.S
as.matrix(e.S)
e.S21 <- correlate(glucagonAUC + weight ~ 1, data = gastricbypassL,
repetition = ~time|id, use = "pairwise")
e.S21
as.array(e.S21)
as.matrix(e.S21, index = "weight")
gastricbypassL$sex <- as.numeric(gastricbypassL$id) %% 2
e.S12 <- correlate(weight ~ sex, data = gastricbypassL,
repetition = ~time|id, use = "pairwise")
e.S12
as.array(e.S12)
e.S22 <- correlate(glucagonAUC + weight ~ sex, data = gastricbypassL,
repetition = ~time|id, use = "pairwise")
e.S22
as.array(e.S22)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.