I'm trying to fit a mcmcglmm using the "MCMCglmm" package in R. I have a data frame with 7 variables.
df <- NNMixedModel2
$Dyad_code
$Sex
$Parity
$Age
$Breed
$Relatedness_m
I've specified which are numeric/factors e.g.
NNMixedModel2$Dyad_code <- as.factor(NNMixedModel2$Dyad_code)
NNMixedModel2$Sex <- as.factor(NNMixedModel2$Sex)
NNMixedModel2$Parity <- as.factor(NNMixedModel2$Parity)
NNMixedModel2$Breed <- as.factor(NNMixedModel2$Breed)
NNMixedModel2$Age <- as.numeric(NNMixedModel2$Age)
NNMixedModel2$Relatedness_m <- as.numeric(NNMixedModel2$Relatedness_m)
NNMixedModel2$weightlg1p <- as.numeric(NNMixedModel2$weightlg1p)
However, when I try to fit the model (below)
prior1.1 <- list(G = list(G1 = list(V = 1, nu = 0.002)), R = list(V = 1, nu = 0.002))
model1.1 <- MCMCglmm(weightlg1p ~ Sex+Parity+Age+Relatedness_m, random = ~Dyad_code, pedigree =NULL, rcov=~us(trait):units, family="gaussian", data = NNMixedModel2, nitt = 13000, thin = 10, burnin = 3000, prior = prior1.1, verbose = FALSE)
I get this error message:
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels
All of my factors have 2 levels
(sex has 377 males and 840 females, parity has 498 of type 1 and 719 of type 2, breed has 90 of one breed and 1127 of the other)
Also, none of the variables have missing values, and when I use the head()
function, the variables are assigned to the correct categories
Can anyone help with this?