downscale: Statistical temporal downscaling

Description Usage Arguments Details Value Examples

View source: R/downscale.R

Description

Performs statistical temporal downscaling of a vector of numerical values, using linear models.

Usage

1
downscale(y, x, n, interval = NULL)

Arguments

y

A vector of numerical values containing the aggregate data.

x

A vector of numerical values of the same length as y, containing the centers of the intervals over which the corresponding y values are supposed to aggregates.

n

A vector of integer values either of length 1 or of the same length as the vectors y and x. Gives the number of disaggregated points we wish per interval.

interval

Interval argument of the base R optimize function used to look for the best first infered value. See the Details section for more information. By default set to three times the range of y.

Details

The downscaling is performed, complying to the following two constraints:

The first constraint is met by fitting, in each interval, a linear model that goes through the center c(x, y) inputted point as the point of the model on the previous segment that intersect the limit between the segment and the previous one. See here for more detailed information. The first point of the first segments is found by minimizing the total smoothness of the model. The minimization is performed over an interval that can be specified as an option by the user.

Value

A vector of numerical values.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Let's consider 10 time intervals of centers from 1 to 10 and let's say we
# want to infer 12 values per interval:
x <- 1:10
n <- 12
# The limits between these intervals are
the_centers <- centers(x, TRUE)
# And the x coordinates of the inferred values will be
new_x <- unlist(subsegment_center(x, n))
# Let's start with a simple example where the initial aggregate data are
# values from 1 to 10:
y1 <- 1:10
y1b <- downscale(y1, x, n)
plot(new_x, y1b)
points(x, y1, col = "blue", pch = 19)
abline(v = the_centers, col = "red")
# On this figure the vertical red lines show the limits of the intervals, the
# blue dots show the aggregated values available for each of these intervals,
# and the black dots show the inferred disaggregated values within each
# interval. The figure shows that the continuity between intervals is
# respected (second of the above-listed constraints). Let's now check that
# the first constraint is also well respected (i.e. that the aggregates of
# the inferred values are equal to the initial aggregate data):
plot(y1, colMeans(matrix(y1b, n)),
     xlab = "initial aggregate data",
     ylab = "aggregates of inferred values")
abline(0, 1)
# That works fine! Let's now consider a slightly more complicated example
# that scrambles the values of y:
y2 <- sample(y1)
y2b <- downscale(y2, x, n)
plot(new_x, y2b)
points(x, y2, col = "blue", pch = 19)
abline(v = the_centers, col = "red")
plot(y2, colMeans(matrix(y2b, n)),
     xlab = "initial aggregate data",
     ylab = "aggregates of inferred values")
     abline(0, 1)

# Works well too!

choisy/mcstats documentation built on May 21, 2019, 3:08 a.m.