Skip to content

Commit abf2eac

Browse files
committed
Version 1.0.3.
Update documentation: roxygenize comments, reorganize help pages.
1 parent 10d1e2b commit abf2eac

File tree

208 files changed

+3208
-5247
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

208 files changed

+3208
-5247
lines changed

ChangeLog

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2017-04-05: Google <[email protected]>
2+
* Version 1.0.3
3+
* Update documentation: roxygenize comments, reorganize help pages.
14
2017-04-04: Google <[email protected]>
25
* Version 1.0.2
36
* Update Vignette: add URL to the TBR white paper.

DESCRIPTION

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ Suggests:
1515
testthat (>= 0.10.0),
1616
knitr (>= 1.12.3)
1717
VignetteBuilder: knitr
18-
Date: 2017-04-04
19-
Version: 1.0.2
18+
Date: 2017-04-05
19+
Version: 1.0.3
2020
License: Apache License 2.0 | file LICENSE
2121
Copyright: Copyright (C) 2017 Google, Inc.
2222
RoxygenNote: 5.0.1

R/aggregate.R

+17-20
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,25 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
#' Aggregate the Metrics of a GeoTimeseries.
16+
#'
17+
#' @param x a GeoTimeseries object.
18+
#' @param by (character vector) name(s) of column(s) by which to group.
19+
#' @param FUN (function) function to apply to each metric column.
20+
#' @param metrics (character vector) metrics to aggregate. Default is all
21+
#' metrics.
22+
#' @param ... optional arguments passed to FUN.
23+
#'
24+
#' @return A data.frame object.
25+
#'
26+
#' @note
27+
#' Uses \code{aggregate.data.frame} to do the aggregation. This function
28+
#' omits rows that have missing values in the '\code{by}' columns.
29+
#'
30+
#' @seealso AggregateTimeseries.
31+
1532
aggregate.GeoTimeseries <- function(x, by=kGeo, FUN=base::sum,
1633
metrics=NULL, ...) {
17-
# Aggregate the Metrics of a GeoTimeseries.
18-
#
19-
# Args:
20-
# x: a GeoTimeseries object.
21-
# by: (character vector) name(s) of column(s) by which to group.
22-
# FUN: (function) function to apply to each metric column.
23-
# metrics: (character vector) metrics to aggregate. Default is all metrics.
24-
# ...: optional arguments passed to FUN.
25-
#
26-
# Returns:
27-
# A data.frame object.
28-
#
29-
# Notes:
30-
#
31-
# Uses 'aggregate.data.frame' to do the aggregation. This function
32-
# omits rows that have missing values in the 'by' columns.
33-
#
34-
# Documentation:
35-
# seealso: AggregateTimeseries.
36-
3734
SetMessageContextString("aggregate.GeoTimeseries")
3835
on.exit(SetMessageContextString())
3936

R/aggregatetimeseries.R

+26-45
Original file line numberDiff line numberDiff line change
@@ -12,56 +12,37 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
AggregateTimeseries <- function(obj, freq=c("weekly", "monthly"), ...) {
16-
# Aggregate the metrics of a time series object over specified time
17-
# intervals.
18-
#
19-
# Args:
20-
# obj: an object.
21-
# freq: (string) 'weekly' or 'monthly' aggregation.
22-
# ...: further arguments passed to or from other methods.
23-
#
24-
# Returns:
25-
# An object of the same class as 'obj'.
26-
#
27-
# Notes:
28-
# A generic S3 method.
29-
#
30-
# Documentation:
31-
# seealso: AggregateTimeseries.GeoTimeseries.
15+
#' Aggregate the metrics of a time series object over specified time
16+
#' intervals.
17+
#'
18+
#' @param obj an object.
19+
#' @param freq (string) 'weekly' or 'monthly' aggregation.
20+
#' @param ... further arguments passed to or from other methods.
21+
#'
22+
#' @return An object of the same class as 'obj'.
23+
#'
24+
#' @note
25+
#' \itemize{
26+
#' \item{'Weekly' frequency}: each day in the time series is mapped
27+
#' to the next Sunday, then aggregated.
28+
#' \item{'Monthly' frequency}: each day in the time series is mapped to
29+
#' the last day of the month, then aggregated. No check is made about
30+
#' the current frequency. This works best on daily data. So it is
31+
#' possible to attempt to change a 'monthly' frequency back to 'weekly',
32+
#' but this simply re-maps the last day of the month to the next Sunday.
33+
#' }
34+
#'
35+
#' @seealso \code{\link{aggregate.GeoTimeseries}}.
36+
#'
37+
#' @rdname AggregateTimeseries
3238

39+
AggregateTimeseries <- function(obj, freq=c("weekly", "monthly"), ...) {
3340
UseMethod("AggregateTimeseries")
3441
}
3542

36-
AggregateTimeseries.GeoTimeseries <- function(obj, freq, ...) {
37-
# Convert a GeoTimeseries to a weekly or monthly
38-
# GeoTimeseries. (Note: intended to transform daily data.)
39-
#
40-
# Args:
41-
# obj: a GeoTimeseries object.
42-
# freq: desired frequency: 'weekly' or 'monthly'.
43-
# ...: ignored.
44-
#
45-
# Returns:
46-
# A GeoTimeseries object with the weekly or monthly metrics
47-
# aggregated. The sums are associated with the last day of the
48-
# week (which is by our definition _Sunday_), or the last day of
49-
# the month.
50-
#
51-
# Notes:
52-
# 'Weekly' frequency: each day in the time series is mapped to the
53-
# next Sunday, then aggregated. 'Monthly' frequency: each day in
54-
# the time series is mapped to the last day of the month, then
55-
# aggregated.
56-
#
57-
# No check is made about the current frequency. This works best on
58-
# daily data. So it is possible to attempt to change a 'monthly'
59-
# frequency back to 'weekly', but this simply re-maps the last day
60-
# of the month to the next Sunday.
61-
#
62-
# Documentation:
63-
# seealso: AggregateTimeseries (generic), aggregate.GeoTimeseries.
43+
#' @rdname AggregateTimeseries
6444

45+
AggregateTimeseries.GeoTimeseries <- function(obj, freq, ...) {
6546
SetMessageContextString("AggregateTimeseries.GeoTimeseries")
6647
on.exit(SetMessageContextString())
6748

R/as_gbrroasanalysisdata.R

+29-26
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,35 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
#' Coerces an object to a GBRROASAnalysisData object.
16+
#'
17+
#' @param obj an object.
18+
#' @param ... further arguments to be passed to or from other methods.
19+
#' @return A GBRROASAnalysisData object.
20+
#'
21+
#' @seealso \code{\link{DoGBRROASAnalysis}}.
22+
#'
23+
#' @rdname as.GBRROASAnalysisData
24+
as.GBRROASAnalysisData <- function(obj, ...) {
25+
UseMethod("as.GBRROASAnalysisData")
26+
}
27+
28+
#' @param response (string) name of the response variable column.
29+
#' @param cost (string) name of the cost variable column.
30+
#' @param pretest.period (vector of non-negative integers) number(s) of the
31+
#' period(s) forming the pretest period.
32+
#' @param intervention.period (vector of non-negative integers) number(s) of
33+
#' the period(s) forming the intervention period. All must be larger
34+
#' than the largest period in the pretest period.
35+
#' @param cooldown.period (NULL or vector of non-negative integers) number(s)
36+
#' of the period(s) forming the cooldown period. All must be larger than
37+
#' the largest period in the intervention period.
38+
#' @param control.group (NULL or a vector of positive integers) number(s) of
39+
#' geo groups forming the control group.
40+
#' @param treatment.group (NULL or a vector of positive integers) number(s) of
41+
#' geo groups forming the control group.
42+
#'
43+
#' @rdname as.GBRROASAnalysisData
1544
as.GBRROASAnalysisData.GeoExperimentData <- function(obj,
1645
response=character(0),
1746
cost=character(0),
@@ -21,32 +50,6 @@ as.GBRROASAnalysisData.GeoExperimentData <- function(obj,
2150
control.group=1L,
2251
treatment.group=2L,
2352
...) {
24-
# Coerces an object to a GBRROASAnalysisData object.
25-
#
26-
# Args:
27-
# obj: a GeoExperimentData object.
28-
# response: (string) name of the response variable column.
29-
# cost: (string) name of the cost variable column.
30-
# pretest.period: (vector of non-negative integers) number(s) of the
31-
# period(s) forming the pretest period.
32-
# intervention.period: (vector of non-negative integers) number(s) of the
33-
# period(s) forming the intervention period. All must be larger than the
34-
# largest period in the pretest period.
35-
# cooldown.period: (NULL or vector of non-negative integers) number(s) of
36-
# the period(s) forming the cooldown period. All must be larger than the
37-
# largest period in the intervention period.
38-
# control.group: (NULL or a vector of positive integers) number(s) of geo
39-
# groups forming the control group.
40-
# treatment.group: (NULL or a vector of positive integers) number(s) of geo
41-
# groups forming the control group.
42-
# ...: ignored.
43-
#
44-
# Returns:
45-
# A GBRROASAnalysisData object.
46-
#
47-
# Documentation:
48-
# seealso: as.GBRROASAnalysisData (generic).
49-
5053
SetMessageContextString("as.GBRROASAnalysisData.GeoExperimentData")
5154
on.exit(SetMessageContextString())
5255

R/as_geoexperimentdata.R

+21-29
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,32 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
as.GeoExperimentData <- function(obj, ...) {
16-
# Coerces an object to a GeoExperimentData object.
17-
#
18-
# Args:
19-
# obj: an object.
20-
# ...: further arguments passed to methods.
21-
#
22-
# Returns:
23-
# A GeoExperimentData object.
24-
#
25-
# Notes:
26-
# A generic S3 method.
15+
#' Coerces an object to a GeoExperimentData object.
16+
#'
17+
#' @param obj an object.
18+
#' @param ... further arguments passed to methods.
19+
#'
20+
#' @return A GeoExperimentData object.
21+
#'
22+
#' @rdname as.GeoExperimentData
2723

24+
as.GeoExperimentData <- function(obj, ...) {
2825
UseMethod("as.GeoExperimentData")
2926
}
3027

28+
#' Coerces a GeoTimeseries object to a GeoExperiment object.
29+
#'
30+
#' @param strict (flag) if FALSE, the additional columns are optional and no
31+
#' error is thrown if any of them is missing;
32+
#'
33+
#' @return A GeoExperimentData object.
34+
#'
35+
#' @note The GeoTimeseries object is supposed to have the columns 'period',
36+
#' 'geo.group', and 'assignment'. If any of these columns are missing,
37+
#' the corresponding columns in the resulting object will be 'NA'.
38+
#'
39+
#' @rdname as.GeoExperimentData
3140
as.GeoExperimentData.GeoTimeseries <- function(obj, strict=TRUE, ...) {
32-
# Coerces a GeoTimeseries object to a GeoExperiment object.
33-
#
34-
# Args:
35-
# obj: a GeoTimeseries object with the additional columns 'period',
36-
# 'geo.group', and 'assignment'. If any of these columns are
37-
# missing, the corresponding columns in the resulting object
38-
# will be 'NA'.
39-
# strict: (flag) if FALSE, the additional columns are optional and
40-
# no error is thrown if any of them is missing;
41-
# ...: ignored.
42-
#
43-
# Returns:
44-
# A GeoExperimentData object.
45-
#
46-
# Documentation:
47-
# seealso: as.GeoExperimentData (generic).
48-
4941
SetMessageContextString("as.GeoExperimentData.GeoTimeseries")
5042
on.exit(SetMessageContextString())
5143

R/as_geotimeseries.R

+7-12
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
as.GeoTimeseries <- function(obj, ...) {
16-
# Coerce an object to a GeoTimeseries object.
17-
#
18-
# Args:
19-
# obj: an object.
20-
# ...: additional arguments to be passed to or from methods.
21-
#
22-
# Returns:
23-
# A GeoTimeseries object.
24-
#
25-
# Notes:
26-
# A S3 generic method.
15+
#' Coerce an object to a GeoTimeseries object.
16+
#'
17+
#' @param obj an object.
18+
#' @param ... additional arguments to be passed to or from methods.
19+
#'
20+
#' @return A GeoTimeseries object.
2721

22+
as.GeoTimeseries <- function(obj, ...) {
2823
UseMethod("as.GeoTimeseries")
2924
}

R/as_matrix.R

+23-11
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
as.matrix.GeoTimeseries <- function(x, response, ...) {
16-
# Coerces a response metric of a GeoTimeseries to a matrix representation
17-
# with geos in rows, dates in columns.
18-
#
19-
# Args:
20-
# x: a GeoTimeseries object.
21-
# response: (string) name of the response metric to use.
22-
# ...: ignored.
23-
#
24-
# Returns:
25-
# A numeric matrix of the response metric, geos in rows, dates in columns.
15+
#' Coerces a response metric of a GeoTimeseries to a matrix representation
16+
#' with geos in rows, dates in columns.
17+
#'
18+
#' @param x a GeoTimeseries object.
19+
#' @param response (string) name of the response metric to use.
20+
#' @param ... ignored.
21+
#' @return A numeric matrix of the response metric, geos in rows, dates in
22+
#' columns.
2623

24+
as.matrix.GeoTimeseries <- function(x, response, ...) {
2725
SetMessageContextString("as.matrix.GeoTimeseries")
2826
on.exit(SetMessageContextString())
2927

@@ -44,3 +42,17 @@ as.matrix.GeoTimeseries <- function(x, response, ...) {
4442

4543
return(obj.result)
4644
}
45+
46+
#' Extracts the real-valued matrix of quantiles from a TBRQuantiles object.
47+
#'
48+
#' @param x a TBRQuantiles object.
49+
#' @param ... ignored.
50+
#'
51+
#' @return A real-valued matrix of the quantiles. The column names are the
52+
#' same as those in the TBRQuantiles object.
53+
54+
as.matrix.TBRQuantiles <- function(x, ...) {
55+
m <- as.matrix(as.data.frame(x)[!(names(x) %in% c(kDate, kPeriod))])
56+
rownames(m) <- as.character(x[[kDate]])
57+
return(m)
58+
}

0 commit comments

Comments
 (0)