Skip to content
Snippets Groups Projects
Commit 7cd25960 authored by Otto, Dr. Saskia's avatar Otto, Dr. Saskia
Browse files

fixed issue with global environments

parent 23b125a0
Branches
No related tags found
No related merge requests found
# Generated by roxygen2: do not edit by hand # Generated by roxygen2: do not edit by hand
export("%>%") export("%>%")
export(calc_vif)
export(explore_na)
export(impute)
export(test_tac)
export(trafficlight) export(trafficlight)
import(graphics)
importFrom(magrittr,"%>%") importFrom(magrittr,"%>%")
...@@ -26,8 +26,8 @@ calc_vif <- function(x) { ...@@ -26,8 +26,8 @@ calc_vif <- function(x) {
for (v in 1:ncol(x)) { for (v in 1:ncol(x)) {
v.name <- colnames(x)[v] v.name <- colnames(x)[v]
other.v.names <- colnames(x)[-v] other.v.names <- colnames(x)[-v]
mod.formula <- as.formula(paste(v.name, "~", paste(other.v.names, collapse = "+"))) mod.formula <- stats::as.formula(paste(v.name, "~", paste(other.v.names, collapse = "+")))
mod <- lm(mod.formula, data = x) mod <- stats::lm(mod.formula, data = x)
R2 <- summary(mod)$r.squared R2 <- summary(mod)$r.squared
result[v, "Rsquared"] <- R2 result[v, "Rsquared"] <- R2
result[v, "Tolerance"] <- 1 - R2 result[v, "Tolerance"] <- 1 - R2
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#' @param respect logical; this argument controls whether a unit column-width is the #' @param respect logical; this argument controls whether a unit column-width is the
#' same physical measurement on the device as a unit row-height (default is TRUE). #' same physical measurement on the device as a unit row-height (default is TRUE).
#' #'
#' @import graphics
#' @export #' @export
#' @author Saskia A. Otto #' @author Saskia A. Otto
#' @examples #' @examples
...@@ -26,10 +27,10 @@ ...@@ -26,10 +27,10 @@
#' colnames(mat) <- paste0("variable", 1:10) #' colnames(mat) <- paste0("variable", 1:10)
#' explore_na(x = mat, time = 1981:2000) #' explore_na(x = mat, time = 1981:2000)
#' colnames(mat) <- LETTERS[1:10] #' colnames(mat) <- LETTERS[1:10]
#' explore_na(x = mat, time = 1981:2000, madj_y = -1.5, hadj_y = 2, respect = FALSE) #' explore_na(x = mat, time = 1981:2000, madj_y = -2.5, hadj_y = 2, respect = FALSE)
explore_na <- function(x, time = NULL, cex_x = 1, cex_y = 1, explore_na <- function(x, time = NULL, cex_x = 1, cex_y = 1,
madj_y = 0, hadj_y = 1, respect = TRUE,...){ madj_y = 0, hadj_y = 1, respect = TRUE){
if(!is.null(time)) { if(!is.null(time)) {
rownames(x) <- time rownames(x) <- time
...@@ -48,7 +49,7 @@ explore_na <- function(x, time = NULL, cex_x = 1, cex_y = 1, ...@@ -48,7 +49,7 @@ explore_na <- function(x, time = NULL, cex_x = 1, cex_y = 1,
x <- x[reverse,] x <- x[reverse,]
# Data Map # Data Map
layout(matrix(c(1,1,2,1,1,2,3,3,4), ncol=3, byrow = TRUE), widths = c(2,2,1.5), layout(matrix(c(1,1,2,1,1,2,3,3,4), ncol=3, byrow = TRUE), widths = c(2.5,2,1.5),
heights = c(2,1,1.5), respect = respect) heights = c(2,1,1.5), respect = respect)
# graphics::layout(matrix(c(1,1,1,1), ncol = 2), widths = c(3.5,3.5), heights = c(2,2), # graphics::layout(matrix(c(1,1,1,1), ncol = 2), widths = c(3.5,3.5), heights = c(2,2),
# respect = respect) # respect = respect)
...@@ -68,7 +69,7 @@ explore_na <- function(x, time = NULL, cex_x = 1, cex_y = 1, ...@@ -68,7 +69,7 @@ explore_na <- function(x, time = NULL, cex_x = 1, cex_y = 1,
title(xlab="Number of years", line=2, cex.lab=1.2) title(xlab="Number of years", line=2, cex.lab=1.2)
#barplot stations #barplot stations
par(mar = c(4, 5+madj_y, 1.5, .5)) par(mar = c(4, 7+madj_y, 1.5, .5))
barplot(apply(x>0, 2, sum), ylab = "", barplot(apply(x>0, 2, sum), ylab = "",
las = 2, cex.axis = cex_y, space = 0, col = "#db7170", xaxs = "i") las = 2, cex.axis = cex_y, space = 0, col = "#db7170", xaxs = "i")
title(ylab="Number of variables", line=2.5, cex.lab=1.2) title(ylab="Number of variables", line=2.5, cex.lab=1.2)
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/calc_vif.R
\name{calc_vif}
\alias{calc_vif}
\title{Calculate the variance inflation factors}
\usage{
calc_vif(x)
}
\arguments{
\item{x}{matrix or data frame containing only numerical variables.}
}
\value{
The function returns a matrix with 3 columns:
\describe{
\item{\code{Rsquared}}{}
\item{\code{Tolerance}}{}
\item{\code{VIF}}{}
}
}
\description{
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet
clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
}
\examples{
x <- data.frame(a = 1:20, b = 1:20*2 + rnorm(20) )
calc_vif(x)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/explore_na.R
\name{explore_na}
\alias{explore_na}
\title{Create multiple plots to explore gaps in the time series}
\usage{
explore_na(
x,
time = NULL,
cex_x = 1,
cex_y = 1,
madj_y = 0,
hadj_y = 1,
respect = TRUE
)
}
\arguments{
\item{x}{matrix or data frame containing time series of multiple variables.}
\item{time}{vector of time units that will be used for the x ax}
\item{cex_x}{double; the magnification to be used for the x labels relative to the
current setting of cex.}
\item{cex_y}{double; the magnification to be used for the y labels relative to the
current setting of cex.}
\item{madj_y}{double; adjustment of left margin relative to the
current setting for longer or short variable names in the image plot and right barplot.}
\item{hadj_y}{double; horizontal adjustment of the y labels in the image plot.}
\item{respect}{logical; this argument controls whether a unit column-width is the
same physical measurement on the device as a unit row-height (default is TRUE).}
}
\description{
This function creates an image plot where available values for the different variables and years
are indicated in gray and missing values in white. At the right side and bottom, two barplots
are added showing the frequency of available variables per year and the available years per
variable.
}
\examples{
mat <- matrix(1:200, ncol = 10)
mat[sample(1:200, sample(10:80, 1))] <- NA
colnames(mat) <- paste0("variable", 1:10)
explore_na(x = mat, time = 1981:2000)
colnames(mat) <- LETTERS[1:10]
explore_na(x = mat, time = 1981:2000, madj_y = -2.5, hadj_y = 2, respect = FALSE)
}
\author{
Saskia A. Otto
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/impute.R
\name{impute}
\alias{impute}
\title{Imputation of missing values by local mean substitution}
\usage{
impute(x, n = 2)
}
\arguments{
\item{x}{numeric vector containing NAs.}
\item{n}{integer; the number of previous and following values to be included in the mean.
The default is 2 so the mean is based on a 5yr-period (including the year of the missing
value).}
}
\value{
The function returns the same numeric input vector, but with replaced missing values.
}
\description{
The function substitutes missing values in time series with a mean of the \emph{n} previous and following years
(or less depending on the position of NAs, whether it is at the beginning or end of the time series, and
the presence of further NAs in the selected time period).
}
\examples{
x <- c(NA, 1, 4, 2, 5, NA, 9, NA, 12, 11, NA)
impute(x)
}
\author{
Saskia A. Otto
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/test_tac.R
\name{test_tac}
\alias{test_tac}
\title{Compute (partial) autocorrelation functions and test for significance}
\usage{
test_tac(x)
}
\arguments{
\item{x}{numeric; an evenly spaced time vector which should be tested for temporal
autocorrelation. Temporal gaps should be included as NAs.}
}
\value{
The function returns a list with 2 components:
\describe{
\item{\code{tac}}{TRUE if any lag in the (partial) autocorrelation functions
is significantly correlated (if correlation value > 0.4), else FALSE.}
\item{\code{max_lag}}{The maximal lag that is correlated.}
}
}
\description{
Compute (partial) autocorrelation functions and test for significance
}
\examples{
test_tac(x = 1:20)
test_tac(x = rnorm(20))
}
...@@ -63,7 +63,7 @@ numeric vector of probabilities with values in [0,1]. (Values up to ...@@ -63,7 +63,7 @@ numeric vector of probabilities with values in [0,1]. (Values up to
\item{quantile_type}{an integer between 1 and 9 selecting one of the nine quantile \item{quantile_type}{an integer between 1 and 9 selecting one of the nine quantile
algorithms detailed below to be used. Default is 7 (see also \code{\link{quantile}}).} algorithms detailed below to be used. Default is 7 (see also \code{\link{quantile}}).}
\item{intervals}{logical; number of evenly-spaced intervals. Default is 5.} \item{intervals}{logical; number of evenly spaced intervals. Default is 5.}
\item{cols}{a character vector with colors for each quantile or interval.} \item{cols}{a character vector with colors for each quantile or interval.}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment