0

Here I made some longitudinal data. Variable result is biomarker level from patients. Variable visit represent visit labels. Variable time means days from baseline t1. There are two response status, 'yes' and 'no'. What I want to find out is whether there is any difference in biomarker level between responder and non-responder over the time-course.

I use linear mix model for the analysis.

#generate data    
df = data.frame(result = rnorm(200)+2, 
            visit = rep(c('t1', 't2', 't3', 't4', 't5'), 40),
            time = rep(c(0, 8, 14, 30, 60), 40),
            response = rep(c('yes', 'no'), each=100),
            id = rep(1:40, each=5) ) 

# run lme model 
library(lme4)
library(lmerTest)
lmer(result~time*response+(1|id),data=df)
lmer(result~factor(visit)*response+(1|id), data=df)
lmer(result~factor(visit, ordered=TRUE)*response+(1|id), data=df)

My question is: 1. In this analysis,should I use time(continuous) or visit (factor)?
2. If I use visit(factor), should it be ordered or unordered? Is there any guideline in terms of choosing what type time variable to use (factor vs continuous)?

thanks a lot.

Carl
  • 4,232
  • 2
  • 12
  • 24
zesla
  • 11,155
  • 16
  • 82
  • 147

1 Answers1

0

... should I treat visit time as continuous variable or as factor?

A factor since I figure you (properly?) want observations at the same time period to have the same random effect term. However, that would just be the same as having a random effect for visits if all visit levels and time fall at the same time. They do not in your example though I figure there is something wrong with it since e.g., id = 2 has its fist visit at time t = 60

> df[df$id == 2, ]
       result visit time response id
5  1.84451763    t1   60       no  2
6  1.30286252    t2    0       no  2
7  0.40109211    t3    8       no  2
8 -0.01516773    t4   14       no  2

I guess the alternative would be something like (time|id) in which case each individual have a random slope of time or (time|response) in which case each of the two responds categories have a random slope. That might make sense in your application?

  • so sorry I made a mistake in generating the dataset. I just corrected it. Each visit correspond to a specific time. So should I use visit (factor) or time (continuous) as a variable? @Benjamin Christoffersen – zesla Dec 03 '17 at 04:29