Mixed effect model for dependent variable with two timepoints and predictor with one timepoint? I have a dataset with a two timepoints (TP) of the variable (X1), one timepoint of a variable X2.
The goal is to find if a change between TP 1 and TP 2 in X1 is associated with a variable (X2), controlling for age and sex.
When trying out Mixed model in R (LME) with the following code, it won't run, saying there is too many NAs. I only have NA in the X2 at timepoint 2.
Some example data:
ID <- c(1,1,2,2,3,3,4,4)
TP <- c(1,2,1,2,1,2,1,2)
X1<-c(2.3,2.6,3.6,4.1,5.3,7.2,8.8, 9.9)
X2<-c(0.33, NA, 0.44, NA, 0.55, NA, 0.66, NA)
Age<- c(33.2, 34.2, 45.1, 46.2, 56.7, 58.9, 76.5, 78.2)
Sex<- c(1,1,2,2,1,1,2,2)
data <- data.frame(ID,TP,X1,X2,Age,Sex)

With my dataframe looking like this:
data
  ID TP  X1   X2  Age Sex
1  1  1 2.3 0.33 33.2   1
2  1  2 2.6   NA 34.2   1
3  2  1 3.6 0.44 45.1   2
4  2  2 4.1   NA 46.2   2
5  3  1 5.3 0.55 56.7   1
6  3  2 7.2   NA 58.9   1
7  4  1 8.8 0.66 76.5   2
8  4  2 9.9   NA 78.2   2

And my code:
library(nlme)
model <- lme(X1 ~ X2 + Age + Sex + TP, data = data, random = ~ 1 | ID)

And the error:
Error in na.fail.default: 
  missing values in object

Anyone have any idea of why it won't run? Wrong coding of X2 in the dataframe?  Wrong method? I have read about using change score as dependent variable in regression analysis, but seems like there is a discussion on how great method it is.
I'll be truly glad for any advice :)

You can have lmer automatically remove any data with missing data by using the option na.action = na.omit as in
model <- lme(X1 ~ X2 + Age + Sex + TP, data = data, random = ~ 1 | ID, na.action = na.omit)
