Parameterized Function for lcmm model

18 views Asked by At

I want to write a function "lcga0" that does the same as "demomodel" parameterizing the dependent variable, because I want to run the model 2x for 2 different dependent variables. How can I write this function?

dataframe <- data.frame(id = c(1, 2, 1 ,2), time = c(1, 1, 2,2), rt=c(12, 13, 11, 15))
demomodel <- (rt ~ poly(time, degree = 2, raw = TRUE),
              subject = "id", data = dataframe)
# works as expected

rlcga0 <- function(y,z){
  lcmm(reformulate(
    termlabels = "poly(time, degree = 2, raw = T)",
    response = y),
    subject = "id", data = z,
    link = "9-quant-splines")
}

Model <- rlcga0("rt", dataframe)
# error (s.below)

I tried the function stats::reformulate to embbed the regression formula. I expected the same result for "Model" as for "demomodel". However, I get an error message: Fehler in [.data.frame(data, , v) : nicht definierte Spalten gewählt. What did I wrong? Thank you a lot for your help!

0

There are 0 answers