I have a growth dataset based off of recaptures. There are columns with the capture length, the recapture length, and the time (in yrs) based off the recapture minus the capture.
> str(data)
'data.frame': 60 obs. of 3 variables:
$ sizecapture : num 40.3 43 38.3 41.5 37.6 ...
$ sizerecapture: num 43 48.7 39.5 42 46.7 43.5 43.5 47.2 45.7 59.9 ...
$ timeinterval : num 0.945 1.036 0.997 0.997 2.471 ...
I am following Ogle 2013 vignette (http://derekogle.com/fishR/examples/oldFishRVignettes/VonBertalanffyExtra.pdf) in R, for the Fabens method of trying to derive size at age. For this method I don't need an initial age (as I don't know age at all). I am not interested in extrapolating, but for only estimating the age of individuals that I have sizes for.
I can easily follow the instructions for calculating the two parameters needed to inform the nls model: the k and the Linf. My aim is to create a age at length curve with the growth data, but when I get errors when I try to fitPlot. I get the error "Error in mdl$model[[gpos[2]]] : subscript out of bounds". I have also tried curve() and get the error "Error in FVB1(x) : could not find function "FVB1".
I also can't figure out how to extract the confidence intervals that fit with the predicted data.
I have searched and have found some similar cases but nothing that has worked. I'll continue to research, but am I missing something very basic? Below is a subsample of the data. I'd appreciate any help.
Thank you
install.packages("FSA")
install.packages("FSAdata")
install.packages("nlstools")
install.packages(car)
library(FSA)
library(FSAdata)
library(nlstools)
library(car)
sizecapture <- c(40.30,43.00,38.30,41.50,37.60,41.63,41.80,38.40,40.00,41.20,37.70,41.70,43.70,41.80,42.70,44.60,45.50,44.50,45.60,44.80,47.00,49.20,44.50,45.20,46.40,46.90,49.40,61.00,36.50,42.10,43.90,43.90,46.40,45.50,47.20,64.30,43.00,59.90,39.60,36.80)
sizerecapture < c(43.0,48.7,39.5,42.0,46.7,43.5,43.5,47.2,45.7,59.9,48.1,46.5,45.7,49.1,48.7,47.1,46.9,48.3,47.2,53.7,52.0,51.2,56.2,56.3,57.5,57.7,55.4,74.5,45.6,44.9,46.7,51.0,49.4,58.0,56.8,71.6,43.8,44.6,43.7,41.9)
timeinterval <-c(0.9452055,1.0356164,0.9972603,0.9972603,2.4712329,0.9534247,1.1945205,2.0027397,1.3178082,4.5342466,2.1863014,0.9178082,1.1315068,2.3698630,2.0575342,1.3835616,1.1726027,1.1972603,3.1698630,1.9589041,1.0712329,0.9150685,2.5671233,2.7780822,3.2000000,2.2246575,1.9150685,4.1753425,0.9287671,1.0328767,1.3945205,2.6739726,0.9205479,3.1479452,1.9506849,1.7178082,1.0520548,3.0767123,1.3726027,1.2520548)
data <- data.frame(sizecapture, sizerecapture, timeinterval)
### using Ogle 2013 to calculate Linf and k
# k and Linf
with(data,mean((log(sizerecapture)-log(sizecapture))/timeinterval))
#0.0676`
max(data$sizerecapture) # largest size is 74.5
Fabens.sv <- list(Linf=74.5, K=0.0676)
# declare the model
fvb <- vbFuns("Fabens")
# fit and summarize
FVB1<- nls(sizerecapture~
fvb(sizecapture,timeinterval,Linf,K),start=Fabens.sv,data=data)
summary(FVB1,correlation=TRUE)
# confidence intervals through bootstrapping
boot <- nlsBoot(FVB1, niter=500)
confint(boot,plot=TRUE)
# plotting a fitted line plot
ages2plot <- 0:40
LCI <- UCI <- numeric(length(ages2plot))
fitPlot(FVB1, xlim=range(ages2plot))
estes <- boot$coefboot
for (i in 1:length(ages2plot)) {
pv <-estes[,"Linf"]*(1-exp(-ests[,"K]*(ages2plot)))
LCI[i] <- quantile(pv,0.025)
UCI[i] <- quantile(pv,0.975)
}
lines(UCI~ages2plot,type="1")
lines(LCI~ages2plot,type="1")
# tried to just get a visual and errors arise
curve(FVB1)