It seems to mean that the variables don't share a common set of values. If one is predicting the other, it is predicting values that are not present (or the other way round). Mismatch seems to be the proportion of cases assigned a value not present in the levels of the other variable.
In the iris dataset example you post, we can elicit this same output if we introduce a new value to one of the variables in the confusion matrix. Since they're factors, we need to create a new factor level first.
data(iris)
irisfit <- fda(Species ~ ., data = iris)
iris$Predict<-predict(irisfit, iris)
iris$Predict=factor(iris$Predict,levels= c("setosa", "versicolor",
"virginica","monsterosa")) #adding a new level 'monsterosa'
iris$Predict[1]<-"monsterosa" #assign it to one of the observations
Now we can re-run the confusion function and get a mismatch:
confusion(iris$Predict, iris$Species)
true
predicted setosa versicolor virginica
setosa 49 0 0
versicolor 0 48 1
virginica 0 2 49
monsterosa 1 0 0
attr(,"error")
[1] 0.02013423
attr(,"mismatch")
[1] 0.006666667
And if we refactor the other variable to include all levels present in both variables, the mismatch goes away:
iris$Species=factor(iris$Species,levels= c("setosa", "versicolor",
"virginica","monsterosa"))
confusion(iris$Predict, iris$Species)
true
predicted setosa versicolor virginica monsterosa
setosa 49 0 0 0
versicolor 0 48 1 0
virginica 0 2 49 0
monsterosa 1 0 0 0
attr(,"error")
[1] 0.02666667
I would compare as.character(unique(Habitat$Field))
and as.character(unique(Habitat$Map))
to track it down. The as.character is not needed, but makes it easy to read.
Now that you've added data, I see the issue seems to be that you have trailing spaces at the end of some variables and double spaces between words in others.
# see problem
as.character(levels(Habitat$Field))
as.character(levels(Habitat$Map))
# fix problem
# unfactor them for now so we can replace spaces
Habitat$Field<-as.character(Habitat$Field)
Habitat$Map<-as.character(Habitat$Map)
# replace unwanted spaces
Habitat$Field <- gsub("[[:space:]]*$","",Habitat$Field) #gets ending spaces
Habitat$Map <- gsub("[[:space:]]*$","",Habitat$Map) #gets ending spaces
Habitat$Map <- gsub("[[:space:]]{2,}"," ",Habitat$Map) # gets double spaces
Habitat$Field <- gsub("[[:space:]]{2,}"," ",Habitat$Field) # gets double spaces
# factor them again
Habitat$Field <-factor(Habitat$Field)
Habitat$Map<-factor(Habitat$Map)