Skip to content

Commit

Permalink
a bunch of changes from last week before I gave the presentation ak W…
Browse files Browse the repository at this point in the history
…KUSER2
  • Loading branch information
EmilyMarkowitz-NOAA committed Sep 27, 2022
1 parent 2c93143 commit b730b34
Show file tree
Hide file tree
Showing 15 changed files with 181 additions and 26 deletions.
Binary file modified docs/articles/A-data-prep_files/figure-html/indicie_abund-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/articles/A-data-prep_files/figure-html/model_check1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/articles/A-data-prep_files/figure-html/model_check1-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/articles/A-data-prep_files/figure-html/model_check1-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/articles/A-data-prep_files/figure-html/model_check1-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/articles/A-data-prep_files/figure-html/model_check1-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/articles/A-data-prep_files/figure-html/model_check1-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ articles:
A-data-prep: A-data-prep.html
B-model-tuning: B-model-tuning.html
C-model-comparisons: C-model-comparisons.html
last_built: 2022-09-14T04:19Z
last_built: 2022-09-15T09:05Z

Binary file modified docs/reference/Rplot002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/concentration_transform-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions inst/RKC_Table_for_SS3.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"Year","Unit","Fleet","Estimate_metric_tons","SD_log","SD_mt"
1975,1,1,55086.3664680953,0.171768225980164,6972.54733501455
1976,1,1,65470.3351296188,0.141971478844956,6845.61352290981
1977,1,1,133213.322193431,0.131052464250909,12833.6750343921
1978,1,1,122010.882820562,0.133830029891504,12174.586232954
1979,1,1,52499.7393473005,0.117441711009707,4772.98827551041
1980,1,1,66102.6413401603,0.161379121843015,8010.32086858916
1981,1,1,54748.458022305,0.139954805570668,5805.61604518637
1982,1,1,59697.7224909949,0.135418163979481,6146.47121899825
1983,1,1,11724.4150494259,0.136306740272387,1232.7572663098
1984,1,1,20266.6083268922,0.194466939237012,3059.97179171081
1985,1,1,6368.07379833552,0.152038288987626,746.175313609095
1986,1,1,5701.92642931749,0.157422025368026,692.781170936785
1987,1,1,16230.0644198496,0.160561980949003,2014.92417942088
1988,1,1,13305.714321122,0.198163234060186,2041.4023858978
1989,1,1,9390.60664222219,0.158393021632646,1141.86658915542
1990,1,1,13575.1839898581,0.182480072583956,1913.28934423042
1991,1,1,11706.9721945507,0.16175775487874,1463.03271594677
1992,1,1,10441.12516558,0.150491818519894,1205.25203061196
1993,1,1,15263.6137732514,0.164176317371063,1917.21582195798
1994,1,1,8029.10155147612,0.160703778078611,1002.57799962765
1995,1,1,9336.24775015882,0.151673405350281,1085.74424706002
1996,1,1,14420.9503368817,0.160138096445218,1796.37682253123
1997,1,1,18651.3604652483,0.170725057812704,2444.73211615809
1998,1,1,30921.9152913355,0.145793207471633,3426.44521893735
1999,1,1,15125.4148562987,0.180370056259922,2074.7941430946
2000,1,1,24137.8581041955,0.188746903334191,3438.51325824607
2001,1,1,20193.7299568301,0.163471285344484,2491.41944949634
2002,1,1,19796.8900180387,0.16006678797876,2402.93625855544
2003,1,1,36323.1338379832,0.146954443999817,4055.72449425159
2004,1,1,32061.2114878945,0.145265178260193,3526.41041937724
2005,1,1,43414.5661809076,0.140961751064862,4673.71461309702
2006,1,1,40916.8005779837,0.15054541568757,4682.6107819699
2007,1,1,39118.9069629281,0.137848849606206,4089.42344961727
2008,1,1,35149.9760022064,0.167412136036367,4413.73039418472
2009,1,1,32823.6340244099,0.150936397043287,3719.3270088975
2010,1,1,41408.016598501,0.158042002822653,4961.70301168793
2011,1,1,40670.4294963024,0.155344382999688,4859.6269649061
2012,1,1,30134.9290950014,0.192388373888423,4449.18675856786
2013,1,1,21878.2371139554,0.192962729622322,3172.41278841796
2014,1,1,62170.1913447548,0.172763588533307,8065.26836705498
2015,1,1,29304.0976283825,0.178442029236038,3951.87994999746
2016,1,1,35323.7807753248,0.151943694007378,4100.59082099494
2017,1,1,28353.5746576032,0.138396557777348,2989.84697628087
2018,1,1,13977.8131445133,0.147862988603511,1633.91296697567
2019,1,1,15791.4932852872,0.125064347923998,1582.15538496432
File renamed without changes.
39 changes: 39 additions & 0 deletions inst/WEP_21740_estimate_summary.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Year,design_mt,design_se,design_CV,VAST_mt,VAST_se,VAST_CV
1982,2912869.454486416,366650.88711717725,0.1258727494816013,2667484.33091046,179208.163180597,0.06718246143152791
1983,5921380.161968083,499143.7611125582,0.08429517231784325,6151399.71380587,405047.05544457,0.06584632348561324
1984,4542404.991758591,464160.1305973523,0.10218378401738522,4439444.35404203,295634.382049826,0.0665926540515496
1985,5949852.336062129,418009.0853859097,0.070255371356420307,5291771.82039227,408981.58338582,0.07728632247705323
1986,4835722.135391059,478095.57561297267,0.09886746223773869,4650631.15777925,314247.088439233,0.0675708474351019
1987,5498433.448041663,610657.7572403908,0.11106031618112688,5068210.3276205,348629.155122208,0.0687874284187191
1988,7183962.710836036,747658.6039176624,0.10407328573545079,7357650.07127894,549356.00041287,0.07466460012243806
1989,6550414.874269996,604703.9227264143,0.09231536235997645,6260342.02803977,401679.801168119,0.06416259676692017
1990,7296652.939987248,959543.3433242347,0.13150458864032413,7144458.35245256,581448.876369378,0.08138459875964947
1991,5129537.608363281,640562.6389468294,0.12487726728086479,4833501.6988483,317022.568055515,0.06558859142038853
1992,4526153.250785523,513351.364333414,0.1134189091463752,4615508.10473282,305750.091899756,0.06624408081663527
1993,5294816.269467322,470340.1557745388,0.08883030719814887,5614500.47074671,341132.04194531,0.060759108263097286
1994,5027325.306792388,527058.0127987807,0.10483865288897774,4818868.34827918,302989.005096428,0.06287555151919132
1995,5477837.810663369,1038777.9948099507,0.18963284980578024,3968615.51138742,295401.217664184,0.07443432522414153
1996,3125253.082904012,277008.76898231084,0.08863562778247447,2897750.96954574,172269.776597515,0.059449475958425965
1997,3562163.1154822307,422762.04561318987,0.11868127087604131,3098109.90198394,195743.417941499,0.06318156041402875
1998,2687755.2709504506,294522.5967407706,0.10957939509002276,2478943.70416205,147939.85897581,0.05967858758850583
1999,3798474.081189157,448444.99931213114,0.11805924951098788,3660847.04234752,252539.649737349,0.06898393918567212
2000,5103629.008714339,575116.0074569454,0.11268765940371978,4884665.7704983,323258.433632122,0.06617820928189021
2001,4196853.90064979,339921.119611104,0.0809942703887011,4323860.76299874,269451.41877,0.062317320917412364
2002,4953438.269580395,449589.5181575799,0.09076312122804844,4709504.83038019,272086.955045769,0.05777400487851371
2003,8392260.852660038,2033046.0519881903,0.24225248567479757,6989874.36750033,445872.563783451,0.06378835159849959
2004,3862974.1622436037,357189.39621049335,0.09246486805468013,3741517.13693269,219121.980497311,0.058565007850518096
2005,4868615.630033517,451533.1119716299,0.09274363521043073,4633887.28934447,294414.985784663,0.0635352064910306
2006,3045380.115051798,283799.0740667199,0.09319003321261683,2943625.07559454,186129.269870685,0.06323131006522338
2007,4338219.901694481,447324.59353051963,0.10311247554689366,4105506.9156838,322786.030630234,0.07862269806369862
2008,3023267.2646527803,345552.195382876,0.11429760095079201,2820768.43406998,216694.981004644,0.07682125848663976
2009,2282409.5969438655,277023.1011568922,0.12137308812924055,2002098.07534345,171352.532541996,0.08558648282632275
2010,3737878.325986712,429270.7446821153,0.11484342379411132,3473478.09698875,261741.535370682,0.07535430714176451
2011,3112312.195173578,282800.35223984084,0.0908650336166127,3231823.29215819,219243.744616829,0.06783902608438083
2012,3487228.582257503,343685.87107897433,0.0985555901977853,3406466.30043168,205009.731404556,0.06018252151168394
2013,4575402.878174288,366207.1835463446,0.08003823778955861,4605138.818145,300483.813000451,0.06524967538795913
2014,7429952.482956876,484924.6569891398,0.06526618549734732,7725092.94997703,430043.622355983,0.05566840750534422
2015,6394358.598855162,402369.24904520804,0.06292566217935411,7184441.71879338,386039.020486674,0.05373264000135961
2016,4910079.820786608,449028.1070343755,0.09145026627335763,5319830.4815208,318561.771623974,0.05988194036079615
2017,4814372.364344428,359596.56890628225,0.07469230497613336,5313873.58215,313161.410529437,0.058932792752425904
2018,3112796.662357958,395624.24941258086,0.12709607864745448,2896217.91100342,172619.326586044,0.059601636303063435
2019,5458365.637724932,459752.21389716904,0.08422891473587606,5483762.62166049,316397.348933495,0.05769712709367597
39 changes: 39 additions & 0 deletions inst/YFS_10210_estimate_summary.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Year,design_mt,design_se,design_CV,VAST_mt,VAST_se,VAST_CV
1982,3381305.2084300886,291225.3955984968,0.08612810073235308,3521368.6070884,179462.964535082,0.05096398149680465
1983,3452463.1710949587,206261.58790946356,0.059743313016731504,3738517.9195966,166908.274819814,0.0446455730344136
1984,3141188.420565819,186901.24905681718,0.0595001712833103,3361669.91012075,143441.367719073,0.04266967654594042
1985,2398080.618037712,157388.45197254317,0.06563100956185958,2587383.12007674,120629.626763072,0.046622251581935885
1986,1909917.610484912,153940.74588987493,0.08060072593958159,1989414.76174262,95207.0441469815,0.04785680994122375
1987,2511839.2149314675,194991.8439643891,0.07762911049611478,2588701.46153807,126214.000086391,0.04875571863408355
1988,2180754.464279983,208670.20982311442,0.0956871638880312,2208510.00940631,102121.979199496,0.04624021569499173
1989,2313624.8514987743,173032.22952192446,0.0747883691730894,2394868.63830687,117028.073542756,0.04886617648702969
1990,2179613.453823549,150791.85379770116,0.0691828422756233,2289380.48247795,108674.441592203,0.047468929880356704
1991,2391856.886017234,139975.66551394432,0.0585217561854308,2577423.40127667,114553.278381036,0.04444488178554387
1992,2201520.75518717,196409.21854935467,0.08921524727240478,2123163.03540304,122146.793826589,0.05753057668668477
1993,2468434.2561738333,158602.96474783652,0.06425245653237577,2568746.36831677,114064.819016758,0.044404858503606016
1994,2597187.9110918455,172478.3366807862,0.06640964866045335,2684046.85127489,126471.318185835,0.04711963881173037
1995,2012395.3316758415,144187.15204297585,0.07164951626224586,2046308.0975044,100262.890410718,0.04899696704176406
1996,2216501.4799586674,194417.46760035018,0.08771366469106784,2281573.82388446,105819.469910656,0.046380033292323895
1997,2161395.2259868467,129026.01047506965,0.05969570438750235,2290807.86001158,105172.191312001,0.045910524906034395
1998,2210176.8898115084,140568.85424236325,0.06360072575654858,2360005.73926455,98049.5701631341,0.04154632699905609
1999,1257181.0526365715,91350.96928666251,0.07266333603666746,1292915.09268583,63399.0626956391,0.04903575111335223
2000,1589782.4310447439,101318.48831559838,0.06373104038457374,1696589.88551807,79877.2709134515,0.04708107221154405
2001,1679523.0645515868,121940.67365807116,0.07260434597879602,1748655.67027633,82925.2213733087,0.04742227002312267
2002,1910068.9092502536,131157.3259632972,0.06866627969709192,1972152.71272364,94498.97852242,0.04791666381246524
2003,2158129.6931818686,207578.34607389322,0.09618437053606689,2212830.68209715,100430.31828698,0.0453854509066188
2004,2542073.4344851817,193968.96842218054,0.07630344811870589,2616294.99407953,121640.56330968,0.046493443432389335
2005,2820839.126185498,364316.6689408054,0.12915187738247785,2714585.71981628,129498.250226675,0.04770460895058391
2006,2132477.870406415,159018.48959011654,0.07456981936220997,2206350.31447977,102046.117545768,0.046251094794903046
2007,2153087.296296771,192643.01993740344,0.08947292581621849,2191060.27174454,101692.268623742,0.046412355668689016
2008,2099671.3700461816,255366.00474119006,0.12162189206569662,2060386.10136854,98352.2797469891,0.04773487827434965
2009,1739209.1240583032,152022.13981998697,0.08740877546988464,1710288.35961112,84312.8350826143,0.04929743841663349
2010,2368262.7894852473,280170.7547088456,0.11830222387176127,2287106.05956602,133397.838139597,0.058326039398850324
2011,2403220.7251662943,243211.6453725838,0.10120237514003397,2299205.82544436,123193.354992211,0.05358082935806838
2012,1951405.2238545658,139100.16354732384,0.07128204939031704,2031563.14303464,104324.875990921,0.051352022381684924
2013,2279024.3588450984,174176.91375719424,0.07642608692671404,2286126.16355424,111119.081992915,0.04860583976702239
2014,2512256.1769946464,231751.22546860835,0.09224824585598071,2485514.42966922,122422.899602487,0.04925455195155693
2015,1932347.1025047048,145607.9307914331,0.07535288592960154,1947155.29432183,93978.6450137237,0.048264586439396094
2016,2859811.317715998,165459.41194713995,0.05785675821413453,3071339.4930203,134412.233514095,0.04376339177728491
2017,2787687.131145511,241156.27633119054,0.08650765490749139,2855445.61878216,130453.48763668,0.04568585960054742
2018,1892925.1856064303,115322.645561378,0.06092298123469283,2054869.05356065,86291.1263079255,0.04199349158448874
2019,2006505.3403326026,210760.6728626922,0.10503868024978995,1977922.94445448,87307.2142584181,0.04414085720740644
81 changes: 56 additions & 25 deletions vignettes/A-data-prep.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,11 @@ ds
fm <- list(
# Null model spatial and temporal with an additional year effect
"fm_1_s_t_st" = "Year +
s(sx,sy,bs=c('ts'),k=376) +
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" =
"fm_2_cov" =
"s(BOTTOM_DEPTH,bs='ts',k=10) +
s(log(GEAR_TEMPERATURE+3),bs='ts',k=10)"
)
Expand Down Expand Up @@ -424,6 +424,7 @@ comb

