# Perom data ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
# Fit a M_b model
M_b <- vglm(cbind(y1, y2, y3, y4, y5, y6) ~ 1,
data = Perom, posbernoulli.b, trace = TRUE)
coef(M_b, matrix = TRUE)
constraints(M_b, matrix = TRUE)
summary(M_b)
# Fit a M_bh model
M_bh <- vglm(cbind(y1, y2, y3, y4, y5, y6) ~ sex + weight,
posbernoulli.b, trace = TRUE, data = Perom)
coef(M_bh, matrix = TRUE)
constraints(M_bh) # (2,2) element of "(Intercept)" is the behavioural effect
summary(M_bh) # Estimate of behavioural effect is positive (trap-happy)
# Fit a M_h model
M_h <- vglm(cbind(y1, y2, y3, y4, y5, y6) ~ sex + weight,
data = Perom,
posbernoulli.t(parallel.t = TRUE), trace = TRUE)
coef(M_h, matrix = TRUE)
constraints(M_h, matrix = TRUE)
summary(M_h)
# Fit a M_0 model
M_0 <- vglm(cbind( y1 + y2 + y3 + y4 + y5 + y6,
6 - y1 - y2 - y3 - y4 - y5 - y6) ~ 1,
data = Perom, posbinomial, trace = TRUE)
coef(M_0, matrix = TRUE)
constraints(M_0, matrix = TRUE)
summary(M_0)
# Simulated data set ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
set.seed(123); nTimePts <- 5; N <- 1000
hdata <- rposbern(n = N, nTimePts = nTimePts, pvars = 2,
is.popn = TRUE) # N is the popn size
nrow(hdata) # Less than N
# The truth: xcoeffs are c(-2, 1, 2) and cap.effect = -1
model1 <- vglm(cbind(y1, y2, y3, y4, y5) ~ x2,
posbernoulli.b, data = hdata, trace = TRUE)
coef(model1)
coef(model1, matrix = TRUE)
constraints(model1, matrix = TRUE)
summary(model1)
head(depvar(model1)) # Capture history response matrix
head(model1@extra$cap.hist1) # Info on its capture history
head(model1@extra$cap1) # When it was first captured
head(fitted(model1)) # Depends on capture history
(trap.effect <- coef(model1)["(Intercept):2"]) # Should be -1
head(model.matrix(model1, type = "vlm"), 21)
head(hdata)
summary(hdata)
dim(depvar(model1))
vcov(model1)
model1@extra$N.hat # Estimate of the population size; should be about N
model1@extra$SE.N.hat # SE of the estimate of the population size
# An approximate 95 percent confidence interval:
round(model1@extra$N.hat + c(-1, 1) * 1.96 * model1@extra$SE.N.hat, 1)
Run the code above in your browser using DataLab