I am constructing a statistical model to examine the relationship between thrust force and kinematic data collected from tags attached to animals. The data is structured with 'slip' as a random effect nested within 'individual'. 'slip' describes the slipping motion of the tag, which changes the relationship between thrust force and kinematic data. In order to take into account the changing relationships due to change in tag positions from tag slips, I wanted to make a linear mixed model.
However, some individuals have no slips, resulting in 'slip' having only one category for those individuals. Since 'slip' is nested within 'individual' in a linear mixed model (LMM), will this pose an issue? If so, what are some approaches to address this issue?
I would like to use the nlme package instead of lme4 as I would like to include an autocorrelation structure to the model.
Here is an example dataset:
# Load required library
library(dplyr)
# Set seed for reproducibility
set.seed(123)
# Generate example data
num_rows_per_individual <- 54
# Individual IDs
individuals <- rep(1:3, each = num_rows_per_individual)
# Generate random thrust force (0 - 100N)
thrust <- runif(num_rows_per_individual * 3, min = 0, max = 100)
# Generate random kinematic data (0.3 - 1Hz)
kinematic_data <- runif(num_rows_per_individual * 3, min = 0.3, max = 1)
# Generate slips
slips <- c(rep(1:3, each = num_rows_per_individual/3), # Individual 1 has 3 levels of slips
rep(1:2, each = num_rows_per_individual/2), # Individual 2 has 2 levels of slips
rep(1, num_rows_per_individual)) # Individual 3 has 1 level of slip
# Combine data into a data frame
data <- data.frame(
individual = individuals,
thrust = thrust,
kinematic_data = kinematic_data,
slips = slips
)
# Display the first few rows of the dataset
head(data)
I tried conducting the analysis using the following code:
lme(thrust ~ kinematic_data, random = ~kinematic_data|individual/slips, data = data, cor=corAR1(), control = lmeControl(opt = "optim"))
I got an output with results, but I was unsure if this was an appropriate approach for such a case.