pred_band | R Documentation |
Calculate a prediction band for a fitted growth curve.
pred_band(age, model, level = 0.95)
age |
a vector of ages to calculate the prediction band. |
model |
a fitted growth model. |
level |
significance level. |
A data frame containing five columns:
age |
age |
Lhat |
predicted length |
sigma |
growth variability |
lower |
lower limit of prediction band |
upper |
upper limit of prediction band |
The variability of length at age (sigma
) increases linearly with
length:
\sigma_L ~=~ \alpha \,+\, \beta \hat L
This calculation of sigma
is demonstrated in the example below.
The lower
and upper
limits of the prediction band are
calculated as \hat L \pm 1.96\sigma_L
at the
95% significance level.
gcm
, gompertz
, gompertzo
,
richards
, richardso
, schnute3
,
vonbert
, and vonberto
are alternative growth
models.
fishgrowth-package
gives an overview of the package.
# Fit a model
init <- list(log_L1=log(20), log_L2=log(70), log_k=log(0.1),
log_sigma_min=log(3), log_sigma_max=log(3))
dat <- list(Aoto=otoliths_had$age, Loto=otoliths_had$len, t1=1, t2=10)
model <- vonbert(init, dat)
fit <- nlminb(model$par, model$fn, model$gr,
control=list(eval.max=1e4, iter.max=1e4))
# Calculate 95% prediction band
x <- seq(1, 18, 0.5)
band <- pred_band(x, model)
# Plot 95% prediction band
areaplot::confplot(cbind(lower,upper)~age, band, xlim=c(0,18), ylim=c(0,100),
ylab="len", col="mistyrose")
points(len~age, otoliths_had, xlim=c(0,18), ylim=c(0,100),
pch=16, col="#0080a010")
lines(Lhat~age, band, lwd=2, col=2)
lines(lower~age, band, lty=1, lwd=0.5, col=2)
lines(upper~age, band, lty=1, lwd=0.5, col=2)
# Calculate sigma by hand
report <- model$report()
alpha <- report$sigma_intercept
beta <- report$sigma_slope
Lhat <- band$Lhat
alpha + beta * Lhat # same values as band$sigma calculated by pred_band()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.