如何解决从 Fabens von Bertalanffy 生长曲线的 nls() 模型中获取预测值
我有一个基于重新捕获的增长数据集。有一些列包含捕获长度、重新捕获长度和基于重新捕获减去捕获的时间(以年为单位)。
> 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 ...
我正在关注 R 中的 Ogle 2013 小插图 (http://derekogle.com/fishR/examples/oldFishRVignettes/VonBertalanffyExtra.pdf),用于尝试推导年龄大小的 Fabens 方法。对于这种方法,我不需要初始年龄(因为我根本不知道年龄)。我对推断不感兴趣,而只是估计我所测量的个体的年龄。
我可以轻松地按照说明计算通知 nls 模型所需的两个参数:k 和 Linf。我的目标是用增长数据创建一个年龄曲线,但是当我尝试 fitPlot 时出现错误。我收到错误“mdl$model[[gpos[2]]] 中的错误:下标越界”。我也试过曲线()并得到错误“FVB1(x)中的错误:找不到函数“FVB1”。
我也不知道如何提取符合预测数据的置信区间。
我已经搜索并发现了一些类似的案例,但没有任何效果。我会继续研究,但我是否遗漏了一些非常基本的东西?下面是数据的子样本。我很感激任何帮助。
谢谢
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,42.70,44.60,45.50,44.50,45.60,44.80,47.00,49.20,45.20,46.40,46.90,49.40,61.00,36.50,42.10,43.90,47.20,64.30,59.90,39.60,36.80)
sizerecapture < c(43.0,48.7,39.5,42.0,46.7,43.5,47.2,45.7,59.9,48.1,46.5,49.1,47.1,46.9,48.3,53.7,52.0,51.2,56.2,56.3,57.5,57.7,55.4,74.5,45.6,44.9,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,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)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。