Forums

Back

Variance estimates for numbers at age other than age of recruitment

SB
Steve Barbeaux, modified 4 Years ago.

Variance estimates for numbers at age other than age of recruitment

Youngling Posts: 12 Join Date: 2/26/16 Recent Posts

Is there a way to generate the variance of the number at age by year at age 3 from my SS model? If so, how? Recruitment is set at age 0.

Thanks

Richard Methot, modified 4 Years ago.

RE: Variance estimates for numbers at age other than age of recruitment

Youngling Posts: 219 Join Date: 11/24/14 Recent Posts
Look for this in the extra sd features.  The specification is entered at the bottom of the control file.
The specification looks like this (where year is negative because is relative to endyr or you can enter a year year):
1 # (0/1) read specs for more stddev reporting
 1 1 -1 5 1 5 1 -1 5 # selex_fleet, 1=len/2=age/3=both, year, N selex bins, 0 or Growth pattern, N growth ages, 0 or NatAge_area(-1 for sum), NatAge_yr, N Natages
 5 15 25 35 43 # vector with selex std bins (-1 in first bin to self-generate)
 1 2 14 26 40 # vector with growth std ages picks (-1 in first bin to self-generate)
 1 2 14 26 40 # vector with NatAge std ages (-1 in first bin to self-generate)

and produces output that looks (in ss_summary.sso) like this:
#_Extra_stdev
LenSelex_std_1_Fem_L_18 0.00454064 0.000652011
LenSelex_std_1_Fem_L_38 0.0929494 0.00606498
LenSelex_std_1_Fem_L_58 0.697168 0.0298097
LenSelex_std_1_Fem_L_78 0.981032 0.00474755
LenSelex_std_1_Fem_L_94 0.998399 0.000560869
LenSelex_std_1_Mal_L_18 0.00454064 0.000652011
LenSelex_std_1_Mal_L_38 0.0929494 0.00606498
LenSelex_std_1_Mal_L_58 0.697168 0.0298097
LenSelex_std_1_Mal_L_78 0.981032 0.00474755
LenSelex_std_1_Mal_L_94 0.998399 0.000560869
Grow_std_1_Fem_A_1 31.8205 0.267992
Grow_std_1_Fem_A_2 37.4523 0.199297
Grow_std_1_Fem_A_14 66.8804 0.188456
Grow_std_1_Fem_A_26 71.9052 0.323649
Grow_std_1_Fem_A_40 72.823 0.391937
Grow_std_1_Mal_A_1 32.247 0.256514
Grow_std_1_Mal_A_2 37.9957 0.192681
Grow_std_1_Mal_A_14 65.8059 0.183196
Grow_std_1_Mal_A_26 69.7139 0.303058
Grow_std_1_Mal_A_40 70.2954 0.350648
NatAge_std_1_Fem_A_1 838.04 439.058
NatAge_std_1_Fem_A_2 1223.6 505.252
NatAge_std_1_Fem_A_14 111.176 44.5521
NatAge_std_1_Fem_A_26 5.04312 2.14049
NatAge_std_1_Fem_A_40 3.2631 1.29083
NatAge_std_1_Mal_A_1 837.959 439.025
NatAge_std_1_Mal_A_2 1222.72 505.021
NatAge_std_1_Mal_A_14 110.937 44.2979
NatAge_std_1_Mal_A_26 5.4797 2.27642
NatAge_std_1_Mal_A_40 3.78478 1.42911

Rick

On Wed, Dec 18, 2019 at 3:24 PM Steve Barbeaux <VLab.Notifications@noaa.gov> wrote:

Is there a way to generate the variance of the number at age by year at age 3 from my SS model? If so, how? Recruitment is set at age 0.

Thanks


--
Steve Barbeaux Stock Synthesis Virtual Lab Forum https://vlab.noaa.gov/group/stock-synthesis/discussions-forums-/-/message_boards/view_message/8521357 VLab.Notifications@noaa.gov


--
Richard D. Methot Jr. Ph.D.
NOAA Fisheries Senior Scientist for Stock Assessments
Mobile: 301-787-0241
SB
Steve Barbeaux, modified 4 Years ago.

RE: Variance estimates for numbers at age other than age of recruitment

Youngling Posts: 12 Join Date: 2/26/16 Recent Posts

Thanks Rick, 

 Is there a way to output a vector of years, not just one at a time for each run?

SB
Steve Barbeaux, modified 4 Years ago.

RE: Variance estimates for numbers at age other than age of recruitment

Youngling Posts: 12 Join Date: 2/26/16 Recent Posts

Hey Rick, 

 In case anyone is interested here is a quick R script to get numbers at age variance by age for a series of years. As it requires the model to be rerun for each year I built it using snowfall to speed up processing. One should change the starter file to ensure the model is being rerun using the par file and change the .ctl file being used is named "new.ctl", and in the "control.ss_new" file  to include a stddev reporting line and age line.  Also assumes one is using ss.exe.  This is not generalized and anyone using it may need to edit it for their own use. I'm guessing this could be easily generalized for r4ss with little effort if others find this useful.  

## Function to report the variance of the numbers at age by year from ss 3.30 for a single year

VAR1<-function(year=1978,file1=file,dir2=dir1,age1=age){
            require(stringr)
            setwd(dir2)
            list.of.files=list.files(dir2)
            setwd('..')
            dir.create(paste0("Year_",year))
            new.dir<-paste0(getwd(),"/Year_",year)
            setwd(dir2)
            file.copy(from=list.of.files,to=new.dir)
            setwd(new.dir)
            res<-readLines(file1)
            nline=length(res)
            res[nline-3]<-paste0("0 0 0 0 0 0 -1 ",year," 1")
            res[nline-2]<-paste0(age1)
            writeLines(res,"new.ctl")
            system("ss.exe",show.output.on.console = F)
            std=readLines("ss.std")
            nline=length(std)
            varage<-c(year,as.numeric(str_split(std[nline-3]," ")[[1]][18]),as.numeric(str_split(std[nline-3]," ")[[1]][19]))
            return(varage)
            }

## Function to report the variance of the numbers at age for a series of years using parallel computing for ss 3.30 models

NAGE_VAR<-function(dir1=getwd(),file="control.ss_new",age=3,years=1978:2019,cpu=4) {
    require(snowfall)
    sfInit( parallel=TRUE, cpus=cpu )
    sfExportAll()
    age3<-sfSapply(years,VAR1)
    sfStop()
    return(t(age3))       
}

 

 

 

IT
Ian Taylor, modified 4 Years ago.

RE: Variance estimates for numbers at age other than age of recruitment

Youngling Posts: 117 Join Date: 12/8/14 Recent Posts

Hi Steve, 

Thanks for contributing the R code. As far as I know you're the first person who wanted variance in numbers at age from multiple years, but perhaps we've all been missing out. Regardless, it's great to have a method available to get these values if we want them.

Thanks again,

-Ian