data <-
data.frame(
x1 = runif(20)
, x2 = runif(20)
, x3 = runif(20)
, xf = factor(rep(c("l1","l2","l3","l4"), each = 5))
, xc = rep(c("c1","c2","c3","c4", "c5"), each = 4)
, pid = gl(n = 2, k = 10)
, pid2 = rep(1:2, each = 10)
)
f <- ~ bsplines(x1, bknots = c(0,1)) + x2 + xf + xc + (x3 | pid2)
cpr:::generate_cp_formula_data(f, data)
stopifnot(isTRUE(
all.equal(
f_for_use
,
. ~ bsplines(x1, bknots = c(0, 1)) + x2 + (x3 | pid2) + xfl2 +
xfl3 + xfl4 + xcc2 + xcc3 + xcc4 + xcc5 - 1
)
))
stopifnot(isTRUE(identical(
names(data_for_use)
,
c("x1", "x2", "x3", "pid", "pid2", "xfl2", "xfl3", "xfl4"
, "xcc2" , "xcc3", "xcc4", "xcc5")
)))
Run the code above in your browser using DataLab