View source: R/reparameterize.r
byPhasebyGroup | R Documentation |
In ICT data with 2+ groups and 2+ phases, dummy coding can be used to estimate group and phase specific intercepts and slopes.
byPhasebyGroup(data, time, phase, group, retime = TRUE)
data |
A |
time |
Character. The name of the time variable, or if |
phase |
Character. The name of the phase variable, or if |
group |
Character. The name of the group variable., or if |
retime |
Logical. Default is |
# produce a design matrix for a hypothetical study with 20 time points,
# 2 phases, and 3 groups
studyDesign <- byPhasebyGroup(NULL, -9:10, 2, 3)
head(studyDesign$data)
studyDesign$dummyNames
# an alternative specification
studyDesign <- byPhasebyGroup(NULL, -9:10, c("baseline", "intervention"),
c("treatment", "control"))
head(studyDesign$data)
studyDesign$dummyNames
# create group and phase specific dummy indicators after creating an
# artificial "Group" variable in the Ovary data.
OvaryICT2 <- OvaryICT
OvaryICT2$Group <- as.numeric(OvaryICT2$Mare<7)
OvaryICT2 <- byPhasebyGroup(OvaryICT2, "Time", "Phase", "Group")
# view the new variables, group and phase specific intercepts and slopes
OvaryICT2$dummyNames
# view the right hand side formula of the fixed effects produced by
# `byPhasebyGroup`, noting the `-1` elimination of an overall intercept
OvaryICT2$fixed
# fit a model using the new variables with
# - no intercept
# - no overall time variable
userFormula <- list()
userFormula$fixed <- formula(paste("follicles ~ ", OvaryICT2$fixed)) # add dependent variable
userFormula$random <- ~ Time | Mare
t0 <- PersonAlytic(output = 'byPhasebyGroup' ,
data = OvaryICT2$data ,
ids = "Mare" ,
dvs = "follicles" ,
time = "Time" ,
ivs = OvaryICT2$dummyNames ,
package = "nlme" ,
userFormula = userFormula ,
correlation = "corARMA(p=1)" ,
autoSelect = list() ,
method = "ML" )
summary(t0)
# note that the following moves the `-1` to the end of the formula, test
# that this still works
userFormula$fixed <- update(formula(paste(" ~ ", OvaryICT2$fixed)), follicles ~ .)
t1 <- PersonAlytic(output = 'byPhasebyGroup' ,
data = OvaryICT2$data ,
ids = "Mare" ,
dvs = "follicles" ,
time = "Time" ,
ivs = OvaryICT2$dummyNames ,
package = "nlme" ,
userFormula = userFormula ,
correlation = "corARMA(p=1)" ,
autoSelect = list() ,
method = "ML" )
summary(t1)
# if nothing returns, the test passes
testthat::expect_equal(summary(t0)$tTable, summary(t1)$tTable)
## Not run:
# multiple DVs with no target_ivs and group models
# this fails to implement the userFormula, see https://github.com/ICTatRTI/PersonAlytics/issues/25
t2 <- PersonAlytic(output = 'MultiDVnoIDnoIV' ,
data = OvaryICT2$data ,
ids = "Mare" ,
dvs = names(OvaryICT)[c(3,9:11)] ,
ivs = OvaryICT2$dummyNames ,
time = "Time" ,
package = "nlme" ,
individual_mods = FALSE ,
target_ivs = NULL ,
autoSelect = list() ,
userFormula = userFormula )
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.