cor.by.group: Correlation Within Groups

View source: R/cor.by.group.R

cor.by.groupR Documentation

Correlation Within Groups

Description

Computes the correlation between x and y separately within each of several groups defined by all of the combinations of the factor variables contained within by. For example, correlate high school GPA with college GPA separately within each of several universities, or correlate working memory score with response time separately in each cell of a 2 x 2 factorial experiment.

Usage

cor.by.group(x, y, INDEX, ...)

Arguments

x

one of the numeric vectors to be correlated.

y

the other numeric vector to be correlated.

INDEX

list of one or more grouping variables, typically factors, each of the same length as x.

...

arguments to cor.

See Also

cor for correlations without division into groups.

Examples

data(grouseticks, package='lme4')
cor.by.group(grouseticks$HEIGHT, grouseticks$TICKS, INDEX=grouseticks$YEAR)
# Correlation of HEIGHTS and TICKS separately for each YEAR

data(Arabidopsis, package='lme4')
cor.by.group(Arabidopsis$nutrient, Arabidopsis$total.fruits,
   INDEX=list(Arabidopsis$reg, Arabidopsis$status))
# Correlation of nutrient and total.fruits for each combination of
# reg x status

sfraundorf/psycholing documentation built on April 23, 2022, 2:50 a.m.