# NOT RUN {
#
# Dobson's beetle data (generalized linear model)
#
# Complementary log-log model
mod <- glm(cbind(y, n-y) ~ ldose, data = beetle,
family = binomial(link = "cloglog"))
plotFit(mod, pch = 19, cex = 1.2, lwd = 2,
xlab = "Log dose of carbon disulphide",
interval = "confidence", shade = TRUE,
col.conf = "lightskyblue")
# Approximate 95% confidence intervals and standard error for LD50
invest(mod, y0 = 0.5)
invest(mod, y0 = 0.5, interval = "Wald")
#
# Nasturtium example (nonlinear least-squares with replication)
#
# Log-logistic model
mod <- nls(weight ~ theta1/(1 + exp(theta2 + theta3 * log(conc))),
start = list(theta1 = 1000, theta2 = -1, theta3 = 1),
data = nasturtium)
plotFit(mod, lwd.fit = 2)
# Compute approximate 95% calibration intervals
invest(mod, y0 = c(309, 296, 419), interval = "inversion")
invest(mod, y0 = c(309, 296, 419), interval = "Wald")
# Bootstrap calibration intervals. In general, nsim should be as large as
# reasonably possible (say, nsim = 9999).
boo <- invest(mod, y0 = c(309, 296, 419), interval = "percentile",
nsim = 300, seed = 101)
boo # print bootstrap summary
plot(boo) # plot results
#
# Bladder volume example (random coefficient model)
#
# Load required packages
library(nlme)
# Plot data
plot(HD^(3/2) ~ volume, data = bladder, pch = 19,
col = adjustcolor("black", alpha.f = 0.5))
# Fit a random intercept and slope model
bladder <- na.omit(bladder)
ris <- lme(HD^(3/2) ~ volume, data = bladder, random = ~volume|subject)
invest(ris, y0 = 500)
invest(ris, y0 = 500, interval = "Wald")
# }
Run the code above in your browser using DataLab