```{r model_fit_load, echo = FALSE}
load(system.file("VigA_model_fits.rdata", package = "surveyIndex") )
# load("../output/VigA_surveyindex_models_model_fits.Rdata")
```

```{r model_fit, eval = FALSE}
Expand Down Expand Up @@ -455,6 +456,23 @@ save(models, fittimes, file = paste0("../inst/VigA_model_fits.Rdata"))
```



``` {r model_aic}
# temp <- sapply(models, `[`, "pModels")
# mods <- sapply(temp, `[`, 1)
# lapply(X = mods, FUN = AIC)
# surveyIndex::get_surveyidx_aic(x = models)
AIC(models$`red king crab fm_1_s_t_st`$pModels[[1]],
models$`red king crab fm_2_cov`$pModels[[1]],
models$`walleye pollock fm_1_s_t_st`$pModels[[1]],
models$`walleye pollock fm_2_cov`$pModels[[1]],
models$`yellowfin sole fm_1_s_t_st`$pModels[[1]],
models$`yellowfin sole fm_2_cov`$pModels[[1]])
```


```{r model_check1}
## Check basis dimensions splines (spatial resolution)
# sink(paste0(".", dir_out, "gamcheck.txt"))
Expand All @@ -469,29 +487,30 @@ lapply(models,function(x) gam.check(x$pModels[[1]]))
lapply(models,function(x) summary(x$pModels[[1]]))
# sink()
surveyIndex::get_surveyidx_aic(x = models)
```


``` {r mode_aic}
temp <- sapply(models, `[`, "pModels")
mods <- sapply(temp, `[`, 1)
lapply(X = mods, FUN = AIC)
```

## 8. Indicies of Abundance

```{r design_based_load, eval = FALSE, echo = FALSE}
design_based <- read.csv(file = "../output/cpue_ebs_plusnw.csv") %>%
dplyr::filter(#srvy == SRVY &
YEAR %in% YEARS &
COMMON_NAME %in% SPECIES)
```

```{r indicie_abund}
dat_design <- dplyr::bind_rows(read.csv(file = system.file("YFS_10210_estimate_summary.csv",
package = "surveyIndex" )) %>%
dplyr::mutate(common_name = "yellowfin sole"),
read.csv(file = system.file("WEP_21740_estimate_summary.csv",
package = "surveyIndex" )) %>%
dplyr::mutate(common_name = "walleye pollock"),
read.csv(file = system.file("RKC_Table_for_SS3.csv",
package = "surveyIndex" )) %>%
dplyr::rename(design_mt = Estimate_metric_tons,
design_se = SD_mt) %>%
dplyr::mutate(design_se = (design_se)^2,
design_CV = NA,
VAST_mt = NA,
VAST_se = NA,
VAST_CV = NA,
common_name = "red king crab") %>%
dplyr::select(-Unit, -Fleet, -SD_log))
dat <- data.frame()
for (i in 1:length(models)){
Expand All @@ -500,15 +519,26 @@ for (i in 1:length(models)){
lo = temp$lo[,1],
up = temp$up[,1],
Year = rownames(temp$idx),
group = names(models)[i],
group = names(models)[i],
formula = paste0("cpue_kgha ~ ",
as.character(temp$pModels[[1]]$formula)[[3]]))
dat <- dplyr::bind_rows(dat, dat0)
}
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$common_name <- paste0(sapply(X = strsplit(x = dat$group, split = " fm"), `[`, 1))
dat <- dplyr::bind_rows(dat %>%
dplyr::mutate(Year = as.numeric(Year)) %>%
dplyr::select(-group),
dat_design %>%
dplyr::select(design_mt, common_name, Year) %>%
dplyr::rename(idx = design_mt) %>%
dplyr::mutate(lo = NA,
up = NA,
formula = "design")) %>%
dplyr::filter(Year %in% YEARS)
dat[dat$Year == 2020, c("idx", "up", "lo")] <- NA
Expand All @@ -524,7 +554,7 @@ ggplot2::ggplot(data = dat,
linetype="dashed",
color="grey") +
ggtitle("Annual Index Model Results") +
facet_wrap(vars(facet_group), scales = "free", ncol = 1) +
facet_wrap(vars(common_name), scales = "free", ncol = 1) +
theme(legend.position = "bottom",
legend.direction = "vertical")
Expand Down Expand Up @@ -565,6 +595,7 @@ for (i in 1:length(unique(dat$facet_group))){
y = Lat,
group = group,
color = idx)) +
scale_color_viridis_c(option = "D") +
geom_point() +
ggtitle(paste0("Annual Index Model Results for ", unique(dat$facet_group)[i])) +
facet_grid(cols = vars(group),
Expand Down

0 comments on commit b730b34

Please sign in to comment.