diff --git a/NAMESPACE b/NAMESPACE index b7c922be..2ded31bd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -232,7 +232,7 @@ export("originality") export("haar2level", "mld", "orthobasis.circ", "orthobasis.haar", "orthobasis.line", "orthobasis.mat", "orthobasis.neig", "is.orthobasis") ## ******* spatial ******* -export("area2link", "area2poly", "area.plot", "dist.neig", "gridrowcol", "multispati.randtest", "mstree", "multispati.rtest", "nb2neig", "neig", "neig2mat", "neig2nb", "poly2area", "scores.neig") +export("area2link", "area2poly", "area.plot", "dist.neig", "gridrowcol", "mstree", "nb2neig", "neig", "neig2mat", "neig2nb", "poly2area", "scores.neig") ## ******* misc ********* export("bwca.dpcoa") @@ -276,6 +276,8 @@ export("testertracenubisCpp") ## "plot.multispati" ## "print.multispati" ## "plot.multispati" +## "multispati.randtest" +## "multispati.rtest" ## ******* internal utilities ******* diff --git a/R/ade4-deprecated.R b/R/ade4-deprecated.R index c44a6ec3..16aff3f2 100644 --- a/R/ade4-deprecated.R +++ b/R/ade4-deprecated.R @@ -1199,3 +1199,81 @@ s.match(x$li, x$ls, xax = xax, yax = yax, sub = "Scores and lag scores", csub = 2, clabel = 0.75) } + +"multispati.randtest" <- function (dudi, listw, nrepet = 999, ...) { + + .Deprecated(new="multispati.randtest", package="ade4", + msg="The 'multispati.randtest' function is now deprecated in 'ade4' and will soon be available in the 'adespatial' package.") + + if(!inherits(dudi,"dudi")) stop ("object of class 'dudi' expected") + if(!inherits(listw,"listw")) stop ("object of class 'listw' expected") + if(listw$style!="W") stop ("object of class 'listw' with style 'W' expected") + + "testmultispati"<- function(nrepet, nr, nc, tab, mat, lw, cw) { + .C("testmultispati", + as.integer(nrepet), + as.integer(nr), + as.integer(nc), + as.double(as.matrix(tab)), + as.double(mat), + as.double(lw), + as.double(cw), + inersim=double(nrepet+1), + PACKAGE="ade4")$inersim + } + + tab<- dudi$tab + nr<-nrow(tab) + nc<-ncol(tab) + mat<-spdep::listw2mat(listw) + lw<- dudi$lw + cw<- dudi$cw + if (!(identical(all.equal(lw,rep(1/nrow(tab), nrow(tab))),TRUE))) { + stop ("Not implemented for non-uniform weights") + } + inersim<- testmultispati(nrepet, nr, nc, tab, mat, lw, cw) + inertot<- sum(dudi$eig) + inersim<- inersim/inertot + obs <- inersim[1] + w <- as.randtest(sim = inersim[-1], obs = obs, call = match.call(), ...) + return(w) +} + +"multispati.rtest" <- function (dudi, listw, nrepet = 99, ...) { + + .Deprecated(new="multispati.rtest", package="ade4", + msg="The 'multispati.rtest' function is now deprecated in 'ade4' and will soon be available in the 'adespatial' package.") + + if(!inherits(listw,"listw")) stop ("object of class 'listw' expected") + if(listw$style!="W") stop ("object of class 'listw' with style 'W' expected") + if (!(identical(all.equal(dudi$lw,rep(1/nrow(dudi$tab), nrow(dudi$tab))),TRUE))) { + stop ("Not implemented for non-uniform weights") + } + + n <- length(listw$weights) + fun.lag <- function (x) spdep::lag.listw(listw,x,TRUE) + fun <- function (permuter = TRUE) { + if (permuter) { + permutation <- sample(n) + y <- dudi$tab[permutation,] + yw <- dudi$lw[permutation] + } else { + y <-dudi$tab + yw <- dudi$lw + } + y <- as.matrix(y) + ymoy <- apply(y, 2, fun.lag) + ymoy <- ymoy*yw + y <- y*ymoy + indexmoran <- sum(apply(y,2,sum)*dudi$cw) + return(indexmoran) + } + inertot <- sum(dudi$eig) + obs <- fun (permuter = FALSE)/inertot + if (nrepet == 0) return(obs) + perm <- unlist(lapply(1:nrepet, fun))/inertot + w <- as.randtest(obs = obs, sim = perm, call = match.call(), ...) + return(w) +} + + diff --git a/R/multispati.randtest.R b/R/multispati.randtest.R deleted file mode 100644 index be4ff2ec..00000000 --- a/R/multispati.randtest.R +++ /dev/null @@ -1,39 +0,0 @@ -"multispati.randtest" <- function (dudi, listw, nrepet = 999, ...) { - - .Deprecated(new="multispati.randtest", package="ade4", - msg="The 'multispati.randtest' function is now deprecated in 'ade4' and will soon be available in the 'adespatial' package.") - - if(!inherits(dudi,"dudi")) stop ("object of class 'dudi' expected") - if(!inherits(listw,"listw")) stop ("object of class 'listw' expected") - if(listw$style!="W") stop ("object of class 'listw' with style 'W' expected") - - "testmultispati"<- function(nrepet, nr, nc, tab, mat, lw, cw) { - .C("testmultispati", - as.integer(nrepet), - as.integer(nr), - as.integer(nc), - as.double(as.matrix(tab)), - as.double(mat), - as.double(lw), - as.double(cw), - inersim=double(nrepet+1), - PACKAGE="ade4")$inersim - } - - tab<- dudi$tab - nr<-nrow(tab) - nc<-ncol(tab) - mat<-spdep::listw2mat(listw) - lw<- dudi$lw - cw<- dudi$cw - if (!(identical(all.equal(lw,rep(1/nrow(tab), nrow(tab))),TRUE))) { - stop ("Not implemented for non-uniform weights") - } - inersim<- testmultispati(nrepet, nr, nc, tab, mat, lw, cw) - inertot<- sum(dudi$eig) - inersim<- inersim/inertot - obs <- inersim[1] - w <- as.randtest(sim = inersim[-1], obs = obs, call = match.call(), ...) - return(w) -} - diff --git a/R/multispati.rtest.R b/R/multispati.rtest.R deleted file mode 100644 index bb55288b..00000000 --- a/R/multispati.rtest.R +++ /dev/null @@ -1,38 +0,0 @@ -"multispati.rtest" <- function (dudi, listw, nrepet = 99, ...) { - - .Deprecated(new="multispati.rtest", package="ade4", - msg="The 'multispati.rtest' function is now deprecated in 'ade4' and will soon be available in the 'adespatial' package.") - - if(!inherits(listw,"listw")) stop ("object of class 'listw' expected") - if(listw$style!="W") stop ("object of class 'listw' with style 'W' expected") - if (!(identical(all.equal(dudi$lw,rep(1/nrow(dudi$tab), nrow(dudi$tab))),TRUE))) { - stop ("Not implemented for non-uniform weights") - } - - n <- length(listw$weights) - fun.lag <- function (x) spdep::lag.listw(listw,x,TRUE) - fun <- function (permuter = TRUE) { - if (permuter) { - permutation <- sample(n) - y <- dudi$tab[permutation,] - yw <- dudi$lw[permutation] - } else { - y <-dudi$tab - yw <- dudi$lw - } - y <- as.matrix(y) - ymoy <- apply(y, 2, fun.lag) - ymoy <- ymoy*yw - y <- y*ymoy - indexmoran <- sum(apply(y,2,sum)*dudi$cw) - return(indexmoran) - } - inertot <- sum(dudi$eig) - obs <- fun (permuter = FALSE)/inertot - if (nrepet == 0) return(obs) - perm <- unlist(lapply(1:nrepet, fun))/inertot - w <- as.randtest(obs = obs, sim = perm, call = match.call(), ...) - return(w) -} - - diff --git a/_pkgdown.yml b/_pkgdown.yml index c0e2470c..6a339811 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -334,8 +334,6 @@ reference: - orthobasis.line - orthobasis.mat - orthobasis.neig - - multispati.randtest - - multispati.rtest - nb2neig - neig - neig2mat diff --git a/man/ade4-deprecated.Rd b/man/ade4-deprecated.Rd index 4c42b99d..13ad920f 100644 --- a/man/ade4-deprecated.Rd +++ b/man/ade4-deprecated.Rd @@ -15,6 +15,8 @@ - \code{freq2genet}: replaced by \code{df2genind} and \code{genind2genpop} in the \code{adegenet} package \cr - \code{fuzzygenet}: replaced by \code{df2genind} in the \code{adegenet} package \cr - \code{multispati}: replaced by \code{multispati} in the \code{adespatial} package \cr + - \code{multispati.rtest} \cr + - \code{multispati.randtest} \cr - \code{optimEH}: replaced by \code{optimEH} in the \code{adiv} package \cr - \code{orisaved}: replaced by \code{orisaved} in the \code{adiv} package \cr - \code{orthogram}: replaced by \code{orthogram} in the \code{adephylo} package \cr diff --git a/man/multispati.randtest.Rd b/man/multispati.randtest.Rd deleted file mode 100644 index ded74306..00000000 --- a/man/multispati.randtest.Rd +++ /dev/null @@ -1,47 +0,0 @@ -\name{multispati.randtest} -\alias{multispati.randtest} -\title{Multivariate spatial autocorrelation test (in C)} -\description{ -This function is now deprecated in 'ade4' and will soon be available in the 'adespatial' package. -This function performs a multivariate autocorrelation test. -} -\usage{ -multispati.randtest(dudi, listw, nrepet = 999, ...) -} -\arguments{ - \item{dudi}{an object of class \code{dudi} for the duality diagram analysis} - \item{listw}{an object of class \code{listw} for the spatial dependence of data observations} - \item{nrepet}{the number of permutations} - \item{\dots}{further arguments passed to or from other methods} -} -\details{ -We note X the data frame with the variables, Q the column weights matrix -and D the row weights matrix associated to the duality diagram \emph{dudi}. -We note L the neighbouring weights matrix associated to \emph{listw}. -This function performs a Monte-Carlo Test on the multivariate spatial -autocorrelation index : \deqn{r = \frac{trace(X^{t}DLXQ)}{trace(X^{t}DXQ)}}{r = trace(t(X)DLXQ) / trace(t(X)DXQ)} -} -\value{ -Returns an object of class \code{randtest} (randomization tests). -} -\references{ -Smouse, P. E. and Peakall, R. (1999) Spatial autocorrelation analysis of individual multiallele and multilocus genetic structure. -\emph{Heredity}, \bold{82}, 561--573. -} -\author{Daniel Chessel \cr -Sébastien Ollier \email{sebastien.ollier@u-psud.fr} -} -\seealso{\code{\link{dudi}},\code{\link[spdep]{mat2listw}}} -\examples{ -if (requireNamespace("spdep", quietly = TRUE) & requireNamespace("adespatial", quietly = TRUE)) { - data(mafragh) - maf.listw <- spdep::nb2listw(mafragh$nb) - maf.pca <- dudi.pca(mafragh$env, scannf = FALSE) - multispati.randtest(maf.pca, maf.listw) - maf.pca.ms <- adespatial::multispati(maf.pca, maf.listw, scannf = FALSE) - plot(maf.pca.ms) -} -} -\keyword{multivariate} -\keyword{spatial} -\keyword{nonparametric} diff --git a/man/multispati.rtest.Rd b/man/multispati.rtest.Rd deleted file mode 100644 index 26bea56f..00000000 --- a/man/multispati.rtest.Rd +++ /dev/null @@ -1,47 +0,0 @@ -\name{multispati.rtest} -\alias{multispati.rtest} -\title{Multivariate spatial autocorrelation test} -\description{ -This function is now deprecated in 'ade4' and will soon be available in the 'adespatial' package. -This function performs a multivariate autocorrelation test. -} -\usage{ -multispati.rtest(dudi, listw, nrepet = 99, ...) -} -\arguments{ - \item{dudi}{an object of class \code{dudi} for the duality diagram analysis} - \item{listw}{an object of class \code{listw} for the spatial dependence of data observations} - \item{nrepet}{the number of permutations} - \item{\dots}{further arguments passed to or from other methods} -} -\details{ -We note X the data frame with the variables, Q the column weight matrix -and D the row weight matrix associated to the duality diagram \emph{dudi}. -We note L the neighbouring weights matrix associated to \emph{listw}. -This function performs a Monte-Carlo Test on the multivariate spatial -autocorrelation index : \deqn{r = \frac{X^{t}DLXQ}{X^{t}DXQ}}{r = t(X)DLXQ / t(X)DXQ} -} -\value{ -Returns an object of class \code{randtest} (randomization tests). -} -\references{ -Smouse, P. E. and Peakall, R. (1999) Spatial autocorrelation analysis of individual multiallele and multilocus genetic structure. -\emph{Heredity}, \bold{82}, 561--573. -} -\author{Daniel Chessel \cr -Sébastien Ollier \email{sebastien.ollier@u-psud.fr} -} -\seealso{\code{\link{dudi}},\code{\link[spdep]{mat2listw}}} -\examples{ -if (requireNamespace("spdep", quietly = TRUE) & requireNamespace("adespatial", quietly = TRUE)) { - data(mafragh) - maf.listw <- spdep::nb2listw(mafragh$nb) - maf.pca <- dudi.pca(mafragh$env, scannf = FALSE) - multispati.rtest(maf.pca, maf.listw) - maf.pca.ms <- adespatial::multispati(maf.pca, maf.listw, scannf = FALSE) - plot(maf.pca.ms) -} -} -\keyword{multivariate} -\keyword{spatial} -\keyword{nonparametric}