if (FALSE) {
data(bauges)
map <- bauges$map
locs <- bauges$loc
## We prepare the data for the MADIFA
tab <- slot(map, "data")
pr <- slot(count.points(locs, map), "data")[,1]
## We then perform the PCA before the MADIFA
pc <- dudi.pca(tab, scannf = FALSE)
(mad <- madifa(pc, pr, nf=7,
scannf = FALSE))
#########################################
## ##
## Graphical exploration of the MADIFA ##
## ##
#########################################
hist(mad)
plot(mad, map)
## this plot represents:
## - the eigenvalues diagram
## - the scores of the columns on the axes
## - a graph of the niche in the available space
## - a map of the Mahalanobis distances computed
## using all environmental variables
## - a map of the Mahalanobis distances computed
## using the two factorial axes used in the
## previous graphs
## - the correlation between habitat variables
## and factorial axes
## - the geographical maps of the two
## factorial axes
## predict with just the first axis
pred <- predict(mad, map, nf=1)
image(pred)
#########################################
## ##
## Mathematical properties of MADIFA ##
## ##
#########################################
## mad$li is equal to mad$l1, up to a constant (mad$l1 is normed)
plot(mad$li[,1],mad$l1[,1])
## This constant is the square root of the corresponding eigenvalue:
## the variance of mad$l1 is equal to the eigenvalue
apply(mad$l1,2,function(x) sum(x^2))/nrow(mad$li)
## the variance of mad$l1 weighted by pr is equal to 1
apply(mad$l1,2,function(x) sum(mad$pr*x^2)/sum(mad$pr))
## Therefore, the eigenvalues are equal to the average of Mahalanobis
## distance for the available resource units on each axis
mean(mahalanobis(matrix(mad$l1[,1], ncol=1), 0, 1))
mad$eig[1]
## Computation of the Mahalanobis distances
ma1 <- mahasuhab(map, locs)
## The sum of squared scores for a given Resource unit is equal to the
## Mahalanobis distances
ma2 <- apply(mad$l1,1, function(x) sum(x^2))
plot(ma2, slot(ma1, "data")[,1])
}
Run the code above in your browser using DataLab