Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
HIDDEN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sPlot
HIDDEN
Commits
90679f2b
Commit
90679f2b
authored
4 years ago
by
Francesco Sabatini
Browse files
Options
Downloads
Patches
Plain Diff
Undone changes of commit aaaaadf
parent
4fa25d73
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
99_HIDDEN_functions.R
+11
-8
11 additions, 8 deletions
99_HIDDEN_functions.R
with
11 additions
and
8 deletions
99_HIDDEN_functions.R
+
11
−
8
View file @
90679f2b
...
@@ -33,6 +33,12 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){
...
@@ -33,6 +33,12 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){
## caution
## caution
## ALL columns with only 0-1 values are AUTOMATICALLY considered as asym.bin sensu FD:gowdis
## ALL columns with only 0-1 values are AUTOMATICALLY considered as asym.bin sensu FD:gowdis
##get all columns with binary variables
## CAUTION - function below doesn't work as expected
# binary.traits <- which(apply(traits[,ii,drop=F], MARGIN=2, function(x)( all(na.omit(x) %in% 0:1) ))==T)
syn.out.tmp
<-
matrix.x
(
comm
=
comm
,
traits
=
traits
[,
ii
,
drop
=
F
],
scale
=
T
)
$
matrix.X
#, asym.bin=binary.traits
W.beals
<-
as.data.frame
(
beals
(
comm
,
include
=
T
,
type
=
2
))
# permute traits
# permute traits
### Create vector of species to resample from, which exclude species with NAs
### Create vector of species to resample from, which exclude species with NAs
traits.ii
<-
traits
[,
ii
,
drop
=
F
]
traits.ii
<-
traits
[,
ii
,
drop
=
F
]
...
@@ -47,15 +53,12 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){
...
@@ -47,15 +53,12 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){
out
[
is.na
(
out
)]
<-
sample
(
toresample
,
replace
=
F
)
out
[
is.na
(
out
)]
<-
sample
(
toresample
,
replace
=
F
)
return
(
out
)
return
(
out
)
})
})
##calculate corXY on observed values using all plots
#index.traits <- lapply(1:(bootstrap+1), function(x){sample(1:nrow(traits), replace=F)})
syn.out.tmp
<-
matrix.x
(
comm
=
comm
,
traits
=
traits.ii
,
scale
=
T
)
$
matrix.X
#, asym.bin=binary.traits
syn.out.perm.tmp
<-
matrix.x
(
comm
=
comm
,
traits
=
traits
[
index.traits
[[
bootstrap
+1
]],
ii
,
drop
=
F
],
W.beals
<-
as.data.frame
(
beals
(
comm
,
include
=
T
,
type
=
2
))
(
RD.tmp
<-
dcor
(
W.beals
,
as.data.frame
(
syn.out.tmp
))
^
2
)
##calculate corresponding permuted corXY using all plots
syn.out.perm.tmp
<-
matrix.x
(
comm
=
comm
,
traits
=
traits.ii
[
index.traits
[[
bootstrap
+1
]],],
scale
=
T
)
$
matrix.X
#, asym.bin=binary.traits
scale
=
T
)
$
matrix.X
#, asym.bin=binary.traits
(
RD.tmp
<-
dcor
(
W.beals
,
as.data.frame
(
syn.out.tmp
))
^
2
)
(
RD.perm.tmp
<-
dcor
(
W.beals
,
as.data.frame
(
syn.out.perm.tmp
))
^
2
)
(
RD.perm.tmp
<-
dcor
(
W.beals
,
as.data.frame
(
syn.out.perm.tmp
))
^
2
)
## calculate corXY for each bootstrap run
corXY
<-
NULL
corXY
<-
NULL
corXY
<-
data.frame
(
Trait.comb
=
lab.tmp
,
bootstr.n
=
0
,
Test
=
"RD"
,
corXY
<-
data.frame
(
Trait.comb
=
lab.tmp
,
bootstr.n
=
0
,
Test
=
"RD"
,
Coef.obs
=
RD.tmp
,
Coef.perm
=
RD.perm.tmp
)
Coef.obs
=
RD.tmp
,
Coef.perm
=
RD.perm.tmp
)
...
@@ -63,7 +66,7 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){
...
@@ -63,7 +66,7 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){
index.bootstr
<-
lapply
(
1
:
bootstrap
,
function
(
x
){
sample
(
1
:
n.sites
,
replace
=
T
)})
index.bootstr
<-
lapply
(
1
:
bootstrap
,
function
(
x
){
sample
(
1
:
n.sites
,
replace
=
T
)})
for
(
b
in
1
:
bootstrap
){
for
(
b
in
1
:
bootstrap
){
RD.tmp
<-
dcor
(
W.beals
[
index.bootstr
[[
b
]],],
as.data.frame
(
syn.out.tmp
)[
index.bootstr
[[
b
]],])
^
2
RD.tmp
<-
dcor
(
W.beals
[
index.bootstr
[[
b
]],],
as.data.frame
(
syn.out.tmp
)[
index.bootstr
[[
b
]],])
^
2
syn.out.perm.tmp
<-
matrix.x
(
comm
=
comm
,
traits
=
traits
.ii
[
index.traits
[[
b
]],],
syn.out.perm.tmp
<-
matrix.x
(
comm
=
comm
,
traits
=
traits
[
index.traits
[[
b
]],
ii
,
drop
=
F
],
scale
=
T
)
$
matrix.X
#, asym.bin=binary.traits
scale
=
T
)
$
matrix.X
#, asym.bin=binary.traits
RD.perm.tmp
<-
dcor
(
W.beals
[
index.bootstr
[[
b
]],],
as.data.frame
(
syn.out.perm.tmp
)[
index.bootstr
[[
b
]],])
^
2
RD.perm.tmp
<-
dcor
(
W.beals
[
index.bootstr
[[
b
]],],
as.data.frame
(
syn.out.perm.tmp
)[
index.bootstr
[[
b
]],])
^
2
corXY
<-
rbind
(
corXY
,
corXY
<-
rbind
(
corXY
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment