I am analyzing plant Functional Diversity as function of environmental variables. The nature of my data is hierarchical, I have a variable x measured at plant scale, and another one, z, measured at Site scale. Therefore, I chose to use Mixed Models to account for spatial structure.
My doubts are related to the structure of the model. I can't figure out whether adding x and z as fixed effect and Site as random effect is correct or not. I have a unique value of z for each Site.
Here a synthetic example in R:
sites <- as.factor(c("A","B","C","D","E"))
n_sites <- length(sites)
n_samples <- 100
n_obs <- n_sites*n_sample
#Response variable
y <- runif(n_obs, 0, 1)
#Continuous fixed predictors
x <- y + runif(n_obs, -0.1, 0.5)
z <- rep(runif(n_sites,0,1),each=n_samples)
#Categorical random variable
group <- rep(sites,n_samples)
#Model
lmer( y ~ z + x + ( x | group ) )
Group affects the difference in y when x=0 as well as the rate at which y is affected by x.
Using this model structure, is z correctly explaining regional scale variance (among sites) and x the variance within sites?
Is it redundant / incorrect to add as fixed factor a variable (z) having the same number of observations of the random factor (group)?
I would greatly appreciate any advice aimed at solving my doubts!