Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check the parameter name in MTI function #88

Open
HanDongyan opened this issue Jul 2, 2024 · 0 comments
Open

Check the parameter name in MTI function #88

HanDongyan opened this issue Jul 2, 2024 · 0 comments

Comments

@HanDongyan
Copy link

HanDongyan commented Jul 2, 2024

The result of MTI function is not same with Ecopath windows version.
There are some parameters names not update, like Bimomass (BB in MTI)
please update it.

Below is a update MTI function I used.

MTI_new<- function (Rpath, Rpath.params, increase = T) {
Group <- Type <- V1 <- NULL
x <- copy(Rpath.params)
y <- copy(Rpath)
nfleets <- length(which(x$model$Type == 3))
ndetritus <- length(which(x$model$Type == 2))
ngroups <- length(x$model$Group)
fleetnames <- x$model$Group[which(x$model$Type == 3)]
detritusnames <- x$model$Group[which(x$model$Type == 2)]
livingnames <- x$model$Group[which(x$model$Type < 2)]
allnames <- x$model$Group
DC <- as.data.table(x$diet)
DC <- DC[Group != "Import"]
DC.types <- x$model[Type < 2, Type]
DC.colsum <- DC[, colSums(.SD, na.rm = T), .SDcols = livingnames]
DC.check <- round(DC.colsum + DC.types, 3)
for (ipred in 1:length(livingnames)) {
if (DC.check[ipred] != 1) {
DC[, :=(ipred + 1, .SD/DC.colsum[ipred]),
.SDcols = livingnames[ipred]]
}
}
fleetrows <- as.data.table(matrix(rep(0, nfleets * ncol(DC)),
nfleets, ncol(DC)))
fleetrows[, :=(V1, fleetnames)]
DC <- rbindlist(list(DC, fleetrows), use.names = F)
detcols <- as.data.table(matrix(rep(0, ndetritus * ngroups),
ngroups, ndetritus))
setnames(detcols, paste0("V", seq_along(detritusnames)),
detritusnames)
DC <- cbind(DC, detcols)
totcatch <- y$Landings + y$Discards
totcatch.sum <- colSums(totcatch)
for (ifleet in 1:ncol(totcatch)) {
fleet.prop <- as.data.table(totcatch[, ifleet]/totcatch.sum[ifleet])
setnames(fleet.prop, "V1", fleetnames[ifleet])
if (ifleet == 1) {
fleetcols <- fleet.prop
}
else {
fleetcols <- cbind(fleetcols, fleet.prop)
}
}
DC <- cbind(DC, fleetcols)
DCi.order <- c("Group", DC$Group)
setcolorder(DC, DCi.order)
DC[is.na(DC)] <- 0
DC[, :=(Group, NULL)]
bio <- y$Biomass
BQB <- bio * y$QB
Tij <- DC * BQB[col(as.matrix(DC))]
Tij <- Tij[, which(!names(Tij) %in% fleetnames), with = F]
Tij <- cbind(Tij, totcatch)
Tim <- rowSums(Tij)
FCij <- c()
for (iprey in 1:nrow(Tij)) {
fij <- Tij[iprey, ]/Tim[iprey]
FCij <- rbind(FCij, fij)
}
FCji <- t(FCij)
FCji[is.na(FCji)] <- 0
net.impact <- as.matrix(DC - FCji)
identity.matrix <- diag(ncol(net.impact))
MTI <- MASS::ginv(identity.matrix - net.impact) - identity.matrix
return(MTI)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant