diff --git a/NAMESPACE b/NAMESPACE
index 90cea17..c451746 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -19,6 +19,7 @@ export(get_surveyidx_aic)
export(get_surveyidx_resid)
export(get_surveyidx_sim)
export(get_surveyidx_stratmean)
+export(plot_simulation_list)
export(plot_surveyidx)
export(plot_surveyidx_grid)
export(qres_tweedie)
diff --git a/R/functions.R b/R/functions.R
index 15ece16..15d71c6 100644
--- a/R/functions.R
+++ b/R/functions.R
@@ -1127,6 +1127,97 @@ get_surveyidx_sim <- function(
prob0=out_mu0))
}
+
+##' Plot survey index list (e.g. retrospective analysis)
+##'
+##' @title Plot survey index list (e.g. retrospective analysis)
+##' @param x (named) list of "surveyIdx" objects for example from "retro.surveyIdx" or "leaveout.surveyIdx"
+##' @param base Either index of x that should considered the "base run" (integer), OR object of class "surveyIdx". Confidence bounds will be shown for this model only.
+##' @param rescale Should indices be rescaled to have mean 1 (over the set of intersecting years)? Default: FALSE
+##' @param lwd line width argument to plot
+##' @param main if not NULL override main plotting default title of "Age group a"
+##' @param allCI show 95\% confidence lines for all indices? Default FALSE.
+##' @param includeCI Show confidence intervals? Default TRUE.
+##' @param ylim Y axis range. If NULL (default) then determine automatically.
+##' @return nothing
+##' @export
+plot_simulation_list<-function(x, base=1, rescale=FALSE,lwd=1.5,main=NULL,allCI=FALSE,includeCI=TRUE,ylim=NULL){
+ if(class(base)=="surveyIdx"){
+ x = c( list(base), x)
+ base = 1
+ }
+ stopifnot(is.numeric(base))
+ nx = length(x)
+ mainwasnull = is.null(main)
+ n = ncol(x[[base]]$idx)
+ if(n>1){
+ op <- par(mfrow=n2mfrow(n))
+ on.exit(par(op))
+ }
+
+ cols = rainbow(nx)
+ if(nx==2) cols = 2:3
+ cols[base] = "black"
+ allyears = lapply(x, function(x) rownames(x$idx))
+ rsidx = 1:nrow(x[[nx]]$idx)
+ if(rescale){
+ commonyears = allyears[[1]]
+ if(nx>1){
+ for(i in 2:nx){
+ commonyears = intersect(commonyears,allyears[[i]])
+ }
+ if(length(commonyears)==0) stop("rescaling not possible because the set of common years is empty")
+ }
+ }
+
+ ss <- ssbase <- 1
+
+ for(aa in 1:n){
+
+ rangevec = x[[1]]$idx[,aa]
+ for(xx in 2:nx) rangevec = c(rangevec,x[[xx]]$idx[,aa])
+ if(includeCI){
+ for(xx in 1:nx) rangevec = c(rangevec,x[[xx]]$lo[,aa],x[[xx]]$up[,aa])
+ }
+
+ yl = range(rangevec)
+ if(rescale){
+ rsidx = which(rownames(x[[base]]$idx) %in% commonyears )
+ ssbase = mean( x[[base]]$idx[rsidx,aa], na.rm=TRUE)
+ yl = yl/ssbase
+ }
+ if(!is.null(ylim)) yl = ylim
+
+ if(mainwasnull) main <- paste("Age group", colnames(x[[base]]$idx)[aa])
+ y = as.numeric(rownames(x[[base]]$idx))
+ plot(y,x[[base]]$idx[,aa]/ssbase,type="b",ylim=yl,main=main,xlab="Year",ylab="Index")
+
+ if(includeCI)
+ polygon(c(y, rev(y)), c(x[[base]]$lo[,aa], rev(x[[base]]$up[,aa]))/ssbase, col = "lightgrey", border = NA)
+
+ for(i in 1:length(x)){
+ y = as.numeric(rownames(x[[i]]$idx))
+ if(rescale){
+ rsidx = which(rownames(x[[i]]$idx) %in% commonyears )
+ ss = mean( x[[i]]$idx[rsidx,aa], na.rm=TRUE)
+ }
+ lines(y,x[[i]]$idx[,aa]/ss,col=cols[i],type="b", lwd=lwd)
+
+ if(includeCI && allCI && i!=base){
+ lines(y,x[[i]]$lo[,aa]/ss,col=cols[i],lwd=lwd*0.6,lty=2)
+ lines(y,x[[i]]$up[,aa]/ss,col=cols[i],lwd=lwd*0.6,lty=2)
+ }
+
+ }
+ y = as.numeric(rownames(x[[base]]$idx))
+ lines(y,x[[base]]$idx[,aa]/ssbase,type="b",lwd=lwd)
+
+ }
+ if(!is.null(names(x))){
+ legend("topleft",legend=names(x),col=cols,lty=1,lwd=lwd,pch=1)
+ }
+}
+
# Randomized quantile residuals ------------------------------------------------
#' Randomized quantile residuals for class 'surveyIndex'
diff --git a/README.Rmd b/README.Rmd
index 9df471e..caa183c 100644
--- a/README.Rmd
+++ b/README.Rmd
@@ -6,7 +6,6 @@ output:
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
-link_foss <- "https://github.com/EmilyMarkowitz-NOAA/surveyIndex"
```
@@ -36,13 +35,19 @@ cat(
)
```
-> Code is still in development
+> Code is still in development at https://github.com/EmilyMarkowitz-NOAA/surveyIndex
-Code was originally developed by: **Casper W. Berg** (@casperwberg)
+*Code was originally developed by:*
-> Berg et al. (2014): "Evaluation of alternative age-based methods for estimating relative abundance from survey data in relation to assessment models", Fisheries Research 151(2014) 91-99.
+**Casper W. Berg** (@casperwberg)
-And then modified and adapted for the AFSC by:
+National Institute of Aquatic Resources,
+
+Technical University of Denmark
+
+[**Berg et al. (2014): "Evaluation of alternative age-based methods for estimating relative abundance from survey data in relation to assessment models", Fisheries Research 151(2014) 91-99.**](https://doi.org/10.1016/j.fishres.2013.10.005)
+
+*And then modified and adapted for the AFSC by:*
**Emily Markowitz** (@EmilyMarkowitz-noaa; Emily.Markowitz AT noaa.gov)
diff --git a/README.md b/README.md
index a22aad6..d9a4ec2 100644
--- a/README.md
+++ b/README.md
@@ -7,15 +7,23 @@ data.
[![](https://img.shields.io/github/last-commit/EmilyMarkowitz-NOAA/surveyIndex.svg)](https://github.com/EmilyMarkowitz-NOAA/surveyIndex/commits/main)
-> Code is still in development
+> Code is still in development at
+> Here are all of the models we want to try fitting: Site built with pkgdown 2.0.6. Site built with pkgdown 2.0.6.9000. Site built with pkgdown 2.0.6. Site built with pkgdown 2.0.6.9000.Page not found (404)
diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html
index 6742769..9aea796 100644
--- a/docs/LICENSE-text.html
+++ b/docs/LICENSE-text.html
@@ -744,7 +744,7 @@ License
diff --git a/docs/articles/A-data-prep.html b/docs/articles/A-data-prep.html
index b14ea8a..febf395 100644
--- a/docs/articles/A-data-prep.html
+++ b/docs/articles/A-data-prep.html
@@ -227,8 +227,8 @@ 2. Prepare the data for s
Quarter = "2") %>%
dplyr::mutate(across((c("Year", "Ship", "COMMON_NAME")), as.factor)) %>%
dplyr::select(wCPUE, GEAR_TEMPERATURE, BOTTOM_DEPTH, COMMON_NAME, EFFORT,
- Year, Ship, Lon, Lat, lat, lon, sx, sy, ctime,
- TimeShotHour, timeOfYear, Gear, Quarter, HaulDur, hauljoin)
+ Year, Ship, Lon, Lat, lat, lon, sx, sy,
+ ctime, TimeShotHour, timeOfYear, Gear, Quarter, HaulDur, hauljoin)
head(dat_wrangled)
#> # A tibble: 6 × 20
@@ -291,7 +291,7 @@
4. Prepare covariate data
dat_cov <- surveyIndex::pred_grid_ebs %>%
dplyr::select(-Shape_Area) %>%
- dplyr::mutate(
+ dplyr::mutate(
sx = ((lon - mean(lon, na.rm = TRUE))/1000),
sy = ((lat - mean(lat, na.rm = TRUE))/1000))
@@ -335,7 +335,7 @@
4a. Data that varies over onl
# to make future runs of this faster:
save(extrap_data0, extrap_data,
file = paste0("../inst/VigA_bottom_depth_raster_",
- min(YEARS),"-",max(YEARS), ".rdata"))
+ min(YEARS),"-",max(YEARS), ".rdata"))
# Just so we can see what we are looking at:
plot(extrap_data0, main = "Interpolated Bottom Depths")
4a. Data that varies over onl
dat_cov <- cbind.data.frame(dat_cov,
- "BOTTOM_DEPTH" = extrap_data$var1.pred) %>%
+ "BOTTOM_DEPTH" = extrap_data$var1.pred) %>%
stats::na.omit()
head(dat_cov)
@@ -379,12 +379,12 @@
4b. Data tha
}
extrap_data0 <- coldpool::ebs_bottom_temperature[[tmp]] %>%
- as(., Class = "SpatialPointsDataFrame") %>%
- sf::st_as_sf() %>%
+ as(., Class = "SpatialPointsDataFrame") %>%
+ sf::st_as_sf() %>%
sf::st_transform(crs = crs_latlon) %>%
stars::st_rasterize() %>%
- stars::st_extract(x = .,
- at = as.matrix(dat_cov[,c("lon", "lat")]))
+ stars::st_extract(x = .,
+ at = as.matrix(dat_cov[,c("lon", "lat")]))
names(extrap_data0) <- paste0("GEAR_TEMPERATURE", YEARS)
@@ -424,59 +424,60 @@
5b. Catch DataNow, we need to fill in the data with the zeros!
- # Identify vars that will be used --------------------------------------------
+# Identify vars that will be used --------------------------------------------
- varsbyyr <- unique( # c("GEAR_TEMPERATURE", "cpi")
- gsub(pattern = "[0-9]+",
- replacement = "",
- x = names(dat_cov)[grepl(names(dat_cov),
- pattern = "[0-9]+")]))
-
- vars <- unique( # c("BOTTOM_DEPTH")
- names(dat_cov)[!grepl(names(dat_cov),
- pattern = "[0-9]+")])
- vars <- vars[!(vars %in% c("LONG", "LAT", "lon", "lat", "sx", "sy"))]
-
- ## Fill catch data with zeros ---------------------------------------------------------
-
- data_hauls <- dat_wrangled %>%
- dplyr::select(Year, sx, sy,
- dplyr::all_of(varsbyyr), dplyr::all_of(vars),
- Ship, hauljoin,
- lat, lon,
- ctime, TimeShotHour, timeOfYear, Gear, Quarter,
- EFFORT, HaulDur) %>%
- # dplyr::filter(!is.na(GEAR_TEMPERATURE)) %>%
- na.omit() %>%
- dplyr::distinct()
-
- data_catch <- dat_wrangled %>%
- dplyr::select(COMMON_NAME, wCPUE, hauljoin)
-
- dat_catch_haul <- dplyr::left_join(x = data_hauls,
- y = data_catch,
- by = c("hauljoin")) %>%
- dplyr::mutate(wCPUE = ifelse(is.na(wCPUE), 0, wCPUE))
-
- head(dat_catch_haul)
-#> # A tibble: 6 × 18
-#> Year sx sy GEAR_TEMPE…¹ BOTTO…² Ship haulj…³ lat lon ctime
+varsbyyr <- unique( # c("GEAR_TEMPERATURE", "cpi")
+ gsub(pattern = "[0-9]+",
+ replacement = "",
+ x = names(dat_cov)[grepl(names(dat_cov),
+ pattern = "[0-9]+")]))
+
+vars <- unique( # c("BOTTOM_DEPTH")
+ names(dat_cov)[!grepl(names(dat_cov),
+ pattern = "[0-9]+")])
+vars <- vars[!(vars %in% c("LONG", "LAT", "lon", "lat", "sx", "sy"))]
+
+## Fill catch data with zeros ---------------------------------------------------------
+
+data_hauls <- dat_wrangled %>%
+ dplyr::select(Year, sx, sy,
+ dplyr::all_of(varsbyyr), dplyr::all_of(vars),
+ Ship, hauljoin,
+ lat, lon, Lat, Lon,
+ ctime, TimeShotHour, timeOfYear, Gear, Quarter,
+ EFFORT, HaulDur) %>%
+ # dplyr::filter(!is.na(GEAR_TEMPERATURE)) %>%
+ na.omit() %>%
+ dplyr::distinct()
+
+data_catch <- dat_wrangled %>%
+ dplyr::select(COMMON_NAME, wCPUE, hauljoin)
+
+dat_catch_haul <- dplyr::left_join(x = data_hauls,
+ y = data_catch,
+ by = c("hauljoin")) %>%
+ dplyr::mutate(wCPUE = ifelse(is.na(wCPUE), 0, wCPUE))
+
+head(dat_catch_haul)
+#> # A tibble: 6 × 20
+#> Year sx sy GEAR_TEMPE…¹ BOTTO…² Ship haulj…³ lat lon Lat
#> <fct> <dbl> <dbl> <dbl> <dbl> <fct> <chr> <dbl> <dbl> <dbl>
-#> 1 2016 0.00647 -0.00183 6.1 54 94 10_E-1… 7.26e5 -4.32e5 2016
-#> 2 2016 0.00647 -0.00183 6.1 54 94 10_E-1… 7.26e5 -4.32e5 2016
-#> 3 2016 0.00647 -0.00183 6.1 54 94 10_E-1… 7.26e5 -4.32e5 2016
-#> 4 2016 0.00518 -0.00217 5.2 73 162 31_D-1… 6.98e5 -5.16e5 2016
-#> 5 2016 0.00518 -0.00217 5.2 73 162 31_D-1… 6.98e5 -5.16e5 2016
-#> 6 2016 0.00518 -0.00217 5.2 73 162 31_D-1… 6.98e5 -5.16e5 2016
-#> # … with 8 more variables: TimeShotHour <dbl>, timeOfYear <dbl>, Gear <chr>,
-#> # Quarter <chr>, EFFORT <dbl>, HaulDur <dbl>, COMMON_NAME <fct>, wCPUE <dbl>,
-#> # and abbreviated variable names ¹GEAR_TEMPERATURE, ²BOTTOM_DEPTH, ³hauljoin
-
allpd <- lapply(YEARS, FUN = surveyIndex::get_prediction_grid, x = dat_cov,
- vars = vars, varsbyyr = varsbyyr)
- names(allpd) <- as.character(YEARS)
-
- head(allpd[1][[1]])
+
allpd <- lapply(YEARS, FUN = surveyIndex::get_prediction_grid, x = dat_cov,
+ vars = vars, varsbyyr = varsbyyr)
+names(allpd) <- as.character(YEARS)
+
+head(allpd[1][[1]])
#> lon lat sx sy BOTTOM_DEPTH GEAR_TEMPERATURE
#> 7 -176.2507 62.09301 -0.007524943 0.003800355 92.30377 0.06603578
#> 11 -175.9816 62.13632 -0.007255819 0.003843669 91.79176 -0.19408995
@@ -497,12 +498,12 @@
5a. Covariate Data
- ## split data by species, make into DATRASraw + Nage matrix
- ds <- split(dat_catch_haul,dat_catch_haul$COMMON_NAME)
- ds <- lapply(ds, surveyIndex::get_datrasraw)
- ## OBS, response is added here in "Nage" matrix -- use wCPUE
- ds <- lapply(ds,function(x) { x[[2]]$Nage <- matrix(x$wCPUE,ncol=1); colnames(x[[2]]$Nage)<-1; x } )
-
+## split data by species, make into DATRASraw + Nage matrix
+ds <- split(dat_catch_haul,dat_catch_haul$COMMON_NAME)
+ds <- lapply(ds, surveyIndex::get_datrasraw)
+## OBS, response is added here in "Nage" matrix -- use wCPUE
+ds <- lapply(ds,function(x) { x[[2]]$Nage <- matrix(x$wCPUE,ncol=1); colnames(x[[2]]$Nage)<-1; x } )
+
ds
#> $`red king crab`
#> Object of class 'DATRASraw'
@@ -547,10 +548,10 @@
6. Formulas"fm_1_s_t_st" = "Year +
s(sx,sy,bs=c('ts'),k=376) +
s(sx,sy,bs=c('ts'),k=10,by=Year)",
-
+
# Mdoel with simple covariates
"fm_2_cov" =
-"s(BOTTOM_DEPTH,bs='ts',k=10) +
+ "s(BOTTOM_DEPTH,bs='ts',k=10) +
s(log(GEAR_TEMPERATURE+3),bs='ts',k=10)"
)
7. Fit the Model
-
comb <- tidyr::crossing(
- "SPECIES" = SPECIES,
- "fm_name" = gsub(pattern = " ", replacement = "_", x = names(fm))) %>%
- dplyr::left_join(
- x = .,
- y = data.frame("fm" = gsub(pattern = "\n", replacement = "",
- x = unlist(fm), fixed = TRUE),
- "fm_name" = gsub(pattern = " ", replacement = "_",
- x = names(fm))),
- by = "fm_name")
+
comb <- tidyr::crossing(
+ "SPECIES" = SPECIES,
+ "fm_name" = gsub(pattern = " ", replacement = "_", x = names(fm))) %>%
+ dplyr::left_join(
+ x = .,
+ y = data.frame("fm" = gsub(pattern = "\n", replacement = "",
+ x = unlist(fm), fixed = TRUE),
+ "fm_name" = gsub(pattern = " ", replacement = "_",
+ x = names(fm))),
+ by = "fm_name")
comb
#> # A tibble: 6 × 3
@@ -581,36 +582,36 @@
7. Fit the Model#> 5 yellowfin sole fm_1_s_t_st Year + s(sx,sy,bs=c('ts'),k=376) + s(sx,sy…
#> 6 yellowfin sole fm_2_cov s(BOTTOM_DEPTH,bs='ts',k=10) +s(log(GEAR_TEMPERAT…
-
- models <- fittimes <- list()
-
- for(i in 1:nrow(comb)){
- cat("Fitting ",comb$SPECIES[i],"\n", comb$fm_name[i], ": ", comb$fm[i], "\n")
-
- temp <- paste0(comb$SPECIES[i], " ", comb$fm_name[i])
-
- fittimes[[ temp ]] <-
- system.time ( models[[ temp ]] <-
- surveyIndex::get_surveyidx(
- x = ds[[ comb$SPECIES[i] ]],
- ages = 1,
- myids = NULL,
- predD = allpd,
- cutOff = 0,
- fam = "Tweedie",
- modelP = comb$fm[i],
- gamma = 1,
- control = list(trace = TRUE,
- maxit = 20)) )
+
+models <- fittimes <- list()
- }
+for(i in 1:nrow(comb)){
+ cat("Fitting ",comb$SPECIES[i],"\n", comb$fm_name[i], ": ", comb$fm[i], "\n")
+
+ temp <- paste0(comb$SPECIES[i], " ", comb$fm_name[i])
+
+ fittimes[[ temp ]] <-
+ system.time ( models[[ temp ]] <-
+ surveyIndex::get_surveyidx(
+ x = ds[[ comb$SPECIES[i] ]],
+ ages = 1,
+ myids = NULL,
+ predD = allpd,
+ cutOff = 0,
+ fam = "Tweedie",
+ modelP = comb$fm[i],
+ gamma = 1,
+ control = list(trace = TRUE,
+ maxit = 20)) )
+
+}
- save(models, fittimes, file = paste0("../inst/VigA_model_fits.Rdata"))
-
## Check basis dimensions splines (spatial resolution)
- # sink(paste0(".", dir_out, "gamcheck.txt"))
+
## Check basis dimensions splines (spatial resolution)
+# sink(paste0(".", dir_out, "gamcheck.txt"))
par(mfrow = c(2,2))
- lapply(models,function(x) gam.check(x$pModels[[1]]))
@@ -660,16 +661,14 @@ #>
#> Method: ML Optimizer: outer newton
@@ -645,7 +646,7 @@
7. Fit the Model#>
#> k' edf k-index p-value
#> s(BOTTOM_DEPTH) 9.000 4.388 0.76 <2e-16 ***
-#> s(log(GEAR_TEMPERATURE + 3)) 9.000 0.944 0.77 <2e-16 ***
+#> s(log(GEAR_TEMPERATURE + 3)) 9.000 0.944 0.77 0.01 **
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
7. Fit the Model#> Basis dimension (k) checking results. Low p-value (k-index<1) may
#> indicate that k is too low, especially if edf is close to k'.
#>
-#> k' edf k-index p-value
-#> s(sx,sy) 3.75e+02 1.26e+02 0.87 0.165
-#> s(sx,sy):Year2015 9.00e+00 6.23e+00 0.87 0.090 .
-#> s(sx,sy):Year2016 9.00e+00 1.29e-02 0.87 0.145
-#> s(sx,sy):Year2017 9.00e+00 1.94e+00 0.87 0.155
-#> s(sx,sy):Year2018 9.00e+00 8.12e+00 0.87 0.140
-#> s(sx,sy):Year2019 9.00e+00 2.01e+00 0.87 0.085 .
-#> s(sx,sy):Year2021 9.00e+00 6.41e-03 0.87 0.115
-#> ---
-#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
+#> k' edf k-index p-value
+#> s(sx,sy) 3.75e+02 1.26e+02 0.87 0.11
+#> s(sx,sy):Year2015 9.00e+00 6.23e+00 0.87 0.14
+#> s(sx,sy):Year2016 9.00e+00 1.29e-02 0.87 0.16
+#> s(sx,sy):Year2017 9.00e+00 1.94e+00 0.87 0.14
+#> s(sx,sy):Year2018 9.00e+00 8.12e+00 0.87 0.13
+#> s(sx,sy):Year2019 9.00e+00 2.01e+00 0.87 0.11
+#> s(sx,sy):Year2021 9.00e+00 6.41e-03 0.87 0.17
#>
#> Method: ML Optimizer: outer newton
@@ -702,10 +701,10 @@
7. Fit the Model#> k' edf k-index p-value
#> s(sx,sy) 3.75e+02 1.52e+02 1 0.99
#> s(sx,sy):Year2015 9.00e+00 1.80e+00 1 0.99
-#> s(sx,sy):Year2016 9.00e+00 1.15e-03 1 0.99
-#> s(sx,sy):Year2017 9.00e+00 2.08e-03 1 0.99
-#> s(sx,sy):Year2018 9.00e+00 1.87e+00 1 1.00
-#> s(sx,sy):Year2019 9.00e+00 6.64e+00 1 0.99
+#> s(sx,sy):Year2016 9.00e+00 1.15e-03 1 1.00
+#> s(sx,sy):Year2017 9.00e+00 2.08e-03 1 0.98
+#> s(sx,sy):Year2018 9.00e+00 1.87e+00 1 0.99
+#> s(sx,sy):Year2019 9.00e+00 6.64e+00 1 0.98
#> s(sx,sy):Year2021 9.00e+00 1.95e+00 1 0.99
+# sink()
#>
@@ -752,11 +751,11 @@
7. Fit the Model#> $`yellowfin sole fm_2_cov`
#> $`yellowfin sole fm_2_cov`$mfrow
#> [1] 2 2
- # sink()
-
## Model summaries
- # sink(paste0(".", dir_out, "summaries.txt"))
- lapply(models,function(x) summary(x$pModels[[1]]))
+
## Model summaries
+# sink(paste0(".", dir_out, "summaries.txt"))
+lapply(models,function(x) summary(x$pModels[[1]]))
#> $`red king crab fm_1_s_t_st`
#>
#> Family: Tweedie(p=1.99)
@@ -936,15 +935,15 @@
7. Fit the Model#>
#> R-sq.(adj) = 0.152 Deviance explained = 35.1%
#> -ML = 7295.9 Scale est. = 1.4146 n = 1497
- # sink()
+# sink()
- surveyIndex::get_surveyidx_aic(x = models)
+surveyIndex::get_surveyidx_aic(x = models)
#> numeric(0)
-
temp <- sapply(models, `[`, "pModels")
- mods <- sapply(temp, `[`, 1)
+
temp <- sapply(models, `[`, "pModels")
+mods <- sapply(temp, `[`, 1)
- lapply(X = mods, FUN = AIC)
+lapply(X = mods, FUN = AIC)
#> $`red king crab fm_1_s_t_st.pModels`
#> [1] 2296.156
#>
@@ -967,40 +966,124 @@
7. Fit the Model8. Indicies of Abundance
-
dat <- data.frame()
+
+dat <- data.frame()
for (i in 1:length(models)){
temp <- models[[i]]
- dat <- dplyr::bind_rows(dat,
- data.frame(idx = temp$idx[,1],
- Year = rownames(temp$idx),
- group = names(models)[i]))
+ dat0 <- data.frame(idx = temp$idx[,1],
+ lo = temp$lo[,1],
+ up = temp$up[,1],
+ Year = rownames(temp$idx),
+ group = names(models)[i],
+ formula = paste0("cpue_kgha ~ ",
+ as.character(temp$pModels[[1]]$formula)[[3]]))
+
+ dat <- dplyr::bind_rows(dat, dat0)
}
-dat$facet_group <- sapply(X = strsplit(x = dat$group, split = " "),
- `[`, 1)
+dat$facet_group <- paste0(sapply(X = strsplit(x = dat$group, split = " fm"), `[`, 1))
+# dat$model <- paste0(sapply(X = strsplit(x = dat$group, split = " fm"), `[`, 2))
-dat$idx[dat$Year == 2020] <- NA
+dat[dat$Year == 2020, c("idx", "up", "lo")] <- NA
ggplot2::ggplot(data = dat,
- mapping = aes(x = Year,
- y = idx,
- group = group,
- color = group)) +
+ mapping = aes(x = Year,
+ y = idx,
+ group = formula,
+ color = formula)) +
geom_line(size = 1.5) +
- geom_point(size = 2) +
+ geom_point(size = 2) +
+ geom_ribbon(aes(ymin = lo, ymax = up, fill = formula),
+ alpha=0.1,
+ linetype="dashed",
+ color="grey") +
+ ggtitle("Annual Index Model Results") +
facet_wrap(vars(facet_group), scales = "free", ncol = 1) +
- theme(legend.position = "bottom")
8. Predict and plot
+
9. Predict and plot
-# predict.gam(object = models$`red king crab fm_2_cov`,
-# newdata = dat_catch_haul %>%
-# dplyr::filter(Year == 2021) %>%
-# dplyr::select(Year, sx, sy, GEAR_TEMPERATURE, BOTTOM_DEPTH))
10. Simulations
+
+
+
+sims <- fittimes_sims <- list()
+for(i in 1:nrow(comb)){
+
+ cat("Simulating ",comb$SPECIES[i],"\n", comb$fm_name[i], ": ", comb$fm[i], "\n")
+
+ temp <- paste0(comb$SPECIES[i], " ", comb$fm_name[i])
+
+ fittimes[[ temp ]] <-
+ system.time ( sims[[ temp ]] <-
+ surveyIndex::get_surveyidx_sim(
+ model = models[[i]],
+ d = ds[[ comb$SPECIES[i] ]]) )
+}
+#> Simulating red king crab
+#> fm_1_s_t_st : Year + s(sx,sy,bs=c('ts'),k=376) + s(sx,sy,bs=c('ts'),k=10,by=Year)
+#> Simulating red king crab
+#> fm_2_cov : s(BOTTOM_DEPTH,bs='ts',k=10) +s(log(GEAR_TEMPERATURE+3),bs='ts',k=10)
+#> Simulating walleye pollock
+#> fm_1_s_t_st : Year + s(sx,sy,bs=c('ts'),k=376) + s(sx,sy,bs=c('ts'),k=10,by=Year)
+#> Simulating walleye pollock
+#> fm_2_cov : s(BOTTOM_DEPTH,bs='ts',k=10) +s(log(GEAR_TEMPERATURE+3),bs='ts',k=10)
+#> Simulating yellowfin sole
+#> fm_1_s_t_st : Year + s(sx,sy,bs=c('ts'),k=376) + s(sx,sy,bs=c('ts'),k=10,by=Year)
+#> Simulating yellowfin sole
+#> fm_2_cov : s(BOTTOM_DEPTH,bs='ts',k=10) +s(log(GEAR_TEMPERATURE+3),bs='ts',k=10)
+
+par(mfrow = c(2, 2)) # Create a 2 x 2 plotting matrix
+for(i in 1:nrow(comb)){
+ plot(sims[[i]]$sim, main = paste0(names(sims)[i], " sims"))
+ plot(sims[[i]]$mu[[1]], main = paste0(names(sims)[i], " mu"))
+}
8. Predict and plot
-
Nuances in model choices
diff --git a/docs/articles/C-model-comparisons.html b/docs/articles/C-model-comparisons.html
index 038fe81..37e3387 100644
--- a/docs/articles/C-model-comparisons.html
+++ b/docs/articles/C-model-comparisons.html
@@ -241,7 +241,7 @@ 4. Assess the model#> indicate that k is too low, especially if edf is close to k'.
#>
#> k' edf k-index p-value
-#> s(sx,sy) 375.00 95.70 0.94 0.57
+#> s(sx,sy) 375.00 95.70 0.94 0.54
#> s(sx,sy):Year 10.00 3.08 0.94 0.60
vis.gam(bb)
@@ -307,7 +307,7 @@
4. Assess the model
-
All vignettes
diff --git a/docs/authors.html b/docs/authors.html
index 1e6ceca..6b2c181 100644
--- a/docs/authors.html
+++ b/docs/authors.html
@@ -98,7 +98,7 @@ Citation
diff --git a/docs/index.html b/docs/index.html
index 426cf5d..22a0b63 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -81,13 +81,14 @@ surveyIndex
--Code is still in development
+Code is still in development at https://github.com/EmilyMarkowitz-NOAA/surveyIndex
Code was originally developed by: Casper W. Berg (@casperwberg)
---Berg et al. (2014): “Evaluation of alternative age-based methods for estimating relative abundance from survey data in relation to assessment models”, Fisheries Research 151(2014) 91-99.
-
And then modified and adapted for the AFSC by:
+Code was originally developed by:
+Casper W. Berg (@casperwberg)
+National Institute of Aquatic Resources,
+Technical University of Denmark
+ +And then modified and adapted for the AFSC by:
Emily Markowitz (@EmilyMarkowitz-noaa; Emily.Markowitz AT noaa.gov)
Margaret Siple (@MargaretSiple-noaa; Margaret.Siple AT noaa.gov)
Alaska Fisheries Science Center
@@ -128,20 +129,20 @@noaa_afsc_public_foss
Public data from FOSS
Plot survey index list (e.g. retrospective analysis)
plot_simulation_list.Rd
Plot survey index list (e.g. retrospective analysis)
+plot_simulation_list(
+ x,
+ base = 1,
+ rescale = FALSE,
+ lwd = 1.5,
+ main = NULL,
+ allCI = FALSE,
+ includeCI = TRUE,
+ ylim = NULL
+)
(named) list of "surveyIdx" objects for example from "retro.surveyIdx" or "leaveout.surveyIdx"
Either index of x that should considered the "base run" (integer), OR object of class "surveyIdx". Confidence bounds will be shown for this model only.
Should indices be rescaled to have mean 1 (over the set of intersecting years)? Default: FALSE
line width argument to plot
if not NULL override main plotting default title of "Age group a"
show 95% confidence lines for all indices? Default FALSE.
Show confidence intervals? Default TRUE.
Y axis range. If NULL (default) then determine automatically.
nothing
+