# NOT RUN {
# }
# NOT RUN {
#########################################################
#########################################################
library("JRM")
data("war", package = "JRM")
###################################################
# Bivariate brobit model with partial observability
###################################################
reb.eq <- onset ~ instab + oil + warl + lpopl + lmtnest + ethfrac +
polity2l + s(gdpenl) + s(relfrac)
gov.eq <- onset ~ instab + oil + warl + ncontig + nwstate + s(gdpenl)
bpo <- SemiParBIV(list(reb.eq, gov.eq), data = war, Model = "BPO")
conv.check(bpo)
# perhaps model is to complex
set.seed(1)
sbpo <- summary(bpo)
sbpo$theta; sbpo$CItheta
# let's exclude the correlation parameter in fitting
bpo0 <- SemiParBIV(list(reb.eq, gov.eq), data = war, Model = "BPO0")
conv.check(bpo0)
summary(bpo0)
war.eq <- onset ~ instab + oil + warl + ncontig + nwstate + lpopl +
lmtnest + ethfrac + polity2l + s(gdpenl) + s(relfrac)
Probit <- gam(war.eq, family = binomial(link = "probit"), data = war)
summary(Probit)
coef(Probit)[(which(names(coef(Probit)) == "s(gdpenl).9"))]
coef(bpo0)[(which(names(coef(bpo)) == "s(gdpenl).9"))]
probitW <- bpoW <- bpoReb <- bpoGov <- NA
gdp.grid <- seq(0, 8)
median.values <- data.frame(t(apply(war, 2, FUN = median)))
for (i in 1:length(gdp.grid)){
newd <- median.values; newd$gdpenl <- gdp.grid[i]
eta1 <- predict(bpo0, eq = 1, newd)
eta2 <- predict(bpo0, eq = 2, newd)
probitW[i] <- predict(Probit, newd, type = "response")
bpoW[i] <- pnorm(eta1)*pnorm(eta2)
bpoReb[i] <- pnorm(eta1)
bpoGov[i] <- pnorm(eta2)
}
plot(gdp.grid, probitW, type = "l", ylim = c(0, 0.55), lwd = 2,
col = "grey", xlab = "GDP per Capita (in thousands)",
ylab = "Pr(Outcome)", main = "Probabilities for All Outcomes",
cex.main = 1.5, cex.lab = 1.3, cex.axis = 1.3)
lines(gdp.grid, bpoW, lwd = 2)
lines(gdp.grid, bpoReb, lwd = 2, lty = 2)
lines(gdp.grid, bpoGov, lwd = 2, lty = 3)
#dev.copy(postscript, "probWAR.eps", width = 8)
#dev.off()
# }
# NOT RUN {
#
# }
Run the code above in your browser using DataLab