Skip to content

Commit

Permalink
rgdal changes; bug fix in ar.phase2
Browse files Browse the repository at this point in the history
  • Loading branch information
hanase committed Feb 20, 2024
1 parent 18514fd commit 7988e36
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 37 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
7.4-2.9001 (2024-02-19)
-----
Fixed bug related to a combination of ar.phase2 and missing data (thanks to Shunqi Cheng).

7.4-1/2 (2023-10-17)
-----
Removed rgdal from suggested packages.

7.4-0 (2023-09-14)
-----
Annual subnational projections are now possible, controlled by the argument "annual"
Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Package: bayesTFR
Version: 7.4-0
Date: 2023-09-14
Version: 7.4-2.9001
Date: 2024-02-19
Title: Bayesian Fertility Projection
Author: Hana Sevcikova ([email protected]), Leontine Alkema ([email protected]), Peiran Liu ([email protected]), Adrian Raftery ([email protected]), Bailey Fosdick ([email protected]), Patrick Gerland ([email protected])
Maintainer: Hana Sevcikova <[email protected]>
Depends: R (>= 3.5.0)
Imports: mvtnorm, MASS, coda, graphics, grDevices, stats, utils, wpp2019, data.table, lifecycle
Suggests: rworldmap, snowFT, googleVis, rgdal, sp, wpp2017, wpp2015, wpp2012, wpp2010, ggplot2, sf, spData, scales
Suggests: rworldmap, snowFT, googleVis, sp, wpp2017, wpp2015, wpp2012, wpp2010, ggplot2, sf, spData, scales
Description: Making probabilistic projections of total fertility rate for all countries of the world, using a Bayesian hierarchical model <doi:10.1007/s13524-011-0040-5> <doi:10.18637/jss.v106.i08>. Subnational probabilistic projections are also supported <doi:10.4054/DemRes.2018.38.60>.
License: GPL-3 | file LICENSE
URL: https://bayespop.csss.washington.edu
Expand Down
11 changes: 5 additions & 6 deletions R/plot_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -1210,11 +1210,10 @@ tfr.map <- function(pred, quantile=0.5, year=NULL, par.name=NULL, adjusted=FALSE
tfr <- data.frame(cbind(un=data.period$country.codes, tfr=data))
map <- rworldmap::getMap(resolution=resolution)
#first get countries excluding Antarctica which crashes spTransform (says the help page for joinCountryData2Map)
sPDF <- map[-which(map$ADMIN=='Antarctica'), ]
if(requireNamespace("rgdal", quietly=TRUE)) {
#transform map to the Robinson projection
sPDF <- sp::spTransform(sPDF, CRSobj=sp::CRS("+proj=robin +ellps=WGS84"))
}
sPDF <- map[-which(map$ADMIN=='Antarctica'), ]
#transform map to the Robinson projection
sPDF <- sp::spTransform(sPDF, CRSobj = sp::CRS("+proj=robin +ellps=WGS84"))

## recode missing UN codes and UN member states
sPDF$UN <- sPDF$ISO_N3
## N. Cyprus -> assign to Cyprus
Expand All @@ -1223,7 +1222,7 @@ tfr.map <- function(pred, quantile=0.5, year=NULL, par.name=NULL, adjusted=FALSE
sPDF$UN[sPDF$ISO3=="KOS"] <- 688
## W. Sahara -> no UN numerical code assigned in Natural Earth map (its ISO3 changed in rworlmap 1.3.6)
sPDF$UN[sPDF$ISO3=="ESH"] <- 732
## Somaliland -> assign to Somalia -> fixed in rworlmap version 1.3.6
## Somaliland -> assign to Somalia (SOM) -> fixed in rworlmap version 1.3.6
#sPDF$UN[sPDF$ISO3=="SOL"] <- 706

#mtfr <- joinCountryData2Map(tfr, joinCode='UN', nameJoinColumn='un')
Expand Down
7 changes: 5 additions & 2 deletions R/predict_tfr.R
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,13 @@ make.tfr.prediction <- function(mcmc.set, start.year=NULL, end.year=2100, replac
}
else
{
for(year in 1:fps.end.obs.index)
last.not.na <- 1
for(year in 1:fps.end.obs.index) {
all.f_ps[icountry,year,] <- all.tfr.list[[prediction.countries[icountry]]][all.T_end.min+year-1]
if(!is.na(all.f_ps[icountry,year,1])) last.not.na <- year
}
if (!is.null(mcmc.set$meta$ar.phase2) && (mcmc.set$meta$ar.phase2))
f_ps_previous[, icountry] <- all.tfr.list[[prediction.countries[icountry]]][all.T_end.min+year-2]
f_ps_previous[, icountry] <- all.tfr.list[[prediction.countries[icountry]]][all.T_end.min+last.not.na-2]
}
first.two.na <- which(is.na(all.f_ps[icountry,,1]))[1:2]
which.Wsecond[icountry] <- first.two.na[2]
Expand Down
13 changes: 7 additions & 6 deletions man/convert.trajectories.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ convert.tfr.trajectories(dir = file.path(getwd(), 'bayesTFR.output'),
}
\details{
The function creates two files. One is called \dQuote{ascii_trajectories.csv}, it is a comma-separated table with the following columns:
\itemize{\item{\dQuote{LocID}}{country code}
\item{\dQuote{Period}}{prediction interval, e.g. 2015-2020}
\item{\dQuote{Year}}{middle year of the prediction interval}
\item{\dQuote{Trajectory}}{identifier of the trajectory}
\item{\dQuote{TF}}{total fertility rate}
}
\describe{
\item{LocID}{country code}
\item{Period}{prediction interval, e.g. 2015-2020}
\item{Year}{middle year of the prediction interval}
\item{Trajectory}{identifier of the trajectory}
\item{TF}{total fertility rate}
}

The second file is called \dQuote{ascii_trajectories_wide.csv}, it is also a comma-separated table and it contains the same information as above but in a \sQuote{transposed} format. I.e. the data for one country are ordered in columns, thus, there is one column per country. The country columns are ordered alphabetically.

Expand Down
40 changes: 20 additions & 20 deletions man/write.projection.summary.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,32 @@ write.projection.summary(dir = file.path(getwd(), "bayesTFR.output"),
}
\details{
The first file that the function creates is called \file{projection_summary_user_friendly.csv} (or \file{projection_summary_user_friendly_adjusted.csv} if \code{adjusted=TRUE}), it is a comma-separated table with the following columns:
\itemize{\item{\dQuote{country_name}: }{country name}
\item{\dQuote{country_code}: }{country code}
\item{\dQuote{variant}: }{name of the variant, such as \dQuote{median}, \dQuote{lower 80}, \dQuote{upper 80}, \dQuote{lower 95}, \dQuote{upper 95}, \dQuote{-0.5child}, \dQuote{+0.5child}, \dQuote{constant}}
\item{period1: }{e.g. \dQuote{2005-2010}: TFR for the first time period. If \code{est.uncertainty} is \code{TRUE}, the first time period is the first observed time period. Otherwise it is the last observed one.}
\item{period2: }{e.g. \dQuote{2010-2015}: TFR for the second time period}
\item{\dots }{further columns with TFR projections}
\describe{\item{country_name}{country name}
\item{country_code}{country code}
\item{variant}{name of the variant, such as \dQuote{median}, \dQuote{lower 80}, \dQuote{upper 80}, \dQuote{lower 95}, \dQuote{upper 95}, \dQuote{-0.5child}, \dQuote{+0.5child}, \dQuote{constant}}
\item{\emph{period1:}}{e.g. \dQuote{2005-2010}: TFR for the first time period. If \code{est.uncertainty} is \code{TRUE}, the first time period is the first observed time period. Otherwise it is the last observed one.}
\item{\emph{period2:}}{e.g. \dQuote{2010-2015}: TFR for the second time period}
\item{\dots}{further columns with TFR projections}
}

The second file, called \file{projection_summary.csv} (or \file{projection_summary_adjusted.csv} if \code{adjusted=TRUE}), also comma-separated table, contains the same information as above in a UN-specific format:
\itemize{\item{\dQuote{RevID}: }{revision number, passed to the function as an argument}
\item{\dQuote{VarID}: }{variant identifier, extracted from the \code{\link{UN_variants}} dataset}
\item{\dQuote{LocID}: }{country code}
\item{\dQuote{TimeID}: }{time identifier, extracted from the \code{\link{UN_time}} dataset}
\item{\dQuote{TFR}: }{the total fertility rate for this variant, location and time period}
\describe{\item{RevID}{revision number, passed to the function as an argument}
\item{VarID}{variant identifier, extracted from the \code{\link{UN_variants}} dataset}
\item{LocID}{country code}
\item{TimeID}{time identifier, extracted from the \code{\link{UN_time}} dataset}
\item{TFR}{the total fertility rate for this variant, location and time period}
}

The third comma-separated file, called \file{projection_summary_parameters.csv} contains the following columns:
\itemize{\item{\dQuote{country_name}: }{country name}
\item{\dQuote{country_code}: }{country code}
\item{\dQuote{TF_time_start_decline}: }{start period of TFR decline}
\item{\dQuote{TF_max}: }{TFR at the onset of the fertitility transition (median of the \eqn{U_c} parameter)}
\item{\dQuote{TF_max_decrement}: }{maximum decrement of TFR decline (median of the \eqn{d_c} parameter)}
\item{\dQuote{TF_end_level}: }{median of the end level of the fertility transition (\eqn{\Delta_{c4}}{Triangle_c4} parameter)}
\item{\dQuote{TF_end_level_low}: }{2.5 percentile of the \eqn{\Delta_{c4}}{Triangle_c4} distribution}
\item{\dQuote{TF_end_level_high}: }{97.5 percentile of the \eqn{\Delta_{c4}}{Triangle_c4} distribution}
\item{\dQuote{TF_time_end_decline}: }{period of the end decline, measured using the prediction median}
\describe{\item{country_name}{country name}
\item{country_code}{country code}
\item{TF_time_start_decline}{start period of TFR decline}
\item{TF_max}{TFR at the onset of the fertitility transition (median of the \eqn{U_c} parameter)}
\item{TF_max_decrement}{maximum decrement of TFR decline (median of the \eqn{d_c} parameter)}
\item{TF_end_level}{median of the end level of the fertility transition (\eqn{\Delta_{c4}}{Triangle_c4} parameter)}
\item{TF_end_level_low}{2.5 percentile of the \eqn{\Delta_{c4}}{Triangle_c4} distribution}
\item{TF_end_level_high}{97.5 percentile of the \eqn{\Delta_{c4}}{Triangle_c4} distribution}
\item{TF_time_end_decline}{period of the end decline, measured using the prediction median}
}
Note that this file is not created if \code{adjusted=TRUE}.
}
Expand Down

0 comments on commit 7988e36

Please sign in to comment.