Skip to content

Commit

Permalink
Merge pull request #84 from DylanCarbone/master
Browse files Browse the repository at this point in the history
Fixed error caused by attempting to log transforming vector with name…
  • Loading branch information
AugustT authored Dec 14, 2023
2 parents bc866f4 + 927254e commit fccb3df
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions R/msi_tool.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ msi_tool <- function(wd = getwd(),
year = rdata[,"year"],
index = rdata[,"index"],
se = rdata[,"se"])[order(rdata[,"species"],
rdata[,"year"]), ]
rdata[,"year"]), ]

# Calculate and plot mean CV for indices per species
CVtemp <- INP2[INP2$index >= 10, ] # select records with index >= 10 for CV calculation
Expand Down Expand Up @@ -130,22 +130,23 @@ msi_tool <- function(wd = getwd(),
INP5$se[INP5$index == TRUNC & !is.na(INP5$index)] <- 0

# reset parameters
index <- as.vector(INP5["index"])
se <- as.vector(INP5["se"])
index <- unlist(INP5["index"], use.names = F)
se <- unlist(INP5["se"], use.names = F)
nobs <- NROW(INP5)
uspecies <- sort(unique(INP5$species))
nspecies <- length(uspecies)
year <- rep(uyear, nspecies)

# Transform indices and standard deviations to log scale (Delta method)
LNindex <- as.vector(log(index))
LNse <- as.vector(se/index)
LNindex <- log(index)
LNse <- se/index

# Monte Carlo simulations of species indices
MC <- matrix(NA, nobs, nsim)
for (s in 1:nsim) {
for (o in 1:nobs) {
MC[o,s] <- rnorm(1, LNindex[o,1], LNse[o,1])

MC[o,s] <- rnorm(1, LNindex[o], LNse[o])
}
}
MC[MC < log(TRUNC)] <- log(TRUNC)
Expand Down Expand Up @@ -534,4 +535,4 @@ msi_tool <- function(wd = getwd(),
arrows(uyear, simMSImean, uyear, (simMSImean-simMSIsd), angle = 90, code = 3, length=0)
arrows(uyear, simMSImean, uyear, (simMSImean+simMSIsd), angle = 90, code = 3, length=0)
}
}
}

0 comments on commit fccb3df

Please sign in to comment.