View source: R/data-processing.R
calc_phase_pairs | R Documentation |
Calculates a vector containing a unique phase number for every sequential occurrence of a phase or treatment condition. This is useful for creating a grouping variable to be used in calculating effect sizes for each pair of A-B phases within treatment reversal designs.
calc_phase_pairs(x, session = seq_along(x))
x |
vector of phase/condition labels. |
session |
numeric vector of measurement occasions, used to sort |
A vector containing an integer phase number for every observation.
# Basic use-case
x <- rep(c("A","B","C","B","C","A","C"), c(4:10))
calc_phase_pairs(x)
# Using session argument to handle sort order
session <- sample(seq_along(x))
x_scrambled <- x[session]
dat <- data.frame(
x = x_scrambled,
session = session,
phase_pair = calc_phase_pairs(x_scrambled, session = session)
)
dat_sorted <- dat[order(session),]
identical(x, dat_sorted$x)
# With a grouped data.frame
library(dplyr)
Schmidt2007 %>%
group_by(Behavior_type, Case_pseudonym) %>%
mutate(phase_pair = calc_phase_pairs(Condition, session = Session_number))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.