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
1f944e41
Commit
1f944e41
authored
8 years ago
by
Maria Voigt
Browse files
Options
Downloads
Patches
Plain Diff
fixing bug in cross-validation and including it back again
also for the non-exclude scenario
parent
d49b167d
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
+19
-16
19 additions, 16 deletions
src/model_fitting/abundance_model.R
with
19 additions
and
16 deletions
src/model_fitting/abundance_model.R
+
19
−
16
View file @
1f944e41
...
@@ -367,26 +367,27 @@ if(is_verbose){print(paste("8. Start running models", Sys.time()))}
...
@@ -367,26 +367,27 @@ if(is_verbose){print(paste("8. Start running models", Sys.time()))}
save.image
(
file.path
(
outdir
,
"image_before_fail.RData"
))
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
)){
if
(
is.na
(
exclude_year
)){
result
<-
as.data.frame
(
matrix
(
NA
,
ncol
=
3
*
result
<-
as.data.frame
(
matrix
(
NA
,
ncol
=
3
*
length
(
model_terms
)
+
4
,
#
5
length
(
model_terms
)
+
5
,
nrow
=
1
))
nrow
=
1
))
names
(
result
)
<-
c
(
"model"
,
paste
(
"coeff"
,
model_terms
,
sep
=
"_"
),
names
(
result
)
<-
c
(
"model"
,
paste
(
"coeff"
,
model_terms
,
sep
=
"_"
),
paste
(
"P"
,
model_terms
,
sep
=
"_"
),
paste
(
"P"
,
model_terms
,
sep
=
"_"
),
paste
(
"SE"
,
model_terms
,
sep
=
"_"
),
paste
(
"SE"
,
model_terms
,
sep
=
"_"
),
"theta"
,
"SE.theta"
,
"AIC"
#
, "R2"
"theta"
,
"SE.theta"
,
"AIC"
,
"R2"
)}
else
{
)}
else
{
result
<-
as.data.frame
(
matrix
(
NA
,
ncol
=
3
*
result
<-
as.data.frame
(
matrix
(
NA
,
ncol
=
3
*
length
(
model_terms
)
+
5
,
#+
6,
length
(
model_terms
)
+
6
,
nrow
=
1
))
nrow
=
1
))
names
(
result
)
<-
c
(
"model"
,
paste
(
"coeff"
,
model_terms
,
sep
=
"_"
),
names
(
result
)
<-
c
(
"model"
,
paste
(
"coeff"
,
model_terms
,
sep
=
"_"
),
paste
(
"P"
,
model_terms
,
sep
=
"_"
),
paste
(
"P"
,
model_terms
,
sep
=
"_"
),
paste
(
"SE"
,
model_terms
,
sep
=
"_"
),
paste
(
"SE"
,
model_terms
,
sep
=
"_"
),
"theta"
,
"SE.theta"
,
"AIC"
,
#
"R2",
"theta"
,
"SE.theta"
,
"AIC"
,
"R2"
,
"R2_cross"
)
"R2_cross"
)
}
}
# make model
# make model
...
@@ -424,25 +425,27 @@ results_res <- foreach(i = 1:nrow(all_model_terms),
...
@@ -424,25 +425,27 @@ results_res <- foreach(i = 1:nrow(all_model_terms),
# what do I need to do
# what do I need to do
# I need to get only the prediction estimates columns that are true in
# I need to get only the prediction estimates columns that are true in
#
all_model_terms[i, ]==1
#all_model_terms[i, ]==1
#
predictors_obs_pred <- predictors_obs
predictors_obs_pred
<-
predictors_obs
#
predictors_obs_pred$offset_term <- 0
predictors_obs_pred
$
offset_term
<-
0
# Comparison of observed data vs prediction
# Comparison of observed data vs prediction
#
prediction_per_transect <- predict.glm(res,
prediction_per_transect
<-
predict.glm
(
res
,
#
newdata = predictors_obs_pred,
newdata
=
predictors_obs_pred
,
#
type = "response")
type
=
"response"
)
#
comparison_lm = lm(log(predictors_obs$
nr_ou_per_km2
+ 1) ~
comparison_lm
=
lm
(
log
(
predictors_obs
$
ou_dens
+
1
)
~
#
log(prediction_per_transect + 1) )
log
(
prediction_per_transect
+
1
)
)
#
result[ , "R2"] <- summary(comparison_lm)$r.squared
result
[
,
"R2"
]
<-
summary
(
comparison_lm
)
$
r.squared
# if we are excluding years, this is the test of predicted data vs observed data
# if we are excluding years, this is the test of predicted data vs observed data
# for this year (with which the model wasn't fitted)
# for this year (with which the model wasn't fitted)
if
(
!
is.na
(
exclude_year
)){
if
(
!
is.na
(
exclude_year
)){
predictors_excluded_year_pred
<-
predictors_excluded_year
predictors_excluded_year_pred
$
offset_term
<-
0
prediction_transect_excluded_year
<-
predict.glm
(
res
,
prediction_transect_excluded_year
<-
predict.glm
(
res
,
newdata
=
predictors_excluded_year
,
newdata
=
predictors_excluded_year
,
type
=
"response"
)
type
=
"response"
)
cross_lm
=
lm
(
log
(
predictors_excluded_year
$
nr_ou_per_km2
+
1
)
~
cross_lm
=
lm
(
log
(
predictors_excluded_year
$
ou_dens
+
1
)
~
log
(
prediction_transect_excluded_year
+
1
))
log
(
prediction_transect_excluded_year
+
1
))
result
[
,
"R2_cross"
]
<-
summary
(
cross_lm
)
$
r.squared
result
[
,
"R2_cross"
]
<-
summary
(
cross_lm
)
$
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