# NOT RUN {
data(bauges)
map <- bauges$kasc
locs <- bauges$loc
## We prepare the data for the MADIFA
(datamad1 <- data2enfa(map, locs))
## We then perform the PCA before the MADIFA
pc <- dudi.pca(datamad1$tab, scannf = FALSE)
(mad <- madifa(pc, datamad1$pr, nf=7,
scannf = FALSE))
#########################################
## ##
## Graphical exploration of the MADIFA ##
## ##
#########################################
hist(mad)
plot(mad, datamad1$index, datamad1$attr)
## 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
plot(sqrt(predict(mad, datamad1$index, datamad1$attr, 1)))
#########################################
## ##
## 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 <- c(mahasuhab(map, locs))[datamad1$index]
## 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(ma1,ma2)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab