Title: | Spatial Analysis and Data Mining for Field Ecologists |
---|---|
Description: | Set of tools for reading, writing and transforming spatial and seasonal data, model selection and specific statistical tests for ecologists. It includes functions to interpolate regular positions of points between landmarks, to discretize polylines into regular point positions, link distant observations to points and convert a bounding box in a spatial object. It also provides miscellaneous functions for field ecologists such as spatial statistics and inference on diversity indexes, writing data.frame with Chinese characters. |
Authors: | Patrick Giraudoux [aut, cre] , Jean-Philippe Antonietti [ctb], Colin Beale [ctb], Ulrike Groemping [ctb], Renaud Lancelot [ctb], David Pleydell [ctb], Mike Treglia [ctb] |
Maintainer: | Patrick Giraudoux <[email protected]> |
License: | GPL (>= 2) |
Version: | 2.0.3 |
Built: | 2024-11-24 04:39:52 UTC |
Source: | https://github.com/pgiraudoux/pgirmess |
Convert a bounding box into a sf object.
bbox2sf(n,s,w,e,bbox=NA,crs=4326)
bbox2sf(n,s,w,e,bbox=NA,crs=4326)
n |
the top north latitude |
s |
the bottom south latitude |
w |
the most western longitude |
e |
the most eastern longitude |
bbox |
a bounding box 2 x 2 matrix as produced e.g. by |
crs |
the ID number of a coordinate reference system as defined in the EPSG system https://epsg.io/ (default 4326, WGS84) |
This function converts a set of coordinates limiting a bounding box into a an object of class "sfc_POLYGON" (see st_sfc
). It can be used for instance to clip a subset of a larger spatial object (e.g. using st_intersection
)
A simple feature geometry of class "sfc_POLYGON" with a coordinate reference system, see st_sfc
.
n<-79 s<--54 w<--166 e<-178 myPoly1<-bbox2sf(n,s,e,w) plot(myPoly1) # bbox as a 2 x 2 matrix as produced by sp:bbox mybbox<-matrix(c(w,e,s,n),nrow=2,byrow=TRUE) myPoly2<-bbox2sf(bbox=mybbox) plot(myPoly2,border="red") # bbox as produced by sf:st_bbox if (require(sf)) { myPoly3<-bbox2sf(bbox=st_bbox(myPoly2)) plot(myPoly3,border="blue") }
n<-79 s<--54 w<--166 e<-178 myPoly1<-bbox2sf(n,s,e,w) plot(myPoly1) # bbox as a 2 x 2 matrix as produced by sp:bbox mybbox<-matrix(c(w,e,s,n),nrow=2,byrow=TRUE) myPoly2<-bbox2sf(bbox=mybbox) plot(myPoly2,border="red") # bbox as produced by sf:st_bbox if (require(sf)) { myPoly3<-bbox2sf(bbox=st_bbox(myPoly2)) plot(myPoly3,border="blue") }
Computes the lower limit and upper limit of the 95 percent confidence interval of percentage estimates
CI(x, ...)
CI(x, ...)
x |
a two-dimensional table, matrix or data.frame with 2 columns, giving the counts of successes and failures, respectively |
... |
other arguments to pass to |
Simple wrapper of prop.test
. The default confidence interval is 95 percent, but can be modified passing values to prop.test
by the conf.level
argument.
A 3 column matrix.
Column 1: percentage estimate
Column 2: lower limit of the confidence interval
column 3: upper limit of the confidence interval
x<-c(2,10,7,8,7) # eg: number of positive cases y<-c(56,22,7,20,5)# eg: number of negative cases CI(cbind(x,y)) CI(cbind(x,y), conf.level=0.99)
x<-c(2,10,7,8,7) # eg: number of positive cases y<-c(56,22,7,20,5)# eg: number of negative cases CI(cbind(x,y)) CI(cbind(x,y), conf.level=0.99)
Gives an index vector of the class category of each value of a numerical vector
classnum(x, breaks = "Sturges")
classnum(x, breaks = "Sturges")
x |
a vector of values for which the indices are desired |
breaks |
one of:
|
The default for 'breaks' is '"Sturges"': see 'nclass.Sturges'. Other names for which algorithms are supplied are '"Scott"' and '"FD"' for '"Friedman-Diaconis"' (with corresponding functions 'nclass.scott' and 'nclass.FD'). Case is ignored and partial matching is used. Breaks and labels are stored as attributes.
A vector of the same length as x, with the index of the class which each value of x belongs to
x<-rnorm(30) classnum(x) classnum(x,breaks="fd") classnum(x, breaks=c(-1,0,1)) classnum(x,breaks=5)
x<-rnorm(30) classnum(x) classnum(x,breaks="fd") classnum(x, breaks=c(-1,0,1)) classnum(x,breaks=5)
Gives a correlation matrix and the probability of Ho for each correlation estimate
cormat(donnees, method = "spearman", sep = FALSE)
cormat(donnees, method = "spearman", sep = FALSE)
donnees |
a data frame of numerics |
method |
a string of characters among 'pearson', 'spearman' (default), 'kendall' |
sep |
If true, gives the results in two matrices (default = F) |
Wrapper for 'cor' and 'cor.test'. The results can be given in one or two matrices.
If sep = F (default) a list including:
method |
The method used |
prob.cor |
Upper triangle, the correlations; lower triangle, the probability of Ho |
If sep = T a list including:
method |
The method used |
coef.estimates |
The correlation matrix |
p.value |
The Ho probability matrix |
cormat(longley) cormat(longley,sep=TRUE)
cormat(longley) cormat(longley,sep=TRUE)
Computes Moran's or Geary's coefficients on distance classes from a set of spatial coordinates and corresponding z values
correlog(coords, z, method="Moran", nbclass = NULL,...)
correlog(coords, z, method="Moran", nbclass = NULL,...)
coords |
a two columns array, data.frame or matrix of spatial coordinates. Column 1 = X, Column 2 = Y. |
z |
a vector for the values at each location. Must have the same length as the row number of coords |
method |
the method used. Must be "Moran" (default) or "Geary" |
nbclass |
number of bins. If NULL Sturges method is used to compute an optimal number |
... |
further arguments to pass to e.g. |
Uses the library spdep including moran.test
or geary.test
. Distances are euclidian and in the same unit as the spatial coordinates. Moran's Ho: I values larger than 0 due to chance; Geary's Ho: C values lesser than 1 due to chance. Correlog has print and plot methods; statistically significant values (p<0.05) are plotted in red.
An object of class "correlog", a matrix including:
class |
bin centers |
I |
the coefficient values |
p.value |
probability of Ho |
n |
the number of pairs |
Computing can take a long time for large data sets
Patrick Giraudoux [email protected], Colin Beale [email protected] and Mike Treglia [email protected]
see library spdep
library(spdep) data(oldcol) attach(COL.OLD) coords<-cbind(X,Y) res<-correlog(coords,CRIME) plot(res) res<-correlog(coords,CRIME,method="Geary") plot(res)
library(spdep) data(oldcol) attach(COL.OLD) coords<-cbind(X,Y) res<-correlog(coords,CRIME) plot(res) res<-correlog(coords,CRIME,method="Geary") plot(res)
Convert a POSIXt date into categories corresponding to the time spanning from the late months of a year to the early months of the following year
date2winter(x, first = 10, last=4)
date2winter(x, first = 10, last=4)
x |
a vector of POSIXt dates |
first |
number of the first month to include (default 10, October) |
last |
number of the last month to include (default 4, April) |
In ecology, time data must often be analysed on a time span category covering two successive years (e.g. the winter period). This function convert POSIXt dates into categories corresponding to the time span stretching from a user defined month of a given year (by default October) to a user-defined month of the following year (by default April). If date month is out of the user defined time span the value 'Excluded' is returned.
A vector of the same length as x, with the time span category each value belongs to.
dates <- strptime(c("02/12/2002", "15/01/2003","15/10/2003","15/6/2003",NA),"%d/%m/%Y") date2winter(dates)
dates <- strptime(c("02/12/2002", "15/01/2003","15/10/2003","15/6/2003",NA),"%d/%m/%Y") date2winter(dates)
Computes the edge of a square from its diagonal.
diag2edge(cordseg)
diag2edge(cordseg)
cordseg |
The diagonal coordinates. This can be a vector c(x1,y1,x2,y2), a 2 x 2 matrix or a data.frame (each line a coordinate) |
The first point coordinates are the left top of the diagonal. The other coordinates computed are the other
top of the square edge. Can be used e.g. to pass a square edge to pave
in order
to compute a sampling grid.
A 2x2 matrix of points coordinates
# diagonal sloping up coord<-matrix(c(20,20,90,90),nr=2,byrow=TRUE) plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1) lines(coord,lty=2) # square edge lines(diag2edge(coord),col="red") # diagonal sloping down coord<-matrix(c(20,90,90,20),nr=2,byrow=TRUE) plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1) lines(coord,lty=2) # square edge lines(diag2edge(coord),col="red") # diagonal vertical coord<-matrix(c(20,90,20,20),nr=2,byrow=TRUE) plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1) lines(coord,lty=2) # square edge lines(diag2edge(coord),col="red")
# diagonal sloping up coord<-matrix(c(20,20,90,90),nr=2,byrow=TRUE) plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1) lines(coord,lty=2) # square edge lines(diag2edge(coord),col="red") # diagonal sloping down coord<-matrix(c(20,90,90,20),nr=2,byrow=TRUE) plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1) lines(coord,lty=2) # square edge lines(diag2edge(coord),col="red") # diagonal vertical coord<-matrix(c(20,90,20,20),nr=2,byrow=TRUE) plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1) lines(coord,lty=2) # square edge lines(diag2edge(coord),col="red")
Computes the empirical confidence interval of the bootstrap of the difference between two Shannon indices
difshannonbio(dat1, dat2, R = 1000, probs = c(0.025, 0.975))
difshannonbio(dat1, dat2, R = 1000, probs = c(0.025, 0.975))
dat1 |
a data.frame of two columns; column = category, column 2 = biomass |
dat2 |
a data.frame of two columns; column = category, column 2 = biomass |
R |
number of permutations |
probs |
the limits of the confidence interval |
Designated to compare the difference between two Shannon's indices computed from two data frames. In each data frame, the first column is the category of prey item, and the second column the estimated biomass.
A list with the confidence interval of H' and J'
data(preybiom) attach(preybiom) jackal<-preybiom[site=="Y" & sp=="C",5:6] genet<-preybiom[site=="Y" & sp=="G",5:6] difshannonbio(jackal,genet,R=150)
data(preybiom) attach(preybiom) jackal<-preybiom[site=="Y" & sp=="C",5:6] genet<-preybiom[site=="Y" & sp=="G",5:6] difshannonbio(jackal,genet,R=150)
Computes new coordinates from bearings (North = 0) and distances
dirProj(df,deg=TRUE)
dirProj(df,deg=TRUE)
df |
a matrix or data frame of 4 columns giving x, y coordinates, bearings and distances |
deg |
if TRUE (default) bearings are in degree, otherwise in radian |
Computings are based on euclidian distance. Therefore, the coordinates should be given in a projected (plan) system (e.g. UTM, Lambert, etc.) and the distance in the same units as the projection system (e.g. meters).
a matrix of two columns with the projected coordinates
df<-data.frame(x1=0,y1=0,alpha=runif(3,0,360),d=runif(3,0,1)) df plot(-1:1,-1:1,type="n") points(0,0,pch=19) points(dirProj(df)) text(dirProj(df)[,1],dirProj(df)[,2],1:3,pos=4)
df<-data.frame(x1=0,y1=0,alpha=runif(3,0,360),d=runif(3,0,1)) df plot(-1:1,-1:1,type="n") points(0,0,pch=19) points(dirProj(df)) text(dirProj(df)[,1],dirProj(df)[,2],1:3,pos=4)
Computes the direction of segments from the first top clockwise (North = 0)
dirSeg(x,deg=TRUE)
dirSeg(x,deg=TRUE)
x |
a matrix or data frame of 4 columns giving the coordinates of each segment tops x1, y1, x2, y2 |
deg |
if TRUE (default) the output is in degrees, otherwise in radians |
The first two colomns give the first top coordinates, x then y, and the next two the second top coordinates.
A vector of directions
x2<-rnorm(10) y2<-rnorm(10) mydata<-cbind(0,0,x2,y2) dirs<-dirSeg(mydata) dirs plot(range(mydata[,c(1,3)]),range(mydata[,c(2,4)]),type="n") Segments(mydata) text(mydata[,3],mydata[,4],paste(round(dirs,0),"\u00b0"),cex=0.7)
x2<-rnorm(10) y2<-rnorm(10) mydata<-cbind(0,0,x2,y2) dirs<-dirSeg(mydata) dirs plot(range(mydata[,c(1,3)]),range(mydata[,c(2,4)]),type="n") Segments(mydata) text(mydata[,3],mydata[,4],paste(round(dirs,0),"\u00b0"),cex=0.7)
Computes distances to the nearest neighbour
distNNeigh(db)
distNNeigh(db)
db |
A matrix or data.frame of points coordinates column 1 = x,column 2 = y. |
Computes distances to the nearest neighbour for each line of a matrix of points coordinates
A vector of distances
distNNeigh(cbind(rnorm(30),rnorm(30)))
distNNeigh(cbind(rnorm(30),rnorm(30)))
Computes the distances between each nodes of a polyline.
distNode(pts,decdeg=FALSE)
distNode(pts,decdeg=FALSE)
pts |
A matrix or data.frame of the node coordinates column 1 = x,column 2 = y. |
decdeg |
TRUE if point coordinates are longitude-latitude decimal degrees, in which case distances are measured in meters |
If degdec is FALSE (default), distance computed is Euclidian. Units depends on the coordinate systems. If decdeg = TRUE, D = 1852 * 60 * (180/pi) * acos ( sin(la1) * sin(la2) + cos(la1) * cos(la2) * cos(abs(lg1 - lg2)). This method calculates the great circle distance, is based on spherical trigonometry, and assumes that:
1 minute of arc is 1 nautical mile
1 nautical mile is 1.852 km
A vector of distances
x<-c(10,56,100) y<-c(23,32,150) distNode(cbind(x,y))
x<-c(10,56,100) y<-c(23,32,150) distNode(cbind(x,y))
Computes the distances between the top coordinates of segments.
distSeg(mydata,decdeg=FALSE)
distSeg(mydata,decdeg=FALSE)
mydata |
A matrix or data frame of 4 columns giving the coordinates of each segment tops x1, y1, x2, y2 |
decdeg |
TRUE if point coordinates are longitude-latitude decimal degrees, in which case distances are measured in meters |
If degdec is FALSE (default), distance computed is Euclidian. Units depends on the coordinate systems. If decdeg = TRUE, D = 1852 * 60 * (180/pi) * acos ( sin(la1) * sin(la2) + cos(la1) * cos(la2) * cos(abs(lg1 - lg2)). This method calculates the great circle distance, is based on spherical trigonometry, and assumes that:
1 minute of arc is 1 nautical mile
1 nautical mile is 1.852 km
When computing with decdeg=TRUE duplicated coordinates strictly identical can lead to produce NaN. The corresponding distance is coerced to zero with warnings and if so, an attribute 'NaNcoerced2zero' with the row numbers of the distances that have been coerced to zero is created
A vector of distances, possibly with the attribute 'NaNcoerced2zero' with the row numbers of the distances that have been coerced to zero if any.
x1<-rnorm(20) y1<-rnorm(20) x2<-rnorm(20) y2<-rnorm(20) mydata<-cbind(x1,y1,x2,y2) distSeg(mydata)
x1<-rnorm(20) y1<-rnorm(20) x2<-rnorm(20) y2<-rnorm(20) mydata<-cbind(x1,y1,x2,y2) distSeg(mydata)
Computes the total length of a polyline.
distTot(pts,decdeg=FALSE)
distTot(pts,decdeg=FALSE)
pts |
A matrix or data.frame of the node coordinates column 1 = x,column 2 = y. |
decdeg |
TRUE if point coordinates are longitude-latitude decimal degrees, in which case distances are measured in meters |
If degdec is FALSE (default), distance computed is Euclidian. Units depends on the coordinate systems. If decdeg = TRUE, D = 1852 * 60 * (180/pi) * acos ( sin(la1) * sin(la2) + cos(la1) * cos(la2) * cos(abs(lg1 - lg2)). This method calculates the great circle distance, is based on spherical trigonometry, and assumes that:
1 minute of arc is 1 nautical mile
1 nautical mile is 1.852 km
A numeric distance.
x<-c(10,56,100) y<-c(23,32,150) distTot(cbind(x,y))
x<-c(10,56,100) y<-c(23,32,150) distTot(cbind(x,y))
Compute the new coordinates of polygon expanded by a factor.
expandpoly(mypol, fact)
expandpoly(mypol, fact)
mypol |
matrix or data.frame of polygon coordinates |
fact |
expansion factor |
The polygon area obtained after expansion is equal to times the original polygon area
A matrix of polygon coordinates
x<-c(-5,-4.5,0,10,5) y<-c(-10,0,5,5,-8) poly<-cbind(x,y) plot(-10:20,-20:10,type="n") polygon(poly) polygon(expandpoly(poly,1.5),border="red") polygon(expandpoly(poly,0.5),border="blue")
x<-c(-5,-4.5,0,10,5) y<-c(-10,0,5,5,-8) poly<-cbind(x,y) plot(-10:20,-20:10,type="n") polygon(poly) polygon(expandpoly(poly,1.5),border="red") polygon(expandpoly(poly,0.5),border="blue")
Computes the distance between the centroid and the most distant coordinate of a geographical coordinate set.
findR(coords)
findR(coords)
coords |
A matrix or data frame of 2 columns of geographical coordinates |
The distance
mydata<-cbind(x=rnorm(20),y=rnorm(20)) radius<-findR(mydata) centroid<-matrix(colMeans(mydata),ncol=2) plot(mydata,asp=1) points(centroid,pch=19,col="red",cex=2) polygon(polycirc(radius,centroid),border="red")
mydata<-cbind(x=rnorm(20),y=rnorm(20)) radius<-findR(mydata) centroid<-matrix(colMeans(mydata),ncol=2) plot(mydata,asp=1) points(centroid,pch=19,col="red",cex=2) polygon(polycirc(radius,centroid),border="red")
Test of multiple comparison after Friedman test
friedmanmc(y, groups, blocks,alpha=0.05)
friedmanmc(y, groups, blocks,alpha=0.05)
y |
a numeric vector of data values, or a data matrix |
groups |
a vector giving the group for the corresponding elements of 'y' if this is a vector; ignored if 'y' is a matrix. If not a factor object, it is coerced to one. |
blocks |
a vector giving the block for the corresponding elements of 'y' if this is a vector; ignored if 'y' is a matrix. If not a factor object, it is coerced to one. |
alpha |
the significiance level |
Method for formula still not implemented. Formula 7.5a (Siegel & Castellan, 1988 p 180-181) can lead to p-values larger than 1 when differences between groups are small. Eventually, they are set to NA and a warning is generated.
A list of class 'mc' with the following items:
statistic |
statistics used |
alpha |
the significance level |
dif.com |
a data.frame with observed and critical differences, statistical significance at the alpha risk (true/false) and p-value |
Siegel & Castellan (1988) Non parametric statistics for the behavioural sciences. Mc Graw Hill Int. Edt.
friedman.test
; for other functions about median multiple comparison see package 'PMCMRplus'
data(siegelp179) attach(siegelp179) friedman.test(score,treatment,block) friedmanmc(score,treatment,block) friedmanmc(score,treatment,block,alpha=0.01) mymatrix<-matrix(score,nc=3) friedman.test(mymatrix) friedmanmc(mymatrix) detach(siegelp179)
data(siegelp179) attach(siegelp179) friedman.test(score,treatment,block) friedmanmc(score,treatment,block) friedmanmc(score,treatment,block,alpha=0.01) mymatrix<-matrix(score,nc=3) friedman.test(mymatrix) friedmanmc(mymatrix) detach(siegelp179)
Multiple comparison test between treatments or treatments versus control after Kruskal-Wallis test
kruskalmc(resp,...) ## Default S3 method: kruskalmc(resp, categ, alpha = 0.05, cont=NULL,...) ## S3 method for class 'formula' kruskalmc(resp,data=NULL,...)
kruskalmc(resp,...) ## Default S3 method: kruskalmc(resp, categ, alpha = 0.05, cont=NULL,...) ## S3 method for class 'formula' kruskalmc(resp,data=NULL,...)
resp |
a numeric vector of data values or a formula of the type 'response~category'. |
categ |
a factor object giving the group for the corresponding elements of 'x' |
alpha |
the significance level |
cont |
NULL (default) for multiple comparison between treatments; 'one-tailed' or 'two-tailed' for corresponding multiple comparisons treatments versus control; partial matching allowed |
data |
a data.frame including the variables used in the formula |
... |
other parameters to be passed as arguments (not used here) |
When the value of a Kruskal-Wallis test is significant, it indicates that at least one of the groups is different from at least one of the others. This test helps determining which groups are different with pairwise comparisons adjusted appropriately for multiple comparisons. Those pairs of groups which have observed differences larger than a critical value are considered statistically different at a given significance level. Three types of multiple comparisons are implemented: comparisons between treatments, 'one-tailed' and 'two-tailed' comparison treatments versus control. The first factor level is considered the control. NAs are omitted from data before processing.
For further details please consider the refence below where the method is fully described, or visit https://giraudoux.pagesperso-orange.fr/#pgirmess where a copy of the corresponding book section can be downloaded.
A list of class 'mc' with the following items:
statistic |
statistics used |
signif.level |
the significance level |
dif.com |
a data.frame with observed and critical differences |
Alternative methods are proposed in the section 'see also', on François Gillet's suggestion. The three methods do not give necessarily the same results, and the why is still to investigate
Siegel and Castellan (1988) Non parametric statistics for the behavioural sciences. MacGraw Hill Int., New York. pp 213-214
kruskal.test
; to reorder factor levels see relevel
; for other functions about median multiple comparison see package 'PMCMRplus'; kruskal
resp<-c(0.44,0.44,0.54,0.32,0.21,0.28,0.7,0.77,0.48,0.64,0.71,0.75,0.8,0.76,0.34,0.80,0.73,0.8) categ<-as.factor(rep(c("A","B","C"),times=1,each=6)) kruskalmc(resp, categ) kruskalmc(resp, categ, alpha=0.01) kruskalmc(resp, categ, cont="one-tailed") kruskalmc(resp, categ, cont="two-tailed") kruskalmc(resp~categ) kruskalmc(resp~categ, alpha=0.01) kruskalmc(resp~categ, cont="one-tailed") kruskalmc(resp~categ, cont="two-tailed")
resp<-c(0.44,0.44,0.54,0.32,0.21,0.28,0.7,0.77,0.48,0.64,0.71,0.75,0.8,0.76,0.34,0.80,0.73,0.8) categ<-as.factor(rep(c("A","B","C"),times=1,each=6)) kruskalmc(resp, categ) kruskalmc(resp, categ, alpha=0.01) kruskalmc(resp, categ, cont="one-tailed") kruskalmc(resp, categ, cont="two-tailed") kruskalmc(resp~categ) kruskalmc(resp~categ, alpha=0.01) kruskalmc(resp~categ, cont="one-tailed") kruskalmc(resp~categ, cont="two-tailed")
Kolmogorof-Smirnov goodness of fit test to normal distribution
ks.gof(var)
ks.gof(var)
var |
a numeric vector |
A wrapper of ks.test()
A list with class '"htest"' containing the following components:
statistic |
the value of the test statistic. |
p.value |
a character string indicating what type of test was performed. |
alternative |
a character string describing the alternative hypothesis. |
method |
a character string indicating what type of test was performed. |
data.name |
a character string giving the name(s) of the data. |
see ks.test
x<-rnorm(50) ks.gof(x)
x<-rnorm(50) ks.gof(x)
Count the nearest observations to points corresponding to track intervals (e.g. observation counts along a road discretized into points).
mergeTrackObs(sppdfInt,sppdfObs,obscol=NULL)
mergeTrackObs(sppdfInt,sppdfObs,obscol=NULL)
sppdfInt |
|
sppdfObs |
|
obscol |
The column number in which the number of observations at this point can be found in sppdfObs, if any (default=NULL, no such data) |
Road side counts and faeces collections are often carried out along tracks (paths, roads, transects, trails, etc.). Tracks can be discretized in regular intervals e.g. with transLines2pix
or st_thintrack
, each point being the center of a track interval. mergeTrackobs computes the number of observations that are the closest to each interval (compare to the other intervals) and give it in the column 'nObs'. if the argument 'obscol' is NULL, observations are considered presence/absence. If the number of observations is a true count (0 or any positive number) the argument 'obscol' can be used to identify the column of 'sppdfObs' where those counts must be found. Coordinate reference systems must be the identical.
A sfc
object, of POINT geometry, with the following columns:
ID, ID number
nObs, The number of observations in the interval
geometry, POINT geometry
if(require(sf)){ # track sl<-st_sfc(st_linestring(cbind(c(1,2,3),c(1,1.5,1)))) plot(sl, col = "blue") #observations obs <- structure(list(ID = 1:15, long = c(1.04609377280342, 1.0890625305741, 1.08125002916125, 1.24921880953755, 1.34687507719818, 1.50312510545521, 1.88984392539134, 2.37812526369453, 2.39375026652023, 2.36640651157525, 2.38593776510738, 2.62031280749291, 2.69843782162142, 2.85078159917202, 2.90546910906198), lat = c(1.04062476682306, 1.05624976964876, 1.03671851611663, 1.13828103448369, 1.16562478942867, 1.26718730779574, 1.43124983746561, 1.32968731909855, 1.32187481768569, 1.30624981485999, 1.28281231062144, 1.20468729649293, 1.13828103448369, 1.08749977530016, 1.03671851611663)), .Names = c("ID", "long", "lat"), row.names = c(NA, -15L), class = "data.frame") points(obs[,2:3],col="red") obs<-st_as_sf(obs,coords=c(2:3)) # possibly a count (number of individuals observed) on each location obs$n<-c(3,4,0,1,1,5,6,4,3,4,4,7,2,2,1) # examples # Presence/absence on each observation track<-transLines2pix(sl,0.1) trackObs<-mergeTrackObs(track,obs) par(mfrow=c(1,2)) plot(sl,reset=FALSE) plot(track,add=TRUE,col="blue") plot(st_geometry(obs),add=TRUE,col="red",pch=1) plot(sl,reset=FALSE) plot(track,add=TRUE,col="blue") plot(trackObs,cex=trackObs$nObs,pch=19, col="red",add=TRUE) # 0 or more observations on each location head(obs) st_drop_geometry(obs) # the counts are in column "n" (column 2 in the data.frame) trackObs<-mergeTrackObs(track,obs,obscol="n") par(mfrow=c(1,2)) plot(sl,reset=TRUE) plot(track,add=TRUE,col="blue") plot(st_geometry(obs),add=TRUE,col="red",pch=1) plot(sl) plot(track,add=TRUE,col="blue") plot(st_geometry(trackObs),cex=trackObs$nObs/3,pch=19, col="red",add=TRUE) }
if(require(sf)){ # track sl<-st_sfc(st_linestring(cbind(c(1,2,3),c(1,1.5,1)))) plot(sl, col = "blue") #observations obs <- structure(list(ID = 1:15, long = c(1.04609377280342, 1.0890625305741, 1.08125002916125, 1.24921880953755, 1.34687507719818, 1.50312510545521, 1.88984392539134, 2.37812526369453, 2.39375026652023, 2.36640651157525, 2.38593776510738, 2.62031280749291, 2.69843782162142, 2.85078159917202, 2.90546910906198), lat = c(1.04062476682306, 1.05624976964876, 1.03671851611663, 1.13828103448369, 1.16562478942867, 1.26718730779574, 1.43124983746561, 1.32968731909855, 1.32187481768569, 1.30624981485999, 1.28281231062144, 1.20468729649293, 1.13828103448369, 1.08749977530016, 1.03671851611663)), .Names = c("ID", "long", "lat"), row.names = c(NA, -15L), class = "data.frame") points(obs[,2:3],col="red") obs<-st_as_sf(obs,coords=c(2:3)) # possibly a count (number of individuals observed) on each location obs$n<-c(3,4,0,1,1,5,6,4,3,4,4,7,2,2,1) # examples # Presence/absence on each observation track<-transLines2pix(sl,0.1) trackObs<-mergeTrackObs(track,obs) par(mfrow=c(1,2)) plot(sl,reset=FALSE) plot(track,add=TRUE,col="blue") plot(st_geometry(obs),add=TRUE,col="red",pch=1) plot(sl,reset=FALSE) plot(track,add=TRUE,col="blue") plot(trackObs,cex=trackObs$nObs,pch=19, col="red",add=TRUE) # 0 or more observations on each location head(obs) st_drop_geometry(obs) # the counts are in column "n" (column 2 in the data.frame) trackObs<-mergeTrackObs(track,obs,obscol="n") par(mfrow=c(1,2)) plot(sl,reset=TRUE) plot(track,add=TRUE,col="blue") plot(st_geometry(obs),add=TRUE,col="red",pch=1) plot(sl) plot(track,add=TRUE,col="blue") plot(st_geometry(trackObs),cex=trackObs$nObs/3,pch=19, col="red",add=TRUE) }
Produces a matrix with scatterplot, regression line and a loess smooth in the upper right panel; correlation coefficient (Pearson, Spearman or Kendall) and the probability of Ho in the lower left panel
pairsrp(dataframe, meth = "spearman", pansmo = FALSE, abv = FALSE, lwt.cex = NULL, ...)
pairsrp(dataframe, meth = "spearman", pansmo = FALSE, abv = FALSE, lwt.cex = NULL, ...)
dataframe |
a data.frame of numeric values |
meth |
a character string indicating which correlation coefficient is to be computed. One of 'pearson', 'kendall', or 'spearman'(default). Can be abbreviated. |
pansmo |
True if a loess smooth is to be plotted. Default to False. |
abv |
True if the variable names must be abbreviates. Default to False. |
lwt.cex |
character size expansion in the lower panel. |
... |
graphical parameters can be given as arguments to 'plot'. |
This function is a wrapper for pairs() and cor()
data(iris) pairsrp(iris[,1:4],meth="pears",pansmo=TRUE,abv=TRUE)
data(iris) pairsrp(iris[,1:4],meth="pears",pansmo=TRUE,abv=TRUE)
Provide a user-defined cell grid of polygon squares (or square node points) along a segment. This can be used to define a sampling grid for spatial analysis.
pave(cordseg, yc, xc, fix.edge=NULL, ydown = TRUE, output = "list")
pave(cordseg, yc, xc, fix.edge=NULL, ydown = TRUE, output = "list")
cordseg |
the segment coordinates. This can be a vector c(x1,y1,x2,y2), a 2 x 2 matrix or a data.frame (each line a coordinate) |
yc |
the number of segment divisions (y cells) |
xc |
the number of columns (x cells) |
fix.edge |
the edge length of a cell (user specified, default to NULL) |
ydown |
if TRUE (default) squares are computed decreasing y |
output |
a character string indicating which output is required. One of "list", "points" or "spdf". Partial match allowed |
The segment must have x1 < x2. If not, it is automatically reordered. When "spdf" is selected the output is an object of class
SpatialPolygonsDataFrame
. The value of the edge length of a cell can passed with the argument fix.edge. In this case, the coordinates of the segment right top are re-computed to adjust the cell edge to an user defined fixed value.
According to the output selected, a list of polygon coordinates, a 2 column matrix with the nodes coordinates or a SpatialPolygonsDataFrame
.
# segment sloping up coord<-matrix(c(20,20,90,90),nr=2,byrow=TRUE) plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1) lines(coord) # point grids gr<-pave(coord,20,4,output="points") # y decreasing points(gr) gr<-pave(coord,20,4,output="points",ydown=FALSE) # y increasing points(gr,col="blue") # square polygon grids gr<-pave(coord,20,4) # y decreasing for (i in 1:length(gr)) polygon(gr[[i]]) gr<-pave(coord,20,4,ydown=FALSE) # y increasing for (i in 1:length(gr)) polygon(gr[[i]],border="blue") # segment sloping down coord<-matrix(c(20,90,90,20),nr=2,byrow=TRUE) plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1) lines(coord) # point grids gr<-pave(coord,20,4,output="points") # y decreasing points(gr) gr<-pave(coord,20,4,output="points",ydown=FALSE) # y increasing points(gr,col="blue") # fixed edge plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1) lines(coord) gr<-pave(coord,20,4,fix.edge=4,output="points") points(gr,col="blue") plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1) lines(coord) gr<-pave(coord,20,4,fix.edge=5.5,output="points") points(gr,col="red") # square polygon grids coord<-matrix(c(20,90,90,20),nr=2,byrow=TRUE) plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1) lines(coord,lwd=2) gr<-pave(coord,20,4)# y decreasing for (i in 1:length(gr)) polygon(gr[[i]]) gr<-pave(coord,20,4,ydown=FALSE) # y increasing for (i in 1:length(gr)) polygon(gr[[i]],border="blue") # geting a SpatialPolygonsDataFrame gr<-pave(coord,20,4,output="spdf") # y decreasing
# segment sloping up coord<-matrix(c(20,20,90,90),nr=2,byrow=TRUE) plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1) lines(coord) # point grids gr<-pave(coord,20,4,output="points") # y decreasing points(gr) gr<-pave(coord,20,4,output="points",ydown=FALSE) # y increasing points(gr,col="blue") # square polygon grids gr<-pave(coord,20,4) # y decreasing for (i in 1:length(gr)) polygon(gr[[i]]) gr<-pave(coord,20,4,ydown=FALSE) # y increasing for (i in 1:length(gr)) polygon(gr[[i]],border="blue") # segment sloping down coord<-matrix(c(20,90,90,20),nr=2,byrow=TRUE) plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1) lines(coord) # point grids gr<-pave(coord,20,4,output="points") # y decreasing points(gr) gr<-pave(coord,20,4,output="points",ydown=FALSE) # y increasing points(gr,col="blue") # fixed edge plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1) lines(coord) gr<-pave(coord,20,4,fix.edge=4,output="points") points(gr,col="blue") plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1) lines(coord) gr<-pave(coord,20,4,fix.edge=5.5,output="points") points(gr,col="red") # square polygon grids coord<-matrix(c(20,90,90,20),nr=2,byrow=TRUE) plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1) lines(coord,lwd=2) gr<-pave(coord,20,4)# y decreasing for (i in 1:length(gr)) polygon(gr[[i]]) gr<-pave(coord,20,4,ydown=FALSE) # y increasing for (i in 1:length(gr)) polygon(gr[[i]],border="blue") # geting a SpatialPolygonsDataFrame gr<-pave(coord,20,4,output="spdf") # y decreasing
Return a random permutation of a contingency table n rows x 2 columns keeping the marginal totals
permcont(Table)
permcont(Table)
Table |
a contingency table |
The contingency table is split in a two colums table of 0/1 categories, sampled and re-organised with the function table()
A matrix with the permuted values
tab<-cbind(n1=c(10,12,8,7,5),n2=c(4,5,8,10,12)) tab permcont(tab)
tab<-cbind(n1=c(10,12,8,7,5),n2=c(4,5,8,10,12)) tab permcont(tab)
Permutation test for lm, lme and glm (binomial and Poisson) objects
PermTest(obj, B=1000,...) ## S3 method for class 'lm' PermTest(obj, B=1000,...) ## S3 method for class 'lme' PermTest(obj, B=1000,...) ## S3 method for class 'glm' PermTest(obj, B=1000,...)
PermTest(obj, B=1000,...) ## S3 method for class 'lm' PermTest(obj, B=1000,...) ## S3 method for class 'lme' PermTest(obj, B=1000,...) ## S3 method for class 'glm' PermTest(obj, B=1000,...)
obj |
an object of class lm, lme, or glm |
B |
number of permutations, default = 1000 |
... |
used to pass other arguments |
For glm, when the response is a two-column matrix with the columns giving the numbers of successes and failures, PermTest.glm uses permcont(); PermTest.lme requires the library nlme.
A list object of class PermTest including:
p.value |
the p value obtained |
B |
the number of permutations |
call |
the call |
This generic function is implemented in R language, thus can be quite slow.
The implementation of PermTest.lme has been helped by Renaud Lancelot
if(require(MASS)){ mylm<-lm(Postwt~Prewt,data=anorexia) PermTest(mylm,B=250) ## Dobson (1990) Page 93: Randomized Controlled Trial : counts <- c(18,17,15,20,10,20,25,13,12) outcome <- gl(3,1,9) treatment <- gl(3,3) glm.D93 <- glm(counts ~ outcome + treatment, family=poisson) PermTest(glm.D93,B=100) } if(require(nlme)){ fm2 <- lme(distance ~ age + Sex, data = Orthodont, random = ~ 1) PermTest(fm2,B=100) }
if(require(MASS)){ mylm<-lm(Postwt~Prewt,data=anorexia) PermTest(mylm,B=250) ## Dobson (1990) Page 93: Randomized Controlled Trial : counts <- c(18,17,15,20,10,20,25,13,12) outcome <- gl(3,1,9) treatment <- gl(3,3) glm.D93 <- glm(counts ~ outcome + treatment, family=poisson) PermTest(glm.D93,B=100) } if(require(nlme)){ fm2 <- lme(distance ~ age + Sex, data = Orthodont, random = ~ 1) PermTest(fm2,B=100) }
Computes the Pianka's index of niche overlap
piankabio(dataframe1, dataframe2)
piankabio(dataframe1, dataframe2)
dataframe1 |
a data frame of two columns: column 1 = dietary category, column 2 = biomass |
dataframe2 |
a data frame of two columns: column 1 = dietary category, column 2 = biomass |
Computes the Pianka's index of niche overlap
Return the Pianka's index
Pianka R.D. 1973 The scructure of lizard communities. Annual Review of Ecology and Systematics, 4: 53-74.
Amroun M., Giraudoux P., Delattre P. 2006 Comparative study of the diets of two sympatric carnivores - the Jackal (Canis aureus) and the Genet (Genetta genetta) - at two sites in Kabylia, Algeria. Mammalia, 70 (3): 247-254
data(preybiom) attach(preybiom) jackal<-preybiom[site=="Y" & sp=="C",5:6] genet<-preybiom[site=="Y" & sp=="G",5:6] piankabio(jackal,genet)
data(preybiom) attach(preybiom) jackal<-preybiom[site=="Y" & sp=="C",5:6] genet<-preybiom[site=="Y" & sp=="G",5:6] piankabio(jackal,genet)
Bootstrap Pianka's index and return the limits of the empirical confidence interval specified with probs
piankabioboot(dataframe1, dataframe2, B = 1000, probs = c(0.025, 0.975))
piankabioboot(dataframe1, dataframe2, B = 1000, probs = c(0.025, 0.975))
dataframe1 |
a data frame of two columns: column 1 = dietary category, column 2 = biomass |
dataframe2 |
a data frame of two columns: column 1 = dietary category, column 2 = biomass |
B |
number of permutations |
probs |
the limits of the confidence interval |
Bootstrap Pianka's index and return the limits of the empirical confidence interval sepcified with probs
a vector of the two CI limits
data(preybiom) attach(preybiom) jackal<-preybiom[site=="Y" & sp=="C",5:6] genet<-preybiom[site=="Y" & sp=="G",5:6] piankabioboot(jackal,genet,B=100)
data(preybiom) attach(preybiom) jackal<-preybiom[site=="Y" & sp=="C",5:6] genet<-preybiom[site=="Y" & sp=="G",5:6] piankabioboot(jackal,genet,B=100)
Computes the polygon coordinates of a circle
polycirc(radius, pts = c(0, 0), nbr = 50)
polycirc(radius, pts = c(0, 0), nbr = 50)
radius |
the length of the radius. |
pts |
the coordinates of the center. |
nbr |
the number of segments required to draw the perimeter |
The matrix of coordinates can then be used with the function polygon
A matrix of coordinates.
plot(1:10,1:10,type="n",asp=1) polygon(polycirc(5),col="blue") polygon(polycirc(2,c(5,5)), col="red")
plot(1:10,1:10,type="n",asp=1) polygon(polycirc(5),col="blue") polygon(polycirc(2,c(5,5)), col="red")
Computes the polygon coordinates of a circle sector
polycirc2(radius = 1, center = c(0, 0), edges = 50, init = pi/2, angle = pi/2)
polycirc2(radius = 1, center = c(0, 0), edges = 50, init = pi/2, angle = pi/2)
radius |
the circle radius |
center |
the centre coordinates (defaut to x=0, y=0) |
edges |
the circular outline of the sector is approximated by a polygon with this many edges |
init |
number (in radian) specifying the starting angle |
angle |
number (in radian) specifying the sector angle |
The matrix of coordinates obtained is intended to be passed to the function polygon
A matrix of coordinates
polygon
,polycirc
, floating.pie
plot(c(-1,+1),c(-1,+1),type="n",asp=1) polygon(polycirc2(),col="red") polygon(polycirc2(init=pi,angle=pi/4),col="green") polygon(polycirc2(init=1.5*pi,angle=pi/4),col="violet") polygon(polycirc2(radius=0.5,center=c(0.5,1)),col="blue") polycirc2(init=pi,angle=pi/4)
plot(c(-1,+1),c(-1,+1),type="n",asp=1) polygon(polycirc2(),col="red") polygon(polycirc2(init=pi,angle=pi/4),col="green") polygon(polycirc2(init=1.5*pi,angle=pi/4),col="violet") polygon(polycirc2(radius=0.5,center=c(0.5,1)),col="blue") polycirc2(init=pi,angle=pi/4)
This data set gives the results of dietary analysis performed by Amroun Mansour in two sites of Kabylie, Algeria
data(preybiom)
data(preybiom)
A data frame with 2196 observations on the following variables.
faeces
a factor for faeces corresponding to faeces identification numbers
site
a factor for study sites with levels S
Sebaou Y
Yacouren
saison
a factor for seasons with levels H
HD
HP
S
SD
SP
sp
a factor for species with levels C
Jackal G
Genet
category
a factor for dietary items with levels dech
ind
ins
mam
mol
oisauv
oisdom
rept
vege
vegn
biomasse
a numeric vector for the weight of each dietary item
M. Amroun, P. Giraudoux and P. Delattre 2006 Comparative study of the diets of two sympatric carnivores - the Jackal (Canis aureus) and the Genet (Genetta genetta) - at two sites in Kabylia, Algeria. Mammalia, 70 (3/4): 247-254.
print method for objects of class 'mc'
## S3 method for class 'mc' print(x, ...)
## S3 method for class 'mc' print(x, ...)
x |
an object of class 'mc' |
... |
further arguments to be passed to or from other methods. They are ignored in this function |
resp<-c(0.44,0.44,0.54,0.32,0.21,0.28,0.7,0.77,0.48,0.64,0.71,0.75,0.8,0.76,0.34,0.80,0.73,0.8) categ<-as.factor(rep(c("A","B","C"),times=1,each=6)) kruskalmc(resp, categ)
resp<-c(0.44,0.44,0.54,0.32,0.21,0.28,0.7,0.77,0.48,0.64,0.71,0.75,0.8,0.76,0.34,0.80,0.73,0.8) categ<-as.factor(rep(c("A","B","C"),times=1,each=6)) kruskalmc(resp, categ)
Draw line segments between pairs of points from a vector, matrix or data frame of 4 points coordinates x0, y0, x1, y1
Segments(mydata, ...)
Segments(mydata, ...)
mydata |
a vector, matrix or data frame |
... |
further graphical parameters (from 'par') |
a wrapper to 'segments' to handle coordinates passed as vector, matrix or data frame. Any vector is turned into a matrix of four columns.
mydata<-cbind(rnorm(20),rnorm(20),rnorm(20),rnorm(20)) plot(range(rbind(mydata[,1],mydata[,3])),range(rbind(mydata[,2],mydata[,4])), type="n",xlab="",ylab="") Segments(mydata,col=rainbow(20)) myvec<-rnorm(4) plot(myvec[c(1,3)],myvec[c(2,4)],type="n",xlab="",ylab="") Segments(myvec) myvec<-rnorm(16) plot(myvec,myvec,type="n",xlab="",ylab="") Segments(myvec)
mydata<-cbind(rnorm(20),rnorm(20),rnorm(20),rnorm(20)) plot(range(rbind(mydata[,1],mydata[,3])),range(rbind(mydata[,2],mydata[,4])), type="n",xlab="",ylab="") Segments(mydata,col=rainbow(20)) myvec<-rnorm(4) plot(myvec[c(1,3)],myvec[c(2,4)],type="n",xlab="",ylab="") Segments(myvec) myvec<-rnorm(16) plot(myvec,myvec,type="n",xlab="",ylab="") Segments(myvec)
Handles lm, glm and list of e.g. lm, glm, nls, lme and nlme objects and provides parameters to compare models according to Anderson et al. (2001)
selMod(aModel, Order = "AICc", ...) ## S3 method for class 'lm' selMod(aModel, Order = "AICc", dropNull = FALSE, selconv=TRUE, ...) ## S3 method for class 'list' selMod(aModel, Order = "AICc", ...)
selMod(aModel, Order = "AICc", ...) ## S3 method for class 'lm' selMod(aModel, Order = "AICc", dropNull = FALSE, selconv=TRUE, ...) ## S3 method for class 'list' selMod(aModel, Order = "AICc", ...)
aModel |
a lm or glm model or a list of relevant models (see details) |
dropNull |
if TRUE, drops the simplest model (e.g. y |
Order |
if set to "AICc" (default) sort the models on this parameter, otherwise "AIC" is allowed |
selconv |
if TRUE (default) keep the models for which convergence is obtained (glm object only) and with no anova singularity (lm and glm) |
... |
other parameters to be passed as arguments (not used here) |
This function provides parameters used in the information theoretic methods for model comparisons.
lm and glm objects can be passed directly as the upper scope of term addition (all terms added).
Every model from y1 is computed adding one term at a time until the upper scope model is derived. This is a stepwise analysis where the terms are added sequentially and this does NOT provide all combinations of terms and interactions. Offset terms cannot be proceeded here.
A list of user specified lm, glm, nls, lme or nlme objects (actually any object for which AIC and logLik functions are applicable) to compare can alternately be passed.
A dataframe including:
LL, the maximized log-likelihood
K, the number of estimated parameters
N2K, the number of observations/K
AIC, the Akaike index criterion
deltAIC,the difference between AIC and the lowest AIC value
w_i, the Akaike weights
deltAICc, the difference between AICc and the lowest AICc value; advised to be used when n2K 40
w_ic, the AICc weights
The models examined from first to last are stored as attribute
Patrick Giraudoux and David Pleydell: [email protected], [email protected]
Anderson, D.R., Link, W.A., Johnson, D.H. and Burnham, K.P. (2001). Suggestions for presenting the results of data analyses. Journal of Wildlife Management, 65, 373-378
Burnham, K.P. and Anderson, D.R. (2002) Model Selection and Multimodel Inference: a Practical Information-Theoretic Approach, 2nd edn., Springer-Verlag, New York. 353 pp
if(require(MASS)){ anorex.1 <- lm(Postwt ~ Prewt*Treat, data = anorexia) selMod(anorex.1) anorex.2 <- glm(Postwt ~ Prewt*Treat, family=gaussian,data = anorexia) selMod(anorex.2) anorex.3<-lm(Postwt ~ Prewt+Treat, data = anorexia) mycomp<-selMod(list(anorex.1,anorex.2,anorex.3)) mycomp attributes(mycomp)$models }
if(require(MASS)){ anorex.1 <- lm(Postwt ~ Prewt*Treat, data = anorexia) selMod(anorex.1) anorex.2 <- glm(Postwt ~ Prewt*Treat, family=gaussian,data = anorexia) selMod(anorex.2) anorex.3<-lm(Postwt ~ Prewt+Treat, data = anorexia) mycomp<-selMod(list(anorex.1,anorex.2,anorex.3)) mycomp attributes(mycomp)$models }
Computes Shannon's and equitability indices
shannon(vect, base=2)
shannon(vect, base=2)
vect |
a probability vector whose sum = 1 or a frequency vector |
base |
logarithm base used (default=2) |
Computes Shannon's and equitability indices. The vector passed can be a probability vector whose sum equal 1 or a vector of frequencies (e.g. the number of food item of each category).
A vector of two values: Shannon's and equitability indices. The base logarithm used is stored as attribute
x<-c(0.1,0.5,0.2,0.1,0.1) sum(x) shannon(x) x<-rpois(10,6) shannon(x, base=exp(1))
x<-c(0.1,0.5,0.2,0.1,0.1) sum(x) shannon(x) x<-rpois(10,6) shannon(x, base=exp(1))
Computes Shannon's and equitability indices from a data frame of two columns: column 1, dietary category; column 2, abundance (n, biomass,...)
shannonbio(data1)
shannonbio(data1)
data1 |
a data frame of two columns: column 1, dietary category; column 2, abundance (n, biomass,...) |
Computes Shannon's and equitability indices from a data frame of two columns: column 1, dietary category; column 2, abundance (n, biomass,...)
A vector of two values: Shannon's and equitability indices
data(preybiom) shannonbio(preybiom[,5:6])
data(preybiom) shannonbio(preybiom[,5:6])
Boostrap Shannon's and equitability indices and return an object of class boot. Confidence intervals can be computed with boot.ci().
shannonbioboot(data1, B = 1000)
shannonbioboot(data1, B = 1000)
data1 |
a data frame of two columns: column 1, dietary category; column 2, abundance (n, biomass,...) |
B |
number of permutations |
Boostrap Shannon\'s and equitability indices and return an object of class boot. Confidence intervals can be computed with boot.ci(). Requires the boot library.
An object of class boot including the bootstrap statistics for H' (t1*) and J' (t2*)
data(preybiom) myboot<-shannonbioboot(preybiom[,5:6],B=100) library(boot) boot.ci(myboot, index=1,type=c("norm","basic","perc")) # confidence intervals for H' boot.ci(myboot, index=2,type=c("norm","basic","perc")) # confidence intervals for J'
data(preybiom) myboot<-shannonbioboot(preybiom[,5:6],B=100) library(boot) boot.ci(myboot, index=1,type=c("norm","basic","perc")) # confidence intervals for H' boot.ci(myboot, index=2,type=c("norm","basic","perc")) # confidence intervals for J'
Ranks of 18 matched groups of rats after training under three methods of reinforcement.
data(siegelp179)
data(siegelp179)
A data frame with 54 observations on the following 3 variables.
Group (each of three litter mates)
A factor for the type of reinforcement with levels RR
RU
UR
Speed of transfer to another behaviour (the lower, the better the learning)
18 blocks made of three rats of the same litter, each being given a different learning pattern (RR, RU or UR)
Grosslight J.H. and Radlow R. (1956) Patterning effect of the nonreinforcement-reinforcement sequence in a discrimination situation. Journal of Comparative and Physiological Psychology, 49: 542-546 in Siegel & Castellan 1988. Non parametric statistics for the behavioural sciences. Mc Graw Hill Int. Edt.
data(siegelp179)
data(siegelp179)
Thin a track stored as a sf
POINT object, just keeping the points separated by a user defined minimal distance.
st_thintrack(spdf,mindist=100)
st_thintrack(spdf,mindist=100)
spdf |
a |
mindist |
minimal distance requested between two points (default = 100) |
Tracks downloaded from GPS often provide an unnecessary large density of points at irregular distances. This function starts reading from the first point of the track and removes all points within a user specified radius (USR), then reads the next point and removes all points within the USR, and so on...
A sf
POINT object of the track thinned.
if(require(sf)){ mySPDF<-structure(list(x = c(748775, 748807, 748834, 748854, 748871, 748873, 748880, 748910, 748919, 748917, 748921, 748923, 748924, 748921, 748921, 748921, 748922, 748915, 748616, 748613, 748612, 748613, 748613, 748615, 748613, 748616, 748615, 748618, 748615, 748619, 748618, 748620, 748586, 748553, 748494, 748444, 748424, 748366, 748305, 748305), y = c(105716, 105761, 105808, 105856, 105911, 105964, 106019, 106065, 106114, 106167, 106219, 106274, 106329, 106385, 106441, 106494, 106550, 106571, 105835, 105779, 105723, 105665, 105600, 105537, 105473, 105412, 105350, 105293, 105234, 105180, 105123, 105070, 105023, 104960, 104956, 104947, 104906, 104905, 104901, 104904), ID = 1:40), .Names = c("x", "y", "ID"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40" ), class = "data.frame") mySPDF<-st_as_sf(mySPDF,coords=c("x","y")) plot(st_geometry(mySPDF),pch=19,cex=0.5) plot(st_thintrack(mySPDF),pch=19,cex=0.7,col="red",add=TRUE) plot(mySPDF,pch=19,cex=0.5) plot(st_thintrack(mySPDF,min=200),pch=19,cex=0.7,col="red",add=TRUE) }
if(require(sf)){ mySPDF<-structure(list(x = c(748775, 748807, 748834, 748854, 748871, 748873, 748880, 748910, 748919, 748917, 748921, 748923, 748924, 748921, 748921, 748921, 748922, 748915, 748616, 748613, 748612, 748613, 748613, 748615, 748613, 748616, 748615, 748618, 748615, 748619, 748618, 748620, 748586, 748553, 748494, 748444, 748424, 748366, 748305, 748305), y = c(105716, 105761, 105808, 105856, 105911, 105964, 106019, 106065, 106114, 106167, 106219, 106274, 106329, 106385, 106441, 106494, 106550, 106571, 105835, 105779, 105723, 105665, 105600, 105537, 105473, 105412, 105350, 105293, 105234, 105180, 105123, 105070, 105023, 104960, 104956, 104947, 104906, 104905, 104901, 104904), ID = 1:40), .Names = c("x", "y", "ID"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40" ), class = "data.frame") mySPDF<-st_as_sf(mySPDF,coords=c("x","y")) plot(st_geometry(mySPDF),pch=19,cex=0.5) plot(st_thintrack(mySPDF),pch=19,cex=0.7,col="red",add=TRUE) plot(mySPDF,pch=19,cex=0.5) plot(st_thintrack(mySPDF,min=200),pch=19,cex=0.7,col="red",add=TRUE) }
Convert a contingency table (data frame) into a data.frame of factors
tabcont2categ(tab)
tabcont2categ(tab)
tab |
A data.frame (contingency table) |
Convert a contingency table (data frame) into a data.frame of factors
A data frame
mydata<-as.data.frame(matrix(rpois(9,5),nr=3,nc=3)) names(mydata)<-LETTERS[1:3] row.names(mydata)<-letters[1:3] tabcont2categ(mydata)
mydata<-as.data.frame(matrix(rpois(9,5),nr=3,nc=3)) names(mydata)<-LETTERS[1:3] row.names(mydata)<-letters[1:3] tabcont2categ(mydata)
Convert a transect coordinate file with some waypoints separated by NA into a matrix with intermediate coordinates replacing NA.
trans2pix(vect)
trans2pix(vect)
vect |
A two column matrix or data.frame |
If vect has more than two column the two first column only are read. This function computes the intermediate coordinates between two waypoints replacing NA values.
A matrix with the intermediate coordinates computed.
x<-c(10,NA, NA, NA,56,NA,NA,100) y<-c(23,NA, NA, NA,32,NA,NA,150) cols=c("red","blue","blue","blue","red","blue","blue","red") plot(x,y,col=cols,pch=19) plot(trans2pix(cbind(x,y)),col=cols,pch=19)
x<-c(10,NA, NA, NA,56,NA,NA,100) y<-c(23,NA, NA, NA,32,NA,NA,150) cols=c("red","blue","blue","blue","red","blue","blue","red") plot(x,y,col=cols,pch=19) plot(trans2pix(cbind(x,y)),col=cols,pch=19)
Convert a transect coordinate file (e.g.: waypoints) into a matrix with segment coordinates.
trans2seg(vect)
trans2seg(vect)
vect |
A two column matrix or data.frame |
The argument passed is a matrix or data.frame of two columns each row is a transect interval; each column must start (first row) and end (last row) with a landmark ; intermediate waypoints must have coordinates in the two columns of the row. Other rows must be NA values.
A matrix of 4 columns to be passed e.g. to functions as "segments".
trans2pix
x<-c(10,NA, NA, NA,56,NA,NA,100) y<-c(23,NA, NA, NA,32,NA,NA,150) cols=c("red","blue","blue","blue","red","blue","blue","red") plot(x,y,col=cols,pch=19) mysegs<-trans2seg(cbind(x,y)) segments(mysegs[,1],mysegs[,2],mysegs[,3],mysegs[,4])
x<-c(10,NA, NA, NA,56,NA,NA,100) y<-c(23,NA, NA, NA,32,NA,NA,150) cols=c("red","blue","blue","blue","red","blue","blue","red") plot(x,y,col=cols,pch=19) mysegs<-trans2seg(cbind(x,y)) segments(mysegs[,1],mysegs[,2],mysegs[,3],mysegs[,4])
Convert a simple feature geometry made of MULTILINESTRING and/or LINESTRING into a POINT geometry with points at regular distance between nodes
transLines2pix(spldf,mindist=100)
transLines2pix(spldf,mindist=100)
spldf |
A |
mindist |
the distance between two points (default to 100) |
This function can be used e.g to discretize track lines (roads, paths, transects, etc.) into series of regular points. Each point is the centre of one interval. Beware that if mindist is larger than the distance between nodes, the output file will keep the nodes. Furthermore, mindist might not be fully respected in some spatial configurations. In such cases to filter points using st_thintrack
complementarily is advised.
A sf object
with a POINT geometry type.
trans2pix
, st_thintrack
, mergeTrackObs
if (require(sf)) { l1 = st_linestring(cbind(c(1,2,3),c(3,2,2))) S1<-st_multilinestring(list(l1,cbind(l1[,1]+.05,l1[,2]+.05))) S2<-st_linestring(cbind(c(1,2,3),c(1,1.5,1))) sl<-st_sfc(list(S1,S2)) plot(sl, col = c("red", "blue"),reset=FALSE) trpt<-transLines2pix(sl,mindist=0.1) plot(st_geometry(trpt),add=TRUE) }
if (require(sf)) { l1 = st_linestring(cbind(c(1,2,3),c(3,2,2))) S1<-st_multilinestring(list(l1,cbind(l1[,1]+.05,l1[,2]+.05))) S2<-st_linestring(cbind(c(1,2,3),c(1,1.5,1))) sl<-st_sfc(list(S1,S2)) plot(sl, col = c("red", "blue"),reset=FALSE) trpt<-transLines2pix(sl,mindist=0.1) plot(st_geometry(trpt),add=TRUE) }
Simplify the list of a TukeyHSD object keeping the significant differences only.
TukeyHSDs(TukeyHSD.object)
TukeyHSDs(TukeyHSD.object)
TukeyHSD.object |
An object of calls "TukeyHSD" |
When TukeyHSD is used on a fitted model with large numbers of categories, the number of pairwise comparisons is extremely large (n(n-1)/2). TukeyHSDs simplify the TukeyHSD object keeping the significant pairwise comparisons only. A plot method exists for TukeyHSD objects.
An object of class "multicomp" and "TukeyHSD"
summary(fm1 <- aov(breaks ~ wool + tension, data = warpbreaks)) myobject<-TukeyHSD(fm1, "tension", ordered = TRUE) myobject TukeyHSDs(myobject)
summary(fm1 <- aov(breaks ~ wool + tension, data = warpbreaks)) myobject<-TukeyHSD(fm1, "tension", ordered = TRUE) myobject TukeyHSDs(myobject)
Center a numerical vector on a parameter position and provides absolute values and colors according to negative and positive values
val4symb(x, FUN=mean, col = c("blue", "red"),...)
val4symb(x, FUN=mean, col = c("blue", "red"),...)
x |
a numerical vector |
FUN |
a function computing a position parameter, typically |
col |
a character vector of 2 values, default=c("blue","red"), blue for <0, red for >=0 |
... |
optional arguments to 'FUN' |
A list with
size |
the absolute values of the difference to the position parameter (eg mean, median) |
col |
a character vector with 2 colors, each corresponding to positive or negative values |
x<-rnorm(30) y<-rnorm(30) z<-val4symb(rnorm(30)) symbols(x,y,circle=z$size,inches=0.2,bg=z$col) z<-val4symb(scale(rnorm(30))) symbols(x,y,circle=z$size,inches=0.2,bg=z$col) z<-val4symb(rnorm(30),col=c("green","violet")) symbols(x,y,circle=z$size,inches=0.2,bg=z$col) z<-val4symb(rnorm(30),trim=0.025) symbols(x,y,circle=z$size,inches=0.2,bg=z$col) z<-val4symb(rnorm(30),median) symbols(x,y,circle=z$size,inches=0.2,bg=z$col) myfun<-function(x) 20 # passes an arbitrary constant z<-val4symb(1:30,myfun) symbols(x,y,circle=z$size,inches=0.2,bg=z$col)
x<-rnorm(30) y<-rnorm(30) z<-val4symb(rnorm(30)) symbols(x,y,circle=z$size,inches=0.2,bg=z$col) z<-val4symb(scale(rnorm(30))) symbols(x,y,circle=z$size,inches=0.2,bg=z$col) z<-val4symb(rnorm(30),col=c("green","violet")) symbols(x,y,circle=z$size,inches=0.2,bg=z$col) z<-val4symb(rnorm(30),trim=0.025) symbols(x,y,circle=z$size,inches=0.2,bg=z$col) z<-val4symb(rnorm(30),median) symbols(x,y,circle=z$size,inches=0.2,bg=z$col) myfun<-function(x) 20 # passes an arbitrary constant z<-val4symb(1:30,myfun) symbols(x,y,circle=z$size,inches=0.2,bg=z$col)
Write a simple data.frame into a text file with header, no row.names, fields separated by tab.
write.delim(x, file = "", row.names = FALSE, quote = FALSE, sep = "\t", ...)
write.delim(x, file = "", row.names = FALSE, quote = FALSE, sep = "\t", ...)
x |
a data.frame |
file |
a character string for file name |
row.names |
either a logical value indicating whether the row names of 'x' are to be written along with 'x', or a character vector of row names to be written |
quote |
a logical value or a numeric vector. If 'TRUE', any character or factor columns will be surrounded by double quotes. If a numeric vector, its elements are taken as the indices of the columns to quote. In both cases, row and column names are quoted if they are written. If 'FALSE', nothing is quoted. |
sep |
the field separator string. Values within each row of 'x' are separated by this string. |
... |
additional arguments accepted by write.table |
Simple wrapper of write.table.
A tab delimited text file.
data(preybiom) write.delim(preybiom[1:10,]) # output to the console ## Not run: write.delim(preybiom[1:10,],file="Myfile.txt") # write a file in the working directory ## End(Not run)
data(preybiom) write.delim(preybiom[1:10,]) # output to the console ## Not run: write.delim(preybiom[1:10,],file="Myfile.txt") # write a file in the working directory ## End(Not run)
Handle a data.frame with Chinese characters and write it into a UTF-8 text file with header, no row.names, tab delimited fields.
writecn.delim(db, file = "",row.names = FALSE, quote = FALSE, sep = "\t", ...)
writecn.delim(db, file = "",row.names = FALSE, quote = FALSE, sep = "\t", ...)
db |
a data.frame |
file |
file name (character string) |
row.names |
either a logical value indicating whether the row names of 'x' are to be written along with 'x', or a character vector of row names to be written |
quote |
a logical value or a numeric vector. If 'TRUE', any character or factor columns will be surrounded by double quotes. If a numeric vector, its elements are taken as the indices of the columns to quote. In both cases, row and column names are quoted if they are written. If 'FALSE', nothing is quoted. |
sep |
the field separator string. Values within each row of 'x' are separated by this string. |
... |
additional arguments to pass to |
Writing a data.frame into text files can be quite cumbersome if the system locale is not Chinese. This function set up the locale to Chinese, write the data.frame using write.table
with fileEncoding = "UTF-8", then restore the original locale.
An ascii text file, tab delimited.