I have a data set where the response (dependent) variable measured only at a single time point. However the predictors can be both longitudinal as well as measured at a single time point. Here is an reproducible example :
dat <- data.frame(
id=rep(1:100),
y = rbinom(n = 100, size = 1, prob = 0.45),
x_cat = as.factor(rbinom(n = 100, size = 1, prob = 0.2)),
x1_w1 = rnorm(n = 100, mean = 10, sd = 7),
x1_w2 = rnorm(n = 100, mean = 10, sd = 7),
x2_w1 = as.factor(rbinom(n = 100, size = 1, prob = 0.4)),
x2_w2 = as.factor(rbinom(n = 100, size = 1, prob = 0.48))
)
> head(dat)
id y x_cat x1_w1 x1_w2 x2_w1 x2_w2
1 1 0 0 12.592883 14.124617 1 0
2 2 1 1 10.615650 12.672418 0 0
3 3 1 0 10.597431 21.168571 0 0
4 4 1 0 4.338312 5.257146 0 0
5 5 1 0 9.671094 5.704907 0 0
6 6 1 0 19.468497 6.862050 0 0
So for each id
, there is a binary response y
, a categorical predictor x_cat
which measured only at a single time point.
Also x1
is a longitudinal (time varying) continuous predictor which measured at two time points (x1_w1 , x1_w2
) and x2
is a longitudinal (time varying) categorical predictor which measured at two time points (x2_w1 , x2_w2
).
Basically I need to create a prediction model to predict y
based on the predictors.Since there are longitudinal predictors , the standard logistic regression using glm
may not be suitable . Because longitudinal predictors and correlated with each other.
So based on the resources I followed , I think that the most suitable alternative is the mixed model approach. May be using glmer
or lmer
functions in lme4
package.
I referred this example which is quite relevant to my situation. it is recommended in there too: https://www.researchgate.net/post/How_to_estimate_time_dependent_covariates_effects_in_logistic_regression
There are lot of examples of how to use this lme4
package when the response variable is also longitudinal.But i couldn't find any suitable tutorial/example when the response is measured at only one time point like in my situation.
So can any one help me to figure out how to apply lme4
or (any suitable package) to my situation ?
Any help would be highly appreciated.
Thank you