Skip to content

Commit

Permalink
Check AddInd SD, AC only when fitIerr = TRUE; #79
Browse files Browse the repository at this point in the history
  • Loading branch information
quang-huynh committed Jan 11, 2025
1 parent 7446f6f commit 62d6f15
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The current version of the `MSEtool` package is available for download from [CRA
- `updateData` and `updateData_MS` use the Baranov catch equation to simulate `Data@CAA` in the projection. Previously, the catch at age was simulated with only the retention curve.
- `multiMSE` solves for F from multi-fleet TAC simultaneously with function `CalcMPDynamics_MF`
- fix check for simulated `Data@VInd` in `multiMSE`
- turn off check for valid `Data@AddInd` statistics (AC, SD) when `cpars$AddIerr` is provided

## Updates
- When indices are provided to the operating model, the default value of beta = 1 (hyperstability parameter) if not specified in `cpars`.
Expand Down
48 changes: 26 additions & 22 deletions R/Data_make_update.R
Original file line number Diff line number Diff line change
Expand Up @@ -1172,18 +1172,20 @@ AddRealData <- function(SimData, RealData, ObsPars, StockPars, FleetPars, nsim,
# Calculate statistics
Stats_List <- lapply(1:nsim, function(x) Calc_Stats(lResids_Hist[x,]))
Stats <- do.call('rbind', Stats_List)
check_Index <- check_Index_Fit(Stats, i)
if (check_Index) {
# Generate residuals for projections
Resid_Hist <- exp(lResids_Hist) # historical residuals in normal space
Resid_Proj <- Gen_Residuals(Stats, nsim, proyears)

if (fitIerr) ObsPars$AddIerr[,i, ] <- cbind(Resid_Hist, Resid_Proj)
ObsPars$AddInd_Stat[[i]] <- Stats[,1:2] # index fit statistics
} else {
ObsPars$AddIerr[,i, ] <- ObsPars$Ierr_y
ObsPars$AddInd_Stat[[i]] <- Stats[,1:2] # index fit statistics

if (fitIerr) {
check_Index <- check_Index_Fit(Stats, i)
if (check_Index) {
# Generate residuals for projections
Resid_Hist <- exp(lResids_Hist) # historical residuals in normal space
Resid_Proj <- Gen_Residuals(Stats, nsim, proyears)

ObsPars$AddIerr[,i, ] <- cbind(Resid_Hist, Resid_Proj)
} else {
ObsPars$AddIerr[,i, ] <- ObsPars$Ierr_y
}
}
ObsPars$AddInd_Stat[[i]] <- Stats[,1:2] # index fit statistics
}
}
}
Expand Down Expand Up @@ -1687,18 +1689,20 @@ AddRealData_MS <- function(SimData,
# Calculate statistics
Stats_List <- lapply(1:nsim, function(x) Calc_Stats(lResids_Hist[x,]))
Stats <- do.call('rbind', Stats_List)
check_Index <- check_Index_Fit(Stats, i)
if (check_Index) {
# Generate residuals for projections
Resid_Hist <- exp(lResids_Hist) # historical residuals in normal space
Resid_Proj <- Gen_Residuals(Stats, nsim, proyears)

if (fitIerr) ObsPars[[p]][[f]]$AddIerr[,i, ] <- cbind(Resid_Hist, Resid_Proj)
ObsPars[[p]][[f]]$AddInd_Stat[[i]] <- Stats[,1:2] # index fit statistics
} else {
ObsPars[[p]][[f]]$AddIerr[,i, ] <- ObsPars[[p]][[f]]$Ierr_y
ObsPars[[p]][[f]]$AddInd_Stat[[i]] <- Stats[,1:2] # index fit statistics

if (fitIerr) {
check_Index <- check_Index_Fit(Stats, i)
if (check_Index) {
# Generate residuals for projections
Resid_Hist <- exp(lResids_Hist) # historical residuals in normal space
Resid_Proj <- Gen_Residuals(Stats, nsim, proyears)

ObsPars[[p]][[f]]$AddIerr[,i, ] <- cbind(Resid_Hist, Resid_Proj)
} else {
ObsPars[[p]][[f]]$AddIerr[,i, ] <- ObsPars[[p]][[f]]$Ierr_y
}
}
ObsPars[[p]][[f]]$AddInd_Stat[[i]] <- Stats[,1:2] # index fit statistics
}
}
}
Expand Down

0 comments on commit 62d6f15

Please sign in to comment.