Skip to content

Commit

Permalink
tests RW ALK
Browse files Browse the repository at this point in the history
  • Loading branch information
OlavNikolaiBreivik committed Feb 25, 2025
1 parent b43cb32 commit 24abc3b
Show file tree
Hide file tree
Showing 19 changed files with 30 additions and 65 deletions.
Binary file not shown.
47 changes: 0 additions & 47 deletions spatioTemporalIndices/tests/testthat/NEAhadLengthAgeAR1/script.R

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
suppressMessages(library(spatioTemporalIndices))

dat_l = readRDS("NEAhadLengthAgeRW_betaLength/haddock2018-2020_length_ex_rus_reduced.rds")
dat_alk = readRDS("NEAhadLengthAgeRW_betaLength/haddock2018-2020_age_ex_rus_reduced.rds")
dat_l = readRDS("NEAhadLengthAgeRW/haddock2018-2020_length_ex_rus_reduced.rds")
dat_alk = readRDS("NEAhadLengthAgeRW/haddock2018-2020_age_ex_rus_reduced.rds")

conf_l = defConf(years = 2018:2020, # years to use, use all years with data by default
maxLength = 60, # Numeric = use directly; NULL = use input data to determine
minLength = 20, # Numeric = use directly; NULL = use input data to determine
spatioTemporal =0 ,
spatial =0,
rwBeta0 = 1,
rwBeta0 = 0,
dLength = 5,
reduceLength = 3,
stratasystem = list(dsn="NEAhadLengthAgeRW_betaLength/strata", layer = "Vintertoktet_nye_strata"),
stratasystem = list(dsn="NEAhadLengthAgeRW/strata", layer = "Vintertoktet_nye_strata"),
applyALK = 1,
cutoff =100)

Expand All @@ -21,46 +21,59 @@ conf_alk = defConf_alk(maxAge = 8,
minAge = 3,
spatioTemporal = 0,
spatial =0,
rwBeta0 = 1,
betaLength = 1)
rwBeta0 = 1)

confPred = defConfPred(conf=conf_l,Depth="DATA",cellsize = 200)

# run model
# run model with random walk beta0 in ALK
run = fitModel(dat_l,conf_l, confPred,dat_alk,conf_alk,ignore.parm.uncertainty = TRUE,silent = TRUE)

#RW for beta0 and beta_length in ALK
conf_alk$rwBeta0 = 1
conf_alk$betaLength = 1
run2 = fitModel(dat_l,conf_l, confPred,dat_alk,conf_alk,ignore.parm.uncertainty = TRUE,silent = TRUE)

#no RW for beta0 and no RW for beta_length
#no RW for beta0 and beta_length in ALK
conf_alk$rwBeta0 = 0
conf_alk$betaLength = 2
run2 = fitModel(dat_l,conf_l, confPred,dat_alk,conf_alk,ignore.parm.uncertainty = TRUE,silent = TRUE)
run3 = fitModel(dat_l,conf_l, confPred,dat_alk,conf_alk,ignore.parm.uncertainty = TRUE,silent = TRUE)

resultsOut = list(objective = run$opt$objective,
objective2 = run2$opt$objective,
objective3 = run3$opt$objective,
logAgeIndex = run$rl$logAgeIndex,
logAgeIndex2 = run2$rl$logAgeIndex)
resultsOut$AIC = AIC(run,run2)
logAgeIndex2 = run2$rl$logAgeIndex,
logAgeIndex3 = run3$rl$logAgeIndex)
resultsOut$AIC = AIC(run,run2,run3)


load("NEAhadLengthAgeRW_betaLength/resultsExp.RData")

load("NEAhadLengthAgeRW/resultsExp.RData")

expect_equal(resultsOut$logAgeIndex, resultsExp$logAgeIndexExp,tolerance = 1e-4)
expect_equal(resultsOut$objective, resultsExp$objectiveExp,tolerance = 1e-4)
expect_equal(resultsOut$logAgeIndex2, resultsExp$logAgeIndex2Exp,tolerance = 1e-4)
expect_equal(resultsOut$objective2, resultsExp$objective2Exp,tolerance = 1e-4)
expect_equal(resultsOut$logAgeIndex3, resultsExp$logAgeIndex3Exp,tolerance = 1e-4)
expect_equal(resultsOut$objective3, resultsExp$objective3Exp,tolerance = 1e-4)
expect_equal(resultsOut$AIC, resultsExp$AICExp,tolerance = 1e-4)

test_that("Plot runs without error", {
expect_silent(plotResults(run, what = "ALK", year = 2020))
expect_silent(plotResults(run2, what = "ALK", year = 2020))
})




if(FALSE){
resultsExp = list(objectiveExp = run$opt$objective,
objective2Exp = run2$opt$objective,
objective3Exp = run3$opt$objective,
logAgeIndexExp = run$rl$logAgeIndex,
logAgeIndex2Exp = run2$rl$logAgeIndex,
AICExp = AIC(run,run2))
save(resultsExp,file = "NEAhadLengthAgeRW_betaLength/resultsExp.RData")
logAgeIndex3Exp = run3$rl$logAgeIndex)
resultsExp$AICExp = AIC(run,run2,run3)
save(resultsExp,file = "NEAhadLengthAgeRW/resultsExp.RData")
}


Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
2 changes: 0 additions & 2 deletions spatioTemporalIndices/tests/testthat/test-NEAhaddockAR1.R

This file was deleted.

2 changes: 2 additions & 0 deletions spatioTemporalIndices/tests/testthat/test-NEAhaddockRW.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source("NEAhadLengthAgeRW/script.R")

0 comments on commit 24abc3b

Please sign in to comment.