tokami / TropFishR

Tropical Fisheries Analysis with R
24 stars 19 forks source link

Error in seq.default(val_first, val_last) for the lfqRestructure() function #22

Closed jethroppaPH closed 6 years ago

jethroppaPH commented 6 years ago

I am following your tutorial here. The data I used can be found here.

Here's what I did:

library(TropFishR)

lfq1 <- read.csv("lfq-data.csv")

dates <- colnames(lfq1)[-1]
dates <- strsplit(dates, "X")
dates <- unlist(lapply(dates, function(x) x[2]))
dates <- as.Date(dates, "%Y.%m.%d") # I changed this part to follow the format of dates in my data

lfq1new <- list(dates = dates,
                midLengths = lfq1$midlength,
                catch = as.matrix(lfq1[,-1]))

class(lfq1new) <- "lfq"

plot(lfq1new, Fname = "catch")

set.seed(1)

lfq1a <- lfqModify(lfq1new, bin_size = 4)

lfqbin <- lfqRestructure(lfq1a, MA = 5, addl.sqrt = FALSE)

But the last code throws an error:

Error in seq.default(val_first, val_last) : 
  'from' must be a finite number
In addition: Warning messages:
1: In min(which(lfq$catch[, i] != 0)) :
  no non-missing arguments to min; returning Inf
2: In max(which(lfq$catch[, i] != 0)) :
  no non-missing arguments to max; returning -Inf

What should I do? At first I thought that maybe the data arrangement is wrong, but I am pretty sure that it is correct, since I followed the tutorial given in the link above (the data follows the "Data arrangement 3").

marchtaylor commented 6 years ago

Hello - here is a script that works for reading your data. There were a few possible problems: 1) lfq1$midlength doesn't exist, so no lengths were entered, 2) One sample contained no counts, so it should be removed, 3) lfqModify with bin_size=4 does not make sense for your data since it is already close to this resolution. I would suggest that you begin with smaller bins and then see if you would like to aggregate.

library(TropFishR)

lfq1 <- read.csv("lfq-data.csv")

dates <- colnames(lfq1)[-1]
dates <- strsplit(dates, "X")
dates <- unlist(lapply(dates, function(x) x[2]))
dates <- as.Date(dates, "%Y.%m.%d") # I changed this part to follow the format of dates in my data

lfq1new <- list(
  dates = dates,
  midLengths = lfq1[,1],
  catch = as.matrix(lfq1[,-1])
)
colnames(lfq1new$catch) <- as.character(dates)

class(lfq1new) <- "lfq"

samp.incl <- apply(lfq1new$catch, 2, function(x){sum(x) != 0})
lfq1new$catch <- lfq1new$catch[,samp.incl]
lfq1new$dates <- lfq1new$dates[samp.incl]
dim(lfq1new$catch)
length(lfq1new$dates)
length(lfq1new$midLengths)

plot(lfq1new, Fname = "catch")

set.seed(1)

# lfq1a <- lfqModify(lfq1new, bin_size = 4)

lfq1new <- lfqRestructure(lfq1new, MA = 5)

plot(lfq1new, Fname = "rcounts")
plot(lfq1new, Fname = "catch")
jethroppaPH commented 6 years ago

So it means that I mustn't include months or days that does not contain measured samples. Anyway, thank you very very much. I am currently re-learning the concept of fish stock assessment, but using R instead of FiSAT.

marchtaylor commented 6 years ago

Yes, that's right - lfq data need not be derived from regular, evenly-spaced sampling. Hope your transition from FiSAT isn't too painful. We think TropFishR has a lot of advantages, but it's lack of click-based interface definitely makes the learning curve steeper. If you see any ways to improve the tutorials please feel free to pass on your suggestions.

jethroppaPH commented 6 years ago

Yes. I think I can manage it since my previous supervisor taught me the concept of stock assessment tools in a hard way - manually computing the desired values and graphing the result using (at that time) a spreadsheet. :-D He told me that, although using the FiSAT makes it easier, learning the concept of what the tool does is better.

Zihda commented 2 years ago

I am following your tutorial here. The data I used can be found here.

Here's what I did: Error in as.Date.default(dates, "%Y-%d-%m") : do not know how to convert 'dates' to class “Date”

changomaf commented 1 year ago

Hello out there. im still a beginner in TropfishR. Basically im a user and not a developer. I tried this code and helped me alot with my lfq data. i got similar problem.

But now i have problem, I used a certain code for VPA, it dsoesnt estimate number of survivors, as well as it cant draw a histogram. howver i can reach up to YPR but for the x-axis of isopleths it shows exploitation rate. i guess my codes have problems can you please help if you know any