# NOT RUN {
# }
# NOT RUN {
################################################################
##
## Study of the habitat selection by the chamois in the French
## mountains of Les Bauges
## Loads the data
data(bauges)
names(bauges)
kasc <- bauges$kasc
locs <- bauges$locs
## displays the data
image(kasc)
image(getkasc(kasc,1))
points(locs, col = "red", pch = 16)
## Prepares the data for the GNESFA:
litab <- kasc2df(kasc)
pc <- dudi.pca(litab$tab, scannf = FALSE)
Dp <- count.points(locs, kasc)[litab$index]
## Example of use with Dp = Reference
gn <- gnesfa(pc, Reference = Dp, scannf=FALSE)
## One main axis:
barplot(gn$eig)
## The correlation with variables indicate that
## the elevation, the proximity to grass and to
## deciduous forests:
s.arrow(gn$cor)
## The factorial map of the niche...
scatterniche(gn$li, Dp, pts = TRUE)
## The chamois is rather located at high elevation,
## in the grass, far from deciduous forests
##########################################################
##########################################################
##
##
## Some interesting properties of the GNESFA
##
##
##########################################################
##########################################################
################################
################################
##
## Interesting properties of the
## choice: Dp as Reference
## identical to the MADIFA
## (Calenge et al. in revision,
## See the help page of the function madifa
## for other properties)
gn <- gnesfa(pc, Reference = Dp, scannf=FALSE,
nfFirst = 7)
gn
## This is the same as the MADIFA:
mad <- madifa(pc, Dp, scannf=FALSE)
## Indeed:
plot(gn$li[,1], mad$li[,1])
cor(gn$li[,1], mad$li[,1])
## And consequently the sum of the squared scores,
## On the axes of the GNESFA...
su <- apply(gn$l1,1,function(x) sum(x^2))
## ... is equal to the Mahalanobis distances between
## the points and the centroid of the niche
## (Clark et al. 1993, see the help page of mahasuhab)
su2 <- mahasuhab(kasc, locs)[litab$index]
## Indeed:
all(su - su2 < 1e-7)
plot(su, su2)
################################
################################
##
## Centering twice is identical to
## the ENFA (Hirzel et al. 2002, see the help
## page of the function enfa)...
#######
##
## ... If Dp is the Reference:
gn <- gnesfa(pc, Reference = Dp, center = "twice", scannf = FALSE)
gn
enf <- enfa(pc, Dp, scannf = FALSE)
plot(enf$li[,2], gn$li[,1])
cor(enf$li[,2], gn$li[,1])
## The first specialization axis of the ENFA
## is the first axis of the GNESFA!
#######
##
## ... If Dp is the Focus:
gn <- gnesfa(pc, Focus = Dp, center = "twice",
scannf = FALSE, nfFirst = 6)
plot(enf$li[,2], gn$li[,6])
cor(enf$li[,2], gn$li[,6])
## The first specialization axis of the ENFA
## is the last axis of the GNESFA!
#######
##
## Whatever the distribution chosen as Reference,
## projecting the cloud of points on the hyperplane
## orthogonal to the marginality axis, and performing
## a GNESFA in this subspace is identical to an ENFA!
## The marginality axis of the ENFA is identical
## to the component "projmar" of the GNESFA
plot(enf$li[,1],gn$projmar)
cor(enf$li[,1],gn$projmar)
################################
################################
##
## Interesting properties of the
## case: Dp as Focus, one categorical
## variable. Relationships with the selection
## ratios of Manly et al. (1972, see the
## help page of wi)
## For example, take the Elevation, and
## define a factor with 4 levels
elev <- data.frame(el = cut(litab$tab$Elevation, 4))
## Now, compute the complete disjonctive table
dis <- acm.disjonctif(elev)
head(dis)
## Now perform the GNESFA with Dp as Focus:
pc <- dudi.pca(dis, scannf = FALSE)
gn <- gnesfa(pc, Dp, scannf = FALSE, nfFirst = 3)
#######
##
## This analysis is closely related to the concept of
## selection ratios
## Compute the percentage of use of each level:
us <- apply(dis, 2, function(x) sum(x*Dp)/sum(Dp))
av <- apply(dis, 2, function(x) sum(x)/length(x))
## The selection ratios
wi <- widesI(us, av)$wi
## Compute the sum of the eigenvalue
sum(gn$eig)
## Compute the sum of the selection ratios - 1
sum(wi) - 1
## In other words, when the GNESFA (Dp as Focus) is
## applied on only one categorical variable, this
## analysis finds a set of axes which partition the
## sum of the selection ratios so that it is maximum
## on the first axes!!
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab