Skip to content

Commit

Permalink
Fix (most of) the check errors/warnings/notes
Browse files Browse the repository at this point in the history
  • Loading branch information
mdenwood committed Feb 22, 2022
1 parent f2b26fc commit 298e44a
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 45 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.Rproj.user
inst/doc
.DS_Store
.Rhistory
9 changes: 5 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Package: EVI
Title: Epidemic Volatility Index as an Early-Warning Tool
Version: 0.1.0-1
Version: 0.1.1-1
Date: 2022-02-22
Authors@R:
c(
person(given = "Eletherios",
Expand Down Expand Up @@ -36,6 +37,8 @@ License: GPL (>= 3)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
Depends:
R (>= 3.5.0)
Imports:
ggplot2,
cowplot
Expand All @@ -47,6 +50,4 @@ Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
VignetteBuilder: knitr
Language: en-GB
Depends:
R (>= 2.10)
Language: en-US
21 changes: 21 additions & 0 deletions EVI.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ export(medvol)
export(mova)
export(rollsd)
export(status)
import(cowplot)
import(ggplot2)
importFrom(stats,sd)
47 changes: 23 additions & 24 deletions R/EVI.graphs.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#'
#' An EVI_output is required as input, derived from the \code{\link[EVI:deviant]{deviant()}} function.
#'
#' @param EVI_output output of the \code{\link[EVI:deviant]{deviant()}} function
#' @param graph Type of graph to be plotted. Options: "EVI", "PPV", "NPV". "EVI" (the default) is giving a plot of the confirmed cases, with red dots corresponding to time points that an early warning was issued and grey dots corresponding to time points without an early warning indication. "PPV" is giving a plot of the confirmed cases with colored dots corresponding to time points with an early warning. Color intensity is increasing with higher PPV. "NPV" is giving a plot of the confirmed cases with colored dots corresponding to time points without an early warning. Color intensity is increasing with higher NPV.
#' @param ln TRUE or FALSE; If TRUE (the default) the output of the graph will be presented on the logarithmic scale. IF FALSE the output data will be presented on the original scale.
#' @param type By default, points are plotted on EVI graphs. In cases where, changes are very sudden or data sparsely available, type="l" introduces lines on top of points for the "EVI" type of graph.
Expand All @@ -18,17 +19,15 @@
#' evi.graphs(EVI_output=EVI_output, graph="EVI", ln=T, type="l") # For the line EVI plot
#' @export
#'
#' @import ggplot2
#' @import cowplot
#'
#' @references
#' Kostoulas, P., Meletis, E., Pateras, K. et al. The epidemic volatility index, a novel early warning tool for identifying new waves in an epidemic. Sci Rep 11, 23775 (2021). \doi{10.1038/s41598-021-02622-3}


evi.graphs=function(EVI_output,graph=c("EVI"), ln=T, type="p") {
evi.graphs <- function(EVI_output,graph=c("EVI"), ln=T, type="p") {

list.of.packages <- c("ggplot2", "cowplot")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
require(ggplot2)
require(cowplot)
#EVI_output=temp
EVI_output$cases_1=EVI_output$Cases*EVI_output$Index
EVI_output$cases_1[EVI_output$cases_1 == 0] <- NA
Expand All @@ -42,32 +41,32 @@ evi.graphs=function(EVI_output,graph=c("EVI"), ln=T, type="p") {
EVI_output$variable<-"x"

if (graph=="EVI" && ln==F) {
sp3<-ggplot(EVI_output, aes(x=Days,group=variable))+
sp3<-ggplot(EVI_output, aes_string(x="Days",group="variable"))+
list(
geom_point(aes(y=(Cases), color=Index>0), size=0.5),
geom_point(aes_string(y=("Cases"), color="Index>0"), size=0.5),
scale_color_manual(values=c("grey69", "red3")),
theme(legend.position = "none"),
labs(y = "Cases", x="Days"),
if (type=="l") geom_path(aes(y=Cases,colour=factor(Index>0)))
if (type=="l") geom_path(aes_string(y="Cases",colour="factor(Index>0)"))
)
}

if (graph=="EVI" && ln==T) {
sp3<-ggplot(EVI_output, aes(x=Days,group=variable))+
sp3<-ggplot(EVI_output, aes_string(x="Days",group="variable"))+
list(
geom_point(aes(y=log(Cases), color=Index>0), size=0.5),
geom_point(aes_string(y="log(Cases)", color="Index>0"), size=0.5),
scale_color_manual(values=c("grey69", "red3")),
theme(legend.position = "none"),
labs(y = "ln(Cases)", x="Days"),
if (type=="l") geom_path(aes(y=log(Cases),colour=factor(Index>0)))
if (type=="l") geom_path(aes_string(y="log(Cases)",colour="factor(Index>0)"))
)
}

if (graph=="PPV" && ln==F) {
sp3<-ggplot(EVI_output, aes(x=Days,group=variable))+
sp3<-ggplot(EVI_output, aes_string(x="Days",group="variable"))+
list(
geom_point(aes(y=(cases_1), col=ppv), size=0.5),
geom_point(aes(y=(cases_0)), col="grey69", size=0.5),
geom_point(aes_string(y="(cases_1)", col="ppv"), size=0.5),
geom_point(aes_string(y="(cases_0)"), col="grey69", size=0.5),
labs(y = "Cases", x=""),
scale_color_gradient(low = "green", high = "red", limits=c(0, 1)),
labs(color= "PPV"),
Expand All @@ -79,10 +78,10 @@ evi.graphs=function(EVI_output,graph=c("EVI"), ln=T, type="p") {
}

if (graph=="PPV" && ln==T) {
sp3<-ggplot(EVI_output, aes(x=Days,group=variable))+
sp3<-ggplot(EVI_output, aes_string(x="Days",group="variable"))+
list(
geom_point(aes(y=log(cases_1), col=ppv), size=0.5),
geom_point(aes(y=log(cases_0)), col="grey69", size=0.5),
geom_point(aes(y="log(cases_1)", col="ppv"), size=0.5),
geom_point(aes(y="log(cases_0)"), col="grey69", size=0.5),
labs(y = "ln(Cases)", x=""),
scale_color_gradient(low = "green", high = "red", limits=c(0, 1)),
labs(color= "PPV"),
Expand All @@ -94,10 +93,10 @@ evi.graphs=function(EVI_output,graph=c("EVI"), ln=T, type="p") {
}

if (graph=="NPV" && ln==F) {
sp3<-ggplot(EVI_output, aes(x=Days,group=variable))+
sp3<-ggplot(EVI_output, aes_string(x="Days",group="variable"))+
list(
geom_point(aes(y=(cases_0), col=npv), size=0.5),
geom_point(aes(y=(cases_1)), col="grey69", size=0.5),
geom_point(aes_string(y="(cases_0)", col="npv"), size=0.5),
geom_point(aes_string(y="(cases_1)"), col="grey69", size=0.5),
labs(y = "Cases"),
scale_color_gradient(low = "green", high = "red", limits=c(0, 1)),
labs(color= "NPV"),
Expand All @@ -110,10 +109,10 @@ evi.graphs=function(EVI_output,graph=c("EVI"), ln=T, type="p") {


if (graph=="NPV" && ln==T) {
sp3<-ggplot(EVI_output, aes(x=Days,group=variable))+
sp3<-ggplot(EVI_output, aes_string(x="Days",group="variable"))+
list(
geom_point(aes(y=log(cases_0), col=npv), size=0.5),
geom_point(aes(y=log(cases_1)), col="grey69", size=0.5),
geom_point(aes_string(y="log(cases_0)", col="npv"), size=0.5),
geom_point(aes_string(y="log(cases_1)"), col="grey69", size=0.5),
labs(y = "ln(Cases)"),
scale_color_gradient(low = "green", high = "red", limits=c(0, 1)),
labs(color= "NPV"),
Expand Down
6 changes: 4 additions & 2 deletions R/deviant.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
#'
#' @examples
#' data("Italy")
#' deviant(new_cases=Italy$Cases, cum=F, r_a=7, r=0.2, lag_max=30)
#' deviant(new_cases=Italy$Cases, cum=FALSE, r_a=7, r=0.2, lag_max=30)
#' #This step should take some time and the time elapsed will be printed
#'
#' @importFrom stats sd
#'
#' @export
#'
#' @references
Expand Down Expand Up @@ -196,7 +198,7 @@ deviant=function(new_cases, cum = FALSE, r_a=7, r=0.2, lag_max=30){

EVI_out=as.data.frame(cbind(Days, EVI, Cases, Index, ppv, npv,
lag_all, c_all, se_all, sp_all))
EVI_output<<-(EVI_out)
EVI_output<-(EVI_out)

end_time = Sys.time()

Expand Down
5 changes: 3 additions & 2 deletions R/deviant_update.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
#' @examples
#' # If we have first observed only the 148 cases from the Italian data we run the deviant function on these cases:
#'
#' deviant(new_cases=Italy$Cases[1:148], cum=F, r_a=7, r=0.2, lag_max=30)
#' data("Italy")
#' deviant(new_cases=Italy$Cases[1:148], cum=FALSE, r_a=7, r=0.2, lag_max=30)
#'
#' # When the number of cases for the next day is observed we want to obtain the estimates for this day without having to reanalyze the entire time series. This is done by using the deviant_update function:
#'
#' deviant_update(new_cases=Italy$Cases[1:149], cum=F, r_a=7, r=0.2, lag_max=30)
#' deviant_update(new_cases=Italy$Cases[1:149], cum=FALSE, r_a=7, r=0.2, lag_max=30)
#'
#' # The result of running the deviant_update function is to update the output of the deviant_function by adding an additional row with estimates for the new data.
#' # In this example the EVI_output file will now have 149 rows. If two additional days are analyzed two additional rows will be added and so on.
Expand Down
12 changes: 8 additions & 4 deletions man/EVI-package.Rd

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

4 changes: 2 additions & 2 deletions man/deviant.Rd

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

7 changes: 4 additions & 3 deletions man/deviant_update.Rd

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

4 changes: 3 additions & 1 deletion man/evi.graphs.Rd

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

1 change: 0 additions & 1 deletion man/medvol.Rd

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

2 changes: 0 additions & 2 deletions man/mova.Rd

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

0 comments on commit 298e44a

Please sign in to comment.