Skip to content

Commit

Permalink
quantiles margin down
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Feb 27, 2019
1 parent 62a4ec2 commit a448159
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: antaresWeeklyMargin
Title: Setup an 'Antares' Study for Weekly Margin Simulation
Version: 0.0.2.970
Version: 0.0.2.980
Authors@R: c(
person("Victor", "Perrier", email = "[email protected]", role = c("aut", "cre")),
person("Fabiola", "Aravena-Rojas", email = "[email protected]", role = c("aut")),
Expand Down
26 changes: 18 additions & 8 deletions R/margins_quantiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#'
#' @param margin a \code{data.table} containing margins.
#' @param hours Couple of hours.
#' @param type Type of margin.
#'
#' @return a \code{data.table}
#' @export
Expand All @@ -17,8 +18,8 @@
#'
#' @importFrom data.table copy melt %chin% :=
#' @importFrom stats median quantile
margins_quantiles <- function(margin, hours = c("09h", "19h")) {

margins_quantiles <- function(margin, hours = c("09h", "19h"), type = c("upward", "downward")) {
type <- match.arg(type)
margin <- copy(margin)
margin[, jour := format(datetime, format = "%A")]
margin[, date := format(datetime, format = "%Y-%m-%d")]
Expand All @@ -30,12 +31,21 @@ margins_quantiles <- function(margin, hours = c("09h", "19h")) {
id.vars = c("datetime", "date", "jour", "heure"),
measure.vars = setdiff(names(margin), c("datetime", "date", "jour", "heure"))
)
margin <- margin[, list(
mediane = median(value),
q1 = quantile(value, probs = 1/100),
q4 = quantile(value, probs = 4/100),
q10 = quantile(value, probs = 10/100)
), by = list(date, jour, heure)]
if (type == "upward") {
margin <- margin[, list(
mediane = median(value),
q1 = quantile(value, probs = 1/100),
q4 = quantile(value, probs = 4/100),
q10 = quantile(value, probs = 10/100)
), by = list(date, jour, heure)]
} else {
margin <- margin[, list(
mediane = median(value),
q1 = quantile(value, probs = 99/100),
q4 = quantile(value, probs = 96/100),
q10 = quantile(value, probs = 90/100)
), by = list(date, jour, heure)]
}
melt(
data = margin,
id.vars = c("jour", "date", "heure"),
Expand Down
4 changes: 2 additions & 2 deletions inst/markdown/report/index.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ Legend:
Table of quantiles :

```{r down-quantiles-solo, echo=FALSE}
marg <- margins_quantiles(marges_down$margin_area_solo, hours = c("04h", "16h"))
marg <- margins_quantiles(marges_down$margin_area_solo, hours = c("04h", "16h"), type = "downward")
ft_margins_quantiles(marg, layout = "horizontal", language = "en")
```

Expand Down Expand Up @@ -243,7 +243,7 @@ Legend:
Table of quantiles :

```{r down-quantiles-inter, echo=FALSE}
marg_i <- margins_quantiles(marges_down$margin_area_inter, hours = c("04h", "16h"))
marg_i <- margins_quantiles(marges_down$margin_area_inter, hours = c("04h", "16h"), type = "downward")
ft_margins_quantiles(marg_i, layout = "horizontal", language = "en")
```

Expand Down
5 changes: 4 additions & 1 deletion man/margins_quantiles.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a448159

Please sign in to comment.