## Not run:
if (interactive () &&
requireNamespace("wbwdi", quietly = TRUE) &&
requireNamespace("ggplot2", quietly = TRUE) &&
requireNamespace("dplyr", quietly = TRUE)) {
# Curve correlation of per capita GDP and fertility rate in Paraguay
wdi_dat <- wbwdi::wdi_get(entities = c("PRY"), start_year=1960, end_year=2023,
indicators = c("NY.GDP.PCAP.KD","SP.DYN.TFRT.IN"), format="wide") |>
dplyr::rename(percapitaGDP = NY.GDP.PCAP.KD, fertility = SP.DYN.TFRT.IN)
ggplot2::ggplot(wdi_dat, aes(percapitaGDP, fertility, color=year)) + geom_point()
y <- as.matrix(wdi_dat[ , c("percapitaGDP", "fertility")])
set.seed(345)
ci <- list()
ci[[1]] <- ccor_posim(y=y, time=wdi_dat$year, method="indep")
ci[[2]] <- ccor_posim(y=y, time=wdi_dat$year, method="mvn")
ci[[3]] <- ccor_boot(y=y, time=wdi_dat$year, ndraw=399)
tabl <- matrix(NA, 3, 3)
for (k in 1:3) tabl[k, ] <- c(ci[[k]]$cor, ci[[k]]$ci)
dimnames(tabl) <- list(c("Posim_indep", "Posim_MVN", "Bootstrap"), c("Est","Lower95","Upper95"))
round(tabl, 4)
}
## End(Not run)
Run the code above in your browser using DataLab