decomposes: Decompose Numeric Data by Group

Description Usage Arguments Value See Also Examples

View source: R/quest_functions.R

Description

decomposes decomposes numeric data by group into within-group and between- group components via within-group centering and group-mean aggregation. There is an option to create a grand-mean centered version of the between-group components.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
decomposes(
  data,
  vrb.nm,
  grp.nm,
  grand = TRUE,
  n.shift = NULL,
  undefined = NA,
  suffix.wth = "_w",
  suffix.btw = "_b",
  suffix.grand = "c",
  suffix.lead = "_dw",
  suffix.lag = "_gw"
)

Arguments

data

data.frame of data.

vrb.nm

character vector of colnames from data specifying the variables.

grp.nm

character vector of colnames from data specifying the groups.

grand

logical vector of length 1 specifying whether grand-mean centered versions of the the between-group components should be computed.

n.shift

integer vector specifying the direction and magnitude of the shifts. For example a one-lead is +1 and a two-lag is -2. See Shift_by details.

undefined

atomic vector of length 1 (probably makes sense to be the same typeof as the vectors in data[vrb.nm]). Specifies what to insert for undefined values after the shifting takes place. See details of Shift_by.

suffix.wth

character vector with a single element specifying the string to append to the end of the within-group component colnames of the return object.

suffix.btw

character vector with a single element specifying the string to append to the end of the between-group component colnames of the return object.

suffix.grand

character vector with a single element specifying the string to append to the end of the grand-mean centered version of the between-group component colnames of the return object. Note, this is a string that is appended after suffix.btw has already been appended.

suffix.lead

character vector with a single element specifying the string to append to the end of the positive shift colnames of the return object. Note, decomposes will add abs(n.shift) to the end of suffix.lead.

suffix.lag

character vector with a single element specifying the string to append to the end of the negative shift colnames of the return object. Note, decomposes will add abs(n.shift) to the end of suffix.lag.

Value

data.frame with nrow = nrow(data and rownames = row.names(data). The first set of columns correspond to the within-group components, followed by the between-group components. If grand = TRUE, then the next set of columns correspond to the grand-mean centered between-group components. If shift != NULL, then the last columns are the shifts by group indicated by n.shift, where the shifts of data[vrb.nm] are first and then the shifts of the within-group components are second.

See Also

decompose centers_by aggs shifts_by

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
ChickWeight2 <- as.data.frame(ChickWeight)
row.names(ChickWeight2) <- as.numeric(row.names(ChickWeight)) / 1000
decomposes(data = ChickWeight2, vrb.nm = c("weight","Time"), grp.nm = "Chick")
decomposes(data = ChickWeight2, vrb.nm = c("weight","Time"), grp.nm = "Chick",
   suffix.wth = ".wth", suffix.btw = ".btw", suffix.grand = ".grand")
decomposes(data = as.data.frame(CO2), vrb.nm = c("conc","uptake"),
   grp.nm = c("Type","Treatment")) # multiple grouping columns
decomposes(data = as.data.frame(CO2), vrb.nm = c("conc","uptake"),
   grp.nm = c("Type","Treatment"), n.shift = 1) # with lead
decomposes(data = as.data.frame(CO2), vrb.nm = c("conc","uptake"), grp.nm = c("Type","Treatment"),
   n.shift = c(+2, +1, -1, -2)) # with multiple lead/lags

quest documentation built on Sept. 10, 2021, 5:07 p.m.

Related to decomposes in quest...