Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
manuscript_code
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository 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
Maria Voigt
manuscript_code
Commits
697cf6eb
Commit
697cf6eb
authored
8 years ago
by
Maria Voigt
Browse files
Options
Downloads
Patches
Plain Diff
adding the random grid as roger suggested
parent
a40f1dc1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/model_fitting/abundance_model.R
+22
-22
22 additions, 22 deletions
src/model_fitting/abundance_model.R
with
22 additions
and
22 deletions
src/model_fitting/abundance_model.R
+
22
−
22
View file @
697cf6eb
...
@@ -34,18 +34,18 @@ option_list <- list (
...
@@ -34,18 +34,18 @@ option_list <- list (
dest
=
"ESW_aerial"
,
dest
=
"ESW_aerial"
,
type
=
"double"
,
type
=
"double"
,
help
=
"aerial effective strip width"
),
help
=
"aerial effective strip width"
),
make_option
(
"--exclude-year"
,
dest
=
"exclude_year"
,
type
=
"integer"
,
default
=
NA
,
help
=
"year to exclude"
,
metavar
=
"2015"
),
make_option
(
"--exclude-grid"
,
dest
=
"exclude_grid"
,
type
=
"integer"
,
default
=
NA
,
help
=
"index of grid-cells to exclude"
,
metavar
=
"1"
),
make_option
(
"--exclude-random"
,
dest
=
"exclude_random"
,
type
=
"integer"
,
default
=
NA
,
help
=
"randomly excluding the percentage given"
,
metavar
=
"20"
),
make_option
(
"--include-aerial"
,
make_option
(
"--include-aerial"
,
dest
=
"include_aerial"
,
action
=
"store_true"
,
dest
=
"include_aerial"
,
action
=
"store_true"
,
default
=
FALSE
,
help
=
"include aerial transects"
),
default
=
FALSE
,
help
=
"include aerial transects"
),
make_option
(
"--stability"
,
action
=
"store_true"
,
default
=
FALSE
,
make_option
(
"--stability"
,
action
=
"store_true"
,
default
=
FALSE
,
help
=
"do stability analysis"
),
help
=
"do stability analysis"
),
make_option
(
"--exclude-year"
,
dest
=
"exclude_year"
,
type
=
"integer"
,
default
=
NA
,
help
=
"year to exclude"
,
metavar
=
"2015"
),
make_option
(
"--exclude-grid"
,
dest
=
"exclude_grid"
,
type
=
"integer"
,
default
=
NA
,
help
=
"index of grid-cells to exclude"
,
metavar
=
"1"
),
make_option
(
"--exclude-grid-random"
,
dest
=
"exclude_grid_rand"
,
type
=
"integer"
,
default
=
NA
,
help
=
"exclude the given percent randomly"
,
metavar
=
"10"
),
make_option
(
c
(
"-q"
,
"--quiet"
),
dest
=
"verbose_script"
,
make_option
(
c
(
"-q"
,
"--quiet"
),
dest
=
"verbose_script"
,
action
=
"store_false"
,
action
=
"store_false"
,
default
=
TRUE
,
default
=
TRUE
,
...
@@ -98,8 +98,8 @@ if(is_verbose){print(paste("exclude year", exclude_year))}
...
@@ -98,8 +98,8 @@ if(is_verbose){print(paste("exclude year", exclude_year))}
exclude_grid
<-
options
$
exclude_grid
exclude_grid
<-
options
$
exclude_grid
if
(
is_verbose
){
print
(
paste
(
"exclude grid"
,
exclude_grid
))}
if
(
is_verbose
){
print
(
paste
(
"exclude grid"
,
exclude_grid
))}
exclude_rand
om
<-
options
$
exclude_rand
om
exclude_
grid_
rand
<-
options
$
exclude_
grid_
rand
if
(
is_verbose
){
print
(
paste
(
"exclude random"
,
exclude_rand
om
))}
if
(
is_verbose
){
print
(
paste
(
"exclude
grid
random"
,
exclude_
grid_
rand
))}
#---------#
#---------#
# Globals #
# Globals #
...
@@ -291,19 +291,19 @@ if (!is.na(exclude_grid)){
...
@@ -291,19 +291,19 @@ if (!is.na(exclude_grid)){
predictors_obs
<-
predictors_obs
[
predictors_obs
$
grid_id
!=
exclude_grid
,
]
predictors_obs
<-
predictors_obs
[
predictors_obs
$
grid_id
!=
exclude_grid
,
]
}
}
if
(
!
is.na
(
exclude_random
)){
if
(
!
is.na
(
exclude_grid_rand
)){
# choose X percent random grid_cells from all cells
#bin_id --> randomly exclude percentage given in grid_rand
# save them in predictors_excluded random and exclude them from the others
ids_to_exclude
<-
sample
(
predictors_obs
$
bin_id
,
ids_to_exclude
<-
sample
(
predictors_obs
$
id
,
size
=
nrow
(
predictors_obs
)
/
100
*
exclude_grid_rand
,
size
=
nrow
(
predictors_obs
)
/
100
*
exclude_random
,
replace
=
FALSE
)
replace
=
FALSE
)
predictors_excluded_random
<-
predictors_obs
[
predictors_obs
$
id
%in%
ids_to_exclude
,
]
predictors_obs
<-
predictors_obs
[
!
predictors_obs
$
id
%in%
ids_to_exclude
,
]
predictors_excluded_grid_rand
<-
predictors_obs
[
predictors_obs
$
bin_id
%in%
ids_to_exclude
,
]
predictors_obs
<-
predictors_obs
[
!
predictors_obs
$
bin_id
%in%
ids_to_exclude
,
]
}
}
# also we increase maxit for the two cases,
# also we increase maxit for the two cases,
# because then slightly less data
# because then slightly less data
if
(
is.na
(
exclude_grid
)
&
is.na
(
exclude_year
)){
if
(
is.na
(
exclude_grid
)
&
is.na
(
exclude_year
)
&
is.na
(
exclude_grid_rand
)
){
nr_maxit
<-
250
}
else
{
nr_maxit
<-
250
}
else
{
nr_maxit
<-
500
}
nr_maxit
<-
500
}
if
(
is_verbose
){
print
(
paste
(
"3. start making all_model_terms"
,
Sys.time
()))}
if
(
is_verbose
){
print
(
paste
(
"3. start making all_model_terms"
,
Sys.time
()))}
...
@@ -400,7 +400,7 @@ if(is_verbose){print(paste("8. Start running models", Sys.time()))}
...
@@ -400,7 +400,7 @@ if(is_verbose){print(paste("8. Start running models", Sys.time()))}
results_res
<-
foreach
(
i
=
1
:
nrow
(
all_model_terms
),
results_res
<-
foreach
(
i
=
1
:
nrow
(
all_model_terms
),
.combine
=
rbind
)
%dopar%
{
.combine
=
rbind
)
%dopar%
{
# make results dataframe
# make results dataframe
if
(
is.na
(
exclude_year
)
&
is.na
(
exclude_grid
)
&
is.na
(
exclude_rand
om
)){
if
(
is.na
(
exclude_year
)
&
is.na
(
exclude_grid
)
&
is.na
(
exclude_
grid_
rand
)){
result
<-
as.data.frame
(
matrix
(
NA
,
ncol
=
3
*
result
<-
as.data.frame
(
matrix
(
NA
,
ncol
=
3
*
length
(
model_terms
)
+
5
,
length
(
model_terms
)
+
5
,
nrow
=
1
))
nrow
=
1
))
...
@@ -489,13 +489,13 @@ results_res <- foreach(i = 1:nrow(all_model_terms),
...
@@ -489,13 +489,13 @@ results_res <- foreach(i = 1:nrow(all_model_terms),
result
[
,
"R2_cross"
]
<-
summary
(
cross_lm_grid
)
$
r.squared
result
[
,
"R2_cross"
]
<-
summary
(
cross_lm_grid
)
$
r.squared
}
}
if
(
!
is.na
(
exclude_rand
om
)){
if
(
!
is.na
(
exclude_
grid_
rand
)){
predictors_excluded_grid_pred
<-
predictors_excluded_rand
om
predictors_excluded_grid_pred
<-
predictors_excluded_
grid_
rand
predictors_excluded_grid_pred
$
offset_term
<-
0
predictors_excluded_grid_pred
$
offset_term
<-
0
prediction_transect_excluded_grid
<-
predict.glm
(
res
,
prediction_transect_excluded_grid
<-
predict.glm
(
res
,
newdata
=
predictors_excluded_rand
om
,
newdata
=
predictors_excluded_
grid_
rand
,
type
=
"response"
)
type
=
"response"
)
cross_lm_random
=
lm
(
log
(
predictors_excluded_rand
om
$
ou_dens
+
1
)
~
cross_lm_random
=
lm
(
log
(
predictors_excluded_
grid_
rand
$
ou_dens
+
1
)
~
log
(
prediction_transect_excluded_random
+
1
))
log
(
prediction_transect_excluded_random
+
1
))
result
[
,
"R2_cross"
]
<-
summary
(
cross_lm_random
)
$
r.squared
result
[
,
"R2_cross"
]
<-
summary
(
cross_lm_random
)
$
r.squared
...
...
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