Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
reservebenefit
worldmap_fish_genetic_diversity
Commits
42fd0cf0
Commit
42fd0cf0
authored
Oct 21, 2019
by
peguerin
Browse files
latclass table
parent
ca1956c1
Changes
1
Hide whitespace changes
Inline
Side-by-side
00-scripts/step5/analysis/tests.R
View file @
42fd0cf0
...
...
@@ -14,10 +14,36 @@
##
##########################################################################
## Libraries
library
(
plyr
)
lib_vect
<-
c
(
"plyr"
,
"SpatialPack"
,
"raster"
,
"rgdal"
,
"rgeos"
)
sapply
(
lib_vect
,
library
,
character.only
=
TRUE
)
##########################################################################
## functions
source
(
"00-scripts/step5/figures/functions.R"
)
## attribute "polar", "tropical" and "temperate" according to lattitude
lat2class
<-
function
(
lat
)
{
if
(
lat
<
24
&&
lat
>
-24
)
{
return
(
"tropical"
)
}
else
if
(
lat
>
66
|
lat
<
-66
)
{
return
(
"polar"
)
}
else
{
return
(
"temperate"
)
}
}
##########################################################################
## load data
## load worldcoast shapefile
grid
<-
readOGR
(
"01-infos/grid_equalarea200km"
,
"gridFish.b_260418"
)
##########################################################################
## read the table
dcT
=
read.table
(
"09-all_descripteurs/total_data_genetic_diversity_with_all_descripteurs.tsv"
,
header
=
T
)
## keep entries with GD!=0
...
...
@@ -41,22 +67,46 @@ dcF.1=dcF.1[which(!is.na(dcF.1$SST)),]
## remove freshwater data with no bathyval information
dcF.1
=
dcF.1
[
which
(
!
is.na
(
dcF.1
$
bathyVal
)),]
## add non transformed coordinates latitude
convertedCoords_M
=
convert_coordinates_into_epsg4326
(
dcM
,
dcM.1
,
grid
)
convertedCoords_F
=
convert_coordinates_into_epsg4326
(
dcF
,
dcF.1
,
grid
)
dcM.2
=
cbind
(
dcM.1
,
convertedCoords_M
)
dcF.2
=
cbind
(
dcF.1
,
convertedCoords_F
)
## load richness data
richness
=
read.csv
(
"01-infos/equalarea_id_coordsCA_FWRS_MR_RS.csv"
)
Fr
=
merge
(
dcF.
1
,
richness
,
by
=
"cell"
,
all.x
=
F
)
Fr
=
merge
(
dcF.
2
,
richness
,
by
=
"cell"
,
all.x
=
F
)
Fr
=
Fr
[
which
(
Fr
$
RS_FW_FISH
!=
0
),]
Fr_wCoords
=
Fr
[,
c
(
2
,
3
,
4
,
6
,
7
,
2
7
)]
#with coordinates
Fr
=
Fr
[,
c
(
1
,
4
,
6
,
7
,
2
7
)]
Fr_wCoords
=
Fr
[,
c
(
2
,
3
,
4
,
6
,
7
,
2
4
,
29
)]
#with coordinates
Fr
=
Fr
[,
c
(
1
,
4
,
6
,
7
,
2
4
,
29
)]
Fr
=
na.omit
(
Fr
)
names
(
Fr
)
=
c
(
"cell"
,
"GD_mean"
,
"nb_species"
,
"nb_indv_mean"
,
"richness"
)
Mr
=
merge
(
dcM.
1
,
richness
,
by
=
"cell"
,
all.x
=
F
)
names
(
Fr
)
=
c
(
"cell"
,
"GD_mean"
,
"nb_species"
,
"nb_indv_mean"
,
"
latitude"
,
"
richness"
)
Mr
=
merge
(
dcM.
2
,
richness
,
by
=
"cell"
,
all.x
=
F
)
Mr
=
Mr
[
which
(
Mr
$
RS_MR_FISH
!=
0
),]
Mr_wCoords
=
Mr
[,
c
(
2
,
3
,
4
,
6
,
7
,
2
8
)]
#with coordinates
Mr
=
Mr
[,
c
(
1
,
4
,
6
,
7
,
2
8
)]
Mr_wCoords
=
Mr
[,
c
(
2
,
3
,
4
,
6
,
7
,
2
4
,
30
)]
#with coordinates
Mr
=
Mr
[,
c
(
1
,
4
,
6
,
7
,
2
4
,
30
)]
Mr
=
na.omit
(
Mr
)
names
(
Mr
)
=
c
(
"cell"
,
"GD_mean"
,
"nb_species"
,
"nb_indv_mean"
,
"richness"
)
names
(
Mr
)
=
c
(
"cell"
,
"GD_mean"
,
"nb_species"
,
"nb_indv_mean"
,
"latitude"
,
"richness"
)
Tr
=
rbind
(
Mr
,
Fr
)
## add marine/freshwater info
is_marine_M
=
rep
(
1
,
dim
(
Mr
)[
1
])
is_marine_F
=
rep
(
0
,
dim
(
Fr
)[
1
])
is_marine
=
c
(
is_marine_M
,
is_marine_F
)
Tr.1
=
cbind
(
Tr
,
is_marine
)
## add latband info
latband
=
coords_to_latband
(
Tr.1
$
latitude
)
Tr.2
=
cbind
(
Tr.1
,
latband
)
## add class info latitude
latclass
=
apply
(
as.data.frame
(
Tr.2
$
latband
),
1
,
function
(
x
)
lat2class
(
x
)
)
Tr.3
=
cbind
(
Tr.2
,
latclass
)
##write table with latband latclass and latitude
write.table
(
Tr.3
,
"14-tables/latclass.tsv"
,
col.names
=
T
,
row.names
=
F
,
sep
=
"\t"
)
...
...
@@ -86,10 +136,15 @@ modified.ttest(Mr$GD_mean,Mr$richness,coordsM, nclass = 13)
coordsF
=
cbind
(
Fr
$
x
,
Fr
$
y
)
modified.ttest
(
Fr
$
GD_mean
,
Fr
$
richness
,
coordsF
,
nclass
=
13
)
##########################################################################
###### between freshwater and marine genetic diversity
coordsM
=
cbind
(
Mr
$
x
,
Mr
$
y
)
coordsF
=
cbind
(
Fr
$
x
,
Fr
$
y
)
coordsT
=
rbind
(
coordsM
,
coordsF
)
GD_meanT
=
data.frame
(
marine
=
Mr
$
GD_mean
,
freshwater
=
Fr
$
GD_mean
)
###### table with 0/1 marine/freshwater, temperature and latitude as a qualitative variable
#coordsM = cbind(Mr$x,Mr$y)
#coordsF = cbind(Fr$x,Fr$y)
#coordsT=rbind(coordsM,coordsF)
#GD_meanT=data.frame(marine=Mr$GD_mean, freshwater= Fr$GD_mean)
#modified.ttest(GD_meanT$marine, GDmeanT$freshwater,coordsT, nclass = 13)
modified.ttest
(
GD_meanT
$
marine
,
GDmeanT
$
freshwater
,
coordsT
,
nclass
=
13
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment