code
stringlengths 1
13.8M
|
---|
NULL
make.name.tree <- function (x, recursive, what.names)
{
if (!is.character(what.names) || length(what.names) != 1)
stop("'what.names' must be a single string")
what.names <- match.arg(what.names, c("inherited", "full"))
.make.name.tree.rec <- function(x, parent_name, depth) {
if (length(x) == 0)
return(character(0))
x_names <- names(x)
if (is.null(x_names))
x_names <- rep.int(parent_name, length(x))
else if (what.names == "full")
x_names <- paste0(parent_name, x_names)
else x_names[x_names == ""] <- parent_name
if (!is.list(x) || (!recursive && depth >= 1L))
return(x_names)
if (what.names == "full")
x_names <- paste0(x_names, ".")
lapply(seq_len(length(x)), function(i) .make.name.tree.rec(x[[i]],
x_names[i], depth + 1L))
}
.make.name.tree.rec(x, "", 0L)
}
.unlist2 <- function (x, recursive = TRUE, use.names = TRUE, what.names = "inherited")
{
ans <- unlist(x, recursive, FALSE)
if (!use.names)
return(ans)
if (!is.character(what.names) || length(what.names) != 1)
stop("'what.names' must be a single string")
what.names <- match.arg(what.names, c("inherited", "full"))
names(ans) <- unlist(make.name.tree(x, recursive, what.names),
recursive, FALSE)
ans
}
unlist2 <- ns_get('AnnotationDbi::unlist2') %||% .unlist2
set_libPaths <- function(lib.loc=NULL){
ol <- Sys.getenv('R_LIBS')
olib <- .libPaths()
res <- list(R_LIBS=ol, .libPaths=olib)
if( is_NA(lib.loc) ) return(res)
if( is.null(lib.loc) ) lib.loc <- .libPaths()
if( is.character(lib.loc) ){
.libPaths(lib.loc)
rlibs <- paste(lib.loc, collapse=.Platform$path.sep)
Sys.setenv(R_LIBS=rlibs)
}else if( is.list(lib.loc) ){
Sys.setenv(R_LIBS=lib.loc$R_LIBS)
.libPaths(lib.loc$.libPaths)
}
res
}
NULL
R.exec <- function(..., lib.loc=NULL){
cmd <- paste(file.path(R.home('bin'), 'R'), ' ', ..., sep='', collapse='')
ol <- set_libPaths(lib.loc)
on.exit(set_libPaths(ol))
message(cmd)
system(cmd, intern=interactive())
}
R.CMD <- function(cmd, ...){
R.exec('CMD ', cmd, ' ', ...)
}
R.SHLIB <- function(libname, ...){
R.CMD('SHLIB', '-o ', libname, .Platform$dynlib.ext, ...)
}
compile_src <- function(pkg=NULL, load=TRUE){
if( !is.null(pkg) ){
p <- as.package(pkg)
path <- p$path
}else{
pkg <- packageName()
path <- packagePath(lib=NA)
}
owd <- getwd()
on.exit(setwd(owd))
srcdir <- file.path(path, 'src')
message("
if( !file.exists(srcdir) ){
message("NO")
} else {
message("YES")
message("
setwd(srcdir)
Sys.setenv(R_PACKAGE_DIR=path)
R.SHLIB(pkg, " *.cpp ")
message("
if( load ){
if( existsFunction('load_dll', where='package:devtools') ){
f <- getFunction('load_dll', where='package:devtools')
f(pkg)
}else{
f <- getFunction('load_c', where='package:devtools')
f(pkg)
}
}
}
}
packageEnv <- function(pkg, skip=FALSE, verbose=FALSE){
if( !missing(pkg) && !is.null(pkg) ){
env <- if( is.environment(pkg) ) topenv(pkg)
else if( isLoadingNamespace(pkg) ) getLoadingNamespace(env=TRUE)
else if( !is.null(path.package(pkg, quiet=TRUE)) ) asNamespace(pkg)
else if( isNamespaceLoaded(pkg) ) asNamespace(pkg)
else if( pkg %in% search() ) as.environment(pkg)
else as.environment(str_c('package:', pkg))
return(env)
}
envir = parent.frame()
pkgmakerEnv <- topenv()
n <- 1
skipEnv <- pkgmakerEnv
while( identical(e <- topenv(envir), skipEnv)
&& !identical(e, emptyenv())
&& !identical(e, .GlobalEnv) ){
if( verbose > 1 ) print(e)
n <- n + 1
envir <- parent.frame(n)
}
if( !skip ){
if( identical(e, .BaseNamespaceEnv) ){
if( verbose ) message("packageEnv - Inferred ", str_ns(skipEnv))
return( skipEnv )
}
if( verbose ) message("packageEnv - Detected ", str_ns(e))
return(e)
}
if( verbose > 1 ) message("Skipping ", str_ns(skipEnv))
skipEnv <- e
while( identical(e <- topenv(envir), skipEnv)
&& !identical(e, emptyenv())
&& !identical(e, .GlobalEnv) ){
if( verbose > 1 ) print(e)
n <- n + 1
envir <- parent.frame(n)
}
if( identical(e, .BaseNamespaceEnv) ){
if( verbose ) message("packageEnv - Inferred ", str_ns(skipEnv))
return( skipEnv )
}
if( verbose ) message("packageEnv - Detected ", str_ns(e))
return(e)
}
topns_name <- function(n=1L, strict=TRUE, unique=TRUE){
if( n==1L && !is.null(ns <- getLoadingNamespace()) ){
return(ns)
}
nf <- sys.nframe()
i <- 0
res <- character()
while( i <= nf && length(res) < n ){
e <- sys.frame(i)
if( !strict || !identical(e, .GlobalEnv) ){
pkg <- methods::getPackageName(e, create=FALSE)
if( pkg != '' ){
res <- c(res, pkg)
}
}
i <- i + 1
}
if( !length(res) ){
e <- packageEnv(skip=TRUE)
if( isNamespace(e) ){
res <- methods::getPackageName(e)
}else{
return('')
}
}
if( unique || n==1L ) res <- match.fun('unique')(res)
if( length(res) || n>1L ) res else ''
}
topns <- function(strict=TRUE){
ns <- topns_name(n=1L, strict=strict)
if( ns == '.GlobalEnv' ) return( .GlobalEnv )
else if( nchar(ns) ) asNamespace(ns)
}
packageName <- function(envir=packageEnv(), .Global=FALSE, rm.prefix=TRUE){
if( is.null(envir) ) envir <- packageEnv()
if( is.character(envir) ){
return( sub("^package:", "", envir) )
}
e <- envir
nm <- environmentName(e)
if( identical(e, .GlobalEnv) && .Global ) return(nm)
else if( isNamespace(e) || identical(e, baseenv()) ) return(nm)
else if( grepl("^package:", nm) ){
if( rm.prefix )
nm <- sub("^package:", "", nm)
return(nm)
}
if( exists('.packageName', e) && .packageName != 'datasets' ){
if( .packageName != '' )
return(.packageName)
}
info <- getLoadingNamespace(info=TRUE)
if( !is.null(info) )
info$pkgname
else{
stop("Could not reliably determine package name [", nm, "]")
}
}
str_ns <- function(envir=packageEnv()){
if( !is.environment(envir) )
stop("Invalid argument: must be an environment [", class(envir), ']')
str_c(if( isNamespace(envir) ) 'namespace' else 'environment',
" '", packageName(envir, rm.prefix=FALSE), "'")
}
packagePath <- function(..., package=NULL, lib.loc=NULL, check = TRUE){
pname <- packageName(package)
path <- NULL
if( !is.null(info <- getLoadingNamespace(info=TRUE)) && info$pkgname == pname ){
path <- info$path
}else {
path <- find.package(package=pname, lib.loc=lib.loc, quiet=TRUE)
}
if( !length(path) || path == '' ){
if( !is.null(info <- getLoadingNamespace(info=TRUE)) ){
path <- info$path
}
}
if( !length(path) || !nzchar(path) ){
if( check ) stop("Could not find path to package ", package)
return(NULL)
}
if( isDevNamespace(pname) ){
dots <- list(...)
Rdirs <- c('data', 'R', 'src', 'exec', 'tests', 'demo'
, 'exec', 'libs', 'man', 'help', 'html'
, 'Meta')
if( length(dots) && !sub("^/?([^/]+).*", "\\1", ..1) %in% Rdirs)
path <- file.path(path,'inst')
}
file.path(path, ...)
}
isPackageInstalled <- function(..., lib.loc=NULL){
inst <- utils::installed.packages(lib.loc=lib.loc)
pattern <- '^([a-zA-Z.]+)(_([0-9.]+)?)?$';
res <- sapply(list(...), function(p){
vers <- gsub(pattern, '\\3', p)
print(vers)
pkg <- gsub(pattern, '\\1', p)
print(pkg)
if( !(pkg %in% rownames(inst)) ) return(FALSE);
p.desc <- inst[pkg,]
if( (vers != '') && compareVersion(vers, p.desc['Version']) > 0 ) return(FALSE);
TRUE
})
all(res)
}
as_package <- function(x, ..., quiet=FALSE, extract=FALSE){
if( !requireNamespace('devtools', quietly = TRUE) )
stop("Package 'devtools' is required to load development packages")
if( is.null(x) ) return( devtools::as.package() )
if( devtools::is.package(x) ) return(x)
if( extract && grepl("\\.tar\\.gz$", x) ){
tmp <- tempfile(x)
on.exit( unlink(tmp, recursive=TRUE) )
pkg <- basename(sub("_[0-9.]+\\.tar\\.gz$", '', x))
desc <- file.path(pkg, 'DESCRIPTION')
untar(x, desc, exdir=tmp)
return(devtools::as.package(file.path(tmp, pkg)))
} else {
if( grepl('^package:', x) ){
libs <- .libPaths()
pkg <- sub('^package:', '', x)
p <- lapply(libs, find.package, package=pkg, quiet=TRUE, verbose=FALSE)
p <- unlist(p[sapply(p, length)>0])
if( !length(p) ){
if( !quiet )
stop("Could not find installed package ", pkg)
return()
}
x <- p[1L]
}
}
res <- try(devtools::as.package(x), silent=TRUE)
if( !is(res, 'try-error') )
return(res)
if( length(res <- find.package(package=x, quiet=TRUE)) )
return(devtools::as.package(res))
if( quiet )
stop("Could not find package ", x)
NULL
}
as.package <- as_package
NotImplemented <- function(msg){
stop("Not implemented - ", msg)
}
packageData <- function(list, envir = .GlobalEnv, ..., options = NULL, stringsAsFactors = getOption('stringsAsFactors')){
if( is.null(stringsAsFactors) ){
stringsAsFactors <- testRversion("<=3.6.3")
}
if( !length(options) ){
options <- setNames(list(1), tempfile())
}
withr::with_options(options, {
if( missing(list) ) return( data(..., envir=envir) )
data(list=list, ..., envir = envir)
.get <- function(x, envir, ...){
res <- get(x, ..., envir = envir)
if( !stringsAsFactors && is.data.frame(res) ){
for(n in colnames(res)[sapply(res, is.factor)]){
res[[n]] <- as.character(res[[n]])
}
}
assign(x, value = res, envir = envir)
res
}
if( length(list) == 1L ) .get(list, envir=envir)
else sapply(list, .get, envir=envir, simplify=FALSE)
})
}
ldata <- function(list, ..., package = NULL, error = TRUE, simplify = TRUE){
if( missing(list) ) list <- NULL
assert_that(is.null(list) || (is.vector(list) && is.character(list))
, msg = "Invalid argument 'list': value must be NULL or a character vector.")
assert_that(is.null(package) || isNZString(package), msg = "Invalid argument 'package': value must be NULL or a non-empty string.")
assert_that(is.scalar(error) && is.logical(error), msg = "Invalid argument 'error': value must be a single logical.")
assert_that(is.scalar(simplify) && is.logical(simplify), msg = "Invalid argument 'simplify': value must be a single logical.")
if( is.null(package) || qrequire(package, character.only = TRUE) ){
dlist <- list.data(package = package)[["data"]]
}else{
msg <- sprintf("Could not find data objects %s in package '%s': package not found.", str_out(list, Inf), package)
if( error ) stop(msg)
else warning(msg)
dlist <- character()
}
if( !missing(list) || length(list) ){
dlist <- dlist[dlist %in% list]
}
if( !error ){
res <- sapply(list, function(x) NULL, simplify = FALSE)
list <- intersect(list, dlist)
}
e <- parent.frame()
res_data <- sapply(list, function(l) packageData(list=l, ..., envir=e, package = package), simplify = FALSE)
if( error ){
if( simplify && length(res_data) == 1L ) res_data <- res_data[[1L]]
return(res_data)
}else{
if( length(miss <- setdiff(names(res), names(res_data))) ){
pkg_str <- "in the currently loaded packages"
if( !is.null(package) ) pkg_str <- paste0("in package ", package)
warning(sprintf("Could not find data object(s) %s: %s", pkg_str, str_out(miss, Inf)))
}
for(n in names(res_data)){
res[[n]] <- res_data[[n]]
}
if( simplify && length(res) == 1L ) res <- res[[1L]]
res
}
}
list.data <- function(package = NULL){
dlist <- data(package = package)[["results"]]
m <- str_match(dlist[, "Item"], "^(([^(]+)|(([^(]+)\\(([^)]+)\\)))$")
key <- ifelse(!is.na(m[, 3L]), m[, 3L], m[, 6L])
stopifnot(!anyNA(key))
obj_name <- ifelse(!is.na(m[, 3L]), m[, 3L], m[, 5L])
stopifnot(!anyNA(obj_name))
data.frame(package = dlist[, "Package"], data = key, object = obj_name, stringsAsFactors = FALSE)
}
load_all_file <- function(path = path.package(package), package, dest = NULL){
if( !missing(path) && !missing(package) ){
stop("Arguments 'path' and 'package' are exclusive: only one of them can be provided.")
}
if( !requireNamespace('devtools', quietly = TRUE) )
stop("Package 'devtools' is required to load development package information.")
if( !missing(package) ) path <- path.package(package)
pkg <- devtools::as.package(path)
if( is.null(dest) ) dest <- tempfile(paste0("load_all_", pkg[["package"]], "_"), fileext = ".R")
cat(sprintf("
, date(), dest, pkg[["package"]], pkg[["path"]], pkg[["path"]])
, file = dest)
dest
} |
setClass("tskrrHeterogeneous",
contains = "tskrr",
slots = c(g = "eigen",
lambda.g = "numeric",
Hg = "matrix"),
prototype = list(lambda.g = 1e-4,
g = structure(list(vectors = matrix(0),
values = numeric(1)),
class = "eigen"),
Hg = matrix(0)
)
)
validTskrrHeterogeneous <- function(object){
if(length([email protected]) != 1)
return("lambda.g should be a single value")
else if([email protected] && !valid_dimensions(object@y, object@Hk, object@Hg))
return("The dimensions of the original kernel matrices and the observations don't match.")
else if(
(length(object@labels$k) == 1 && !is.na(object@labels$k)) &&
(length(object@labels$k) != nrow(object@y))
)
return("The labels element k should either be NA or a character vector with the same number of values as there are rows in the Y matrix.")
else if(
(length(object@labels$g) == 1 && !is.na(object@labels$g)) &&
(length(object@labels$g) != ncol(object@y))
)
return("The labels element g should either be NA or a character vector with the same number of values as there are columns in the Y matrix.")
else
return(TRUE)
}
setValidity("tskrrHeterogeneous", validTskrrHeterogeneous) |
pamward <- function(diss, k=3, method="ward", dist) {
TraMineR.check.depr.args(alist(diss = dist))
if (!inherits(diss, "dist")) {
if (!isSymmetric(diss)) stop("diss should be a dist object or a symmetric matrix")
diss <- as.dist(diss)
}
clustw <- agnes(diss, diss=T, method=method)
clw <- cutree(clustw, k=k)
centers <- disscenter(diss, group=clw, medoids.index="first")
return <- pam(diss, diss=T, k=k, medoids=centers)
} |
params <-
list(EVAL = TRUE)
stopifnot(require(knitr))
opts_chunk$set(
comment=NA,
eval = if (isTRUE(exists("params"))) params$EVAL else FALSE,
dev = "png",
dpi = 150,
fig.asp = 0.618,
fig.width = 5,
out.width = "60%",
fig.align = "center"
)
library("rstanarm")
library("bayesplot")
library("loo")
data(roaches)
str(roaches)
roaches$roach1 <- roaches$roach1 / 100
fit1 <-
stan_glm(
formula = y ~ roach1 + treatment + senior,
offset = log(exposure2),
data = roaches,
family = poisson(link = "log"),
prior = normal(0, 2.5, autoscale = TRUE),
prior_intercept = normal(0, 5, autoscale = TRUE),
seed = 12345
)
loo1 <- loo(fit1, save_psis = TRUE)
print(loo1)
plot(loo1)
yrep <- posterior_predict(fit1)
ppc_loo_pit_overlay(
y = roaches$y,
yrep = yrep,
lw = weights(loo1$psis_object)
)
fit2 <- update(fit1, family = neg_binomial_2)
loo2 <- loo(fit2, save_psis = TRUE, cores = 2)
print(loo2)
plot(loo2, label_points = TRUE)
if (any(pareto_k_values(loo2) > 0.7)) {
loo2 <- loo(fit2, save_psis = TRUE, k_threshold = 0.7)
}
print(loo2)
yrep <- posterior_predict(fit2)
ppc_loo_pit_overlay(roaches$y, yrep, lw = weights(loo2$psis_object))
loo_compare(loo1, loo2) |
cggm <- function(object, GoF = AIC, lambda.id, rho.id, tp.min = 1.0E-6, ntp = 100L, maxit.em = 1.0E+4, thr.em = 1.0E-3, maxit.bcd = 1.0E+5,
thr.bcd = 1.0E-4, trace = 0L, ...){
this.call <- match.call()
if (!inherits(object, "cglasso")) stop(sQuote("object"), " is not an object of class ", sQuote("cglasso"))
Z <- object$Z
n <- nobs(Z)
p <- nresp(Z)
q <- npred(Z)
if (missing(lambda.id) & missing(rho.id)) {
if (!is.element(class(GoF), c("function", "GoF")))
stop (sQuote("GoF"), " is not either a goodness-of-fit function (AIC or BIC) neither an object of class ", sQuote("GoF"))
dots <- list(...)
if (is.function(GoF)) {
if (is.null(dots$type)) dots$type <- ifelse(q == 0L, "FD", "CC")
GoF.name <- deparse(substitute(GoF))
if (!is.element(GoF.name, c("AIC", "BIC")))
stop(sQuote(GoF.name), " is not a valid function. Please, use ", sQuote("AIC"), " or ", sQuote("BIC"))
GoF <- switch(GoF.name,
AIC = do.call(function(...) AIC(object, ...), dots),
BIC = do.call(function(...) BIC(object, ...), dots))
}
object <- select.cglasso(object, GoF = GoF)
nlambda <- object$nlambda
lambda.id <- 1L
nrho <- object$nrho
rho.id <- 1L
} else {
nlambda <- object$nlambda
if (missing(lambda.id)) {
if (q == 0 | nlambda == 1L) lambda.id <- 1L
else stop(sQuote("lambda.id"), " is missing")
} else {
if (!is.vector(lambda.id)) stop(sQuote("lambda.id"), " is not a vector")
if (length(lambda.id) != 1L) stop(sQuote("lambda.id"), " is not a vector of length ", sQuote("1"))
if (any(abs(as.integer(lambda.id) - lambda.id) > 0)) stop(sQuote("lambda.id"), " is not an object of type ", dQuote("integer"))
if (lambda.id <= 0) stop(sQuote("lambda.id"), " is not a positive integer")
if (lambda.id > nlambda) stop("some entry in ", sQuote("lambda.id"), " is larger than ", sQuote(nlambda))
}
nrho <- object$nrho
if (missing(rho.id)) {
if (nrho == 1L) rho.id <- 1L
else stop(sQuote("rho.id"), " is missing")
}
else {
if (!is.vector(rho.id)) stop(sQuote("rho.id"), " is not a vector")
if (length(rho.id) != 1L) stop(sQuote("rho.id"), " is not a vector of length ", sQuote("1"))
if (any(abs(as.integer(rho.id) - rho.id) > 0)) stop(sQuote("rho.id"), " is not an object of type ", dQuote("integer"))
if (rho.id <= 0L) stop(sQuote("rho.id"), " is not a positive integer")
if (rho.id > nrho) stop("some entry in ", sQuote("rho.id"), " is larger than ", sQuote(nrho))
}
}
if (!is.vector(tp.min)) stop(sQuote("tp.min"), " is not a vector")
if (length(tp.min) != 1L) stop(sQuote("tp.min"), " is not a vector of length ", sQuote("1"))
if (tp.min < 0L) stop(sQuote("tp.min"), " is not a positive value")
if (!is.vector(ntp)) stop(sQuote("ntp"), " is not a vector")
if (length(ntp) != 1L) stop(sQuote("ntp"), " is not a vector of length ", sQuote("1"))
if (any(abs(as.integer(ntp) - ntp) > 0)) stop(sQuote("ntp"), " is not an object of type ", dQuote("integer"))
if (ntp <= 0L) stop(sQuote("ntp"), " is not a positive integer")
if (!is.vector(maxit.em)) stop(sQuote("maxit.em"), " is not a vector")
if (length(maxit.em) != 1) stop(sQuote("maxit.em"), " is not an object of length ", sQuote(1))
if (abs(as.integer(maxit.em) - maxit.em) > 0) stop(sQuote("maxit.em"), " is not an object of type ", dQuote("integer"))
if (maxit.em <= 0) stop(sQuote("maxit.em"), " is not a positive integer")
if (!is.vector(thr.em)) stop(sQuote("thr.em"), " is not a vector")
if (length(thr.em) != 1) stop(sQuote("thr.em"), " is not an object of length ", sQuote(1))
if (thr.em <= 0 ) stop(sQuote("thr.em"), " is not a positive value")
if (!is.vector(maxit.bcd)) stop(sQuote("maxit.bcd"), " is not a vector")
if (length(maxit.bcd) != 1) stop(sQuote("maxit.bcd"), " is not an object of length ", sQuote(1))
if (abs(as.integer(maxit.bcd) - maxit.bcd) > 0) stop(sQuote("maxit.bcd"), " is not an object of type ", dQuote("integer"))
if (maxit.bcd <= 0) stop(sQuote("maxit.bcd"), " is not a positive integer")
if (!is.vector(thr.bcd)) stop(sQuote("thr.bcd"), " is not a vector")
if (length(thr.bcd) != 1) stop(sQuote("thr.bcd"), " is not an object of length ", sQuote(1))
if (thr.bcd <= 0 ) stop(sQuote("thr.bcd"), " is not a positive value")
if (!is.vector(trace)) stop(sQuote("trace"), " is not a vector")
if (length(trace) != 1) stop(sQuote("trace"), " is not an object of length ", sQuote(1))
if (is.logical(trace)) stop(sQuote("trace"), " is not an object of type ", dQuote("integer"))
if (abs(as.integer(trace) - trace) > 0) stop(sQuote("trace"), " is not an object of type ", dQuote("integer"))
if (!is.element(trace, c(0L, 1L, 2L))) stop("not allowed value in ", sQuote("trace"), ". Please, choice ", sQuote("0"), ", ", sQuote("1"), " or ", sQuote("2"))
pendiag <- object$diagonal
lambda.max <- object$lambda[lambda.id]
lambda.min <- object$lambda[nlambda]
rho.max <- object$rho[rho.id]
rho.min <- object$rho[nrho]
B.ini <- object$B[, , lambda.id, rho.id]
if (is.vector(B.ini)) B.ini <- t(B.ini)
if (q > 0L) {
mask.B <- B.ini[-1L, ]
mask.B[abs(mask.B) > 0] <- 1
} else mask.B <- NULL
Tht.ini <- object$Tht[, , lambda.id, rho.id]
mask.Tht <- Tht.ini
mask.Tht[abs(mask.Tht) > 0] <- 1
row.order <- Z$Info$order
Yipt.ini <- object$Yipt[row.order, , lambda.id, rho.id]
mu.ini <- object$mu[row.order, , lambda.id, rho.id]
R.ini <- object$R[row.order, , lambda.id, rho.id]
S.ini <- object$S[, , lambda.id, rho.id]
Sgm.ini <- object$Sgm[, , lambda.id, rho.id]
tp.min <- max(min(tp.min, lambda.min, rho.min), 1e-13)
out <- cggm.fit(Z = Z, pendiag = pendiag, lambda.max = lambda.max, rho.max = rho.max, tp.min = tp.min,
ntp = ntp, mask.B = mask.B, mask.Tht = mask.Tht, Yipt.ini = Yipt.ini, B.ini = B.ini,
mu.ini = mu.ini, R.ini = R.ini, S.ini = S.ini, Sgm.ini = Sgm.ini, Tht.ini = Tht.ini,
maxit.em = maxit.em, thr.em = thr.em, maxit.bcd = maxit.bcd, thr.bcd = thr.bcd,
trace = trace)
InfoStructure <- list(Adj_yy = object$InfoStructure$Adj_yy[, , lambda.id, rho.id, drop = FALSE], ncomp = object$InfoStructure$ncomp[lambda.id, rho.id, drop = FALSE],
Ck = object$InfoStructure$Ck[, lambda.id, rho.id, drop = FALSE], pk = object$InfoStructure$pk[, lambda.id, rho.id, drop = FALSE],
Adj_xy = object$InfoStructure$Adj_xy[, , lambda.id, rho.id, drop = FALSE])
out.cggm <- list(call = this.call, Yipt = out$Yipt, B = out$B, mu = out$mu, R = out$R, S = out$S, Sgm = out$Sgm, Tht = out$Tht,
dfB = object$dfB[, lambda.id, rho.id, drop = FALSE], dfTht = object$dfTht[lambda.id, rho.id, drop = FALSE],
InfoStructure = InfoStructure, nit = out$nit, Z = Z, nlambda = 1L, lambda = lambda.max, nrho = 1L,
rho = rho.max, maxit.em = maxit.em, thr.em = thr.em, maxit.bcd = maxit.bcd, thr.bcd = thr.bcd,
conv = out$conv, subrout = out$subrout, trace = trace, nobs = object$n, nresp = object$nresp, npred = object$npred)
class(out.cggm) <- c("cggm", "cglasso")
out.cggm
}
cggm.fit <- function(Z, pendiag, lambda.max, rho.max, tp.min, ntp, mask.B, mask.Tht, Yipt.ini, B.ini,
mu.ini, R.ini, S.ini, Sgm.ini, Tht.ini, maxit.em, thr.em, maxit.bcd, thr.bcd, trace) {
n <- nobs(Z)
p <- nresp(Z)
q <- npred(Z)
Y <- getMatrix(Z, "Y", ordered = TRUE)
Y[is.na(Y)] <- 0
X <- getMatrix(Z, "X", ordered = TRUE)
if (!is.null(X)) X <- as.matrix(X)
ynames <- colnames(Y)
xnames <- colnames(X)
yrnames <- rownames(Y)
ym <- ColMeans(Z)$Y
yv <- ColVars(Z)$Y
names(ym) <- NULL
names(yv) <- NULL
lo <- Z$Info$lo
up <- Z$Info$up
Id <- event(Z, ordered = TRUE)
InfoP <- Z$Info$Pattern
nP <- dim(InfoP)[1L]
tp_lab <- paste0("tp", seq_len(ntp))
lambda <- seq(from = lambda.max, to = tp.min, length = ntp)
rho <- seq(from = rho.max, to = tp.min, length = ntp)
B <- array(0, dim = c(q + 1L, p, 1L, 1L), dimnames = list(coef = c("Int.", xnames), response = ynames, lambda = "lmb", rho = "rho"))
B[, , 1L, 1L] <- B.ini
Yipt <- array(0, dim = c(n, p, 1L, 1L), dimnames = list(yrnames, response = ynames, lambda = "lmb", rho = "rho"))
Yipt[, , 1L, 1L] <- Yipt.ini
mu <- array(0, dim = c(n, p, 1L, 1L), dimnames = list(yrnames, response = ynames, lambda = "lmb", rho = "rho"))
mu[, , 1L, 1L] <- mu.ini
R <- array(0, dim = c(n, p, 1L, 1L), dimnames = list(yrnames, response = ynames, lambda = "lmb", rho = "rho"))
R[, , 1L, 1L] <- R.ini
S <- array(0, dim = c(p, p, 1L, 1L), dimnames = list(response = ynames, response = ynames, lambda = "lmb", rho = "rho"))
S[, , 1L, 1L] <- S.ini
Sgm <- array(0, dim = c(p, p, 1L, 1L), dimnames = list(response = ynames, response = ynames, lambda = "lmb", rho = "rho"))
Sgm[, , 1L, 1L] <- Sgm.ini
Tht <- array(0, dim = c(p, p, 1L, 1L), dimnames = list(response = ynames, response = ynames, lambda = "lmb", rho = "rho"))
Tht[, , 1L, 1L] <- Tht.ini
nit <- array(0L, dim = c(2L, ntp), dimnames = list(steps = c("EM", "nit"), tp = tp_lab))
storage.mode(n) <- "integer"
storage.mode(p) <- "integer"
storage.mode(Y) <- "double"
storage.mode(Id) <- "integer"
storage.mode(nP) <- "integer"
storage.mode(InfoP) <- "integer"
storage.mode(lo) <- "double"
storage.mode(up) <- "double"
storage.mode(ym) <- "double"
storage.mode(yv) <- "double"
storage.mode(pendiag) <- "integer"
storage.mode(mask.Tht) <- "double"
storage.mode(ntp) <- "integer"
storage.mode(rho) <- "double"
storage.mode(maxit.em) <- "integer"
storage.mode(thr.em) <- "double"
storage.mode(maxit.bcd) <- "integer"
storage.mode(thr.bcd) <- "double"
storage.mode(Yipt) <- "double"
storage.mode(B) <- "double"
storage.mode(mu) <- "double"
storage.mode(R) <- "double"
storage.mode(S) <- "double"
storage.mode(Sgm) <- "double"
storage.mode(Tht) <- "double"
storage.mode(nit) <- "integer"
conv <- integer(1)
subrout <- integer(1)
storage.mode(trace) <- "integer"
if (q == 0L) {
out <- .Fortran(C_cggm_v1, n = n, p = p, Y = Y, Id = Id, nP = nP, InfoP = InfoP, lo = lo, up = up,
ym = ym, yv = yv, pendiag = pendiag, wTht = mask.Tht, ntp = ntp, rho = rho,
maxit_em = maxit.em, thr_em = thr.em, maxit_bcd = maxit.bcd, thr_bcd = thr.bcd,
Yipt = Yipt, B = B, mu = mu, R = R, S = S, Sgm = Sgm, Tht = Tht, nit = nit,
conv = conv, subrout = subrout, trace = trace)
out$subrout <- switch(as.character(out$subrout),
"0" = "",
"1" = "e_step",
"2" = "glassosub",
"3" = "cggm_v1")
}
else {
storage.mode(q) <- "integer"
storage.mode(X) <- "double"
storage.mode(mask.B) <- "double"
storage.mode(lambda) <- "double"
out <- .Fortran(C_cggm_v2, n = n, q = q, X = X, p = p, Y = Y, Id = Id, nP = nP, InfoP = InfoP,
lo = lo, up = up, ym = ym, yv = yv, wB = mask.B, pendiag = pendiag, wTht = mask.Tht ,
ntp = ntp, lambda = lambda ,rho = rho, maxit_em = maxit.em, thr_em = thr.em,
maxit_bcd = maxit.bcd, thr_bcd = thr.bcd, Yipt = Yipt, B = B, mu = mu, R = R, S = S,
Sgm = Sgm, Tht = Tht, nit = nit, conv = conv, subrout = subrout, trace = trace)
out$subrout <- switch(as.character(out$subrout),
"0" = "",
"1" = "e_step",
"2" = "multilasso",
"3" = "glassosub",
"4" = "cggm_v2")
}
row.order <- order(Z$Info$order)
out$Yipt <- out$Yipt[row.order, , , , drop = FALSE]
out$mu <- out$mu[row.order, , , , drop = FALSE]
out$R <- out$R[row.order, , , , drop = FALSE]
out$conv <- switch(as.character(out$conv),
"-1" = "memory allocation error",
"0" = "Ok",
"1" = "maximum number of iterations has been exceeded",
"2" = "error in E-step",
"3" = "matrix inversion failed")
out
} |
rkt_ecdf <- function(x, w) {
if (missing(w)) {
df <- data.table(x)
df <- df[, .(w = .N), keyby = x]
} else if (is.numeric(w) && any(duplicated(x))) {
df <- data.table(x, w)
df <- df[, .(w = sum(w)), keyby = x]
} else if (is.numeric(w)) {
df <- data.table(x, w)
df <- df[order(x)]
} else {
stop("\"w\" needs to be numeric")
}
df <- df[!is.na(x) & w > 0]
total <- sum(df$w)
stopifnot(total > 0)
df[, y := cumsum(w) / total]
out <- approxfun(df$x, df$y,
method = "constant",
yleft = 0,
yright = 1,
f = 0,
ties = "ordered")
class(out) <- c("rkt_ecdf", class(out))
attr(out, "singularities") <- df$x
out
}
print.rkt_ecdf <- function(x, ...) {
cat(".:: ROCket ECDF Object \n")
cat("Class:", class(x), "\n")
}
mean.rkt_ecdf <- function(x, ...) {
weighted.mean(environment(x)$x, get_jumps(x))
}
variance.rkt_ecdf <- function(x, ...) {
weighted.mean((environment(x)$x - mean(x))^2, get_jumps(x))
}
plot.rkt_ecdf <- function(x, ...) {
inargs <- list(...)
outargs <- list(f = x,
ylim = c(0, 1),
xlab = expression(x),
ylab = expression(F[n](x)),
main = 'ECDF',
draw_area = FALSE,
h = c(0, 1))
outargs[names(inargs)] <- inargs
do.call(plot_function, outargs)
invisible()
} |
ml_print_uid <- function(x) cat(paste0("<", x$uid, ">"), "\n")
ml_print_class <- function(x, type) {
type <- if (is_ml_estimator(x)) {
"Estimator"
} else if (is_ml_transformer(x)) {
"Transformer"
} else {
class(x)[1]
}
cat(ml_short_type(x), paste0("(", type, ")\n"))
}
ml_print_column_name_params <- function(x) {
cat(" (Parameters -- Column Names)\n")
out_names <- ml_param_map(x) %>%
names() %>%
grep("col|cols$", ., value = TRUE)
for (param in sort(out_names)) {
cat(paste0(
" ", param, ": ",
paste0(ml_param(x, param), collapse = ", "),
"\n"
))
}
}
ml_print_params <- function(x) {
cat(" (Parameters)\n")
out_names <- ml_param_map(x) %>%
names() %>%
grep(".*(?<!col|cols)$", ., value = TRUE, perl = TRUE)
for (param_name in sort(out_names)) {
value <- ml_param(x, param_name, allow_null = TRUE)
param_output <- switch(
class(value)[[1]],
spark_jobj = paste0("jobj of class ", jobj_class(value)[[1]]),
NULL = "null",
paste0(value, collapse = ", ")
)
cat(paste0(" ", param_name, ": ", param_output, "\n"))
}
}
ml_print_transformer_info <- function(x) {
items <- names(x) %>%
setdiff(c("uid", "param_map", "summary", ".jobj")) %>%
grep(".*(?<!col|cols)$", ., value = TRUE, perl = TRUE)
if (length(Filter(length, x[items]))) {
cat(" (Transformer Info)\n")
for (item in sort(items)) {
if (!rlang::is_null(x[[item]])) {
if (rlang::is_atomic(x[[item]])) {
cat(paste0(" ", item, ": ", capture.output(str(x[[item]]))), "\n")
} else {
cat(paste0(" ", item, ": <", class(x[[item]])[1], ">"), "\n")
}
}
}
}
}
print_newline <- function() {
cat("", sep = "\n")
}
ml_model_print_residuals <- function(model,
residuals.header = "Residuals") {
residuals <- model$summary$residuals %>%
(function(x) if (is.function(x)) x() else x) %>%
spark_dataframe()
count <- invoke(residuals, "count")
limit <- 1E5
isApproximate <- count > limit
column <- invoke(residuals, "columns")[[1]]
values <- if (isApproximate) {
fraction <- limit / count
residuals %>%
invoke("sample", FALSE, fraction) %>%
sdf_read_column(column) %>%
quantile()
} else {
residuals %>%
sdf_read_column(column) %>%
quantile()
}
names(values) <- c("Min", "1Q", "Median", "3Q", "Max")
header <- if (isApproximate) {
paste(residuals.header, "(approximate):")
} else {
paste(residuals.header, ":", sep = "")
}
cat(header, sep = "\n")
print(values, digits = max(3L, getOption("digits") - 3L))
invisible(values)
}
ml_model_print_coefficients <- function(model) {
coef <- coefficients(model)
cat("Coefficients:", sep = "\n")
print(coef)
invisible(coef)
}
ml_model_print_coefficients_detailed <- function(model) {
columns <- c("coefficients", "standard.errors", "t.values", "p.values")
values <- as.list(model[columns])
for (value in values) {
if (is.null(value)) {
return(ml_model_print_coefficients(model))
}
}
matrix <- do.call(base::cbind, values)
colnames(matrix) <- c("Estimate", "Std. Error", "t value", "Pr(>|t|)")
cat("Coefficients:", sep = "\n")
stats::printCoefmat(matrix)
}
ml_model_print_centers <- function(model) {
centers <- model$centers
if (is.null(centers)) {
return()
}
cat("Cluster centers:", sep = "\n")
print(model$centers)
} |
tw_get_messages_list <- function(page = 0, page_size = 50){
base_url <- "https://api.twilio.com/"
ua <- user_agent("https://github.com/seankross/twilio")
path <- paste("2010-04-01", "Accounts", get_sid(), "Messages.json", sep = "/")
url <- modify_url(base_url, path = path, query = list(page = page, pagesize = page_size))
resp <- GET(url, ua, authenticate(get_sid(), get_token()))
if(http_type(resp) != "application/json"){
stop("Twilio API did not return JSON.", call. = FALSE)
}
parsed <- fromJSON(content(resp, "text", encoding = "UTF-8"), simplifyVector = FALSE)
check_status(resp)
structure(
map(parsed$messages, twilio_message),
class = "twilio_messages_list"
)
} |
knitr::opts_chunk$set(collapse = TRUE, comment = "
require(bit)
.ff.version <- try(packageVersion("ff"), silent = TRUE)
.ff.is.available <- !inherits(.ff.version, "try-error") && .ff.version >= "4.0.0" && require(ff)
logical()
bit()
bitwhich()
logical(3)
bit(3)
bitwhich(3)
bitwhich(3, TRUE)
bitwhich(3, 2)
bitwhich(3, -2)
l <- logical(3)
length(l) <- 6
l
b <- bit(3)
length(b) <- 6
b
w <- bitwhich(3,2)
length(w) <- 6
w
w <- bitwhich(3,-2)
length(w) <- 6
w
l <- logical(3); l[6]
b <- bit(3); b[6]
w <- bitwhich(3); w[6]
l[6] <- NA; l
b[6] <- NA; b
w[6] <- NA; w
l[[6]]
b[[6]]
w[[6]]
l[[9]] <- TRUE
b[[9]] <- TRUE
w[[9]] <- TRUE
l
b
w
l <- c(FALSE, TRUE, FALSE)
i <- as.integer(l)
as.logical(i)
l <- c(FALSE, TRUE, FALSE)
w <- as.which(l)
w
as.logical(w)
l <- c(FALSE, TRUE, FALSE)
w <- which(l)
w
as.logical(w)
i <- c(7,3)
w <- as.which(i, maxindex=12)
w
as.integer(w)
r <- ri(1, 2^16, 2^20)
all.as <- list(
double = as.double
, integer= as.integer
, logical = as.logical
, bit = as.bit
, bitwhich = as.bitwhich
, which = as.which
, ri = function(x)x
)
all.types <- lapply(all.as, function(f)f(r))
sapply(all.types, object.size)
all.comb <- vector('list', length(all.types)^2)
all.id <- rep(NA, length(all.types)^2)
dim(all.comb) <- dim(all.id) <- c(from=length(all.types), to=length(all.types))
dimnames(all.comb) <- dimnames(all.id) <- list(from= names(all.types) , to= names(all.types))
for (i in seq_along(all.types))
for (j in seq_along(all.as)){
all.comb[[i,j]] <- all.as[[j]](all.types[[i]])
all.id[i,j] <- identical(all.as[[i]](all.comb[[i,j]]), all.types[[i]])
}
all.id
data.frame(booltype=sapply(all.types, booltype), is.boolean=sapply(all.types, is.booltype), row.names=names(all.types))
x <- bit(1e6)
y <- x | c(FALSE, TRUE)
object.size(y) / object.size(x)
x <- bit(1e6)
y <- x | as.bit(c(FALSE, TRUE))
object.size(y) / object.size(x)
l <- logical(6)
b <- bit(6)
c(l,b)
c(b,l)
c(l, as.logical(b))
c(as.bit(l), b)
c.booltype(l, b)
b <- as.bit(c(FALSE,TRUE))
rev(b)
rep(b, 3)
rep(b, length.out=6)
l <- c(NA,NA,FALSE,TRUE,TRUE)
b <- as.bit(l)
length(b)
anyNA(b)
any(b)
all(b)
sum(b)
min(b)
max(b)
range(b)
summary(b)
min(c(FALSE,TRUE))
min.booltype(c(FALSE,TRUE))
b <- as.bit(sample(c(FALSE, TRUE), 1e6, TRUE))
summary(b,range=c(1,3e5))
sapply(chunk(b, by=3e5, method="seq"), function(i)summary(b, range=i))
sapply(chunk(b, by=3e5), function(i)summary(b, range=i))
x <- ff(vmode="single", length=length(b))
x[as.hi(b)] <- runif(sum(b))
summary(x[])
sapply(chunk(x, by=3e5), function(i)summary(x[i]))
sapply(chunk(x, by=3e5), function(i)summary(x[as.hi(b, range=i)]))
set.seed(1); n <- 9
x <- sample(n, replace=TRUE); x
y <- sample(n, replace=TRUE); y
x %in% y
bit_in(x,y)
bit_in(x,y, retFUN=as.logical)
x <- c(NA,NA,1L,1L,2L,3L)
duplicated(x)
bit_duplicated(x, retFUN=as.logical)
bit_duplicated(x, na.rm=NA, retFUN=as.logical)
duplicated(x, incomparables = NA)
bit_duplicated(x, na.rm=FALSE, retFUN=as.logical)
bit_duplicated(x, na.rm=TRUE, retFUN=as.logical)
x <- c(NA,NA,1L,1L,2L,3L)
unique(x)
bit_unique(x)
unique(x, incomparables = NA)
bit_unique(x, na.rm=FALSE)
bit_unique(x, na.rm=TRUE)
x <- c(NA,NA,1L,1L,3L)
y <- c(NA,NA,2L,2L,3L)
union(x,y)
bit_union(x,y)
x <- c(0L,NA,NA,1L,1L,3L)
y <- c(NA,NA,2L,2L,3L,4L)
intersect(x,y)
bit_intersect(x,y)
x <- c(0L,NA,NA,1L,1L,3L)
y <- c(NA,NA,2L,2L,3L,4L)
setdiff(x,y)
bit_setdiff(x,y)
x <- c(0L,NA,NA,1L,1L,3L)
y <- c(NA,NA,2L,2L,3L,4L)
union(setdiff(x,y),setdiff(y,x))
bit_symdiff(x,y)
x <- c(0L,NA,NA,1L,1L,3L)
y <- c(NA,NA,2L,2L,3L,4L)
setequal(y,x)
bit_setequal(x,y)
bit_rangediff(c(1L,7L), (3:5))
bit_rangediff(c(7L,1L), (3:5))
bit_rangediff(c(1L,7L), -(3:5), revy=TRUE)
bit_rangediff(c(1L,7L), -(3:5), revx=TRUE)
bit_rangediff(c(1L,7L), (1:7))
bit_rangediff(c(1L,7L), -(1:7))
bit_rangediff(c(1L,7L), (1:7), revy=TRUE)
(1:9)[-7]
bit_rangediff(c(1L,9L), -7L, revy=TRUE)
x <- c(NA,NA,1L,1L,2L,3L)
any(duplicated(x))
anyDuplicated(x)
any(bit_duplicated(x))
bit_anyDuplicated(x)
x <- c(NA,NA,1L,1L,2L,3L)
sum(duplicated(x))
sum(bit_duplicated(x))
bit_sumDuplicated(x)
x <- sample(9, 9, TRUE)
unique(sort(x))
sort(unique(x))
bit_sort_unique(x)
x <- sample(9, 9, TRUE)
sort(x)
bit_sort(x)
x = sample(12)
bit_sort(x)
merge_unique(bit_sort(x))
bit_sort_unique(x)
x = as.integer(c(3,4,4,5))
y = as.integer(c(3,4,5))
setequal(x,y)
merge_setequal(x,y)
merge_setequal(x,y, method="exact")
x = as.integer(c(0,1,2,2,3,3,3))
y = as.integer(c(1,2,3))
setdiff(x,y)
merge_setdiff(x,y)
merge_setdiff(x,y, method="exact")
merge_rangediff(c(0L,4L),y)
merge_rangediff(c(0L,4L),c(-3L,-2L))
merge_rangediff(c(0L,4L),c(-3L,-2L), revy=TRUE)
merge_rangediff(c(0L,4L),c(-3L,-2L), revx=TRUE)
x = -2:1
y = -1:2
setdiff(x,y)
union(setdiff(x,y),setdiff(y,x))
merge_symdiff(x,y)
merge_intersect(x,y)
merge_rangesect(c(-2L,1L),y)
x = as.integer(c(1,2,2,3,3,3))
y = 2:4
union(x,y)
merge_union(x,y, method="unique")
merge_union(x,y, method="exact")
merge_union(x,y, method="all")
sort(c(x,y))
c(x,y)
x = 2:4
y = as.integer(c(0,1,2,2,3,3,3))
match(x,y)
merge_match(x,y)
x %in% y
merge_in(x,y)
merge_notin(x,y)
x <- c(2L,4L)
merge_rangein(x,y)
merge_rangenotin(x,y)
x <- bit_sort(sample(1000,10))
merge_first(x)
merge_last(x)
merge_firstnotin(c(300L,600L), x)
merge_firstin(c(300L,600L), x)
merge_lastin(c(300L,600L), x)
merge_lastnotin(c(300L,600L), x) |
shinyBS::bsCollapse(
id = "collapsehelp",
open = "somtype",
shinyBS::bsCollapsePanel(
title = "Types of self-organizing maps",
value = "somtype",
style = "success",
p(
HTML(
"Different types of data require different types of maps
to analyze them. <a href='http://sombrero.r-forge.r-project.org/'>SOMbrero</a>
offers three types of algorithms, all based on the on-line (as opposed to batch)
SOM:
<ul>
<li><b>Numeric</b> is the standard self-organizing map, which uses numeric
variables only. The data is expected to contains variables in columns and observations
in rows. <br /> It can be applied, for instance,
to the four first variables of the <a href=
'http://nextcloud.nathalievilla.org/index.php/s/BWnWADSPxayGSGa'
>iris dataset</a>.</li>
<li><b>Korresp</b> applies the self-organizing algorithm to contingency tables
between two factors.<br /> For instance, in the supplied <a href=
'http://nextcloud.nathalievilla.org/index.php/s/Tw2H2ZBKwBAPo0v'
>dataset 'presidentielles 2002'</a>, which contains the results for the first
round of the 2002 French prensidential elections, columns represent presidential
candidates and rows represent the French districts called 'departements', so
that each cell contains the number of votes for a specific candidate in a
specific 'departement'.</li>
<li><b>Relational</b> is used for dissimilarity matrices, in which each cell
contains a measure of distance between two objects. For this method the data
must be a square numeric matrix, in which rows and columns represent the same
observations. The matrix must be symetric, contains only positive entries with a
null diagonal.<br />
For instance, the supplied <a href='http://nextcloud.nathalievilla.org/index.php/s/R2Vyt5Vkg3xlYPD'
>dataset 'Les Miserables'</a> contains the shortest path lengths between
characters of Victor Hugo's novel <I>Les Misérables</I> in the co-appearance
network provided <a href=
'http://www-personal.umich.edu/~mejn/netdata/lesmis.zip'>here</a>.</li>
</ul>"
)
)
),
shinyBS::bsCollapsePanel(
title = "Data loading",
value = "importdata",
style = "success",
p(
HTML(
"You can choose the data among your current environment
datasets (in the class data.frame or matrix). The three examples datasets
are automatically loaded so you can try the methods."
)
),
p(
HTML(
"Data also can be imported as a table, in text or csv format
(columns are separated by specific symbols such as spaces or semicolons (option
'Separator'). Row names can be included in the data set for better post-analyses
of the data (some of the plots will use these names). Check at the bottom of the
'Import Data' panel to see if the data have been properly imported. If not,
change the file importation options."
)
)
),
shinyBS::bsCollapsePanel(
title = "Training options",
value = "train",
style = "success",
p(
HTML(
"The default options in the 'Self-Organize' panel are set
according to the type of map and the size of the dataset, but you can modify the
options at will:
<ul>
<li><b>Topology:</b> choose the topology of the map (squared or hexagonal).</li>
<li><b>Input variables:</b> choose on which variables the map will be trained.</li>
<li><b>Map dimensions:</b> choose the number of rows (X) and columns (Y) of the
map, thus setting the number of prototypes. An advice value is to use the
square root of one tenth the number of observations.</li>
<li><b>Affectation type:</b> type of affectation used during the training.
Default type is 'standard', which corresponds to a hard affectation, and
the alternative is 'heskes', which is Heskes's soft affectation (see Heskes
(1999) for further details).</li>
<li><b>Max. iterations:</b> the number of iterations of the training process.
Default is five times the number of observations.</li>
<li><b>Distance type:</b> type of distance used to determine which prototypes of
the map are neighbors. Default type is 'Letremy' that was originally proposed in
the <a href='http://samos.univ-paris1.fr/Programmes-bases-sur-l-algorithme'>SAS
programs</a> by <a href='http://samm.univ-paris1.fr/-Patrick-Letremy-'> Patrick
Letremy</a> but all methods for 'dist' are also available.</li>
<li><b>Radius type:</b> neighborhood type used to determine which prototypes of
the map are neighbors. Default type is 'letremy' as originally
implemented in the <a
href='http://samos.univ-paris1.fr/Programmes-bases-sur-l-algorithme'>SAS
programs</a> by <a href='http://samm.univ-paris1.fr/-Patrick-Letremy-'> Patrick
Letremy</a> (it combines square and star-like neighborhoods along the learning)
but a Gaussian neighborhood can also be computed.</li>
<li><b>Data scaling:</b> choose how the data must be scaled before training.
Scaling is used to ensure all variables have the same importance during
training, regardless of absolute magnitude. 'none' means no scaling,
'center' means variables are shifted to have 0 mean, 'unitvar' means variables
are centered and divided by their standard deviation to ensure they all have
unit variance and 'χ<sup>2</sup>' is used by the 'Korresp' algorithm and
'cosine' is the dissimilarity transposition of the 'cosine' transformation
performed on kernels.</li>
<li><b>Random seed:</b> Set the seed for the pseudorandom number generator used
during the training. Be sure to remember the seed used for a training if you
want to reproduce your results exactly, because running the algorithm with
different seeds will result in different maps. By default the seed is itself set
randomly when the interface is launched.</li>
<li><b>Scaling value for gradient descent:</b> This is the 'step size' parameter
used during training to determine in what proportion a winning prototype is
shifted towards an observation.</li>
<li><b>Number of intermediate backups:</b> Number of times during training a
backup of the intermediate states of the map is saved. This can be used to
monitor the progress of the training. If no backup (values 0 or 1) is saved,
the energy plot is not available.</li>
<li><b>Prototype initialization method:</b> choose how the prototypes of the map
are initialized at the beginning of training algorithm.<br /> If 'random' is
chosen, prototypes will be given random values in the range of the data. If
'obs', each prototype will be initialized to a random observation in the data.
If 'pca', prototypes are chosen along the first two PC of a PCA. Advised values
are 'random' for the 'Numeric' and the 'Korresp' algorithm and 'obs' for the
'Relational' algorithm.</li>
</ul>"
)
)
),
shinyBS::bsCollapsePanel(
title = "Types of plots",
value = "plots",
style = "success",
p(
HTML(
"Sombrero offers many different plots to analyze your
data's topology using the self-organizing map. <br />There are two main choices
of what to plot (in the plot and superclass panels): plotting <b> prototypes
</b> uses the values of the neurons' prototypes of the map, which are the
representative vectors of the clusters. Plotting <b> observations </b> uses the
values of the observations within each cluster."
)
),
p(
HTML(
"These are the standard types of plots:
<ul>
<li><b>hitmap:</b> represents circles having size proportional to the number
of observations per neuron.</li>
<li><b>color:</b> Neurons are filled with colors according to the prototype
value or the average value level of the observations for a chosen variable.</li>
<li><b>3d:</b> similar to the ‘color’ plot, but in 3-dimensions, with x and y
the coordinates of the grid and z the value of the prototypes or observations
for the considered variable.</li>
<li><b>boxplot:</b> plots boxplots for the observations in every neuron.</li>
<li><b>lines:</b> plots a line for each observation in every neuron, between
variables.</li>
<li><b>barplot:</b> similar to lines, here each variable value is represented
by a bar. </li>
<li><b>mealine:</b> plots, for each neuron, the prototype value or the average
value level of the observations, with lines. Each point on the line represents a
variable. </li>
<li><b>names:</b> prints on the grid the names of the observations in the
neuron to which they belong. <strong>Warning!</strong> If the number of
observations or the size of the names is too large, some names may not be
representedthey are reprensented in the center of the neuron, with a warning.</li>
<li><b>poly.dist:</b> represents the distances between prototypes with polygons
plotted for each neuron. The closer the polygon point is to the border, the
closer the pairs of prototypes. The color used for filling the polygon shows the
number of observations in each neuron. A red polygon means a high number of
observations, a white polygon means there are no observations.</li>
<li><b>smooth.dist:</b> depicts the average distance between a prototype and
its neighbors using smooth color changes, on a map where x and y are the
coordinates of the prototypes on the grid. If the topology is hexagonal,
linear interpolation is done between neuron coordinates to get a full
squared grid.</li>
<li><b>umatrix:</b> is another way of plotting distances between prototypes.
The grid is plotted and filled colors according to the mean distance between the
current neuronand the neighboring neurons. Red indicates proximity.</li>
<li><b>grid.dist:</b> plots all distances on a two-dimensional map. The number
of points on this picture is equal to: <br>
<code>number_of_neurons * (number_of_neurons-1) / 2</code><br>The x axis
corresponds to the prototype distances, the y axis depicts the grid distances.
</li>
<li><b>MDS:</b> plots the number of the neurons according to a Multi Dimensional
Scaling (MDS) projection on a two-dimensional space.</li>
</ul>"
)
),
p(
HTML("Plots in the SuperClasses panel: the plot options are mostly
the same as the ones listed above, but some are specific:
<ul>
<li><b>grid:</b> plots the grid of the neurons, grouped by
superclasses (color).</li>
<li><b>dendrogram:</b> plots the dendrogram of the
hierarchical clustering applied to the prototypes, along with the scree plot
which shows the proportion of unexplained variance for incremental numbers of
superclasses. These are helpful in determining the optimal number of
superclasses.</li>
<li><b>dendro3d:</b> similar to 'dendrogram', but in
three dimensions and without the scree plot.</li>
</ul>"
)
),
p(
HTML("Plots in the 'Combine with external information' panel:
the plot options are mostly the same as the ones listed above, but some are specific:
<ul>
<li><b>pie:</b> requires the selected variable to be a
categorical variable, and plots one pie for each neuron, corresponding to the
values of this variable.</li>
<li><b>words:</b> needs the external data to be a
contingency table or numerical values: names of the columns will be
used as words and printed on the map with sizes proportional to the sum of values
in the neuron.</li>
<li><b>graph:</b> needs the external data to be the
adjacency matrix of a graph. According to the existing edges in the graph and to
the clustering obtained with the SOM algorithm, a clustered graph is built in
which vertices represent neurons and edge are weighted by the number of edges in
the given graph between the vertices affected to the corresponding neurons. This
plot can be tested with the supplied dataset <a href=
'http://nextcloud.nathalievilla.org/index.php/s/R2Vyt5Vkg3xlYPD'
>Les Miserables</a> that
corresponds to the graph those adjacency table is provided at <a href=
'http://nextcloud.nathalievilla.org/index.php/s/R2Vyt5Vkg3xlYPD'
>this link</a>.
</li>
</ul>"
)
),
p(
HTML(
"The <b>show cluster names</b> option in the 'Plot map'
panel can be selected to show the names of the neurons on the map."
)
),
p(
HTML(
"The <b>energy</b> option in the 'Plot map' panel is used
to plot the energy levels of the intermediate backups recorded during training.
This is helpful in determining whether the algorithm did converge. (This option
only works if a 'Number of intermediate backups' larger than 2 is chosen in the
'Self-Organize' panel.)"
)
)
),
shinyBS::bsCollapsePanel(
title = "Grouping prototypes into Superclasses",
value = "superclasses",
style = "success",
p(
HTML(
"Use the options on the dedicated panel to group the
prototypes of a trained map into a determined number of superclasses, using
hierarchical clustering. The 'dendrogram' plot can help you to choose a relevant
number of superclasses (or equivalently a relevant cutting height in the
dendrogram)."
)
)
),
shinyBS::bsCollapsePanel(
title = "Combine with external information",
value = "externalinfo",
style = "success",
p(
HTML(
"Plot external data on the trained map on the dedicated
panel. If you have unused variables in your dataset (not used to train the map),
you can select them as external data. Otherwise, or if you want to use other data,
the external data importation process is similar to the one described in
the <a href='
plots are described in the <a href='
Note that this is the only panel in which factors can be plotted on the
self-organizing map. For instance, if the map is trained on the first four
(numeric) variables of the supplied <a href=
'http://nextcloud.nathalievilla.org/index.php/s/BWnWADSPxayGSGa'
>iris dataset</a>, you can select the species variable and plot the iris species
on the map."
)
)
)
) |
library("listenv")
ovars <- ls(envir = globalenv())
if (exists("x")) rm(list = "x")
if (exists("y")) rm(list = "y")
message("*** parse_env_subset() on multi-dim listenv ...")
x <- listenv()
length(x) <- 6
dim(x) <- c(2, 3)
target <- parse_env_subset(x[2], substitute = TRUE)
str(target)
stopifnot(identical(target$envir, x), target$idx == 2, !target$exists)
target <- parse_env_subset(x[[2]], substitute = TRUE)
str(target)
stopifnot(identical(target$envir, x), target$idx == 2, !target$exists)
target <- parse_env_subset(x[1, 2], substitute = TRUE)
str(target)
stopifnot(identical(target$envir, x), target$idx == 3, !target$exists)
target <- parse_env_subset(x[[1, 2]], substitute = TRUE)
str(target)
stopifnot(identical(target$envir, x), target$idx == 3, !target$exists)
x[[1, 2]] <- 1.2
target <- parse_env_subset(x[1, 2], substitute = TRUE)
str(target)
stopifnot(identical(target$envir, x), target$idx == 3, target$exists)
target <- parse_env_subset(x[[1, 2]], substitute = TRUE)
str(target)
stopifnot(identical(target$envir, x), target$idx == 3, target$exists)
target <- parse_env_subset(x[1, 4], substitute = TRUE)
str(target)
stopifnot(identical(target$envir, x), is.na(target$idx), !target$exists)
target <- parse_env_subset(x[[1, 4]], substitute = TRUE)
str(target)
stopifnot(identical(target$envir, x), is.na(target$idx), !target$exists)
target <- parse_env_subset(x[1, 1:2], substitute = TRUE)
str(target)
stopifnot(identical(target$envir, x),
length(target$idx) == 2L, all(target$idx == c(1,3)),
length(target$exists) == 2L, all(target$exists == c(FALSE, TRUE)))
target <- parse_env_subset(x[1, -3], substitute = TRUE)
str(target)
stopifnot(identical(target$envir, x),
length(target$idx) == 2L, all(target$idx == c(1,3)),
length(target$exists) == 2L, all(target$exists == c(FALSE, TRUE)))
target <- parse_env_subset(x[[1, 4]], substitute = TRUE)
str(target)
target2 <- parse_env_subset(x[[c(1, 4)]], substitute = TRUE)
str(target2)
target$code <- target2$code <- NULL
stopifnot(!isTRUE(all.equal(target2, target)))
dimnames(x) <- list(c("a", "b"), c("A", "B", "C"))
print(x)
target <- parse_env_subset(x[["a", 2]], substitute = TRUE)
str(target)
stopifnot(identical(target$envir, x), target$idx == 3, target$exists)
target <- parse_env_subset(x[["a", "B"]], substitute = TRUE)
str(target)
stopifnot(identical(target$envir, x), target$idx == 3, target$exists)
target <- parse_env_subset(x["a", "B"], substitute = TRUE)
str(target)
stopifnot(identical(target$envir, x), target$idx == 3, target$exists)
target <- parse_env_subset(x["a", 1:3], substitute = TRUE)
str(target)
stopifnot(identical(target$envir, x), length(target$idx) == 3,
all(target$idx == c(1, 3, 5)),
all(target$exists == c(FALSE, TRUE, FALSE)))
target <- parse_env_subset(x["a", ], substitute = TRUE)
str(target)
stopifnot(identical(target$envir, x), length(target$idx) == 3,
all(target$idx == c(1, 3, 5)),
all(target$exists == c(FALSE, TRUE, FALSE)))
target <- parse_env_subset(x["a", -1], substitute = TRUE)
str(target)
stopifnot(identical(target$envir, x), length(target$idx) == 2,
all(target$idx == c(3, 5)),
all(target$exists == c(TRUE, FALSE)))
message("*** parse_env_subset() on multi-dim listenv ... DONE")
message("*** parse_env_subset() on multi-dim listenv - exceptions ...")
x <- listenv()
res <- try(target <- parse_env_subset(x[[1, 2]], substitute = TRUE),
silent = TRUE)
stopifnot(inherits(res, "try-error"))
x <- listenv()
length(x) <- 6
dim(x) <- c(2, 3)
res <- try(target <- parse_env_subset(x[[0]], substitute = TRUE), silent = TRUE)
res <- try(target <- parse_env_subset(x[[1, 0]], substitute = TRUE),
silent = TRUE)
res <- try(target <- parse_env_subset(x[[1, 2, 3]], substitute = TRUE),
silent = TRUE)
message("*** parse_env_subset() on multi-dim listenv - exceptions ... DONE")
rm(list = setdiff(ls(envir = globalenv()), ovars), envir = globalenv()) |
.draw.Z.2pl <- function( aM, bM, theta, N, I, threshlow, threshupp ){
mij <- aM * theta - bM
rij <- matrix( stats::runif( N*I ), nrow=N, ncol=I )
pl <- stats::pnorm( threshlow, mean=mij)
pu <- stats::pnorm( threshupp, mean=mij)
pij <- pl + (pu-pl)*rij
Zij <- stats::qnorm( pij, mean=mij )
return(Zij)
}
.draw.theta.2pl <- function( aM, bM, N, I, Z ){
vtheta <- 1 / ( rowSums( aM^2 ) + 1 )
mtheta <- rowSums( aM * ( Z + bM ) ) * vtheta
theta <- stats::rnorm( N, mean=mtheta, sd=sqrt( vtheta ) )
res <- list("theta"=theta )
return(res)
}
.draw.itempars.2pl <- function( theta, Z, I, N, weights){
Xast <- as.matrix( cbind( theta, -1 ) )
if ( is.null(weights) ){
Sigma <- solve( crossprod(Xast) )
mj <- Sigma %*% crossprod(Xast, Z )
mj <- as.matrix( t(mj))
}
if ( ! is.null( weights ) ){
Xast11 <- sum( theta^2 * weights )
Xast12 <- - sum( theta * weights )
Xast22 <- sum( weights )
Xastdet <- Xast11*Xast22 - Xast12^2
Xastinv11 <- Xast22 / Xastdet
Xastinv22 <- Xast11 / Xastdet
Xastinv12 <- - Xast12 / Xastdet
Sigma <- matrix( c(Xastinv11, Xastinv12, Xastinv12, Xastinv22), 2,2 )
mj <- Sigma %*% crossprod( Xast * weights, Z )
mj <- as.matrix( t(mj))
}
ipars <- sirt_rmvnorm( I, sigma=Sigma ) + mj
a <- ipars[,1]
b <- ipars[,2]
return( list( "a"=a, "b"=b) )
}
.mcmc.deviance.2pl <- function( aM, bM, theta, dat, dat.resp,
weights, eps ){
pij <- stats::pnorm( aM * theta - bM )
llij <- log( dat.resp * ( dat*pij + ( 1-dat )*(1-pij) ) + eps )
if ( is.null( weights ) ){ deviance <- -2*sum( llij ) }
if ( ! is.null( weights ) ){
deviance <- -2*sum( rowSums(llij) * weights )
}
return(deviance)
}
.mcmc.ic.2pl <- function( a.chain, b.chain, theta.chain, N, I,
dat, dat.resp, weights, eps,
deviance.chain ){
aM <- matrix( colMeans( a.chain ), nrow=N, ncol=I, byrow=TRUE )
bM <- matrix( colMeans( b.chain ), nrow=N, ncol=I, byrow=TRUE )
theta <- colMeans( theta.chain )
Dhat <- .mcmc.deviance.2pl( aM, bM, theta, dat, dat.resp,
weights, eps )
Dbar <- mean( deviance.chain )
pD <- Dbar - Dhat
ic <- list( "Dhat"=Dhat, "Dbar"=Dbar, "pD"=pD, "DIC"=Dhat + 2*pD )
return(ic)
}
.mcmc.person.2pno <- function( theta.chain, weights ){
v1 <- stats::var( colMeans( theta.chain ) )
if ( is.null(weights) ){ EAP.rel <- v1 / 1 }
if ( ! is.null(weights) ){
w1 <- weights / sum(weights )
m1 <- colMeans( theta.chain )
v1 <- sum( m1^2 * w1 ) - ( sum( m1*w1 ) )^2
wM <- matrix( w1, nrow=nrow(theta.chain), ncol=ncol(theta.chain), byrow=TRUE )
h1 <- rowSums( wM * theta.chain^2 ) - ( rowSums( wM * theta.chain ) )^2
h1 <- mean(h1)
EAP.rel <- v1 / h1
}
person <- data.frame( "EAP"=colMeans( theta.chain ),
"SD"=colSds(theta.chain) )
res <- list( "EAP.rel"=EAP.rel, "person"=person )
return(res)
} |
recent_commit <- function(file, root, data = FALSE) {
UseMethod("recent_commit", root)
}
recent_commit.default <- function(file, root, data = FALSE) {
stop("a 'root' of class ", class(root), " is not supported", call. = FALSE)
}
recent_commit.git_repository <- function(file, root, data = FALSE) {
assert_that(is.string(file), is.flag(data), noNA(data))
path <- unique(dirname(file))
if (path == ".") {
path <- ""
}
if (data) {
file <- clean_data_path(root = workdir(root), file, normalize = FALSE)
}
name <- basename(file)
blobs <- odb_blobs(root)
blobs <- blobs[blobs$path == path & blobs$name %in% name, ]
blobs <- blobs[blobs$when <= as.data.frame(last_commit(root))$when, ]
blobs <- blobs[blobs$when == max(blobs$when), c("commit", "author", "when")]
blobs <- unique(blobs)
if (nrow(blobs) > 1) {
warning("More than one commit within the same second", call. = FALSE)
}
rownames(blobs) <- NULL
blobs
} |
tabPanel('3D Pie Chart', value = 'tab_pie3d',
fluidPage(
fluidRow(
column(12, align = 'left',
h4('3D Pie Chart')
)
),
hr(),
fluidRow(
column(12,
tabsetPanel(type = 'tabs',
tabPanel('Variable',
column(4,
column(6,
selectInput('pie3_select', 'Select Variable',
choices = "", selected = ""
),
numericInput('pie3_radius', 'Radius', min = 0.1, step = 0.1, value = 1)
),
column(6,
selectInput('pie3_label', 'Select Labels',
choices = "", selected = ""
),
numericInput('pie3_height', 'Height', min = 0.1, step = 0.1, value = 0.1)
)
),
column(8,
plotOutput('pie3_1', '500px')
)
),
tabPanel('Options',
column(4,
fluidRow(
column(6,
textInput('pie3_border', 'Border Color', value = "black"),
numericInput('pie3_start', 'Start', min = 0, step = 1, value = 0),
numericInput('pie3_explode', 'Explode', min = 0, step = 0.1, value = 0),
numericInput('pie3_shade', 'Shade', min = 0, step = 0.1, value = 0.8),
numericInput('pie3_edges', 'Edges', min = 0, step = 1, value = 200)
)
)
),
column(8,
plotOutput('pie3_2', '500px')
)
),
tabPanel('Color',
column(4,
fluidRow(
column(6, numericInput("ncolpie3", "Number of Colors", value = 0, min = 0)),
column(6, uiOutput("ui_ncolpie3"))
)
),
column(8,
plotOutput('pie3_3', '500px')
)
),
tabPanel('Label',
column(4,
fluidRow(
column(6,
textInput('pie3_labcol', 'Label Color', value = "black"),
numericInput('pie3_labcex', 'Label Size', min = 0.1, step = 0.1, value = 1.5),
numericInput('pie3_labrad', 'Label Radius', min = 0.1, step = 0.01, value = 1.25)
)
),
fluidRow(
column(6, numericInput("nlabpospie3", "Number of Labels", value = 0, min = 0)),
column(6, uiOutput("ui_nlabpospie3"))
)
),
column(8,
plotOutput('pie3_4', '500px')
)
),
tabPanel('Title',
column(4,
column(6,
textInput('pie3_title', 'Title', value = 'title'),
textInput('pie3_titlecol', 'Title Color', value = 'black')
),
column(6,
numericInput('pie3_font', 'Font', min = 1, step = 1, value = 1, max = 5),
numericInput('pie3_cex', 'Size', min = 0.1, step = 0.1, value = 1)
)
),
column(8,
plotOutput('pie3_5', '500px')
)
),
tabPanel('Plot',
fluidRow(
column(8, offset = 2,
plotOutput('pie3_final', '600px')
)
)
)
)
)
)
)
) |
context("Chapter 2")
test_that("Chapter 2 functions basically work", {
expect_error(Wald_CI_1x2(100))
expect_output(
object = Wald_CI_1x2(1, 2),
regexp = "estimate = 0.5000 \\(95% CI 0.0000 to 1.0000\\)"
)
expect_error(AgrestiCoull_CI_1x2(19))
expect_output(
object = AgrestiCoull_CI_1x2(19, 20, .15),
regexp = "estimate = 0.8750 \\(85% CI 0.7778 to 0.9722\\)"
)
expect_error(Arcsine_CI_1x2(500))
expect_output(
object = Arcsine_CI_1x2(100, 5e3, .1),
regexp = "estimate = 0.0200 \\(90% CI 0.0169 to 0.0235\\)"
)
expect_error(Blaker_exact_CI_1x2(1))
expect_output(
object = Blaker_exact_CI_1x2(1, 100),
regexp = "estimate = 0.0100 \\(95% CI 0.0005 to 0.0513\\)"
)
expect_error(Blaker_exact_test_1x2(1))
expect_output(
object = Blaker_exact_test_1x2(1, 10, .5),
regexp = "P = 0.02148"
)
expect_error(Blaker_midP_CI_1x2(100))
expect_output(
object = Blaker_midP_CI_1x2(100, 500, .5),
regexp = "estimate = 0.2000 \\(50% CI 0.1881 to 0.2121\\)"
)
expect_error(Blaker_midP_test_1x2(100))
expect_output(
object = Blaker_midP_test_1x2(X=13, n=16, pi0=0.5),
regexp = "P = 0.00845"
)
expect_error(ClopperPearson_exact_CI_1x2(100))
expect_output(
object = ClopperPearson_exact_CI_1x2(X=13, n=16),
regexp = "estimate = 0.8125 \\(95% CI 0.5435 to 0.9595\\)"
)
expect_error(ClopperPearson_midP_CI_1x2(100))
expect_output(
object = ClopperPearson_midP_CI_1x2(X=13, n=16),
regexp = "estimate = 0.8125 \\(95% CI 0.5699 to 0.9500\\)"
)
expect_error(Exact_binomial_test_1x2(100))
expect_output(
object = Exact_binomial_test_1x2(X = 13, n = 16, pi0 = 0.5),
regexp = "P = 0.02127"
)
expect_error(Jeffreys_CI_1x2(100))
expect_output(
object = Jeffreys_CI_1x2(X = 13, n = 16),
regexp = "estimate = 0.8125 \\(95% CI 0.5792 to 0.9442\\)"
)
expect_error(LR_CI_1x2(100))
expect_output(
object = LR_CI_1x2(X = 13, n = 16),
regexp = "estimate = 0.8125 \\(95% CI 0.5828 to 0.9497\\)"
)
expect_error(LR_test_1x2(100))
expect_output(
object = LR_test_1x2(X = 13, n = 16, pi0 = .5),
regexp = "P = 0.00944, T = 6.738 \\(df <- 1\\)"
)
expect_error(MidP_binomial_test_1x2(100))
expect_output(
object = MidP_binomial_test_1x2(X = 13, n = 16, pi0 = .5),
regexp = "P = 0.01273"
)
expect_error(Score_test_1x2(100))
expect_output(
object = Score_test_1x2(X = 13, n = 16, pi0 = .5),
regexp = "P = 0.01242, Z = 2.500"
)
expect_error(Score_test_CC_1x2(100))
expect_output(
object = Score_test_CC_1x2(X = 13, n = 16, pi0 = .5),
regexp = "P = 0.02445, Z = 2.250"
)
expect_error(Wald_CI_CC_1x2(100))
expect_output(
object = Wald_CI_CC_1x2(X = 13, n = 16, alpha = .1),
regexp = "estimate = 0.8125 \\(90% CI 0.6207 to 1.0000\\)"
)
expect_error(Wilson_score_CI_1x2(100))
expect_output(
object = Wilson_score_CI_1x2(X=13, n=16),
regexp = "estimate = 0.8125 \\(95% CI 0.5699 to 0.9341\\)"
)
expect_error(Wilson_score_CI_CC_1x2(100))
expect_output(
object = Wilson_score_CI_CC_1x2(X=13, n=16),
regexp = "estimate = 0.8125 \\(95% CI 0.5369 to 0.9503\\)"
)
expect_error(the_1x2_table_CIs(100))
expect_output(
object = the_1x2_table_CIs(X=13, n=16),
regexp = "Estimate of pi: 13 / 16 = 0.812 "
)
expect_error(Wald_test_1x2(100))
expect_output(
object = Wald_test_1x2(X=13, n=16, pi0=0.1),
regexp = "P = 0.00000, Z = 7.302"
)
expect_error(Wald_test_CC_1x2(100))
expect_output(
object = Wald_test_CC_1x2(X=13, n=16, pi0=0.1),
regexp = "P = 0.00000, Z = 6.982"
)
expect_error(the_1x2_table_tests(100))
expect_output(
object = the_1x2_table_tests(X=13, n=16, pi0=0.5),
regexp = "H_0: pi = 0.500 vs H_A: pi ~= 0.500"
)
}) |
setGeneric("toCControlList", function(object) { standardGeneric("toCControlList"); });
setMethod("toCControlList", signature(object = "GenAlgPLSEvaluator"), function(object) {
return(list(
"evaluatorClass" = 1L,
"numReplications" = object@numReplications,
"innerSegments" = object@innerSegments,
"outerSegments" = object@outerSegments,
"testSetSize" = object@testSetSize,
"sdfact" = object@sdfact,
"plsMethod" = object@methodId,
"numThreads" = object@numThreads,
"maxNComp" = object@maxNComp,
"userEvalFunction" = function() {NULL;},
"statistic" = 0L
));
});
setMethod("toCControlList", signature(object = "GenAlgFitEvaluator"), function(object) {
return(list(
"evaluatorClass" = 3L,
"numReplications" = 0L,
"innerSegments" = object@numSegments,
"outerSegments" = 0L,
"testSetSize" = 0.0,
"sdfact" = object@sdfact,
"plsMethod" = 0L,
"numThreads" = object@numThreads,
"maxNComp" = object@maxNComp,
"userEvalFunction" = function() {NULL;},
"statistic" = object@statisticId
));
});
setMethod("toCControlList", signature(object = "GenAlgUserEvaluator"), function(object) {
return(list(
"evaluatorClass" = 0L,
"numReplications" = 0L,
"innerSegments" = 0L,
"outerSegments" = 0L,
"testSetSize" = 0.0,
"sdfact" = 0.0,
"plsMethod" = 0L,
"numThreads" = 1L,
"maxNComp" = 0L,
"userEvalFunction" = object@evalFunction,
"statistic" = 0L
));
});
setMethod("toCControlList", signature(object = "GenAlgLMEvaluator"), function(object) {
return(list(
"evaluatorClass" = 2L,
"numReplications" = 0L,
"innerSegments" = 0L,
"outerSegments" = 0L,
"testSetSize" = 0.0,
"sdfact" = 0.0,
"plsMethod" = 0L,
"numThreads" = object@numThreads,
"maxNComp" = 0L,
"userEvalFunction" = function() {NULL;},
"statistic" = object@statisticId
));
});
setMethod("toCControlList", signature(object = "GenAlgControl"), function(object) {
return(list(
"populationSize" = object@populationSize,
"numGenerations" = object@numGenerations,
"minVariables" = object@minVariables,
"maxVariables" = object@maxVariables,
"elitism" = object@elitism,
"mutationProb" = object@mutationProbability,
"crossover" = object@crossoverId,
"maxDuplicateEliminationTries" = object@maxDuplicateEliminationTries,
"badSolutionThreshold" = object@badSolutionThreshold,
"verbosity" = object@verbosity,
"fitnessScaling" = object@fitnessScalingId
));
}); |
fssc05Z <- function(fslist, k=2, nnbd=5){
myk = max(1, round(k))
mynnbd = max(1, round(nnbd))
if (inherits(fslist, "dist")){
pdmat = fslist
} else {
dtype = check_list_summaries("fssc05Z", fslist)
pdmat = TDAkit::fsdist(fslist, p=2, as.dist=TRUE)
}
run_sc = T4cluster::sc05Z(pdmat, k=myk, nnbd=mynnbd)
output = as.vector(run_sc$cluster)
return(output)
} |
S_func <- function(x, a) {
return((abs(x) - a) * sign(x) * (abs(x) > a))
} |
dm.ddf <-
function(xdata, ydata, rts = "crs", g = NULL,
wd = NULL, se = FALSE, sg = "ssm", date = NULL, cv = "convex", o = NULL){
if(is.na(match(rts, c("crs", "vrs", "irs", "drs")))) stop('rts must be "crs", "vrs", "irs", or "drs".')
if(is.na(match(se, c(0, 1, FALSE, TRUE)))) stop('se must be either 0(FALSE) or 1(TRUE).')
if(is.na(match(sg, c("ssm", "max", "min")))) stop('sg must be "ssm", "max", or "min".')
if(is.na(match(cv, c("convex", "fdh")))) stop('cv must be "convex" or "fdh".')
if(!is.null(o) && !all(o <= nrow(xdata))) stop('o must be element(s) of n.')
xdata <- as.matrix(xdata)
ydata <- as.matrix(ydata)
g <- if(is.null(g)) cbind(xdata, ydata) else as.matrix(g)
date <- if(!is.null(date)) as.matrix(date)
n <- nrow(xdata)
m <- ncol(xdata)
s <- ncol(ydata)
wd <- if(is.null(wd)) matrix(c(0), ncol = s) else matrix(wd, 1)
se <- ifelse(is.logical(se), ifelse(isTRUE(se), 1, 0), se)
rts <- ifelse(cv == "fdh", "vrs", rts)
o <- if(is.null(o)) c(1:n) else as.vector(o)
results.efficiency <- matrix(NA, nrow = n, ncol = 1)
results.lambda <- matrix(NA, nrow = n, ncol = n)
results.mu <- matrix(NA, nrow = n, ncol = n)
results.xslack <- matrix(NA, nrow = n, ncol = m)
results.yslack <- matrix(NA, nrow = n, ncol = s)
results.beta <- matrix(NA, nrow = n, ncol = m)
results.gamma <- matrix(NA, nrow = n, ncol = s)
for (k in o){
lp.ddf <- make.lp(0, n + n + m + s + m + s)
set.objfn(lp.ddf, c(rep(-1, m + s)), indices = c((n + n + 1):(n + n + m + s)))
if(rts == "vrs") add.constraint(lp.ddf, c(rep(1, n * 2)), indices = c(1:(n * 2)), "=", 1)
if(rts == "crs") set.constr.type(lp.ddf, 0, 1)
if(rts == "irs") add.constraint(lp.ddf, c(rep(1, n * 2)), indices = c(1:(n * 2)), ">=", 1)
if(rts == "drs") add.constraint(lp.ddf, c(rep(1, n * 2)), indices = c(1:(n * 2)), "<=", 1)
if(cv == "fdh") set.type(lp.ddf, 1:n, "binary")
if(rts == "crs" || rts == "drs" || sum(wd) == 0) add.constraint(lp.ddf, c(rep(1, n)),
indices = c((n + 1):(n + n)), "=", 0)
for(i in 1:m){
add.constraint(lp.ddf, c(xdata[, i], xdata[, i], g[k, i], 1),
indices = c(1:(n + n), n + n + i, n + n + m + s + i), "=", xdata[k, i])
}
for(r in 1:s){
if(wd[1, r] == 1){
add.constraint(lp.ddf, c(ydata[, r], g[k, m + r]),
indices = c(1:n, n + n + m + r), "=", ydata[k, r])
add.constraint(lp.ddf, c(1), indices = c(n + n + m + s + m + r), "=", 0)
}else{
add.constraint(lp.ddf, c(ydata[, r], -g[k, m + r], -1),
indices = c(1:n, n + n + m + r, n + n + m + s + m + r), "=", ydata[k, r])
}
if(se == 1) add.constraint(lp.ddf, c(ydata[, r], -1), indices = c(1:n, n + n + m + s + m + r), ">=", 0)
}
if(se == 1) add.constraint(lp.ddf, c(1), indices = c(k), "=", 0)
set.bounds(lp.ddf, lower = c(rep(0, n + n + m + s + m + s)))
solve.lpExtPtr(lp.ddf)
results.efficiency[k] <- -1 * get.objective(lp.ddf)
temp.p <- get.variables(lp.ddf)
results.lambda[k,] <- temp.p[1: n]
results.mu[k,] <- temp.p[(n + 1):(n + n)]
results.beta[k,] <- temp.p[(n + n + 1):(n + n + m)]
results.gamma[k,] <- temp.p[(n + n + m + 1):(n + n + m + s)]
results.xslack[k,] <- temp.p[(n + n + m + s + 1):(n + n + m + s + m)]
results.yslack[k,] <- temp.p[(n + n + m + s + m + 1):(n + n + m + s + m + s)]
if(exists("sg")){
add.constraint(lp.ddf, c(rep(1, m + s)),
indices = c((n + n + 1):(n + n + m + s)), "=", results.efficiency[k])
if(sg == "max") set.objfn(lp.ddf, c(-date[1:n], -date[1:n]), indices = c(1:(n + n)))
if(sg == "min") set.objfn(lp.ddf, c(date[1:n], date[1:n]), indices = c(1:(n + n)))
if(sg == "ssm") set.objfn(lp.ddf, c(rep(-1, m + s)),
indices = c((n + n + m + s + 1):(n + n + m + s + m + s)))
solve.lpExtPtr(lp.ddf)
temp.s <- get.variables(lp.ddf)
results.lambda[k,] <- temp.s[1:n]
results.mu[k,] <- temp.s[(n + 1):(n + n)]
results.beta[k,] <- temp.s[(n + n + 1):(n + n + m)]
results.gamma[k,] <- temp.s[(n + n + m + 1):(n + n + m + s)]
results.xslack[k,] <- temp.s[(n + n + m + s + 1):(n + n + m + s + m)]
results.yslack[k,] <- temp.s[(n + n + m + s + m + 1):(n + n + m + s + m + s)]
}
}
results <- list(eff = results.efficiency, lambda = results.lambda, mu = results.mu, beta = results.beta,
gamma = results.gamma, xslack = results.xslack, yslack = results.yslack)
return(results)
} |
library(data.table)
file_path <- "50_Data/mhlw_houdou.csv"
news <- fread(input = file_path)
news[, id := 1:.N]
fwrite(x = news, file = file_path) |
library(tidyverse)
library(dynbenchmark)
dataset_preprocessing("real/fly-blastoderm-atac_cusanovich")
txt_location <- download_dataset_source_file(
"2to4_files.tar.gz",
"http://krishna.gs.washington.edu/content/members/cusanovich/fly_embryogenesis/updated_data/vignette/2to4_files.tar.gz"
)
system(paste0("tar -xzf ", txt_location, " -C ", dataset_source_file(""), " --strip-components=1"))
cds_2to4 = readRDS(dataset_source_file("2to4_files/cds_2to4_aggregated.rds"))
overlapped_sites = read.table(dataset_source_file('./2to4_files/2to4.overlapped_sites.bed'))
cell_classification = read.table(dataset_source_file('./2to4_files/2to4.germlayers.txt'))
table(cell_classification$V2)
DA_monocle_list = lapply(seq(1,7,1), FUN = function(x) {
DA_file_name = paste0(dataset_source_file('./2to4_files/2to4.sigopen.cluster'), x, '.txt')
DA_file = read.csv(DA_file_name, sep = '\t', header = F)
DA_file$GL = x
return (DA_file)
})
DA_monocle = data.table::rbindlist(DA_monocle_list)
colnames(DA_monocle) = c('chr','start', 'end', 'qvalue', 'GL')
DA_monocle$coord = paste(DA_monocle$chr, DA_monocle$start, DA_monocle$end, sep = '_')
get_top_DA = function(cluster = 1, DA_results=DA_GL, num = 500){
DA_this_cluster = subset(DA_results, GL == cluster)
DA_this_cluster = DA_this_cluster[order(DA_this_cluster[,qvalue]),]
if (num > nrow(DA_this_cluster)){
return (DA_this_cluster[c(1:nrow(DA_this_cluster)),]$coord)
}else {return (DA_this_cluster[c(1:num),]$coord)}
}
DA_sites_to_order = unlist(lapply(c(1,3,4,5,6), get_top_DA, DA_results = DA_monocle,num=100))
overlapped_DA_sites_to_order = subset(overlapped_sites, V4 %in% DA_sites_to_order)$V8
rownames(cell_classification) = cell_classification$V1
germ_layer_pallet = c('Unknown'='
'Mesoderm'= '
cell_classification = cell_classification[rownames(pData(cds_2to4)),]
cds_2to4$germ_layer_name = cell_classification$V2
fData(cds_2to4)$use_for_ordering = FALSE
cds_2to4 = setOrderingFilter(cds_2to4, overlapped_DA_sites_to_order) |
MVBinomDist = function(parameter) {
if (missing(parameter))
stop("Data model: MVBinomDist distribution: List of parameters must be provided.")
if (is.null(parameter[[2]]$par))
stop("Data model: MVBinomDist distribution: Parameter list (prop) must be specified.")
if (is.null(parameter[[2]]$par))
stop("Data model: MVBinomDist distribution: Correlation matrix must be specified.")
par = parameter[[2]]$par
corr = parameter[[2]]$corr
m = length(par)
if (ncol(corr) != m)
stop("Data model: MVBinomDist distribution: The size of the proportion vector is different to the dimension of the correlation matrix.")
if (sum(dim(corr) == c(m, m)) != 2)
stop("Data model: MVBinomDist distribution: Correlation matrix is not correctly defined.")
if (det(corr) <= 0)
stop("Data model: MVBinomDist distribution: Correlation matrix must be positive definite.")
if (any(corr < -1 | corr > 1))
stop("Data model: MVBinomDist distribution: Correlation values must be comprised between -1 and 1.")
call = (parameter[[1]] == "description")
if (call == FALSE) {
n = parameter[[1]]
if (n%%1 != 0)
stop("Data model: MVBinomDist distribution: Number of observations must be an integer.")
if (n <= 0)
stop("Data model: MVBinomDist distribution: Number of observations must be positive.")
multnorm = mvtnorm::rmvnorm(n = n, mean = rep(0, m), sigma = corr)
mvbinom = matrix(0, n, m)
for (i in 1:m) {
uniform = stats::pnorm(multnorm[, i])
if (is.null(par[[i]]$prop))
stop("Data model: MVBinomDist distribution: Proportion must be specified.")
prop = as.numeric(par[[i]]$prop)
if (prop < 0 | prop > 1)
stop("Data model: MVBinomDist distribution: proportion in the binomial distribution must be between 0 and 1.")
mvbinom[, i] = (uniform <= prop)
}
result = mvbinom
} else {
if (call == TRUE) {
par.labels = list()
for (i in 1:m) {
par.labels[[i]] = list(prop = "prop")
}
result = list(list(par = par.labels, corr = "corr"),list("Multivariate Binomial"))
}
}
return(result)
} |
select_topics <- function(match_strings, topics, check = FALSE) {
n <- nrow(topics)
if (length(match_strings) == 0) {
return(integer())
}
indexes <- purrr::map(match_strings, match_eval, env = match_env(topics))
if (purrr::every(indexes, is_empty)) {
if (check) {
warn("No topics matched in '_pkgdown.yml'. No topics selected.")
}
return(integer())
}
sel <- switch(
all_sign(indexes[[1]], match_strings[[1]]),
"+" = integer(),
"-" = seq_len(n)[!topics$internal]
)
for (i in seq2(1, length(indexes))) {
index <- indexes[[i]]
if (check && length(index) == 0) {
topic_must("match a function or concept", match_strings[[i]])
}
sel <- switch(all_sign(index, match_strings[[i]]),
"+" = union(sel, index),
"-" = setdiff(sel, -index)
)
}
sel
}
all_sign <- function(x, text) {
if (is.numeric(x)) {
if (all(x < 0)) {
return("-")
}
if (all(x > 0)) {
return("+")
}
}
stop("Must be all negative or all positive: ", text, call. = FALSE)
}
match_env <- function(topics) {
out <- env(empty_env(),
"-" = function(x) -x,
"c" = function(...) c(...)
)
topic_index <- seq_along(topics$name)
topics$alias <- lapply(topics$alias, unique)
aliases <- set_names(
rep(topic_index, lengths(topics$alias)),
unlist(topics$alias)
)
env_bind(out, !!!aliases)
env_bind(out, !!!set_names(topic_index, topics$name))
any_alias <- function(f, ..., .internal = FALSE) {
alias_match <- topics$alias %>%
unname() %>%
purrr::map(f, ...) %>%
purrr::map_lgl(any)
name_match <- topics$name %>%
purrr::map_lgl(f, ...)
which((alias_match | name_match) & is_public(.internal))
}
is_public <- function(internal) {
if (!internal) !topics$internal else rep(TRUE, nrow(topics))
}
out$starts_with <- function(x, internal = FALSE) {
any_alias(~ grepl(paste0("^", x), .), .internal = internal)
}
out$ends_with <- function(x, internal = FALSE) {
any_alias(~ grepl(paste0(x, "$"), .), .internal = internal)
}
out$matches <- function(x, internal = FALSE) {
any_alias(~ grepl(x, .), .internal = internal)
}
out$contains <- function(x, internal = FALSE) {
any_alias(~ grepl(x, ., fixed = TRUE), .internal = internal)
}
out$has_keyword <- function(x) {
which(purrr::map_lgl(topics$keywords, ~ any(. %in% x)))
}
out$has_concept <- function(x, internal = FALSE) {
match <- topics$concepts %>%
purrr::map(~ str_trim(.) == x) %>%
purrr::map_lgl(any)
which(match & is_public(internal))
}
out$lacks_concepts <- function(x, internal = FALSE) {
nomatch <- topics$concepts %>%
purrr::map(~ match(str_trim(.), x, nomatch = FALSE)) %>%
purrr::map_lgl(~ length(.) == 0L | all(. == 0L))
which(nomatch & is_public(internal))
}
out
}
match_eval <- function(string, env) {
if (env_has(env, string)) {
val <- env[[string]]
if (is.integer(val)) {
return(val)
}
}
expr <- tryCatch(parse_expr(string), error = function(e) NULL)
if (is.null(expr)) {
topic_must("be valid R code", string)
return(integer())
}
if (is_string(expr) || is_symbol(expr)) {
expr <- as.character(expr)
val <- env_get(env, expr, default = NULL)
if (is.integer(val)) {
val
} else {
topic_must("be a known topic name or alias", string)
integer()
}
} else if (is_call(expr)) {
value <- tryCatch(eval(expr, env), error = function(e) NULL)
if (is.null(value)) {
topic_must("be a known selector function", string)
integer()
} else {
value
}
} else {
topic_must("be a string or function call", string)
integer()
}
}
topic_must <- function(message, topic) {
warn(c(
paste0("In '_pkgdown.yml', topic must ", message),
x = paste0("Not ", encodeString(topic, quote = "'"))
))
}
content_info <- function(content_entry, index, pkg, section) {
if (!grepl("::", content_entry, fixed = TRUE)) {
topics <- pkg$topics[select_topics(content_entry, pkg$topics),]
tibble::tibble(
path = topics$file_out,
aliases = purrr::map2(topics$funs, topics$name, ~ if (length(.x) > 0) .x else .y),
name = topics$name,
title = topics$title,
icon = find_icons(topics$alias, path(pkg$src_path, "icons"))
)
} else {
names <- strsplit(content_entry, "::")[[1]]
pkg_name <- names[1]
topic <- names[2]
check_package_presence(pkg_name)
rd_href <- find_rd_href(sub("\\(\\)$", "", topic), pkg_name)
rd <- get_rd(rd_href, pkg_name)
rd_title <- extract_title(rd)
rd_aliases <- find_rd_aliases(rd)
tibble::tibble(
path = rd_href,
aliases = rd_aliases,
name = content_entry,
title = sprintf("%s (from %s)", rd_title, pkg_name),
icon = list(content_entry = NULL)
)
}
}
check_package_presence <- function(pkg_name) {
rlang::check_installed(
pkg = pkg_name,
reason = "as it is mentioned in the reference index."
)
}
get_rd <- function(rd_href, pkg_name) {
rd_name <- fs::path_ext_set(fs::path_file(rd_href), "Rd")
db <- tools::Rd_db(pkg_name)
Rd <- db[[rd_name]]
set_classes(Rd)
}
find_rd_aliases <- function(rd) {
funs <- topic_funs(rd)
if (length(funs) > 0) {
list(funs)
} else {
extract_tag(rd, "tag_name")
}
}
find_rd_href <- function(topic, pkg_name) {
href <- downlit::href_topic(topic, pkg_name)
if (is.na(href)) {
abort(
sprintf(
"Could not find an href for topic %s of package %s",
topic, pkg_name
)
)
}
href
} |
knitr::opts_chunk$set(
collapse = TRUE,
comment = "
)
library(hetu)
example_pin <- "111111-111C"
hetu(example_pin)
knitr::kable(hetu(example_pin))
example_pins <- c("010101-0101", "111111-111C")
knitr::kable(hetu(example_pins))
hetu(example_pins, extract = "sex")
hetu(example_pins, extract = "checksum")
hetu_sex(example_pins)
hetu_age(example_pins)
hetu_age(example_pins, date = "2012-01-01")
hetu_age(example_pins, timespan = "months")
hetu_date(example_pins)
hetu_ctrl(c("010101-0101", "111111-111C"))
hetu_ctrl("010101-1010")
example_temp_pin <- "010101A900R"
knitr::kable(hetu(example_temp_pin, allow.temp = TRUE))
knitr::kable(hetu(example_temp_pins, allow.temp = TRUE))
hetu_ctrl("010101A900R", allow.temp = TRUE)
rhetu(n = 4)
rhetu(n = 4, start_date = "1990-01-01", end_date = "2005-01-01")
random_sample <- rhetu(n = 4, p.male = 0.8)
table(random_sample)
temp_sample <- rhetu(n = 4, p.temp = 0.5)
table(hetu(temp_sample, allow.temp = TRUE, extract = "is.temp"))
bid_sample <- rbid(3)
bid_sample
bid_ctrl(c("0737546-2", "1572860-0"))
bid_ctrl("0737546-1")
citation("hetu")
sessionInfo() |
SamplerHierarchical = R6Class("SamplerHierarchical", inherit = Sampler,
public = list(
samplers = NULL,
initialize = function(param_set, samplers) {
assert_param_set(param_set, no_untyped = TRUE)
assert_list(samplers, types = "Sampler1D")
ids1 = param_set$ids()
ids2 = map_chr(samplers, function(s) s$param$id)
if (!setequal(ids1, ids2)) {
stop("IDs of params in samplers to not correspond to IDs of params in set!")
}
super$initialize(param_set)
self$samplers = samplers
}
),
private = list(
.sample = function(n) map_dtc(self$samplers, function(s) s$sample(n)$data)
)
) |
library(alakazam)
library(shazam)
library(dplyr)
library(ggplot2)
data(ExampleDb, package="alakazam")
db <- subset(ExampleDb, c_call %in% c("IGHA", "IGHG") & sample_id == "+7d")
db_obs <- observedMutations(db, sequenceColumn="sequence_alignment",
germlineColumn="germline_alignment_d_mask",
regionDefinition=NULL,
frequency=FALSE,
nproc=1)
db_obs %>%
select(sequence_id, starts_with("mu_count_")) %>%
head(n=4)
db_obs <- observedMutations(db_obs, sequenceColumn="sequence_alignment",
germlineColumn="germline_alignment_d_mask",
regionDefinition=NULL,
frequency=TRUE,
nproc=1)
db_obs %>%
select(sequence_id, starts_with("mu_freq_")) %>%
head(n=4)
db_obs <- observedMutations(db, sequenceColumn="sequence_alignment",
germlineColumn="germline_alignment_d_mask",
regionDefinition=NULL,
frequency=TRUE,
combine=TRUE,
nproc=1)
db_obs %>%
select(sequence_id, starts_with("mu_freq_")) %>%
head(n=4)
g1 <- ggplot(db_obs, aes(x=c_call, y=mu_freq, fill=c_call)) +
theme_bw() + ggtitle("Total mutations") +
xlab("Isotype") + ylab("Mutation frequency") +
scale_fill_manual(name="Isotype", values=IG_COLORS) +
geom_boxplot()
plot(g1)
db_obs_v <- observedMutations(db, sequenceColumn="sequence_alignment",
germlineColumn="germline_alignment_d_mask",
regionDefinition=IMGT_V_BY_REGIONS,
frequency=FALSE,
nproc=1)
db_obs_v %>%
select(sequence_id, starts_with("mu_count_fwr")) %>%
head(n=4)
db_obs_v <- observedMutations(db_obs_v, sequenceColumn="sequence_alignment",
germlineColumn="germline_alignment_d_mask",
regionDefinition=IMGT_V,
frequency=TRUE,
nproc=1)
db_obs_v %>%
select(sequence_id, starts_with("mu_freq_")) %>%
head(n=4)
g2 <- ggplot(db_obs_v, aes(x=c_call, y=mu_freq_cdr_s, fill=c_call)) +
theme_bw() + ggtitle("CDR silent mutations") +
xlab("Isotype") + ylab("Mutation frequency") +
scale_fill_manual(name="Isotype", values=IG_COLORS) +
geom_boxplot()
g3 <- ggplot(db_obs_v, aes(x=c_call, y=mu_freq_cdr_r, fill=c_call)) +
theme_bw() + ggtitle("CDR replacement mutations") +
xlab("Isotype") + ylab("Mutation frequency") +
scale_fill_manual(name="Isotype", values=IG_COLORS) +
geom_boxplot()
alakazam::gridPlot(g2, g3, ncol=2)
db_obs_ch <- observedMutations(db, sequenceColumn="sequence_alignment",
germlineColumn="germline_alignment_d_mask",
regionDefinition=NULL,
mutationDefinition=CHARGE_MUTATIONS,
frequency=TRUE,
nproc=1)
db_obs_ch %>%
select(sequence_id, starts_with("mu_freq_")) %>%
head(n=4)
g4 <- ggplot(db_obs_ch, aes(x=c_call, y=mu_freq_seq_r, fill=c_call)) +
theme_bw() + ggtitle("Charge replacement mutations") +
xlab("Isotype") + ylab("Mutation frequency") +
scale_fill_manual(name="Isotype", values=IG_COLORS) +
geom_boxplot()
plot(g4) |
CalcConPwrNonMix <- function(theta.0,
d1, o1.stroke, O1.stroke.star, c1.hat,
d2, o2.stroke, O2.stroke.star, O2.stroke.star.null,
n.star,
alpha) {
min <- exp(min(log(theta.0), - log(theta.0)) - 1)
max <- exp(max(log(theta.0), - log(theta.0)) + 1)
if ((max - min) / 0.01 <= 1000) {
theta <- seq(from = min,
to = max,
by = 0.01)
}
else {
theta <- seq(from = min,
to = max,
length.out = 1000)
}
mu.theta.null <- (log((d2 - log(c1.hat) * O2.stroke.star.null) / (o2.stroke + O2.stroke.star.null))
- log((d1 - log(c1.hat) * O1.stroke.star) / (o1.stroke + O1.stroke.star)))
sigma.theta.null <- (sqrt(1 / (n.star
* (1 - exp(- (d1 - log(c1.hat) * O1.stroke.star) / (o1.stroke + O1.stroke.star))
* (1 + ((d1 - log(c1.hat) * O1.stroke.star) / (o1.stroke + O1.stroke.star))^2)))
+ 1 / (n.star
* (1 - exp(- (d2 - log(c1.hat) * O2.stroke.star.null) / (o2.stroke + O2.stroke.star.null))
* (1 + ((d2 - log(c1.hat) * O2.stroke.star.null) / (o2.stroke + O2.stroke.star.null))^2)))))
mu.theta.alter <- (log((d2 - theta * log(c1.hat) * O2.stroke.star) / (o2.stroke + O2.stroke.star))
- log((d1 - log(c1.hat) * O1.stroke.star) / (o1.stroke + O1.stroke.star)))
sigma.theta.alter <- (sqrt(1 / (n.star
* (1 - exp(- (d1 - log(c1.hat) * O1.stroke.star) / (o1.stroke + O1.stroke.star))
* (1 + ((d1 - log(c1.hat) * O1.stroke.star) / (o1.stroke + O1.stroke.star))^2)))
+ 1 / (n.star
* (1 - exp(- (d2 - theta * log(c1.hat) * O2.stroke.star) / (o2.stroke + O2.stroke.star))
* (1 + ((d2 - theta * log(c1.hat) * O2.stroke.star) / (o2.stroke + O2.stroke.star))^2)))))
gamma.theta <- (stats::pnorm((stats::qnorm(alpha / 2) * sigma.theta.null + mu.theta.null
- mu.theta.alter) / sigma.theta.alter)
+ 1 - stats::pnorm((stats::qnorm(1 - alpha / 2) * sigma.theta.null + mu.theta.null
- mu.theta.alter) / sigma.theta.alter))
mu.theta.0 <- (log((d2 - theta.0 * log(c1.hat) * O2.stroke.star) / (o2.stroke + O2.stroke.star))
- log((d1 - log(c1.hat) * O1.stroke.star) / (o1.stroke + O1.stroke.star)))
sigma.theta.0 <- (sqrt(1 / (n.star
* (1 - exp(- (d1 - log(c1.hat) * O1.stroke.star) / (o1.stroke + O1.stroke.star))
* (1 + ((d1 - log(c1.hat) * O1.stroke.star) / (o1.stroke + O1.stroke.star))^2)))
+ 1 / (n.star
* (1 - exp(- (d2 - theta.0 * log(c1.hat) * O2.stroke.star) / (o2.stroke + O2.stroke.star))
* (1 + ((d2 - theta.0 * log(c1.hat) * O2.stroke.star) / (o2.stroke + O2.stroke.star))^2)))))
gamma.theta.0 <- (stats::pnorm((stats::qnorm(alpha / 2) * sigma.theta.null + mu.theta.null
- mu.theta.0) / sigma.theta.0)
+ 1 - stats::pnorm((stats::qnorm(1 - alpha / 2) * sigma.theta.null + mu.theta.null
- mu.theta.0) / sigma.theta.0))
return(list(theta, gamma.theta, gamma.theta.0))
} |
'focal_min' <- function(x,size=3,cover=1e-6,fillNA=FALSE,saveMargin=TRUE
,verbose=0L) {
focal_extrem(x=x,kind="min",size=size,cover=cover,fillNA=fillNA
,saveMargin=saveMargin,verbose=verbose)
}
'focal_max' <- function(x,size=3,cover=1e-6,fillNA=FALSE,saveMargin=TRUE
,verbose=0L) {
focal_extrem(x=x,kind="max",size=size,cover=cover,fillNA=fillNA
,saveMargin=saveMargin,verbose=verbose)
}
'focal_extrem' <- function(x,kind=c("min","max"),size=3,cover=1e-6
,fillNA=FALSE,saveMargin=TRUE,verbose=0L)
{
kind <- match.arg(kind)
fun <- 'focalExtrem'
if (!is.ursa(x))
return(NULL)
sparse <- attr(x$value,"sparse")
if ((!is.null(sparse))&&(any(na.omit(sparse)!=0)))
stop("TODO: expand compression")
if (!is.na(x$con$posZ[1]))
nb <- length(x$con$posZ)
else
nb <- x$dim[2]
if (!is.na(x$con$posR[1]))
nr <- length(x$con$posR)
else
nr <- x$grid$rows
if (!is.na(x$con$posC[1]))
nc <- length(x$con$posC)
else
nc <- x$grid$columns
dimy <- c(nc,nr,nb)
dim(x$value) <- dimy
x$value <- as.numeric(x$value)
if (verbose>2)
.elapsedTime(paste0("start:nodata:",fun))
nodata <- x$con$nodata
if (is.na(nodata))
nodata <- max(x$value,na.rm=TRUE)+1
x$value[is.na(x$value)] <- nodata
if (verbose>2)
.elapsedTime(paste0("finish:nodata:",fun))
if (verbose>1)
print(summary(x$value))
if (verbose)
.elapsedTime(paste0("start:",fun))
x$value <- .Cursa("focalExtrem",x=x$value
,kind=switch(kind,min=-1L,max=1L)
,nodata=as.numeric(nodata)
,dim=as.integer(dimy)
,size=as.integer(size)
,cover=as.numeric(cover)
,fillNA=as.integer(fillNA)
,saveMargin=as.integer(saveMargin)
,verbose=as.integer(verbose)
,res=numeric(prod(dimy)),NAOK=FALSE)$res
if (verbose)
.elapsedTime(paste0("finish:",fun))
if (verbose>1)
print(summary(x$value))
if (verbose>2)
.elapsedTime(paste0("start:nodata:",fun))
if (abs(nodata)<1)
x$value[abs(x$value-nodata)<1e-27] <- NA
else
x$value[abs(x$value/nodata-1)<1e-6] <- NA
if (verbose>2)
.elapsedTime(paste0("finish:nodata:",fun))
dim(x$value) <- c(dimy[1]*dimy[2],dimy[3])
class(x$value) <- "ursaNumeric"
x
} |
library("mlt")
library("survival")
library("flexsurv")
chk <- function(x, y, ...) {
ret <- all.equal(x, y, ...)
if (isTRUE(ret)) return(ret)
print(ret)
return(TRUE)
}
tol <- .001
fit1 <- coxph(Surv(time, status) ~ karno + age + trt, veteran)
fit2 <- survreg(Surv(time, status) ~ karno + age + trt, veteran, dist = "exponential")
fit3 <- flexsurvreg(Surv(time, status) ~ karno + age + trt, data= veteran, dist = "exponential")
veteran$ytime <- with(veteran, Surv(time, status))
dy <- numeric_var("ytime", support = c(0.1, 1000))
by <- log_basis(dy, ui = "increasing")
m <- mlt(ctm(by, shift = ~ karno + age + trt, data = veteran, todistr = "MinExtr"),
data = veteran, fixed = c("log(ytime)" = 1))
stopifnot(chk(fit3$logliki, m$logliki(coef(m)[-2], weights(m)),
tol = tol, check.attributes = FALSE))
stopifnot(chk(logLik(fit2), logLik(m), tol = tol))
stopifnot(chk(logLik(fit3), logLik(m), tol = tol,
check.attributes = FALSE))
fit2 <- survreg(Surv(time, status) ~ karno + age + trt, veteran, dist = "weibull")
fit3 <- flexsurvreg(Surv(time, status) ~ karno + age + trt, data= veteran, dist = "weibull")
veteran$ytime <- with(veteran, Surv(time, status))
dy <- numeric_var("ytime", support = c(0.1, 1000))
by <- log_basis(dy, ui = "increasing")
m <- mlt(ctm(by, shift = ~ karno + age + trt, data = veteran, todistr = "MinExtr"),
data = veteran)
stopifnot(chk(fit3$logliki, m$logliki(coef(m), weights(m)),
tol = tol, check.attributes = FALSE))
stopifnot(chk(logLik(fit2), logLik(m), tol = tol))
stopifnot(chk(logLik(fit3), logLik(m), tol = tol,
check.attributes = FALSE))
vet2 <- survSplit(Surv(time, status) ~., veteran,
cut=c(60, 120), episode ="timegroup")
vet2$timegroup <- factor(vet2$timegroup)
vet2$ytime <- with(vet2, Surv(tstart, time, status))
suppressWarnings(fit3 <- flexsurvreg(Surv(tstart, time, status) ~
karno + karno:timegroup + age + trt, data= vet2, dist = "exponential"))
m <- mlt(ctm(by, shift = ~ karno + karno:timegroup + age + trt, data = vet2, todistr = "MinExtr"),
data = vet2, fixed = c("log(ytime)" = 1))
stopifnot(chk(fit3$logliki, m$logliki(coef(m)[-2], weights(m)),
tol = tol, check.attributes = FALSE))
stopifnot(chk(logLik(fit3), logLik(m), tol = tol, check.attributes = FALSE))
fit3 <- flexsurvreg(Surv(tstart, time, status) ~ karno + karno:timegroup +
age + trt, data= vet2, dist = "weibull")
m <- mlt(ctm(by, shift = ~ karno + karno:timegroup + age + trt, data = vet2, todistr = "MinExtr"),
data = vet2, scale = TRUE)
stopifnot(chk(fit3$logliki, m$logliki(coef(m), weights(m)),
tol = tol, check.attributes = FALSE))
stopifnot(chk(logLik(fit3), logLik(m), tol = tol, check.attributes = FALSE))
fit1 <- coxph(Surv(tstart, time, status) ~ karno + karno:strata(timegroup) +
age + trt, data= vet2)
btg <- as.basis(vet2$timegroup)
by <- Bernstein_basis(dy, order = 3, ui = "increasing")
m <- mlt(ctm(by, interacting = btg,
shift = ~ karno + karno:timegroup + age + trt, data = vet2, todistr = "MinExtr"),
data = vet2, scale = TRUE)
max(abs(coef(fit1) - coef(m)[-(1:12)])) < 1e-1
max(abs(diag(vcov(m))[-(1:12)] - diag(vcov(fit1)))) < 1e-2 |
library(psych)
library(car)
library(lsr)
setwd("c:/Users/Dima/Documents/R/coursera")
AB <- read.table("stats1_datafiles_Stats1.13.Lab.09.txt", header = T)
edit(AB)
leveneTest(AB$errors ~ AB$driving * AB$conversation)
AB.model <- aov(AB$errors ~ AB$driving * AB$conversation)
summary(AB.model)
AB1 <- subset(AB, AB$driving == "Easy")
AB2 <- subset(AB, AB$driving == "Difficult")
aov.AB1 <- aov(AB1$errors ~ AB1$conversation)
summary(aov.AB1)
aov.AB2 <- aov(AB2$errors ~ AB2$conversation)
summary(aov.AB2)
etaSquared(aov.AB1, anova = T)
etaSquared(aov.AB2, anova = T)
TukeyHSD(aov.AB1)
TukeyHSD(aov.AB2) |
ic.varianza <- function(x,
variable = NULL,
introducir = FALSE,
media_poblacion = c("desconocida","conocida"),
confianza = 0.95,
grafico = FALSE){
media_poblacion <- tolower(media_poblacion)
media_poblacion <- match.arg(media_poblacion)
if(confianza >= 0 & confianza <=1){
confianza <- confianza
alfa_2 <- (1-confianza)/2
} else{
stop("El nivel de confianza debe fijarse entre 0 y 1")
}
if(isFALSE(introducir)) {
x <- data.frame(x)
varnames <- names(x)
if(is.null(variable)){
if(length(x) == 1){
x <- x
} else{
warning("Para calcular el intervalo de confianza hay que seleccionar una variable")
stop("El conjunto de datos seleccionado tiene mas de 1 variable.")
}
} else if(length(variable) == 1){
if(is.numeric(variable)){
if(variable <= length(x)){
variable <- variable
} else{
stop("Selecci\u00f3n err\u00f3nea de variable")
}
}
if(is.character(variable)){
if(all(variable %in% varnames)){
variable = match(variable,varnames)
} else {
stop("El nombre de la variable no es v\u00e1lido")
}
}
x <- x[,variable] %>% as.data.frame()
names(x) <- varnames[variable]
} else{
warning("Para calcular el intervalo de confianza hay que seleccionar una variable")
stop("El conjunto de datos seleccionado tiene mas de 1 variable.")
}
x <- na.omit(x)
clase <- sapply(x, class)
if (!clase %in% c("numeric","integer")) {
stop("No puede calcularse el intervalo de confianza porque la variable seleccionada no es cuantitativa")
}
n <- nrow(x)
gl <- n-1
if(media_poblacion == "desconocida"){
varianza_muestral <- as.numeric(readline('Selecciona el valor que quieres utilizar: \n 1. "Varianza muestral" \n 2. "Cuasivarianza muestral" \n'))
if(varianza_muestral == 1){
var_mu <- as.numeric(varianza(x))
} else{
var_mu <- as.numeric(varianza(x, tipo = "cuasi"))
n <- n-1
print("Este es el intervalo de confianza que generalmente calculan los softwares (SPSS, Excel, Stata, ...)")
}
} else{
print("La media poblacional no suele conocerse, este supuesto es te\u00f3rico")
media <- readline(prompt = "Introducir el valor de la media poblacional: ")
media <- as.numeric(media)
sumatorio <- sum((x - media)^2)
}
} else{
n <- readline(prompt = "Introducir el tama\u00f1o de la muestra: ")
n <- as.numeric(n)
gl <- n-1
if(media_poblacion == "desconocida"){
varianza_muestral <- as.numeric(readline('Selecciona el valor que quieres utilizar: \n 1. "Varianza muestral" \n 2. "Cuasivarianza muestral" \n'))
if(varianza_muestral == 1){
var_mu <- readline("Introduce el valor de la varianza muestral: ")
var_mu <- as.numeric(var_mu)
n <- n
} else{
var_mu <- readline("Introduce el valor de la cuasivarianza muestral: ")
var_mu <- as.numeric(var_mu)
n <- n-1
print("Este es el intervalo de confianza que generalmente calculan los softwares (SPSS, Stata, Excel,...)")
}
} else{
print("La media poblacional no suele conocerse, este supuesto es te\u00f3rico")
media <- readline(prompt = "Introducir el valor de la media poblacional: ")
media <- as.numeric(media)
sumatorio <- readline(prompt = "Introducir el valor de la suma cuadratica de las desviaciones de los valores muestrales respecto a la media poblacional: ")
sumatorio <- as.numeric(sumatorio)
}
}
if(media_poblacion == "desconocida"){
print("Intervalo de confianza para la varianza poblacional, supuesta desconocida la media poblacional.")
valor_critico1 <- qchisq(alfa_2,lower.tail = F, df= gl)
valor_critico2 <- qchisq(1-alfa_2, lower.tail = F, df= gl)
limite_inferior <- (n * var_mu) / valor_critico1
limite_superior <- (n * var_mu) / valor_critico2
} else{
print("Intervalo de confianza para la varianza poblacional, supuesta conocida la media poblacional. n peque\u00f1a")
gl <- gl +1
valor_critico1 <- qchisq(alfa_2,lower.tail = F, df= gl)
valor_critico2 <- qchisq(1-alfa_2, lower.tail = F, df= gl)
limite_inferior <- sumatorio / valor_critico1
limite_superior <- sumatorio / valor_critico2
}
if(grafico){
percentil99 <- qchisq(.9999, gl)
df <- data.frame(x=seq(from = 0, to = percentil99, percentil99/200))
df$y <-dchisq(df$x, gl)
plot1 <- ggplot(df) +
geom_path(aes(x,y))+
geom_area(stat = "function", fun = dchisq, args = list(df = gl), fill = "darkgreen", xlim = c(valor_critico2, valor_critico1)) +
geom_area(stat = "function", fun = dchisq, args = list(df = gl), fill = "grey", xlim = c(0, valor_critico2)) +
geom_area(stat = "function", fun = dchisq, args = list(df = gl), fill = "grey", xlim = c(valor_critico1, percentil99)) +
geom_vline(xintercept = 0, color = "black") +
labs(title = paste("Distribuci\u00f3n chi con ", gl, " grados de libertad",sep=""), x = "", y = "") +
scale_y_continuous(breaks = NULL) +
scale_x_continuous(breaks = c(0L,round(valor_critico2,4),round(valor_critico1,4))) +
theme(axis.text.x = element_text(angle = 45))+
geom_point(aes(x= valor_critico2 , y=0), color = "orange4", size = 3) +
geom_point(aes(x= valor_critico1 , y=0), color = "lightblue4", size = 3)
intervalo <- data.frame(ic = round(c(inferior=limite_inferior,superior=limite_superior),4),y=c(0,0))
plot2 <- ggplot(intervalo,aes(x= ic,y)) +
geom_line(aes(group = y), color = "grey",size = 3)+
geom_point(aes(color=ic), size=3,show.legend = FALSE) +
geom_text(aes(label = ic), size = 2.5, vjust=2) +
scale_y_continuous(expand=c(0,0)) +
scale_color_gradientn(colours=c("red","blue"))+
labs(y="",x="Intervalo de confianza") +
tema_blanco
plot <- grid::grid.draw(rbind(ggplotGrob(plot1), ggplotGrob(plot2), size = "last"))
}
IC <- cbind(limite_inferior,limite_superior)
IC <- as.data.frame(IC)
row.names(IC) <- NULL
if(grafico){
return(list(IC,plot))
} else{
return(IC)
}
} |
print.UComp = function(x, ...){
x = UCvalidate(x, TRUE)
}
summary.UComp = function(object, ...){
print(object)
}
plot.UComp = function(x, ...){
if (length(x$comp) < 2){
x = UCcomponents(x)
}
if (is.ts(x$comp)){
plot(x$comp, main = "Time Series Decomposition")
} else {
plot(ts(x$comp, frequency = x$periods[1]),
main = "Time Series Decomposition")
}
}
fitted.UComp = function(object, ...){
if (length(object$yFit) < 2){
object = UCsmooth(object)
}
return(object$yFit)
}
residuals.UComp = function(object, ...){
if (length(object$yFit) < 2){
object = UCfilter(object)
}
return(object$v)
}
logLik.UComp = function(object, ...){
out = object$criteria[1]
class(out) = "logLik"
attr(out, "df") = length(object$p) - 1
attr(out, "nobs") = length(object$y)
return(out)
}
AIC.UComp = function(object, ..., k = 2){
return(object$criteria[2])
}
BIC.UComp = function(object, ...){
return(object$criteria[3])
}
coef.UComp = function(object, ...){
if (length(object$table) < 2){
object = UCvalidate(object, FALSE)
}
return(object$p)
}
predict.UComp = function(object, newdata = NULL, n.ahead = NULL, level = 0.95, ...){
cnst = qt(level + (1 - level) / 2, length(object$y) - length(object$p))
if (!is.null(newdata)){
object$y = newdata
}
if (!is.null(n.ahead) && length(size(n.ahead)) == 1){
object$h = n.ahead
}
if (!is.null(n.ahead) && length(size(n.ahead)) > 1){
object$u = n.ahead
}
m = UCfilter(object)
pred = as.numeric(tail(m$yFit, m$h))
predS = as.numeric(sqrt(tail(m$yFitV, m$h)))
out = cbind(pred, pred - cnst * predS, pred + cnst * predS)
if (is.ts(object$y)){
aux = ts(matrix(0, length(object$y) + 1), start = start(object$y),
frequency = frequency(object$y))
stDate = end(aux)
freq = frequency(object$y)
out = ts(out, start = stDate, frequency = freq)
}
colnames(out) = c("frcst", "lower", "upper")
return(out)
}
tsdiag.UComp = function(object, gof.lag = NULL, ...){
if (length(object$v) < 2){
object = UCfilter(object)
}
nu = dim(object$u)[1]
if (dim(object$u)[2] == 2){
nu = 0
}
nPar = length(object$p) - 1 + nu
aux = list(residuals = object$v,
sigma2 = 1,
nobs = length(object$y) - nPar,
coef = object$p,
x = object$y,
fitted = object$yFit)
if (is.null(gof.lag)){
tsdiag(structure(aux, class = "Arima"))
} else {
tsdiag(structure(aux, class = "Arima"), gof.lag)
}
}
getp0 = function(y, model = "llt/equal/arma(0,0)", periods = NA){
if (any(utf8ToInt(model) == utf8ToInt("?"))){
stop("UComp ERROR: Model should not contain any \'?\'!!!")
}
sys = UCsetup(y, model = model, periods = periods, verbose = FALSE)
sys = UCestim(sys)
p0 = as.vector(sys$p0)
p1 = coef(sys)
names(p0) = names(p1)
return(p0)
}
size = function(y){
out = dim(y)
if (is.null(out))
out = length(y)
return(out)
} |
aur<-function (formula, k, data = NULL, na.action, ...)
{
k <- as.matrix(k)
k1 <- k[1L]
aures <- function(formula, k1, data = NULL, na.action, ...) {
cal <- match.call(expand.dots = FALSE)
mat <- match(c("formula", "data", "na.action"), names(cal))
cal <- cal[c(1L, mat)]
cal[[1L]] <- as.name("model.frame")
cal <- eval(cal)
y <- model.response(cal)
md <- attr(cal, "terms")
x <- model.matrix(md, cal, contrasts)
s <- t(x) %*% x
xin <- solve(s)
bb <- xin %*% t(x) %*% y
I <- diag(NCOL(x))
tk <- solve(s + k1 * I) %*% s
bar <- (I - k1^2 * solve(s + k1 * I) %*% solve(s + k1 *
I)) %*% bb
colnames(bar) <- c("Estimate")
ev <- (t(y) %*% y - t(bb) %*% t(x) %*% y)/(NROW(x) -
NCOL(x))
ev <- diag(ev)
dbb <- ev * (I + k1 * solve(s + k1 * I)) %*% tk %*% xin %*%
tk %*% (I + k1 * solve(s + k1 * I))
bibet <- -k1^2 * solve(s + k1 * I) %*% solve(s + k1 *
I) %*% bb
bibets <- bibet %*% t(bibet)
mse <- dbb + bibets
mse1 <- sum(diag(mse))
mse1 <- round(mse1, digits <- 4L)
names(mse1) <- c("MSE")
Standard_error <- sqrt(diag(abs(dbb)))
dbt <- t(bar)
sdbd_inv <- (sqrt(diag(abs(dbb))))^-1
sdbd_inv_mat <- diag(sdbd_inv)
if (NCOL(dbt) == 1L)
tbb <- dbt * sdbd_inv
else tbb <- dbt %*% sdbd_inv_mat
hggh <- t(tbb)
tst <- t(2L * pt(-abs(tbb), df <- (NROW(x) - NCOL(x))))
colnames(tst) <- c("p_value")
colnames(hggh) <- c("t_statistic")
ans1 <- cbind(bar, Standard_error, hggh, tst)
ans <- round(ans1, digits = 4L)
adw <- list(`*****Almost Unbiased Ridge Estimator******` = ans,
`*****Mean square error value*****` = mse1)
return(adw)
}
npt <- aures(formula, k1, data, na.action)
plotaur <- function(formula, k, data = NULL, na.action, ...) {
j <- 0
arr <- 0
for (j in 1:nrow(k)) {
aurm <- function(formula, k, data, na.action, ...) {
cal <- match.call(expand.dots = FALSE)
mat <- match(c("formula", "data", "na.action"),
names(cal))
cal <- cal[c(1L, mat)]
cal[[1L]] <- as.name("model.frame")
cal <- eval(cal)
y <- model.response(cal)
md <- attr(cal, "terms")
x <- model.matrix(md, cal, contrasts)
s <- t(x) %*% x
xin <- solve(s)
bb <- xin %*% t(x) %*% y
I <- diag(NCOL(x))
tk <- solve(s + k * I) %*% s
bar <- (I - k^2 * solve(s + k * I) %*% solve(s +
k * I)) %*% bb
ev <- (t(y) %*% y - t(bb) %*% t(x) %*% y)/(NROW(x) -
NCOL(x))
ev <- diag(ev)
dbb <- ev * (I + k * solve(s + k * I)) %*% tk %*%
xin %*% tk %*% (I + k * solve(s + k * I))
bibet <- -k^2 * solve(s + k * I) %*% solve(s +
k * I) %*% bb
bibets <- bibet %*% t(bibet)
mse <- dbb + bibets
mse1 <- sum(diag(mse))
return(mse1)
}
arr[j] <- aurm(formula, k[j], data, na.action)
}
MSE <- arr
parameter <- k
pvl <- cbind(parameter, MSE)
colnames(pvl) <- c("Parameter", "MSE")
sval <- pvl
return(sval)
}
paur <- plotaur(formula, k, data, na.action)
if (nrow(k) > 1L)
val <- paur
else val <- npt
val
} |
rotpole_nc_point_to_dt <- function(filename,
variable,
point_lon,
point_lat,
interpolate_to_standard_calendar = FALSE,
verbose = FALSE,
add_grid_coord = FALSE){
ncobj <- nc_open(filename,
readunlim = FALSE)
if(verbose) cat("Succesfully opened file:", filename, "\n")
grid_lon <- ncvar_get(ncobj, "lon")
grid_lat <- ncvar_get(ncobj, "lat")
grid_squared_dist <- (grid_lat - point_lat)^2 + (grid_lon - point_lon)^2
cell_xy <- arrayInd(which.min(grid_squared_dist),
dim(grid_squared_dist))
if(verbose){
cat("Point longitude = ", point_lon, "
cat("Point latitude = ", point_lat, "
cat("Euclidean distance in degrees = ", sqrt(grid_squared_dist[cell_xy]), "\n")
}
values <- as.vector(nc.get.var.subset.by.axes(ncobj,
variable,
list(X = cell_xy[1], Y = cell_xy[2])))
times <- nc.get.time.series(ncobj, variable)
if(all(is.na(times))){
if(verbose) cat("No time information found in nc file.\n")
dates <- NA
} else if(! attr(times, "cal") %in% c("gregorian", "proleptic_gregorian")){
if(verbose) cat("Non-standard calendar found:", attr(times, "cal"), "\n")
if(interpolate_to_standard_calendar){
if(verbose) cat("Interpolating to standard calendar.\n")
dtx <- map_non_standard_calendar(times)
dates <- dtx$dates_full
values <- values[dtx$idx_pcict]
} else {
dates <- as.character(trunc(times, "day"))
}
} else {
times %>%
PCICt::as.POSIXct.PCICt() %>%
as.Date -> dates
}
nc_close(ncobj)
dat <- data.table(date = dates,
value = values)
setnames(dat, "value", variable)
if(add_grid_coord){
dat[, ":="(grid_lon = grid_lon[cell_xy],
grid_lat = grid_lat[cell_xy])]
}
return(dat)
} |
frobenius.norm <- function(x){
return(entrywise.norm(x, 2))
}
entrywise.norm <- function(x, p) {
if (!is.numeric(x)) {
stop("argument x is not numeric")
}
if (is.matrix(x)) {
Xmat <- x
}
else {
if (is.vector(x)) {
Xmat <- matrix(x, nrow = length(x), ncol = 1)
}
else {
stop("argument x is neither vector nor matrix")
}
}
if (p == 0) {
stop("exponent p is zero")
}
if (is.infinite(p)) {
return(maximum.norm(x))
}
return((sum(abs(Xmat)^p))^(1/p))
}
maximum.norm <- function (x) {
if (!is.numeric(x)) {
stop("argument x is not numeric")
}
if (is.matrix(x)) {
Xmat <- x
}
else {
if (is.vector(x)) {
X.mat <- x
}
else {
stop("argument is neither a matrix nor a vector")
}
}
norm <- max(abs(Xmat))
return(norm)
}
frobenius.prod <- function (x, y){
return(sum(hadamard.prod(x, y)))
}
hadamard.prod <- function (x, y)
{
if (!is.numeric(x)) {
stop("argument x is not numeric")
}
if (!is.numeric(y)) {
stop("argument y is not numeric")
}
if (is.matrix(x)) {
Xmat <- x
}
else {
if (is.vector(x)) {
Xmat <- matrix(x, nrow = length(x), ncol = 1)
}
else {
stop("argument x is neither a matrix or a vector")
}
}
if (is.matrix(y)) {
Ymat <- y
}
else {
if (is.vector(y)) {
Ymat <- matrix(y, nrow = length(x), ncol = 1)
}
else {
stop("argument x is neither a matrix or a vector")
}
}
if (nrow(Xmat) != nrow(Ymat))
stop("argumentx x and y do not have the same row order")
if (ncol(Xmat) != ncol(Ymat))
stop("arguments x and y do not have the same column order")
return(Xmat * Ymat)
} |
plotDispEsts.DESeqDataSet <- function( object, ymin, CV=FALSE,
genecol = "black", fitcol = "red", finalcol = "dodgerblue",
legend=TRUE, xlab, ylab, log = "xy", cex = 0.45, ... )
{
if (missing(xlab)) xlab <- "mean of normalized counts"
if (missing(ylab)) {
if (CV) {
ylab <- "coefficient of variation"
} else {
ylab <- "dispersion"
}
}
px = mcols(object)$baseMean
sel = (px>0)
px = px[sel]
f <- if (CV) sqrt else I
py = f(mcols(object)$dispGeneEst[sel])
if(missing(ymin))
ymin = 10^floor(log10(min(py[py>0], na.rm=TRUE))-0.1)
plot(px, pmax(py, ymin), xlab=xlab, ylab=ylab,
log=log, pch=ifelse(py<ymin, 6, 20), col=genecol, cex=cex, ... )
pchOutlier <- ifelse(mcols(object)$dispOutlier[sel],1,16)
cexOutlier <- ifelse(mcols(object)$dispOutlier[sel],2*cex,cex)
lwdOutlier <- ifelse(mcols(object)$dispOutlier[sel],2,1)
if (!is.null(dispersions(object))) {
points(px, f(dispersions(object)[sel]), col=finalcol, cex=cexOutlier,
pch=pchOutlier, lwd=lwdOutlier)
}
if (!is.null(mcols(object)$dispFit)) {
points(px, f(mcols(object)$dispFit[sel]), col=fitcol, cex=cex, pch=16)
}
if (legend) {
legend("bottomright",c("gene-est","fitted","final"),pch=16,
col=c(genecol,fitcol,finalcol),bg="white")
}
}
setMethod("plotDispEsts", signature(object="DESeqDataSet"), plotDispEsts.DESeqDataSet)
plotMA.DESeqDataSet <- function(object, alpha=.1, main="",
xlab="mean of normalized counts", ylim,
colNonSig="gray60", colSig="blue", colLine="grey40",
returnData=FALSE,
MLE=FALSE, ...) {
res <- results(object, ...)
plotMA.DESeqResults(res, alpha=alpha, main=main, xlab=xlab, ylim=ylim, MLE=MLE)
}
plotMA.DESeqResults <- function(object, alpha, main="",
xlab="mean of normalized counts", ylim,
colNonSig="gray60", colSig="blue", colLine="grey40",
returnData=FALSE,
MLE=FALSE, ...) {
sval <- "svalue" %in% names(object)
if (sval) {
test.col <- "svalue"
} else {
test.col <- "padj"
}
if (MLE) {
if (is.null(object$lfcMLE)) {
stop("lfcMLE column is not present: you should first run results() with addMLE=TRUE")
}
lfc.col <- "lfcMLE"
} else {
lfc.col <- "log2FoldChange"
}
if (missing(alpha)) {
if (sval) {
alpha <- 0.005
message("thresholding s-values on alpha=0.005 to color points")
} else {
if (is.null(metadata(object)$alpha)) {
alpha <- 0.1
} else {
alpha <- metadata(object)$alpha
}
}
}
isDE <- ifelse(is.na(object[[test.col]]), FALSE, object[[test.col]] < alpha)
df <- data.frame(mean = object[["baseMean"]],
lfc = object[[lfc.col]],
isDE = isDE)
if (returnData) {
return(df)
}
if (missing(ylim)) {
plotMA(df,
colNonSig=colNonSig, colSig=colSig, colLine=colLine,
xlab=xlab, main=main, ...)
} else {
plotMA(df, ylim=ylim,
colNonSig=colNonSig, colSig=colSig, colLine=colLine,
xlab=xlab, main=main, ...)
}
}
setMethod("plotMA", signature(object="DESeqDataSet"), plotMA.DESeqDataSet)
setMethod("plotMA", signature(object="DESeqResults"), plotMA.DESeqResults)
plotPCA.DESeqTransform = function(object, intgroup="condition", ntop=500, returnData=FALSE)
{
rv <- rowVars(assay(object))
select <- order(rv, decreasing=TRUE)[seq_len(min(ntop, length(rv)))]
pca <- prcomp(t(assay(object)[select,]))
percentVar <- pca$sdev^2 / sum( pca$sdev^2 )
if (!all(intgroup %in% names(colData(object)))) {
stop("the argument 'intgroup' should specify columns of colData(dds)")
}
intgroup.df <- as.data.frame(colData(object)[, intgroup, drop=FALSE])
group <- if (length(intgroup) > 1) {
factor(apply( intgroup.df, 1, paste, collapse=":"))
} else {
colData(object)[[intgroup]]
}
d <- data.frame(PC1=pca$x[,1], PC2=pca$x[,2], group=group, intgroup.df, name=colnames(object))
if (returnData) {
attr(d, "percentVar") <- percentVar[1:2]
return(d)
}
ggplot(data=d, aes_string(x="PC1", y="PC2", color="group")) + geom_point(size=3) +
xlab(paste0("PC1: ",round(percentVar[1] * 100),"% variance")) +
ylab(paste0("PC2: ",round(percentVar[2] * 100),"% variance")) +
coord_fixed()
}
setMethod("plotPCA", signature(object="DESeqTransform"), plotPCA.DESeqTransform)
plotCounts <- function(dds, gene, intgroup="condition",
normalized=TRUE, transform=TRUE,
main, xlab="group",
returnData=FALSE,
replaced=FALSE,
pc, ...) {
stopifnot(length(gene) == 1 & (is.character(gene) | (is.numeric(gene) & (gene >= 1 & gene <= nrow(dds)))))
if (!all(intgroup %in% names(colData(dds)))) stop("all variables in 'intgroup' must be columns of colData")
if (!returnData) {
if (!all(sapply(intgroup, function(v) is(colData(dds)[[v]], "factor")))) {
stop("all variables in 'intgroup' should be factors, or choose returnData=TRUE and plot manually")
}
}
if (missing(pc)) {
pc <- if (transform) 0.5 else 0
}
if (is.null(sizeFactors(dds)) & is.null(normalizationFactors(dds))) {
dds <- estimateSizeFactors(dds)
}
cnts <- counts(dds,normalized=normalized,replaced=replaced)[gene,]
group <- if (length(intgroup) == 1) {
colData(dds)[[intgroup]]
} else if (length(intgroup) == 2) {
lvls <- as.vector(t(outer(levels(colData(dds)[[intgroup[1]]]),
levels(colData(dds)[[intgroup[2]]]),
function(x,y) paste(x,y,sep=":"))))
droplevels(factor(apply( as.data.frame(colData(dds)[, intgroup, drop=FALSE]),
1, paste, collapse=":"), levels=lvls))
} else {
factor(apply( as.data.frame(colData(dds)[, intgroup, drop=FALSE]),
1, paste, collapse=":"))
}
data <- data.frame(count=cnts + pc, group=as.integer(group))
logxy <- if (transform) "y" else ""
if (missing(main)) {
main <- if (is.numeric(gene)) {
rownames(dds)[gene]
} else {
gene
}
}
ylab <- ifelse(normalized,"normalized count","count")
if (returnData) return(data.frame(count=data$count, colData(dds)[intgroup]))
plot(data$group + runif(ncol(dds),-.05,.05), data$count, xlim=c(.5,max(data$group)+.5),
log=logxy, xaxt="n", xlab=xlab, ylab=ylab, main=main, ...)
axis(1, at=seq_along(levels(group)), levels(group))
}
plotSparsity <- function(x, normalized=TRUE, ...) {
if (is(x, "DESeqDataSet")) {
x <- counts(x, normalized=normalized)
}
rs <- rowSums(x)
rmx <- apply(x, 1, max)
plot(rs[rs > 0], (rmx/rs)[rs > 0], log="x", ylim=c(0,1), xlab="sum of counts per gene",
ylab="max count / sum", main="Concentration of counts over total sum of counts", ...)
} |
angle2hms <- function(angle)
{
hourDecimal <- 24 * angle / 360
hour <- floor(hourDecimal)
minute <- floor(60*(hourDecimal - hour))
second <- 3600*(hourDecimal - hour - minute / 60)
floorSecond <- floor(second)
centiSecond <- round(100 * (second - floorSecond))
string <- sprintf("%.0fh%.0fm%.0fs.%.0f", hour, minute, floorSecond, centiSecond)
list(hourDecimal=hourDecimal, hour=hour, minute=minute, second=second, string=string)
}
eclipticalToEquatorial <- function(lambda, beta, epsilon)
{
if (is.data.frame(lambda)) {
beta <- lambda$beta
epsilon <- lambda$epsilon
lambda <- lambda$lambda
}
RPD <- atan2(1, 1) / 45
alpha <- atan2(sin(RPD * lambda) * cos(RPD * epsilon) - tan(RPD * beta) * sin(RPD * epsilon), cos(RPD * lambda))
delta <- asin(sin(RPD * beta) * cos(RPD * epsilon) + cos(RPD * beta) * sin(RPD * epsilon) * sin(RPD * lambda))
data.frame(rightAscension=alpha/RPD, declination=delta/RPD)
}
equatorialToLocalHorizontal <- function(rightAscension, declination, t, longitude, latitude)
{
RPD <- atan2(1, 1) / 45
theta0 <- siderealTime(t)
H <- theta0 * 15 + longitude - rightAscension
A <- atan2(sin(RPD * H), cos(RPD * H) * sin(RPD * latitude) - tan(RPD * declination) * cos(RPD * latitude))
h <- asin(sin(RPD * latitude) * sin(RPD * declination) + cos(RPD * latitude) * cos(RPD * declination) * cos(RPD * H))
data.frame(azimuth=A/RPD, altitude=h/RPD)
}
siderealTime <- function(t)
{
tt <- as.POSIXlt(t)
n <- length(tt$hour)
tt$hour <- rep(0, n)
tt$min <- rep(0, n)
tt$sec <- rep(0, n)
jd <- julianDay(t)
jd0 <- julianDay(tt)
T <- (jd0 - 2415020.0) / 36525
hoursLeftOver <- 24 * (jd - jd0)
res <- 6.6460656 + 2400.051262 * T + 0.00002581 * T * T
res <- res + 1.002737908 * hoursLeftOver
res <- res %% 24
res
}
julianDay <- function(t, year=NA, month=NA, day=NA, hour=NA, min=NA, sec=NA, tz="UTC")
{
if (missing(t)) {
if (is.na(year) || is.na(month) || is.na(day) || is.na(hour)
|| is.na(min) || is.na(sec))
stop("must supply year, month, day, hour, min, and sec")
t <- ISOdatetime(year, month, day, hour, min, sec, tz=tz)
}
tt <- as.POSIXlt(t, tz=tz)
year <- tt$year + 1900
month <- tt$mon + 1
day <- tt$mday + (tt$hour + tt$min / 60 + tt$sec / 3600) / 24
m <- ifelse(month <= 2, month + 12, month)
y <- ifelse(month <= 2, year - 1, year)
A <- floor(y / 100)
B <- 2 - A + floor(A / 4)
jd <- floor(365.25 * y) + floor(30.6001 * (m + 1)) + day + 1720994.5
jd <- ifelse(tt > ISOdatetime(1582, 10, 15, 0, 0, 0), jd + B, jd)
jd
}
julianCenturyAnomaly <- function(jd)
{
(jd - 2415020.0) / 36525
} |
get_scheds_and_rosters <- function(season, type) {
out <- tibble::tibble()
tryCatch(
expr = {
if (type == "schedule") {
path <- glue::glue("https://github.com/nflverse/nflfastR-data/blob/master/schedules/sched_{season}.rds?raw=true")
} else if (type == "roster") {
path <- glue::glue("https://github.com/nflverse/nflfastR-roster/blob/master/data/seasons/roster_{season}.rds?raw=true")
}
warn <- 0
fetched <- curl::curl_fetch_memory(path)
if (fetched$status_code == 404) {
warning(warn <- 2)
} else if (fetched$status_code == 500) {
warning(warn <- 1)
}
out <- read_raw_rds(fetched$content)
},
error = function(e) {
message("The following error has occured:")
message(e)
},
warning = function(w) {
if (warn == 1) {
message("Warning: The data hosting servers are down, please try again later!")
} else if (warn == 2) {
message(glue::glue("Warning: Either the requested season {season} is invalid or no data available at this time!"))
} else {
message("The following warning has occured:")
message(w)
}
},
finally = {
}
)
return(out)
} |
context("Empirical checkerboard copula")
test_that("ECBC returns a matrix of correct dimension", {
x <- runif(10)
y <- runif(10)
expect_type(qad::ECBC(x,y), "double")
expect_equal(dim(qad::ECBC(x,y)), c(3,3))
expect_equal(dim(qad::ECBC(x,y, resolution = 2)), c(2,2))
expect_equal(dim(qad::ECBC(x,y, resolution = 1)), c(1,1))
expect_equal(dim(qad::ECBC(x,y, resolution = 10)), c(10, 10))
expect_warning(qad::ECBC(x,y, resolution = 11), "Resolution cannot exceed sample size")
})
test_that("ECBC returns uniform margins", {
x <- runif(100)
y <- runif(100)
expect_equal(colSums(qad::ECBC(x,y)), rep(1/10, 10))
expect_equal(rowSums(qad::ECBC(x,y)), rep(1/10, 10))
expect_equal(colSums(qad::ECBC(x,y, resolution = 4)), rep(1/4, 4))
expect_equal(rowSums(qad::ECBC(x,y, resolution = 4)), rep(1/4, 4))
expect_equal(colSums(qad::ECBC(x,y, resolution = 100)), rep(1/100, 100))
expect_equal(rowSums(qad::ECBC(x,y, resolution = 100)), rep(1/100, 100))
x <- c(1,1,1,2,2,3,3,3)
y <- c(1,2,3,4,5,6,6,7)
expect_equal(rowSums(qad::ECBC(x,y, resolution = 3)), rep(1/3, 3))
expect_equal(colSums(qad::ECBC(x,y, resolution = 3)), rep(1/3, 3))
})
test_that("ECBC.eval returns correct results", {
M <- diag(1/5, 5)
expect_equal(qad::ECBC.eval(M, eval.points = cbind(c(0,0.2,0.3,0.5,0.7,1), c(0.3,0.5,0.6,0.8,0,1))),
c(0,0.2,0.3,0.5,0,1))
}) |
`[.ensembleData` <-
function (x, i, j)
{
ncolx <- ncol(x)
matchCall <- match.call()
matchCall[[1]] <- as.name("[.data.frame")
if (missing(i)) matchCall$i <- 1:nrow(x)
nForcs <- nForecasts <- ensembleSize(x)
exchangeable <- attr(x, "exchangeable")
forecastHour <- attr(x, "forecastHour")
initializationTime <- attr(x, "initializationTime")
startupSpeed <- attr(x, "startupSpeed")
if (!missing(j) && !is.null(j)) {
if (is.logical(j)) {
if (length(j) != nForecasts)
stop("logical index must refer to the forecasts")
j <- (1:nForecasts)[j]
nForcs <- length(j)
exchangeable <- exchangeable[j]
}
else if (is.character(j)) {
m <- match(j, names(x)[1:nForecasts], nomatch = 0)
if (any(!m))
stop("character index must refer to the forecasts")
if (any(duplicated(j)))
stop("repeated indexes not allowed")
nForcs <- length(j)
I <- 1:nForecasts
names(I) <- ensembleMembers(x)
j <- I[j]
names(j) <- NULL
exchangeable <- exchangeable[j]
}
else {
if (any(abs(j) > nForcs))
stop("column index must be confined to the forecasts")
if (any(duplicated(j)))
stop("repeated indexes not allowed")
j <- (1:nForecasts)[j]
nForcs <- length(j)
exchangeable <- exchangeable[j]
}
if (nForcs < ncolx) {
matchCall$j <- c(j, (nForecasts+1):ncolx)
}
else matchCall$j <- j
}
else matchCall$j <- 1:ncolx
if (!missing(i)) {
v <- (1:nrow(x))
names(v) <- dimnames(x)[[1]]
i <- v[i]
names(i) <- NULL
if (any(duplicated(i)))
stop("repeated entries not allowed")
}
matchCall$drop <- FALSE
listCall <- as.list(matchCall)
nam <- names(listCall)
listCall <- listCall[c(1,2,which(nam == "i"), which(nam == "j"),
length(listCall))]
names(listCall) <- NULL
x <- eval(as.call(listCall), parent.frame())
attr(x, "initializationTime") <- initializationTime
attr(x, "forecastHour") <- forecastHour
attr(x, "startupSpeed") <- startupSpeed
attr(x, "exchangeable") <- exchangeable
attr(x, "ensembleSize") <- nForcs
x
} |
sample_k_uniform_hypergraph <- function(n,m,k,prob)
{
if(n<k) stop("n must be at least as large as k")
if(missing(prob)){
prob <- rep(1/n,n)
}
M <- Matrix::Matrix(0,nrow=m,ncol=n)
for(i in 1:m){
M[i,sample(n,k,replace=FALSE,prob=prob)] <- 1
}
hypergraph_from_incidence_matrix(M)
}
sample_k_regular_hypergraph <- function(n,m,k,prob)
{
if(m<k) stop("m must be at least as large as k")
if(missing(prob)){
prob <- rep(1/m,m)
}
M <- Matrix::Matrix(0,nrow=m,ncol=n)
for(i in 1:n){
M[sample(m,k,replace=FALSE,prob=prob),i] <- 1
}
hypergraph_from_incidence_matrix(M)
} |
get.win.stat_t<-function(trt, con, ep_type, Z_t_trt = NULL, Z_t_con = NULL, priority = c(1,2),
Ctimej = Inf, Start_time_trt = NULL, Start_time_con = NULL, alpha = 0.05,
tau = 0, weight = c("unstratified","MH-type","wt.stratum1","wt.stratum2","equal"),
censoring_adjust = c("No","IPCW","CovIPCW"),
pvalue = c("one-sided","two-sided"),
win.strategy = NULL, status_only = FALSE, return_CI = FALSE,
return_pvalue = FALSE, ...){
n_ep = length(priority)
colname.trt = colnames(trt)
ind.delta1 = which(colname.trt == "Delta_1_trt")
ind.time1 = which(colname.trt == "Y_1_trt")
for(ind.ep in which(ep_type == "tte")){
delta_new_trt = trt[,ind.delta1+ind.ep-1] * (trt[,ind.time1+ind.ep-1] <= (Ctimej - Start_time_trt))
time_new_trt = apply(cbind(trt[,ind.time1+ind.ep-1],(Ctimej - Start_time_trt)),1,
func<-function(x) ifelse(min(x)>0,min(x),0))
trt[,ind.delta1+ind.ep-1] = delta_new_trt
trt[,ind.time1+ind.ep-1] = time_new_trt
delta_new_con = con[,ind.delta1+ind.ep-1] * (con[,ind.time1+ind.ep-1] <= (Ctimej - Start_time_con))
time_new_con = apply(cbind(con[,ind.time1+ind.ep-1],(Ctimej - Start_time_con)),1,
func<-function(x) ifelse(min(x)>0,min(x),0))
con[,ind.delta1+ind.ep-1] = delta_new_con
con[,ind.time1+ind.ep-1] = time_new_con
}
trt_con = merge(trt,con,by="stratum")
if(is.null(win.strategy)){
win_status = win.strategy.default(trt_con = trt_con, priority = priority, tau = tau)
}else{
win_status = win.strategy(trt_con = trt_con, priority = priority, ...)
}
res_KL = switch (censoring_adjust,
"No" = original.KL(win_status = win_status, trt_con = trt_con, n_ep = n_ep),
"IPCW" = ipcw.adjusted.KL(win_status = win_status, trt = trt, con = con, trt_con = trt_con,
priority = priority, n_ep = n_ep, ep_type = ep_type),
"CovIPCW" = covipcw.adjusted.KL(win_status = win_status, trt = trt,con = con,trt_con = trt_con,
Z_t_trt = Z_t_trt, Z_t_con = Z_t_con,
priority = priority, n_ep = n_ep, ep_type = ep_type)
)
KL = res_KL$KL
status_KL = res_KL$status_KL
N_trt = as.data.frame(table(trt$stratum))[,2]
N_con = as.data.frame(table(con$stratum))[,2]
N_trt_con = cbind(as.numeric(levels(factor(trt_con$stratum))), N_trt, N_con )
colnames(N_trt_con)=c('stratum', 'N2_trt', 'N2_con')
KL.summary = apply(cbind(KL$K,KL$L), 2, func<-function(x){
temp = aggregate(x, by=list(Category=trt_con[[1]]), FUN=sum)
as.matrix(temp)[,2]
})
KL.summary = matrix(KL.summary,ncol = 2)
n_str = nrow(KL.summary)
for(stri in 1:n_str){
sum_KL_str = sum(KL.summary[stri,])/(N_trt[stri]*N_con[stri])
if(sum_KL_str>=1){
KL$K[which(KL$stratum==stri)] = KL$K[which(KL$stratum==stri)]/sum_KL_str
KL$L[which(KL$stratum==stri)] = KL$L[which(KL$stratum==stri)]/sum_KL_str
status_KL[which(KL$stratum==stri),] = status_KL[which(KL$stratum==stri),]/sum_KL_str
KL.summary[stri,] = KL.summary[stri,]/sum_KL_str
}
}
win_trt = KL.summary[,1]
win_con = KL.summary[,2]
if(status_only){
return(list(win_status = status_KL))
}else{
P_trt = win_trt/(N_trt*N_con)
P_con = win_con/(N_trt*N_con)
WR = win_trt/win_con
NB = P_trt - P_con
WO = (P_trt + 0.5*(1-P_trt-P_con))/(P_con + 0.5*(1-P_trt-P_con))
N = N_trt + N_con
ind.trt = which(colnames(trt)=="Delta_1_trt")
event_trt = apply(trt[,ind.trt:(ind.trt+n_ep-1)], 1, function(x) max(x)>0)
N_event_trt = tapply(event_trt,trt$stratum,sum)
ind.con = which(colnames(con)=="Delta_1_con")
event_con = apply(con[,ind.con:(ind.con+n_ep-1)], 1, function(x) max(x)>0)
N_event_con = tapply(event_con,con$stratum,sum)
N_event = N_event_trt + N_event_con
w_stratum = switch(weight,
"unstratified" = 1,
"equal" = rep(1/length(N),length(N)),
"MH-type" = (1/N)/sum(1/N),
"wt.stratum1" = N/sum(N),
"wt.stratum2" = N_event/sum(N_event)
)
stratified_WR = switch(weight,
"unstratified" = sum(P_trt*w_stratum)/sum(P_con*w_stratum),
"equal" = sum(P_trt*w_stratum)/sum(P_con*w_stratum),
"MH-type" = sum(P_trt*w_stratum)/sum(P_con*w_stratum),
"wt.stratum1" = sum(w_stratum*WR_stratum),
"wt.stratum2" = sum(w_stratum*WR_stratum)
)
stratified_NB = switch(weight,
"unstratified" = sum(P_trt*w_stratum)-sum(P_con*w_stratum),
"equal" = sum(P_trt*w_stratum)-sum(P_con*w_stratum),
"MH-type" = sum(P_trt*w_stratum)-sum(P_con*w_stratum),
"wt.stratum1" = sum(w_stratum*NB_stratum),
"wt.stratum2" = sum(w_stratum*NB_stratum)
)
stratified_WO = switch(weight,
"unstratified" = sum((P_trt + 0.5*(1-P_trt-P_con))*w_stratum)/
sum((P_con + 0.5*(1-P_trt-P_con))*w_stratum),
"equal" = sum((P_trt + 0.5*(1-P_trt-P_con))*w_stratum)/
sum((P_con + 0.5*(1-P_trt-P_con))*w_stratum),
"MH-type" = sum((P_trt + 0.5*(1-P_trt-P_con))*w_stratum)/
sum((P_con + 0.5*(1-P_trt-P_con))*w_stratum),
"wt.stratum1" = sum(w_stratum*WO_stratum),
"wt.stratum2" = sum(w_stratum*WO_stratum)
)
Win_statisitc = list(Win_Ratio = stratified_WR,
Net_Benefit = stratified_NB,
Win_Odds = stratified_WO,
win_status = win_status)
if(return_CI == TRUE){
theta_KL_0 = (win_trt + win_con)/(2*N_trt*N_con)
theta_KL_0 = cbind(as.numeric(levels(factor(trt_con$stratum))), theta_KL_0)
colnames(theta_KL_0)=c('stratum', 'theta_KL_0')
sum_k_trt = aggregate(KL$K, by=list(trt_con$stratum, trt_con$pid_trt), FUN = sum)
sum_k_con = aggregate(KL$K, by=list(trt_con$stratum, trt_con$pid_con), FUN = sum)
sum_L_trt = aggregate(KL$L, by=list(trt_con$stratum, trt_con$pid_trt), FUN = sum)
sum_L_con = aggregate(KL$L, by=list(trt_con$stratum, trt_con$pid_con), FUN = sum)
names(sum_k_trt) = c('stratum', 'pid_trt', 'sum_k_trt')
names(sum_k_con) = c('stratum', 'pid_con', 'sum_k_con')
names(sum_L_trt) = c('stratum', 'pid_trt', 'sum_l_trt')
names(sum_L_con) = c('stratum', 'pid_con', 'sum_l_con')
KL = merge(KL, sum_k_trt, by=c('stratum', 'pid_trt'))
KL = merge(KL, sum_k_con, by=c('stratum', 'pid_con'))
KL = merge(KL, sum_L_trt, by=c('stratum', 'pid_trt'))
KL = merge(KL, sum_L_con, by=c('stratum', 'pid_con'))
KL = merge(KL, theta_KL_0, by=c('stratum'))
KL = merge(KL, N_trt_con, by=c('stratum'))
sig2_trt_1 = N_trt*N_con*aggregate( (KL$K-KL$theta_KL_0)*(KL$sum_k_trt - KL$K - (KL$N2_con - 1)*KL$theta_KL_0 ),
by=list(KL$stratum), FUN = sum)[,2]/(N_con-1)
sig2_trt_2 = N_trt*N_con*aggregate( (KL$K-KL$theta_KL_0)*(KL$sum_k_con - KL$K - (KL$N2_trt - 1)*KL$theta_KL_0 ),
by=list(KL$stratum), FUN = sum)[,2]/(N_trt-1)
sig2_con_1 = N_trt*N_con*aggregate( (KL$L-KL$theta_KL_0)*(KL$sum_l_con - KL$L - (KL$N2_trt - 1)*KL$theta_KL_0 ),
by=list(KL$stratum), FUN = sum)[,2]/(N_trt-1)
sig2_con_2 = N_trt*N_con*aggregate( (KL$L-KL$theta_KL_0)*(KL$sum_l_trt - KL$L - (KL$N2_con - 1)*KL$theta_KL_0 ),
by=list(KL$stratum), FUN = sum)[,2]/(N_con-1)
sig_trt_con_1 = N_trt*N_con*aggregate( (KL$K-KL$theta_KL_0)*(KL$sum_l_trt - KL$L - (KL$N2_con - 1)*KL$theta_KL_0 ),
by=list(KL$stratum), FUN = sum)[,2]/(N_con-1)
sig_trt_con_2 = N_trt*N_con*aggregate( (KL$K-KL$theta_KL_0)*(KL$sum_l_con - KL$L - (KL$N2_trt - 1)*KL$theta_KL_0 ),
by=list(KL$stratum), FUN = sum)[,2]/(N_trt-1)
sig2_trt = sig2_trt_1/N_trt + sig2_trt_2/N_con
sig2_con = sig2_con_1/N_con + sig2_con_2/N_trt
sig_trt_con = sig_trt_con_1/N_trt + sig_trt_con_2/N_con
theta_tc = (win_trt + win_con)/2
gam = theta_tc + 0.5*(N_trt*N_con-theta_tc-theta_tc)
if(weight%in%c("wt.stratum1","wt.stratum2")){
sig2_wr = (sig2_trt + sig2_con - 2*sig_trt_con)/((theta_tc)^2)
sig2_wo = (sig2_trt + sig2_con - 2*sig_trt_con)*(((N_trt*N_con)/(2*(gam^2)))^2)
sig2_nb = (sig2_trt + sig2_con - 2*sig_trt_con)/((N_trt*N_con)^2)
stratified_sig2_log_wr = sum(((w_stratum)^2)*sig2_wr)/(stratified_WR^2)
stratified_sig2_log_wo = sum(((w_stratum)^2)*sig2_wo)/(stratified_WO^2)
stratified_sig2_nb = sum(((w_stratum)^2)*sig2_nb)
}else{
stratified_sig2_log_wr = sum(((w_stratum)^2)*(sig2_trt + sig2_con - 2*sig_trt_con))/
((sum(w_stratum*theta_tc))^2)
stratified_sig2_log_wo = sum(((w_stratum)^2)*(sig2_trt + sig2_con - 2*sig_trt_con))*
((0.5/sum(w_stratum*gam)+0.5/sum(w_stratum*(N_trt*N_con-gam)))^2)
stratified_sig2_nb = sum(((w_stratum)^2)*(sig2_trt + sig2_con - 2*sig_trt_con))/
((sum(w_stratum*N_trt*N_con))^2)
}
stratified_WR_L = exp(log(stratified_WR) - qnorm(1-alpha/2)*sqrt(stratified_sig2_log_wr))
stratified_WR_U = exp(log(stratified_WR) + qnorm(1-alpha/2)*sqrt(stratified_sig2_log_wr))
stratified_WO_L = exp(log(stratified_WO) - qnorm(1-alpha/2)*sqrt(stratified_sig2_log_wo))
stratified_WO_U = exp(log(stratified_WO) + qnorm(1-alpha/2)*sqrt(stratified_sig2_log_wo))
stratified_NB_L = stratified_NB - qnorm(1-alpha/2)*sqrt(stratified_sig2_nb)
stratified_NB_U = stratified_NB + qnorm(1-alpha/2)*sqrt(stratified_sig2_nb)
CI_t = list(WR = c(stratified_WR_L,stratified_WR_U),
NB = c(stratified_NB_L,stratified_NB_U),
WO = c(stratified_WO_L,stratified_WO_U))
if(return_pvalue){
pvalue_WR = switch(pvalue,
"one-sided" = 1 - pnorm((log(stratified_WR)/sqrt(stratified_sig2_log_wr)),
mean = 0, sd = 1),
"two-sided" = 2 - 2*pnorm(abs(log(stratified_WR)/sqrt(stratified_sig2_log_wr)),
mean = 0, sd = 1))
pvalue_WO = switch(pvalue,
"one-sided" = 1 - pnorm((log(stratified_WO)/sqrt(stratified_sig2_log_wo)),
mean = 0, sd = 1),
"two-sided" = 2 - 2*pnorm(abs(log(stratified_WO)/sqrt(stratified_sig2_log_wo)),
mean = 0, sd = 1))
pvalue_NB = switch(pvalue,
"one-sided" = 1 - pnorm((stratified_NB/sqrt(stratified_sig2_nb)),
mean = 0, sd = 1),
"two-sided" = 2 - 2*pnorm(abs(stratified_NB/sqrt(stratified_sig2_nb)),
mean = 0, sd = 1))
p_value_t = c(pvalue_WR,pvalue_NB,pvalue_WO)
return(list(Win_statisitc = Win_statisitc, p_value_t = p_value_t, CI_t = CI_t))
}else{
return(list(Win_statisitc = Win_statisitc, CI_t = CI_t))
}
}else{
return(Win_statisitc = Win_statisitc)
}
}
} |
installed.versions <- function (pkgs,
lib) {
if (missing(lib) || is.null(lib)) {
lib <- .libPaths()[1L]
if (length(.libPaths()) > 1L)
message(sprintf(ngettext(length(pkgs), "Checking package in %s\n(as %s is unspecified)",
"Checking packages in %s\n(as %s is unspecified)"),
sQuote(lib), sQuote("lib")), domain = NA)
}
if (length(pkgs) > 1) {
ans <- sapply(pkgs,
installed.versions,
lib)
return (ans)
}
desc_path <- sprintf('%s/%s/DESCRIPTION',
lib,
pkgs)
if (!file.exists(desc_path)) {
return (NA)
} else {
lines <- readLines(desc_path)
vers_line <- lines[grep('^Version: *', lines)]
vers <- gsub('Version: ', '', vers_line)
return (vers)
}
} |
install_version <- function(package, version = NA, compare = NA, repos = getOption("repos"), type = getOption("pkgType"), ...) {
contriburl <- contrib.url(repos, type)
available <- available.packages(contriburl)
validate_compare(compare)
should_install <- validate_installed_package(package, version, compare)
if(should_install) {
available_versions <- find_available_versions(package, repos, type)
version_to_install <- determine_version_to_install(available_versions$version, version, compare)
url <- available_versions[available_versions$version == version_to_install, 'url']
install_url(url, ...)
}
should_install
}
validate_installed_package <- function(package, version, compare) {
should_install <- TRUE
packages <- as.data.frame(installed.packages(), stringsAsFactors=FALSE)
if(package %in% row.names(packages)) {
installed_package <- packages[package,]
message(
sprintf(
"Package [%s] with version [%s] is already installed in library [%s].",
package,
installed_package$Version,
installed_package$LibPath
)
)
if(is.na(compare)) {
should_install <- FALSE
} else {
if(compare_versions(installed_package$Version, compare, version)) {
should_install <- FALSE
} else {
stop(
sprintf(
"Installed package [%s] is of the wrong version. Required: [%s]. Actual: [%s]",
package,
version,
installed_package$Version
)
)
}
}
}
should_install
}
validate_compare <- function(compare) {
if(is.null(compare)) {
stop("Compare clause cannot be NULL")
}
if (!(is.na(compare) || compare %in% c('==', '<', '>', '>=', '<='))) {
stop(sprintf("Invalid compare clause: [%s]", compare))
}
}
determine_version_to_install <- function(available_versions, version, compare) {
if(is.na(compare)) {
matching_versions <- available_versions
} else {
matching_version_indices <- sapply(
available_versions,
FUN = function(d) {
compare_versions(d, compare, version)
}
)
matching_versions <- available_versions[matching_version_indices]
}
max(matching_versions)
}
compare_versions <- function(requested, compare, version) {
eval(
parse(
text = sprintf(
"'%s' %s '%s'",
requested,
compare,
version
)
)
)
}
find_available_versions <- function(package, repos = getOption('repos'), type = getOption('pkgType')) {
contriburl <- contrib.url(repos, type)
available <- as.data.frame(available.packages(contriburl, filters=c("R_version", "OS_type", "subarch")), stringsAsFactors=FALSE)
root_versions <- data.frame(version=available[available$Package == package,]$Version, source='root', stringsAsFactors=FALSE)
root_versions$url <- file.path(contriburl, paste(package, "_", root_versions$version, switch(type,
source = ".tar.gz", mac.binary = ".tgz", win.binary = ".zip"), sep = ""))
archive <- read_archive_rds(repos)
if (length(archive) != 0) {
archiveurl <- contrib.url(repos, 'source')
package_tarball_path <- row.names(archive[[package]])
archive_versions <- data.frame(version = sub(".*_(.*).tar.gz", '\\1', package_tarball_path), source='archive', stringsAsFactors=FALSE)
archive_versions$url <- file.path(archiveurl, 'Archive', package_tarball_path)
versions <- merge(root_versions, archive_versions, all=TRUE)
} else {
versions <- root_versions
}
versions
}
read_archive_rds <- function(repos) {
tryCatch({
con <- gzcon(url(sprintf("%s/src/contrib/Meta/archive.rds", repos), "rb"));
on.exit(close(con))
archive <- readRDS(con)
return(archive)
}, warning = function(warning) {
return(list())
}, error = function(error) {
return(list())
}
)
} |
is_equal_knownComp <- function(comp.dist, comp.param)
{
stopifnot( (length(comp.dist) == 4) & (length(comp.param) == 4) )
if (comp.dist[[2]] == comp.dist[[4]]) {
vect.par <- FALSE
if ( any(sapply(comp.param[[2]], length) != 1) | any(sapply(comp.param[[4]], length) != 1) ) vect.par <- TRUE
if (!vect.par) {
param_matrix <- as.matrix(sapply(comp.param[[2]], "==", comp.param[[4]]))
if ( (all(diag(param_matrix) == TRUE)) & (nrow(param_matrix) != 0) & (ncol(param_matrix) != 0) ) {
G1equalG2 <- TRUE
} else {
G1equalG2 <- FALSE
}
} else {
G1equalG2 <- all(unlist(comp.param[[2]][which(sapply(comp.param[[2]],length) !=1 )]) == unlist(comp.param[[4]][which(sapply(comp.param[[4]],length) !=1 )]))
}
} else {
G1equalG2 <- FALSE
}
return(G1equalG2)
} |
ggplot(data = mtcars, mapping = aes(x = mpg, y = vs)) +
geom_point()
ggplot(data = mtcars, mapping = aes(x = mpg, y = vs)) + geom_point()
ggplot2::ggplot(data = mtcars, mapping = aes(x = mpg, y = vs)) + geom_point()
ggplot(data = mtcars, mapping = aes(x = mpg, y = vs)) + ggplot2::geom_point()
ggplot(data = mtcars, mapping = aes(x = mpg, y = vs)) +
ggplot2::geom_point() + g()
ggplot(data = mtcars, mapping = aes(x = mpg, y = vs)) +
ggplot2::geom_point() + g()
ggplot(data = mtcars, mapping = aes(x = mpg, y = vs)) + ggplot2::geom_point() + g()
ggplot(data = mtcars, mapping = aes(x = mpg, y = vs)) +
ggplot2::geom_point() + g() + geom_oint()
x[1]+ c()
g() + x[1]
g()[2] + x[1]
+sin(x)
qqjflk(
log(y + 1) +
sqrt(x2) +
x4 +
sqrt(x5)
) |
generate_chained_crescent_I_function <- function(dimensions)
soo_function(name="Chained Crescent I",
id=sprintf("chained-crescent-I-%id", dimensions),
fun=f_chained_crescent_I,
dimensions=dimensions,
lower_bounds=rep(-Inf, dimensions),
upper_bounds=rep(Inf, dimensions),
best_par=rep(0, dimensions),
best_value=0)
class(generate_chained_crescent_I_function) <- c("soo_function_generator", "function")
attr(generate_chained_crescent_I_function, "id") <- "chained_crescent_I"
attr(generate_chained_crescent_I_function, "name") <- "Chained Crescent I test function"
f_chained_crescent_I <- function(x, ...) {
n = length(x)
s1 = s2 = 0
for (i in 1:(n-1)) {
tmp = (x[i+1] - 1)^2 + x[i+1]
s1 = s1 + x[i]^2 + tmp - 1
s2 = s2 - x[i]^2 - tmp + 1
}
max(s1, s2)
} |
fit_sa <- function(Z, mrfi, family = "onepar", gamma_seq, init = 0, cycles = 5,
refresh_each = length(gamma_seq)+1, refresh_cycles = 60,
verbose = interactive()){
if(!family %in% mrf2d_families){
stop("'", family, "' is not an implemented family.")
}
if(!is.numeric(init)) {
stop("Argument 'init' must be numeric.")
}
C <- length(na.omit(unique(as.vector(Z)))) - 1
R <- mrfi@Rmat
n_R <- nrow(R)
gamma_seq <- gamma_seq/prod(dim(Z))
if(is.vector(init)) {
if(identical(init, 0)){
init <- array(0, dim = c(C+1, C+1, n_R))
} else {
init <- vec_to_array(init, family, C, n_R)
}
} else if(!is_valid_array(init, family)) {
stop("'init' array is incompatible with family '", family,"'")
}
arr_Z <- table_relative_3d(Z, mrfi@Rmat, C)
S <- suf_stat(arr_Z, family)
d <- numeric(length(gamma_seq))
Zseq <- thetaseq <- matrix(NA, nrow = length(gamma_seq), ncol = length(S))
is_sub <- any(is.na(Z))
if(is_sub){
subr <- !is.na(Z)
}
theta_t <- array_to_vec(init, family)
if(!is_sub){
Z_t <- rmrf2d(dim(Z), mrfi, vec_to_array(theta_t, family, C, n_R), cycles)
} else {
Z_t <- rmrf2d(dim(Z), mrfi, vec_to_array(theta_t, family, C, n_R), cycles,
sub_region = subr)
}
for(t in seq_along(gamma_seq)){
cat(ifelse(verbose, paste("\r Iteration:", t), ""))
arr_Z_t <- table_relative_3d(Z_t, mrfi@Rmat, C)
S_t <- suf_stat(arr_Z_t, family)
theta_t <- theta_t - gamma_seq[t]*(S_t - S)
if(t%%refresh_each == 0){
if(!is_sub){
Z_t <- rmrf2d(dim(Z), mrfi, vec_to_array(theta_t, family, C, n_R),
refresh_cycles)
} else {
Z_t <- rmrf2d(dim(Z), mrfi, vec_to_array(theta_t, family, C, n_R),
refresh_cycles, sub_region = subr)
}
} else {
Z_t <- rmrf2d(Z_t, mrfi, vec_to_array(theta_t, family, C, n_R), cycles)
}
Zseq[t,] <- S_t
thetaseq[t,] <- theta_t
d[t] <- sqrt(sum((S_t - S)^2))
}
cat(ifelse(verbose, "\n", ""))
theta_out <- vec_to_array(theta_t, family, C, n_R)
dimnames(theta_out)[[3]] <- mrfi_to_char(mrfi)
out <- list(theta = theta_out,
mrfi = mrfi,
family = family,
method = "Stochastic Approximation",
metrics = data.frame(t = seq_along(gamma_seq), distance = d),
Zseq = Zseq,
thetaseq = thetaseq,
Z = Z,
ncycles = length(gamma_seq))
class(out) <- "mrfout"
return(out)
} |
Gnambs18 <-
structure(list(data = structure(list(Carmines1979 = structure(c(1,
0.233, 0.204, 0.374, 0.221, 0.189, 0.332, 0.27, 0.311, 0.425,
0.233, 1, 0.361, 0.299, 0.358, 0.502, 0.276, 0.277, 0.577, 0.317,
0.204, 0.361, 1, 0.352, 0.399, 0.263, 0.451, 0.185, 0.394, 0.413,
0.374, 0.299, 0.352, 1, 0.28, 0.214, 0.427, 0.05, 0.315, 0.457,
0.221, 0.358, 0.399, 0.28, 1, 0.415, 0.35, 0.209, 0.469, 0.446,
0.189, 0.502, 0.263, 0.214, 0.415, 1, 0.209, 0.246, 0.474, 0.338,
0.332, 0.276, 0.451, 0.427, 0.35, 0.209, 1, 0.048, 0.381, 0.399,
0.27, 0.277, 0.185, 0.05, 0.209, 0.246, 0.048, 1, 0.23, 0.248,
0.311, 0.577, 0.394, 0.315, 0.469, 0.474, 0.381, 0.23, 1, 0.369,
0.425, 0.317, 0.413, 0.457, 0.446, 0.338, 0.399, 0.248, 0.369,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Donnellan2016 = structure(c(1,
0.419, 0.487, 0.378, 0.449, 0.395, 0.45, 0.36, 0.447, 0.663,
0.419, 1, 0.358, 0.295, 0.524, 0.71, 0.345, 0.483, 0.555, 0.5,
0.487, 0.358, 1, 0.494, 0.483, 0.284, 0.701, 0.239, 0.431, 0.586,
0.378, 0.295, 0.494, 1, 0.347, 0.297, 0.451, 0.192, 0.363, 0.462,
0.449, 0.524, 0.483, 0.347, 1, 0.483, 0.418, 0.335, 0.61, 0.519,
0.395, 0.71, 0.284, 0.297, 0.483, 1, 0.281, 0.519, 0.469, 0.46,
0.45, 0.345, 0.701, 0.451, 0.418, 0.281, 1, 0.252, 0.432, 0.523,
0.36, 0.483, 0.239, 0.192, 0.335, 0.519, 0.252, 1, 0.391, 0.399,
0.447, 0.555, 0.431, 0.363, 0.61, 0.469, 0.432, 0.391, 1, 0.551,
0.663, 0.5, 0.586, 0.462, 0.519, 0.46, 0.523, 0.399, 0.551, 1
), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3", "I4",
"I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4",
"I5", "I6", "I7", "I8", "I9", "I10"))), Gnambs2017 = structure(c(1,
0.387, 0.38, 0.345, 0.357, 0.426, 0.365, 0.304, 0.409, 0.569,
0.387, 1, 0.255, 0.247, 0.42, 0.58, 0.294, 0.368, 0.498, 0.414,
0.38, 0.255, 1, 0.486, 0.319, 0.272, 0.355, 0.179, 0.293, 0.413,
0.345, 0.247, 0.486, 1, 0.287, 0.249, 0.314, 0.16, 0.271, 0.369,
0.357, 0.42, 0.319, 0.287, 1, 0.475, 0.314, 0.312, 0.431, 0.375,
0.426, 0.58, 0.272, 0.249, 0.475, 1, 0.309, 0.362, 0.569, 0.459,
0.365, 0.294, 0.355, 0.314, 0.314, 0.309, 1, 0.174, 0.318, 0.412,
0.304, 0.368, 0.179, 0.16, 0.312, 0.362, 0.174, 1, 0.406, 0.328,
0.409, 0.498, 0.293, 0.271, 0.431, 0.569, 0.318, 0.406, 1, 0.492,
0.569, 0.414, 0.413, 0.369, 0.375, 0.459, 0.412, 0.328, 0.492,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Hesketh2012 = structure(c(1,
0.204, 0.331, 0.337, 0.155, 0.209, 0.29, -0.33, 0.23, 0.437,
0.204, 1, 0.188, 0.17, 0.282, 0.618, 0.169, -0.159, 0.35, 0.198,
0.331, 0.188, 1, 0.364, 0.15, 0.192, 0.455, -0.284, 0.17, 0.362,
0.337, 0.17, 0.364, 1, 0.084, 0.17, 0.285, -0.312, 0.152, 0.352,
0.155, 0.282, 0.15, 0.084, 1, 0.275, 0.102, -0.059, 0.307, 0.144,
0.209, 0.618, 0.192, 0.17, 0.275, 1, 0.147, -0.151, 0.366, 0.202,
0.29, 0.169, 0.455, 0.285, 0.102, 0.147, 1, -0.233, 0.147, 0.299,
-0.33, -0.159, -0.284, -0.312, -0.059, -0.151, -0.233, 1, -0.122,
-0.346, 0.23, 0.35, 0.17, 0.152, 0.307, 0.366, 0.147, -0.122,
1, 0.189, 0.437, 0.198, 0.362, 0.352, 0.144, 0.202, 0.299, -0.346,
0.189, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Jamil2006 = structure(c(1,
0.28, 0.4, 0.23, 0.11, 0.32, 0.41, -0.14, 0.22, 0.43, 0.28, 1,
0.21, 0.27, 0.48, 0.68, 0.27, -0.14, 0.37, 0.36, 0.4, 0.21, 1,
0.44, 0.27, 0.22, 0.36, -0.31, 0.36, 0.57, 0.23, 0.27, 0.44,
1, 0.35, 0.23, 0.28, -0.16, 0.28, 0.34, 0.11, 0.48, 0.27, 0.35,
1, 0.52, 0.1, -0.09, 0.2, 0.28, 0.32, 0.68, 0.22, 0.23, 0.52,
1, 0.34, -0.16, 0.33, 0.39, 0.41, 0.27, 0.36, 0.28, 0.1, 0.34,
1, -0.22, 0.28, 0.42, -0.14, -0.14, -0.31, -0.16, -0.09, -0.16,
-0.22, 1, -0.07, -0.23, 0.22, 0.37, 0.36, 0.28, 0.2, 0.33, 0.28,
-0.07, 1, 0.48, 0.43, 0.36, 0.57, 0.34, 0.28, 0.39, 0.42, -0.23,
0.48, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Liss2008 = structure(c(1,
0.498, 0.501, 0.433, 0.436, 0.479, 0.525, 0.475, 0.496, 0.763,
0.498, 1, 0.376, 0.313, 0.459, 0.725, 0.421, 0.533, 0.576, 0.488,
0.501, 0.376, 1, 0.543, 0.399, 0.327, 0.693, 0.305, 0.382, 0.517,
0.433, 0.313, 0.543, 1, 0.34, 0.291, 0.481, 0.257, 0.322, 0.443,
0.436, 0.459, 0.399, 0.34, 1, 0.45, 0.378, 0.426, 0.488, 0.405,
0.479, 0.725, 0.327, 0.291, 0.45, 1, 0.373, 0.523, 0.544, 0.472,
0.525, 0.421, 0.693, 0.481, 0.378, 0.373, 1, 0.363, 0.428, 0.534,
0.475, 0.533, 0.305, 0.257, 0.426, 0.523, 0.363, 1, 0.515, 0.514,
0.496, 0.576, 0.382, 0.322, 0.488, 0.544, 0.428, 0.515, 1, 0.512,
0.763, 0.488, 0.517, 0.443, 0.405, 0.472, 0.534, 0.514, 0.512,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Liss2009 = structure(c(1,
0.511, 0.556, 0.457, 0.383, 0.455, 0.549, 0.47, 0.515, 0.756,
0.511, 1, 0.395, 0.323, 0.5, 0.756, 0.426, 0.546, 0.609, 0.469,
0.556, 0.395, 1, 0.514, 0.253, 0.361, 0.668, 0.381, 0.397, 0.513,
0.457, 0.323, 0.514, 1, 0.255, 0.216, 0.491, 0.253, 0.319, 0.425,
0.383, 0.5, 0.253, 0.255, 1, 0.472, 0.384, 0.482, 0.532, 0.375,
0.455, 0.756, 0.361, 0.216, 0.472, 1, 0.392, 0.557, 0.59, 0.463,
0.549, 0.426, 0.668, 0.491, 0.384, 0.392, 1, 0.437, 0.489, 0.53,
0.47, 0.546, 0.381, 0.253, 0.482, 0.557, 0.437, 1, 0.593, 0.507,
0.515, 0.609, 0.397, 0.319, 0.532, 0.59, 0.489, 0.593, 1, 0.519,
0.756, 0.469, 0.513, 0.425, 0.375, 0.463, 0.53, 0.507, 0.519,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Liss2010 = structure(c(1,
0.426, 0.479, 0.384, 0.355, 0.437, 0.512, 0.409, 0.47, 0.746,
0.426, 1, 0.288, 0.283, 0.389, 0.728, 0.33, 0.505, 0.566, 0.447,
0.479, 0.288, 1, 0.477, 0.299, 0.307, 0.69, 0.251, 0.298, 0.492,
0.384, 0.283, 0.477, 1, 0.282, 0.255, 0.433, 0.236, 0.247, 0.424,
0.355, 0.389, 0.299, 0.282, 1, 0.431, 0.3, 0.417, 0.459, 0.331,
0.437, 0.728, 0.307, 0.255, 0.431, 1, 0.323, 0.499, 0.551, 0.431,
0.512, 0.33, 0.69, 0.433, 0.3, 0.323, 1, 0.321, 0.37, 0.511,
0.409, 0.505, 0.251, 0.236, 0.417, 0.499, 0.321, 1, 0.511, 0.426,
0.47, 0.566, 0.298, 0.247, 0.459, 0.551, 0.37, 0.511, 1, 0.478,
0.746, 0.447, 0.492, 0.424, 0.331, 0.431, 0.511, 0.426, 0.478,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Liss2011 = structure(c(1,
0.472, 0.42, 0.287, 0.402, 0.441, 0.47, 0.456, 0.445, 0.722,
0.472, 1, 0.4, 0.174, 0.561, 0.708, 0.47, 0.556, 0.597, 0.529,
0.42, 0.4, 1, 0.444, 0.475, 0.322, 0.707, 0.252, 0.334, 0.401,
0.287, 0.174, 0.444, 1, 0.337, 0.133, 0.334, 0.15, 0.136, 0.245,
0.402, 0.561, 0.475, 0.337, 1, 0.411, 0.406, 0.427, 0.442, 0.387,
0.441, 0.708, 0.322, 0.133, 0.411, 1, 0.34, 0.606, 0.572, 0.525,
0.47, 0.47, 0.707, 0.334, 0.406, 0.34, 1, 0.284, 0.352, 0.517,
0.456, 0.556, 0.252, 0.15, 0.427, 0.606, 0.284, 1, 0.491, 0.511,
0.445, 0.597, 0.334, 0.136, 0.442, 0.572, 0.352, 0.491, 1, 0.472,
0.722, 0.529, 0.401, 0.245, 0.387, 0.525, 0.517, 0.511, 0.472,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Liss2012 = structure(c(1,
0.5, 0.445, 0.366, 0.409, 0.457, 0.473, 0.462, 0.497, 0.774,
0.5, 1, 0.333, 0.278, 0.493, 0.738, 0.384, 0.539, 0.653, 0.516,
0.445, 0.333, 1, 0.474, 0.37, 0.305, 0.664, 0.288, 0.346, 0.457,
0.366, 0.278, 0.474, 1, 0.268, 0.284, 0.443, 0.241, 0.287, 0.403,
0.409, 0.493, 0.37, 0.268, 1, 0.442, 0.345, 0.44, 0.524, 0.4,
0.457, 0.738, 0.305, 0.284, 0.442, 1, 0.367, 0.53, 0.621, 0.502,
0.473, 0.384, 0.664, 0.443, 0.345, 0.367, 1, 0.365, 0.421, 0.505,
0.462, 0.539, 0.288, 0.241, 0.44, 0.53, 0.365, 1, 0.562, 0.523,
0.497, 0.653, 0.346, 0.287, 0.524, 0.621, 0.421, 0.562, 1, 0.558,
0.774, 0.516, 0.457, 0.403, 0.4, 0.502, 0.505, 0.523, 0.558,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Liss2013 = structure(c(1,
0.615, 0.614, 0.547, 0.46, 0.525, 0.66, 0.389, 0.545, 0.774,
0.615, 1, 0.535, 0.451, 0.584, 0.802, 0.551, 0.571, 0.597, 0.533,
0.614, 0.535, 1, 0.564, 0.517, 0.473, 0.697, 0.359, 0.446, 0.594,
0.547, 0.451, 0.564, 1, 0.39, 0.36, 0.457, 0.236, 0.277, 0.472,
0.46, 0.584, 0.517, 0.39, 1, 0.486, 0.451, 0.427, 0.547, 0.428,
0.525, 0.802, 0.473, 0.36, 0.486, 1, 0.509, 0.6, 0.601, 0.509,
0.66, 0.551, 0.697, 0.457, 0.451, 0.509, 1, 0.402, 0.485, 0.642,
0.389, 0.571, 0.359, 0.236, 0.427, 0.6, 0.402, 1, 0.502, 0.47,
0.545, 0.597, 0.446, 0.277, 0.547, 0.601, 0.485, 0.502, 1, 0.559,
0.774, 0.533, 0.594, 0.472, 0.428, 0.509, 0.642, 0.47, 0.559,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Liss2014 = structure(c(1,
0.538, 0.491, 0.409, 0.465, 0.509, 0.544, 0.483, 0.565, 0.769,
0.538, 1, 0.401, 0.309, 0.47, 0.705, 0.464, 0.544, 0.63, 0.518,
0.491, 0.401, 1, 0.501, 0.368, 0.361, 0.615, 0.285, 0.341, 0.5,
0.409, 0.309, 0.501, 1, 0.285, 0.33, 0.465, 0.285, 0.318, 0.448,
0.465, 0.47, 0.368, 0.285, 1, 0.469, 0.407, 0.412, 0.518, 0.407,
0.509, 0.705, 0.361, 0.33, 0.469, 1, 0.412, 0.537, 0.593, 0.507,
0.544, 0.464, 0.615, 0.465, 0.407, 0.412, 1, 0.404, 0.445, 0.557,
0.483, 0.544, 0.285, 0.285, 0.412, 0.537, 0.404, 1, 0.565, 0.514,
0.565, 0.63, 0.341, 0.318, 0.518, 0.593, 0.445, 0.565, 1, 0.584,
0.769, 0.518, 0.5, 0.448, 0.407, 0.507, 0.557, 0.514, 0.584,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Liss2015 = structure(c(1,
0.637, 0.605, 0.503, 0.539, 0.587, 0.55, 0.446, 0.563, 0.825,
0.637, 1, 0.577, 0.474, 0.591, 0.836, 0.523, 0.606, 0.69, 0.603,
0.605, 0.577, 1, 0.613, 0.552, 0.525, 0.673, 0.378, 0.564, 0.641,
0.503, 0.474, 0.613, 1, 0.377, 0.409, 0.615, 0.26, 0.428, 0.505,
0.539, 0.591, 0.552, 0.377, 1, 0.577, 0.45, 0.472, 0.604, 0.493,
0.587, 0.836, 0.525, 0.409, 0.577, 1, 0.466, 0.615, 0.677, 0.55,
0.55, 0.523, 0.673, 0.615, 0.45, 0.466, 1, 0.369, 0.454, 0.606,
0.446, 0.606, 0.378, 0.26, 0.472, 0.615, 0.369, 1, 0.546, 0.451,
0.563, 0.69, 0.564, 0.428, 0.604, 0.677, 0.454, 0.546, 1, 0.585,
0.825, 0.603, 0.641, 0.505, 0.493, 0.55, 0.606, 0.451, 0.585,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Neps2010b = structure(c(1,
0.555, 0.395, 0.33, 0.489, 0.551, 0.386, 0.421, 0.527, 0.632,
0.555, 1, 0.347, 0.288, 0.564, 0.679, 0.371, 0.484, 0.667, 0.56,
0.395, 0.347, 1, 0.577, 0.486, 0.313, 0.422, 0.202, 0.346, 0.449,
0.33, 0.288, 0.577, 1, 0.393, 0.252, 0.356, 0.17, 0.297, 0.325,
0.489, 0.564, 0.486, 0.393, 1, 0.63, 0.434, 0.376, 0.563, 0.497,
0.551, 0.679, 0.313, 0.252, 0.63, 1, 0.366, 0.413, 0.663, 0.467,
0.386, 0.371, 0.422, 0.356, 0.434, 0.366, 1, 0.319, 0.375, 0.427,
0.421, 0.484, 0.202, 0.17, 0.376, 0.413, 0.319, 1, 0.542, 0.492,
0.527, 0.667, 0.346, 0.297, 0.563, 0.663, 0.375, 0.542, 1, 0.607,
0.632, 0.56, 0.449, 0.325, 0.497, 0.467, 0.427, 0.492, 0.607,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Neps2010c = structure(c(1,
0.319, 0.21, 0.158, 0.238, 0.358, 0.218, 0.272, 0.324, 0.425,
0.319, 1, 0.176, 0.133, 0.364, 0.566, 0.225, 0.414, 0.53, 0.405,
0.21, 0.176, 1, 0.372, 0.234, 0.185, 0.373, 0.207, 0.211, 0.328,
0.158, 0.133, 0.372, 1, 0.233, 0.156, 0.297, 0.148, 0.168, 0.242,
0.238, 0.364, 0.234, 0.233, 1, 0.403, 0.265, 0.384, 0.366, 0.307,
0.358, 0.566, 0.185, 0.156, 0.403, 1, 0.253, 0.404, 0.522, 0.42,
0.218, 0.225, 0.373, 0.297, 0.265, 0.253, 1, 0.207, 0.261, 0.393,
0.272, 0.414, 0.207, 0.148, 0.384, 0.404, 0.207, 1, 0.452, 0.384,
0.324, 0.53, 0.211, 0.168, 0.366, 0.522, 0.261, 0.452, 1, 0.445,
0.425, 0.405, 0.328, 0.242, 0.307, 0.42, 0.393, 0.384, 0.445,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Neps2010d = structure(c(1,
0.263, 0.3947, 0.375, 0.231, 0.333, 0.3199, 0.1423, 0.319, 0.455,
0.263, 1, 0.1469, 0.17, 0.355, 0.511, 0.1625, 0.319, 0.46, 0.255,
0.3947, 0.1469, 1, 0.46, 0.164, 0.21, 0.2818, 0.0856, 0.207,
0.367, 0.375, 0.17, 0.46, 1, 0.159, 0.245, 0.2789, 0.1134, 0.242,
0.35, 0.231, 0.355, 0.164, 0.159, 1, 0.424, 0.1862, 0.3207, 0.423,
0.23, 0.333, 0.511, 0.21, 0.245, 0.424, 1, 0.1999, 0.325, 0.584,
0.321, 0.3199, 0.1625, 0.2818, 0.2789, 0.1862, 0.1999, 1, 0.0285,
0.189, 0.352, 0.1423, 0.319, 0.0856, 0.1134, 0.3207, 0.325, 0.0285,
1, 0.346, 0.11, 0.319, 0.46, 0.207, 0.242, 0.423, 0.584, 0.189,
0.346, 1, 0.301, 0.455, 0.255, 0.367, 0.35, 0.23, 0.321, 0.352,
0.11, 0.301, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Neps2010e = structure(c(1,
0.47, 0.522, 0.452, 0.472, 0.434, 0.446, 0.371, 0.534, 0.628,
0.47, 1, 0.372, 0.354, 0.516, 0.626, 0.367, 0.45, 0.598, 0.5,
0.522, 0.372, 1, 0.602, 0.435, 0.421, 0.465, 0.306, 0.416, 0.519,
0.452, 0.354, 0.602, 1, 0.388, 0.388, 0.444, 0.257, 0.387, 0.442,
0.472, 0.516, 0.435, 0.388, 1, 0.614, 0.407, 0.419, 0.559, 0.474,
0.434, 0.626, 0.421, 0.388, 0.614, 1, 0.395, 0.422, 0.655, 0.538,
0.446, 0.367, 0.465, 0.444, 0.407, 0.395, 1, 0.224, 0.401, 0.488,
0.371, 0.45, 0.306, 0.257, 0.419, 0.422, 0.224, 1, 0.504, 0.405,
0.534, 0.598, 0.416, 0.387, 0.559, 0.655, 0.401, 0.504, 1, 0.551,
0.628, 0.5, 0.519, 0.442, 0.474, 0.538, 0.488, 0.405, 0.551,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Neps2010f = structure(c(1,
0.376, 0.251, 0.156, 0.301, 0.374, 0.247, 0.361, 0.369, 0.531,
0.376, 1, 0.207, 0.139, 0.377, 0.572, 0.238, 0.409, 0.506, 0.419,
0.251, 0.207, 1, 0.323, 0.31, 0.214, 0.308, 0.186, 0.24, 0.308,
0.156, 0.139, 0.323, 1, 0.229, 0.14, 0.223, 0.143, 0.146, 0.212,
0.301, 0.377, 0.31, 0.229, 1, 0.428, 0.283, 0.326, 0.396, 0.34,
0.374, 0.572, 0.214, 0.14, 0.428, 1, 0.245, 0.392, 0.517, 0.422,
0.247, 0.238, 0.308, 0.223, 0.283, 0.245, 1, 0.236, 0.28, 0.32,
0.361, 0.409, 0.186, 0.143, 0.326, 0.392, 0.236, 1, 0.48, 0.458,
0.369, 0.506, 0.24, 0.146, 0.396, 0.517, 0.28, 0.48, 1, 0.475,
0.531, 0.419, 0.308, 0.212, 0.34, 0.422, 0.32, 0.458, 0.475,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Opd2014a = structure(c(1,
0.552, 0.513, 0.455, 0.568, 0.502, 0.577, 0.463, 0.59, 0.725,
0.552, 1, 0.471, 0.416, 0.581, 0.732, 0.535, 0.515, 0.616, 0.584,
0.513, 0.471, 1, 0.518, 0.495, 0.41, 0.668, 0.328, 0.475, 0.552,
0.455, 0.416, 0.518, 1, 0.421, 0.39, 0.539, 0.304, 0.441, 0.47,
0.568, 0.581, 0.495, 0.421, 1, 0.545, 0.528, 0.42, 0.633, 0.558,
0.502, 0.732, 0.41, 0.39, 0.545, 1, 0.468, 0.496, 0.573, 0.522,
0.577, 0.535, 0.668, 0.539, 0.528, 0.468, 1, 0.404, 0.547, 0.621,
0.463, 0.515, 0.328, 0.304, 0.42, 0.496, 0.404, 1, 0.451, 0.493,
0.59, 0.616, 0.475, 0.441, 0.633, 0.573, 0.547, 0.451, 1, 0.596,
0.725, 0.584, 0.552, 0.47, 0.558, 0.522, 0.621, 0.493, 0.596,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Opd2014b = structure(c(1,
0.562, 0.525, 0.501, 0.548, 0.482, 0.596, 0.466, 0.579, 0.75,
0.562, 1, 0.453, 0.428, 0.551, 0.729, 0.527, 0.508, 0.594, 0.571,
0.525, 0.453, 1, 0.545, 0.483, 0.388, 0.68, 0.323, 0.473, 0.559,
0.501, 0.428, 0.545, 1, 0.423, 0.396, 0.578, 0.313, 0.457, 0.508,
0.548, 0.551, 0.483, 0.423, 1, 0.5, 0.523, 0.412, 0.617, 0.545,
0.482, 0.729, 0.388, 0.396, 0.5, 1, 0.456, 0.487, 0.539, 0.509,
0.596, 0.527, 0.68, 0.578, 0.523, 0.456, 1, 0.4, 0.555, 0.628,
0.466, 0.508, 0.323, 0.313, 0.412, 0.487, 0.4, 1, 0.444, 0.497,
0.579, 0.594, 0.473, 0.457, 0.617, 0.539, 0.555, 0.444, 1, 0.591,
0.75, 0.571, 0.559, 0.508, 0.545, 0.509, 0.628, 0.497, 0.591,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Opd2014c = structure(c(1,
0.491, 0.418, 0.439, 0.603, 0.427, 0.521, 0.383, 0.611, 0.679,
0.491, 1, 0.273, 0.347, 0.562, 0.705, 0.424, 0.417, 0.53, 0.538,
0.418, 0.273, 1, 0.409, 0.384, 0.214, 0.575, 0.151, 0.421, 0.397,
0.439, 0.347, 0.409, 1, 0.408, 0.333, 0.477, 0.206, 0.437, 0.418,
0.603, 0.562, 0.384, 0.408, 1, 0.477, 0.459, 0.337, 0.646, 0.532,
0.427, 0.705, 0.214, 0.333, 0.477, 1, 0.32, 0.386, 0.478, 0.451,
0.521, 0.424, 0.575, 0.477, 0.459, 0.32, 1, 0.315, 0.531, 0.554,
0.383, 0.417, 0.151, 0.206, 0.337, 0.386, 0.315, 1, 0.414, 0.431,
0.611, 0.53, 0.421, 0.437, 0.646, 0.478, 0.531, 0.414, 1, 0.605,
0.679, 0.538, 0.397, 0.418, 0.532, 0.451, 0.554, 0.431, 0.605,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Opd2014d = structure(c(1,
0.532, 0.503, 0.478, 0.556, 0.473, 0.577, 0.443, 0.576, 0.744,
0.532, 1, 0.41, 0.427, 0.544, 0.732, 0.491, 0.495, 0.584, 0.55,
0.503, 0.41, 1, 0.526, 0.469, 0.37, 0.643, 0.292, 0.448, 0.516,
0.478, 0.427, 0.526, 1, 0.411, 0.404, 0.528, 0.329, 0.431, 0.481,
0.556, 0.544, 0.469, 0.411, 1, 0.502, 0.498, 0.398, 0.62, 0.537,
0.473, 0.732, 0.37, 0.404, 0.502, 1, 0.418, 0.475, 0.549, 0.49,
0.577, 0.491, 0.643, 0.528, 0.498, 0.418, 1, 0.369, 0.515, 0.59,
0.443, 0.495, 0.292, 0.329, 0.398, 0.475, 0.369, 1, 0.415, 0.477,
0.576, 0.584, 0.448, 0.431, 0.62, 0.549, 0.515, 0.415, 1, 0.573,
0.744, 0.55, 0.516, 0.481, 0.537, 0.49, 0.59, 0.477, 0.573, 1
), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3", "I4",
"I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4",
"I5", "I6", "I7", "I8", "I9", "I10"))), Opd2014e = structure(c(1,
0.557, 0.538, 0.477, 0.569, 0.504, 0.577, 0.466, 0.584, 0.732,
0.557, 1, 0.476, 0.415, 0.579, 0.732, 0.511, 0.526, 0.618, 0.579,
0.538, 0.476, 1, 0.552, 0.51, 0.42, 0.668, 0.323, 0.463, 0.581,
0.477, 0.415, 0.552, 1, 0.433, 0.387, 0.553, 0.302, 0.411, 0.483,
0.569, 0.579, 0.51, 0.433, 1, 0.555, 0.529, 0.443, 0.63, 0.551,
0.504, 0.732, 0.42, 0.387, 0.555, 1, 0.449, 0.505, 0.579, 0.496,
0.577, 0.511, 0.668, 0.553, 0.529, 0.449, 1, 0.384, 0.522, 0.626,
0.466, 0.526, 0.323, 0.302, 0.443, 0.505, 0.384, 1, 0.46, 0.48,
0.584, 0.618, 0.463, 0.411, 0.63, 0.579, 0.522, 0.46, 1, 0.558,
0.732, 0.579, 0.581, 0.483, 0.551, 0.496, 0.626, 0.48, 0.558,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Opd2014f = structure(c(1,
0.389, 0.394, 0.361, 0.365, 0.389, 0.378, 0.253, 0.436, 0.615,
0.389, 1, 0.262, 0.195, 0.438, 0.706, 0.294, 0.414, 0.485, 0.379,
0.394, 0.262, 1, 0.46, 0.266, 0.201, 0.576, 0.11, 0.305, 0.481,
0.361, 0.195, 0.46, 1, 0.194, 0.166, 0.457, 0.09, 0.232, 0.447,
0.365, 0.438, 0.266, 0.194, 1, 0.442, 0.264, 0.309, 0.492, 0.371,
0.389, 0.706, 0.201, 0.166, 0.442, 1, 0.26, 0.419, 0.486, 0.386,
0.378, 0.294, 0.576, 0.457, 0.264, 0.26, 1, 0.207, 0.333, 0.49,
0.253, 0.414, 0.11, 0.09, 0.309, 0.419, 0.207, 1, 0.332, 0.238,
0.436, 0.485, 0.305, 0.232, 0.492, 0.486, 0.333, 0.332, 1, 0.433,
0.615, 0.379, 0.481, 0.447, 0.371, 0.386, 0.49, 0.238, 0.433,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Opd2014g = structure(c(1,
0.463, 0.452, 0.457, 0.521, 0.435, 0.568, 0.44, 0.524, 0.756,
0.463, 1, 0.3, 0.322, 0.503, 0.721, 0.423, 0.494, 0.597, 0.471,
0.452, 0.3, 1, 0.518, 0.43, 0.241, 0.685, 0.216, 0.375, 0.499,
0.457, 0.322, 0.518, 1, 0.37, 0.269, 0.583, 0.285, 0.391, 0.444,
0.521, 0.503, 0.43, 0.37, 1, 0.444, 0.478, 0.413, 0.594, 0.523,
0.435, 0.721, 0.241, 0.269, 0.444, 1, 0.353, 0.46, 0.503, 0.409,
0.568, 0.423, 0.685, 0.583, 0.478, 0.353, 1, 0.328, 0.503, 0.606,
0.44, 0.494, 0.216, 0.285, 0.413, 0.46, 0.328, 1, 0.469, 0.458,
0.524, 0.597, 0.375, 0.391, 0.594, 0.503, 0.503, 0.469, 1, 0.538,
0.756, 0.471, 0.499, 0.444, 0.523, 0.409, 0.606, 0.458, 0.538,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Opd2014h = structure(c(1,
0.361, 0.479, 0.422, 0.309, 0.307, 0.515, 0.115, 0.343, 0.621,
0.361, 1, 0.195, 0.1558, 0.476, 0.693, 0.212, 0.327, 0.552, 0.33,
0.479, 0.195, 1, 0.53, 0.243, 0.183, 0.677, 0.03, 0.211, 0.532,
0.422, 0.1558, 0.53, 1, 0.184, 0.153, 0.546, 0.012, 0.189, 0.463,
0.309, 0.476, 0.243, 0.184, 1, 0.49, 0.257, 0.338, 0.594, 0.362,
0.307, 0.693, 0.183, 0.153, 0.49, 1, 0.178, 0.328, 0.528, 0.286,
0.515, 0.212, 0.677, 0.546, 0.257, 0.178, 1, 0.051, 0.257, 0.559,
0.115, 0.327, 0.03, 0.012, 0.338, 0.328, 0.051, 1, 0.317, 0.09,
0.343, 0.552, 0.211, 0.189, 0.594, 0.528, 0.257, 0.317, 1, 0.383,
0.621, 0.33, 0.532, 0.463, 0.362, 0.286, 0.559, 0.09, 0.383,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Opd2014i = structure(c(1,
0.273, 0.546, 0.385, 0.247, 0.223, 0.54, 0.084, 0.339, 0.7, 0.273,
1, 0.054, 0.108, 0.54, 0.641, 0.172, 0.375, 0.538, 0.266, 0.546,
0.054, 1, 0.453, 0.074, 0.047, 0.632, -0.027, 0.091, 0.598, 0.385,
0.108, 0.453, 1, 0.084, 0.112, 0.557, 0.025, 0.086, 0.438, 0.247,
0.54, 0.074, 0.084, 1, 0.438, 0.179, 0.404, 0.557, 0.198, 0.223,
0.641, 0.047, 0.112, 0.438, 1, 0.062, 0.431, 0.523, 0.233, 0.54,
0.172, 0.632, 0.557, 0.179, 0.062, 1, 0.048, 0.167, 0.517, 0.084,
0.375, -0.027, 0.025, 0.404, 0.431, 0.048, 1, 0.377, 0.114, 0.339,
0.538, 0.091, 0.086, 0.557, 0.523, 0.167, 0.377, 1, 0.264, 0.7,
0.266, 0.598, 0.438, 0.198, 0.233, 0.517, 0.114, 0.264, 1), .Dim = c(10L,
10L), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"))), Opd2014j = structure(c(1, 0.134,
0.46, 0.503, 0.097, 0.184, 0.572, -0.058, 0.213, 0.681, 0.134,
1, 0.31, 0.132, 0.529, 0.698, 0.308, 0.463, 0.717, 0.296, 0.46,
0.31, 1, 0.521, 0.174, 0.132, 0.677, 0, 0.302, 0.579, 0.503,
0.132, 0.521, 1, 0.076, 0.095, 0.515, -0.092, 0.162, 0.548, 0.097,
0.529, 0.174, 0.076, 1, 0.526, 0.177, 0.355, 0.606, 0.09, 0.184,
0.698, 0.132, 0.095, 0.526, 1, 0.254, 0.432, 0.663, 0.218, 0.572,
0.308, 0.677, 0.515, 0.177, 0.254, 1, 0.062, 0.284, 0.609, -0.058,
0.463, 0, -0.092, 0.355, 0.432, 0.062, 1, 0.457, -0.041, 0.213,
0.717, 0.302, 0.162, 0.606, 0.663, 0.284, 0.457, 1, 0.269, 0.681,
0.296, 0.579, 0.548, 0.09, 0.218, 0.609, -0.041, 0.269, 1), .Dim = c(10L,
10L), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"))), Portes2012 = structure(c(1, 0.32,
0.373, 0.316, 0.275, 0.292, 0.253, 0.245, 0.338, 0.541, 0.32,
1, 0.245, 0.213, 0.336, 0.604, 0.154, 0.358, 0.397, 0.328, 0.373,
0.245, 1, 0.436, 0.32, 0.224, 0.442, 0.183, 0.341, 0.414, 0.316,
0.213, 0.436, 1, 0.267, 0.199, 0.304, 0.167, 0.291, 0.368, 0.275,
0.336, 0.32, 0.267, 1, 0.312, 0.232, 0.262, 0.438, 0.301, 0.292,
0.604, 0.224, 0.199, 0.312, 1, 0.146, 0.381, 0.34, 0.314, 0.253,
0.154, 0.442, 0.304, 0.232, 0.146, 1, 0.152, 0.211, 0.279, 0.245,
0.358, 0.183, 0.167, 0.262, 0.381, 0.152, 1, 0.264, 0.27, 0.338,
0.397, 0.341, 0.291, 0.438, 0.34, 0.211, 0.264, 1, 0.333, 0.541,
0.328, 0.414, 0.368, 0.301, 0.314, 0.279, 0.27, 0.333, 1), .Dim = c(10L,
10L), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"))), Shahni1990 = structure(c(1, 0.33,
0.23, 0.23, 0.23, 0.31, 0.15, 0.35, 0.29, 0.56, 0.33, 1, 0.12,
0.15, 0.3, 0.57, 0.06, 0.41, 0.38, 0.27, 0.23, 0.12, 1, 0.36,
0.12, 0.08, 0.55, 0.12, 0.2, 0.31, 0.23, 0.15, 0.36, 1, 0.11,
0.13, 0.26, 0.16, 0.16, 0.26, 0.23, 0.3, 0.12, 0.11, 1, 0.33,
0.1, 0.31, 0.04, 0.21, 0.31, 0.57, 0.08, 0.13, 0.33, 1, 0.06,
0.44, 0.32, 0.24, 0.15, 0.06, 0.55, 0.26, 0.1, 0.06, 1, 0.1,
0.15, 0.21, 0.35, 0.41, 0.12, 0.16, 0.31, 0.44, 0.1, 1, 0.3,
0.32, 0.29, 0.38, 0.2, 0.16, 0.04, 0.32, 0.15, 0.3, 1, 0.28,
0.56, 0.27, 0.31, 0.26, 0.21, 0.24, 0.21, 0.32, 0.28, 1), .Dim = c(10L,
10L), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"))), Song2011a = structure(c(1, 0.47,
0.52, 0.44, 0.56, 0.45, 0.58, 0.44, 0.51, 0.62, 0.47, 1, 0.37,
0.37, 0.47, 0.61, 0.38, 0.46, 0.53, 0.48, 0.52, 0.37, 1, 0.52,
0.55, 0.36, 0.46, 0.38, 0.41, 0.55, 0.44, 0.37, 0.52, 1, 0.46,
0.35, 0.49, 0.35, 0.39, 0.43, 0.56, 0.47, 0.55, 0.46, 1, 0.48,
0.55, 0.43, 0.57, 0.52, 0.45, 0.61, 0.36, 0.35, 0.48, 1, 0.4,
0.58, 0.56, 0.43, 0.58, 0.38, 0.46, 0.49, 0.55, 0.4, 1, 0.38,
0.5, 0.48, 0.44, 0.46, 0.38, 0.35, 0.43, 0.58, 0.38, 1, 0.49,
0.47, 0.51, 0.53, 0.41, 0.39, 0.57, 0.56, 0.5, 0.49, 1, 0.5,
0.62, 0.48, 0.55, 0.43, 0.52, 0.43, 0.48, 0.47, 0.5, 1), .Dim = c(10L,
10L), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"))), Song2011b = structure(c(1, 0.29,
0.44, 0.38, 0.22, 0.24, 0.4, 0.17, 0.43, 0.41, 0.29, 1, 0.28,
0.34, 0.33, 0.58, 0.26, 0.33, 0.47, 0.41, 0.44, 0.28, 1, 0.46,
0.3, 0.29, 0.36, 0.12, 0.4, 0.46, 0.38, 0.34, 0.46, 1, 0.19,
0.23, 0.51, 0.02, 0.4, 0.37, 0.22, 0.33, 0.3, 0.19, 1, 0.4, 0.23,
0.07, 0.47, 0.34, 0.24, 0.58, 0.29, 0.23, 0.4, 1, 0.3, 0.23,
0.5, 0.41, 0.4, 0.26, 0.36, 0.51, 0.23, 0.3, 1, 0.03, 0.39, 0.44,
0.17, 0.33, 0.12, 0.02, 0.07, 0.23, 0.03, 1, 0.16, 0.14, 0.43,
0.47, 0.4, 0.4, 0.47, 0.5, 0.39, 0.16, 1, 0.62, 0.41, 0.41, 0.46,
0.37, 0.34, 0.41, 0.44, 0.14, 0.62, 1), .Dim = c(10L, 10L), .Dimnames = list(
c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"
), c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9",
"I10"))), Vasconcelos2012 = structure(c(1, 0.27, 0.44, 0.42,
0.23, 0.3, 0.37, 0.22, 0.34, 0.47, 0.27, 1, 0.31, 0.26, 0.41,
0.52, 0.26, 0.38, 0.42, 0.32, 0.44, 0.31, 1, 0.52, 0.31, 0.36,
0.48, 0.25, 0.37, 0.46, 0.42, 0.26, 0.52, 1, 0.27, 0.29, 0.49,
0.2, 0.37, 0.44, 0.23, 0.41, 0.31, 0.27, 1, 0.46, 0.27, 0.36,
0.49, 0.35, 0.3, 0.52, 0.36, 0.29, 0.46, 1, 0.29, 0.39, 0.57,
0.38, 0.37, 0.26, 0.48, 0.49, 0.27, 0.29, 1, 0.18, 0.4, 0.47,
0.22, 0.38, 0.25, 0.2, 0.36, 0.39, 0.18, 1, 0.42, 0.28, 0.34,
0.42, 0.37, 0.37, 0.49, 0.57, 0.4, 0.42, 1, 0.44, 0.47, 0.32,
0.46, 0.44, 0.35, 0.38, 0.47, 0.28, 0.44, 1), .Dim = c(10L, 10L
), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6", "I7",
"I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6", "I7",
"I8", "I9", "I10"))), Welsh2011 = structure(c(1, 0.408, 0.431,
0.451, 0.287, 0.46, 0.428, 0.388, 0.401, 0.579, 0.408, 1, 0.326,
0.264, 0.41, 0.632, 0.362, 0.528, 0.471, 0.425, 0.431, 0.326,
1, 0.401, 0.284, 0.304, 0.594, 0.316, 0.341, 0.467, 0.451, 0.264,
0.401, 1, 0.237, 0.369, 0.395, 0.227, 0.227, 0.374, 0.287, 0.41,
0.284, 0.237, 1, 0.415, 0.294, 0.45, 0.437, 0.311, 0.46, 0.632,
0.304, 0.369, 0.415, 1, 0.359, 0.535, 0.485, 0.435, 0.428, 0.362,
0.594, 0.395, 0.294, 0.359, 1, 0.399, 0.409, 0.505, 0.388, 0.528,
0.316, 0.227, 0.45, 0.535, 0.399, 1, 0.506, 0.462, 0.401, 0.471,
0.341, 0.227, 0.437, 0.485, 0.409, 0.506, 1, 0.463, 0.579, 0.425,
0.467, 0.374, 0.311, 0.435, 0.505, 0.462, 0.463, 1), .Dim = c(10L,
10L), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"))), Whiteside2003a = structure(c(1, 0.3,
0.39, 0.51, 0.17, 0.33, 0.29, 0, 0.42, 0.44, 0.3, 1, 0.15, 0.37,
0.56, 0.24, 0.15, 0.5, 0.28, 0.49, 0.39, 0.15, 1, 0.32, 0.23,
0.38, 0.17, 0.31, 0.4, 0.25, 0.51, 0.37, 0.32, 1, 0.28, 0.38,
0, 0.51, 0.46, 0.4, 0.17, 0.56, 0.23, 0.28, 1, 0.25, 0.26, 0.39,
0.24, 0.25, 0.33, 0.24, 0.38, 0.38, 0.25, 1, 0.26, 0.39, 0.44,
0.29, 0.29, 0.15, 0.17, 0, 0.26, 0.26, 1, 0.05, 0.32, 0.38, 0,
0.5, 0.31, 0.51, 0.39, 0.39, 0.05, 1, 0.08, 0.07, 0.42, 0.28,
0.4, 0.46, 0.24, 0.44, 0.32, 0.08, 1, 0.37, 0.44, 0.49, 0.25,
0.4, 0.25, 0.29, 0.38, 0.07, 0.37, 1), .Dim = c(10L, 10L), .Dimnames = list(
c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"
), c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9",
"I10"))), Whiteside2003b = structure(c(1, 0.07, 0.28, 0.21,
0.17, 0.23, 0.25, 0.14, 0.22, 0.41, 0.07, 1, 0.26, 0.23, 0.46,
0.56, 0.23, 0.42, 0.52, 0.26, 0.28, 0.26, 1, 0.53, 0.28, 0.24,
0.43, 0.16, 0.43, 0.47, 0.21, 0.23, 0.53, 1, 0.25, 0.27, 0.35,
0.15, 0.37, 0.4, 0.17, 0.46, 0.28, 0.25, 1, 0.47, 0.29, 0.41,
0.59, 0.34, 0.23, 0.56, 0.24, 0.27, 0.47, 1, 0.3, 0.38, 0.5,
0.34, 0.25, 0.23, 0.43, 0.35, 0.29, 0.3, 1, 0.13, 0.38, 0.42,
0.14, 0.42, 0.16, 0.15, 0.41, 0.38, 0.13, 1, 0.45, 0.28, 0.22,
0.52, 0.43, 0.37, 0.59, 0.5, 0.38, 0.45, 1, 0.43, 0.41, 0.26,
0.47, 0.4, 0.34, 0.34, 0.42, 0.28, 0.43, 1), .Dim = c(10L, 10L
), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6", "I7",
"I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6", "I7",
"I8", "I9", "I10"))), Bagley1997a = structure(c(1, 0.4623, 0.4485,
0.4071, 0.4899, 0.4554, 0.3795, 0.4416, 0.5175, 0.5175, 0.4623,
1, 0.4355, 0.3953, 0.4757, 0.4422, 0.3685, 0.4288, 0.5025, 0.5025,
0.4485, 0.4355, 1, 0.3835, 0.4615, 0.429, 0.3575, 0.416, 0.4875,
0.4875, 0.4071, 0.3953, 0.3835, 1, 0.4189, 0.3894, 0.3245, 0.3776,
0.4425, 0.4425, 0.4899, 0.4757, 0.4615, 0.4189, 1, 0.4686, 0.3905,
0.4544, 0.5325, 0.5325, 0.4554, 0.4422, 0.429, 0.3894, 0.4686,
1, 0.363, 0.4224, 0.495, 0.495, 0.3795, 0.3685, 0.3575, 0.3245,
0.3905, 0.363, 1, 0.352, 0.4125, 0.4125, 0.4416, 0.4288, 0.416,
0.3776, 0.4544, 0.4224, 0.352, 1, 0.48, 0.48, 0.5175, 0.5025,
0.4875, 0.4425, 0.5325, 0.495, 0.4125, 0.48, 1, 0.5625, 0.5175,
0.5025, 0.4875, 0.4425, 0.5325, 0.495, 0.4125, 0.48, 0.5625,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Bagley1997b = structure(c(1,
0.4864, 0.5548, 0.494, 0.5624, 0.4788, 0.5092, 0.5016, 0.5852,
0.608, 0.4864, 1, 0.4672, 0.416, 0.4736, 0.4032, 0.4288, 0.4224,
0.4928, 0.512, 0.5548, 0.4672, 1, 0.4745, 0.5402, 0.4599, 0.4891,
0.4818, 0.5621, 0.584, 0.494, 0.416, 0.4745, 1, 0.481, 0.4095,
0.4355, 0.429, 0.5005, 0.52, 0.5624, 0.4736, 0.5402, 0.481, 1,
0.4662, 0.4958, 0.4884, 0.5698, 0.592, 0.4788, 0.4032, 0.4599,
0.4095, 0.4662, 1, 0.4221, 0.4158, 0.4851, 0.504, 0.5092, 0.4288,
0.4891, 0.4355, 0.4958, 0.4221, 1, 0.4422, 0.5159, 0.536, 0.5016,
0.4224, 0.4818, 0.429, 0.4884, 0.4158, 0.4422, 1, 0.5082, 0.528,
0.5852, 0.4928, 0.5621, 0.5005, 0.5698, 0.4851, 0.5159, 0.5082,
1, 0.616, 0.608, 0.512, 0.584, 0.52, 0.592, 0.504, 0.536, 0.528,
0.616, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Chao2017a = structure(c(1,
0.2968, 0.3752, 0.3024, 0.2968, 0.3584, 0.3304, 0.2856, 0.3696,
0.3864, 0.2968, 1, 0.3551, 0.2862, 0.2809, 0.3392, 0.3127, 0.2703,
0.3498, 0.3657, 0.3752, 0.3551, 1, 0.3618, 0.3551, 0.4288, 0.3953,
0.3417, 0.4422, 0.4623, 0.3024, 0.2862, 0.3618, 1, 0.2862, 0.3456,
0.3186, 0.2754, 0.3564, 0.3726, 0.2968, 0.2809, 0.3551, 0.2862,
1, 0.3392, 0.3127, 0.2703, 0.3498, 0.3657, 0.3584, 0.3392, 0.4288,
0.3456, 0.3392, 1, 0.3776, 0.3264, 0.4224, 0.4416, 0.3304, 0.3127,
0.3953, 0.3186, 0.3127, 0.3776, 1, 0.3009, 0.3894, 0.4071, 0.2856,
0.2703, 0.3417, 0.2754, 0.2703, 0.3264, 0.3009, 1, 0.3366, 0.3519,
0.3696, 0.3498, 0.4422, 0.3564, 0.3498, 0.4224, 0.3894, 0.3366,
1, 0.4554, 0.3864, 0.3657, 0.4623, 0.3726, 0.3657, 0.4416, 0.4071,
0.3519, 0.4554, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Chao2017b = structure(c(1,
0.4284, 0.3906, 0.3591, 0.3843, 0.4221, 0.2646, 0.3654, 0.3906,
0.4284, 0.4284, 1, 0.4216, 0.3876, 0.4148, 0.4556, 0.2856, 0.3944,
0.4216, 0.4624, 0.3906, 0.4216, 1, 0.3534, 0.3782, 0.4154, 0.2604,
0.3596, 0.3844, 0.4216, 0.3591, 0.3876, 0.3534, 1, 0.3477, 0.3819,
0.2394, 0.3306, 0.3534, 0.3876, 0.3843, 0.4148, 0.3782, 0.3477,
1, 0.4087, 0.2562, 0.3538, 0.3782, 0.4148, 0.4221, 0.4556, 0.4154,
0.3819, 0.4087, 1, 0.2814, 0.3886, 0.4154, 0.4556, 0.2646, 0.2856,
0.2604, 0.2394, 0.2562, 0.2814, 1, 0.2436, 0.2604, 0.2856, 0.3654,
0.3944, 0.3596, 0.3306, 0.3538, 0.3886, 0.2436, 1, 0.3596, 0.3944,
0.3906, 0.4216, 0.3844, 0.3534, 0.3782, 0.4154, 0.2604, 0.3596,
1, 0.4216, 0.4284, 0.4624, 0.4216, 0.3876, 0.4148, 0.4556, 0.2856,
0.3944, 0.4216, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Dobson1979 = structure(c(1,
0.2112, 0.2356, 0.1778, 0.235, 0.1876, 0.2464, 0.1656, 0.2156,
0.197, 0.2112, 1, 0.1827, 0.2616, 0.3885, 0.5502, 0.2013, 0.3582,
0.3267, 0.246, 0.2356, 0.1827, 1, 0.2602, 0.3249, 0.1526, 0.4323,
0.1914, 0.3113, 0.3078, 0.1778, 0.2616, 0.2602, 1, 0.2731, 0.2338,
0.2728, 0.198, 0.2486, 0.2237, 0.235, 0.3885, 0.3249, 0.2731,
1, 0.35, 0.3421, 0.2802, 0.3333, 0.2927, 0.1876, 0.5502, 0.1526,
0.2338, 0.35, 1, 0.1694, 0.3276, 0.2926, 0.217, 0.2464, 0.2013,
0.4323, 0.2728, 0.3421, 0.1694, 1, 0.2046, 0.3267, 0.3212, 0.1656,
0.3582, 0.1914, 0.198, 0.2802, 0.3276, 0.2046, 1, 0.2442, 0.2004,
0.2156, 0.3267, 0.3113, 0.2486, 0.3333, 0.2926, 0.3267, 0.2442,
1, 0.2706, 0.197, 0.246, 0.3078, 0.2237, 0.2927, 0.217, 0.3212,
0.2004, 0.2706, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Farid2013 = structure(c(1,
-0.01072, 0.452756, 0.392052, -0.08666, -0.080088, 0.572268,
0.032256, -0.064992, 0.488544, -0.01072, 1, 0.126594, 0.168022,
0.325578, 0.451936, 0.013738, 0.267692, 0.454888, 0.00886000000000001,
0.452756, 0.126594, 1, 0.39674, 0.058054, 0.114347, 0.48608,
0.134653, 0.12821, 0.413813, 0.392052, 0.168022, 0.39674, 1,
0.106357, 0.177007, 0.425239, 0.163067, 0.189574, 0.361531, -0.08666,
0.325578, 0.058054, 0.106357, 1, 0.445261, -0.067097, 0.252557,
0.445978, -0.060035, -0.080088, 0.451936, 0.114347, 0.177007,
0.445261, 1, -0.050807, 0.353588, 0.615328, -0.047204, 0.572268,
0.013738, 0.48608, 0.425239, -0.067097, -0.050807, 1, 0.053813,
-0.034694, 0.515029, 0.032256, 0.267692, 0.134653, 0.163067,
0.252557, 0.353588, 0.053813, 1, 0.357068, 0.043658, -0.064992,
0.454888, 0.12821, 0.189574, 0.445978, 0.615328, -0.034694, 0.357068,
1, -0.033476, 0.488544, 0.00886000000000001, 0.413813, 0.361531,
-0.060035, -0.047204, 0.515029, 0.043658, -0.033476, 1), .Dim = c(10L,
10L), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"))), Franck2008 = structure(c(1, 0.3016,
0.3132, 0.3074, 0.4002, 0.3364, 0.4292, 0.377, 0.3944, 0.4176,
0.3016, 1, 0.2808, 0.2756, 0.3588, 0.3016, 0.3848, 0.338, 0.3536,
0.3744, 0.3132, 0.2808, 1, 0.2862, 0.3726, 0.3132, 0.3996, 0.351,
0.3672, 0.3888, 0.3074, 0.2756, 0.2862, 1, 0.3657, 0.3074, 0.3922,
0.3445, 0.3604, 0.3816, 0.4002, 0.3588, 0.3726, 0.3657, 1, 0.4002,
0.5106, 0.4485, 0.4692, 0.4968, 0.3364, 0.3016, 0.3132, 0.3074,
0.4002, 1, 0.4292, 0.377, 0.3944, 0.4176, 0.4292, 0.3848, 0.3996,
0.3922, 0.5106, 0.4292, 1, 0.481, 0.5032, 0.5328, 0.377, 0.338,
0.351, 0.3445, 0.4485, 0.377, 0.481, 1, 0.442, 0.468, 0.3944,
0.3536, 0.3672, 0.3604, 0.4692, 0.3944, 0.5032, 0.442, 1, 0.4896,
0.4176, 0.3744, 0.3888, 0.3816, 0.4968, 0.4176, 0.5328, 0.468,
0.4896, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Goldsmith1982 = structure(c(1,
0.4103, 0.6459, 0.519, 0.5876, 0.4634, 0.667, 0.358, 0.6658,
0.6819, 0.4103, 1, 0.2366, 0.33, 0.4069, 0.5737, 0.3345, 0.4478,
0.4003, 0.4771, 0.6459, 0.2366, 1, 0.573, 0.6279, 0.3369, 0.7925,
0.2574, 0.7495, 0.7256, 0.519, 0.33, 0.573, 1, 0.507, 0.381,
0.585, 0.294, 0.579, 0.588, 0.5876, 0.4069, 0.6279, 0.507, 1,
0.4576, 0.65, 0.3536, 0.65, 0.6669, 0.4634, 0.5737, 0.3369, 0.381,
0.4576, 1, 0.419, 0.4364, 0.4706, 0.5349, 0.667, 0.3345, 0.7925,
0.585, 0.65, 0.419, 1, 0.322, 0.759, 0.7525, 0.358, 0.4478, 0.2574,
0.294, 0.3536, 0.4364, 0.322, 1, 0.3628, 0.4134, 0.6658, 0.4003,
0.7495, 0.579, 0.65, 0.4706, 0.759, 0.3628, 1, 0.7535, 0.6819,
0.4771, 0.7256, 0.588, 0.6669, 0.5349, 0.7525, 0.4134, 0.7535,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Goldsmith1986a = structure(c(1,
0.1554, 0.7028, 0.588, 0.3178, 0.1064, 0.7252, 0.3626, 0.4942,
0.5502, 0.1554, 1, 0.00430000000000001, 0.0897, 0.2232, 0.4837,
0.1554, 0.3626, 0.2786, 0.2697, 0.7028, 0.00430000000000001,
1, 0.5817, 0.2573, -0.0475, 0.7028, 0.2583, 0.4225, 0.4836, 0.588,
0.0897, 0.5817, 1, 0.2451, 0.0489, 0.588, 0.2709, 0.3867, 0.4338,
0.3178, 0.2232, 0.2573, 0.2451, 1, 0.2063, 0.3178, 0.2576, 0.2764,
0.2937, 0.1064, 0.4837, -0.0475, 0.0489, 0.2063, 1, 0.1064, 0.3465,
0.2503, 0.237, 0.7252, 0.1554, 0.7028, 0.588, 0.3178, 0.1064,
1, 0.3626, 0.4942, 0.5502, 0.3626, 0.3626, 0.2583, 0.2709, 0.2576,
0.3465, 0.3626, 1, 0.357, 0.3717, 0.4942, 0.2786, 0.4225, 0.3867,
0.2764, 0.2503, 0.4942, 0.357, 1, 0.4335, 0.5502, 0.2697, 0.4836,
0.4338, 0.2937, 0.237, 0.5502, 0.3717, 0.4335, 1), .Dim = c(10L,
10L), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"))), Gray1997 = structure(c(1, 0.47734813,
0.50893787, 0.44261371, 0.52859212, 0.43360849, 0.51651369, 0.43796816,
0.55610807, 0.55224869, 0.47734813, 1, 0.47561159, 0.41363047,
0.49397884, 0.40521493, 0.48269133, 0.40928912, 0.51969299, 0.51608633,
0.50893787, 0.47561159, 1, 0.44100353, 0.52666916, 0.43203107,
0.51463467, 0.43637488, 0.55408501, 0.55023967, 0.44261371, 0.41363047,
0.44100353, 1, 0.45803428, 0.37572931, 0.44756811, 0.37950704,
0.48187733, 0.47853311, 0.52859212, 0.49397884, 0.52666916, 0.45803428,
1, 0.44871532, 0.53450892, 0.45322688, 0.57548276, 0.57148892,
0.43360849, 0.40521493, 0.43203107, 0.37572931, 0.44871532, 1,
0.43846209, 0.37178576, 0.47207327, 0.46879709, 0.51651369, 0.48269133,
0.51463467, 0.44756811, 0.53450892, 0.43846209, 1, 0.44287056,
0.56233287, 0.55843029, 0.43796816, 0.40928912, 0.43637488, 0.37950704,
0.45322688, 0.37178576, 0.44287056, 1, 0.47681968, 0.47351056,
0.55610807, 0.51969299, 0.55408501, 0.48187733, 0.57548276, 0.47207327,
0.56233287, 0.47681968, 1, 0.60123787, 0.55224869, 0.51608633,
0.55023967, 0.47853311, 0.57148892, 0.46879709, 0.55843029, 0.47351056,
0.60123787, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Hensley1976 = structure(c(1,
0.1856, 0.4106, 0.4359, 0.1946, 0.1677, 0.3888, 0.2133, 0.1847,
0.345, 0.1856, 1, 0.1376, 0.1491, 0.389, 0.4179, 0.1878, 0.4671,
0.4889, 0.1932, 0.4106, 0.1376, 1, 0.4847, 0.1674, 0.1317, 0.424,
0.1773, 0.1407, 0.3722, 0.4359, 0.1491, 0.4847, 1, 0.1798, 0.1422,
0.4501, 0.1908, 0.1522, 0.3953, 0.1946, 0.389, 0.1674, 0.1798,
1, 0.318, 0.1982, 0.36, 0.37, 0.1942, 0.1677, 0.4179, 0.1317,
0.1422, 0.318, 1, 0.1701, 0.3807, 0.3963, 0.1719, 0.3888, 0.1878,
0.424, 0.4501, 0.1982, 0.1701, 1, 0.2169, 0.1871, 0.3556, 0.2133,
0.4671, 0.1773, 0.1908, 0.36, 0.3807, 0.2169, 1, 0.4437, 0.2151,
0.1847, 0.4889, 0.1407, 0.1522, 0.37, 0.3963, 0.1871, 0.4437,
1, 0.1909, 0.345, 0.1932, 0.3722, 0.3953, 0.1942, 0.1719, 0.3556,
0.2151, 0.1909, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Hensley1977a = structure(c(1,
0.324, 0.318, 0.276, 0.318, 0.324, 0.372, 0.384, 0.39, 0.402,
0.324, 1, 0.2862, 0.2484, 0.2862, 0.2916, 0.3348, 0.3456, 0.351,
0.3618, 0.318, 0.2862, 1, 0.2438, 0.2809, 0.2862, 0.3286, 0.3392,
0.3445, 0.3551, 0.276, 0.2484, 0.2438, 1, 0.2438, 0.2484, 0.2852,
0.2944, 0.299, 0.3082, 0.318, 0.2862, 0.2809, 0.2438, 1, 0.2862,
0.3286, 0.3392, 0.3445, 0.3551, 0.324, 0.2916, 0.2862, 0.2484,
0.2862, 1, 0.3348, 0.3456, 0.351, 0.3618, 0.372, 0.3348, 0.3286,
0.2852, 0.3286, 0.3348, 1, 0.3968, 0.403, 0.4154, 0.384, 0.3456,
0.3392, 0.2944, 0.3392, 0.3456, 0.3968, 1, 0.416, 0.4288, 0.39,
0.351, 0.3445, 0.299, 0.3445, 0.351, 0.403, 0.416, 1, 0.4355,
0.402, 0.3618, 0.3551, 0.3082, 0.3551, 0.3618, 0.4154, 0.4288,
0.4355, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Hensley1977b = structure(c(1,
0.4402, 0.4047, 0.3621, 0.3337, 0.4118, 0.4757, 0.4331, 0.4331,
0.5112, 0.4402, 1, 0.3534, 0.3162, 0.2914, 0.3596, 0.4154, 0.3782,
0.3782, 0.4464, 0.4047, 0.3534, 1, 0.2907, 0.2679, 0.3306, 0.3819,
0.3477, 0.3477, 0.4104, 0.3621, 0.3162, 0.2907, 1, 0.2397, 0.2958,
0.3417, 0.3111, 0.3111, 0.3672, 0.3337, 0.2914, 0.2679, 0.2397,
1, 0.2726, 0.3149, 0.2867, 0.2867, 0.3384, 0.4118, 0.3596, 0.3306,
0.2958, 0.2726, 1, 0.3886, 0.3538, 0.3538, 0.4176, 0.4757, 0.4154,
0.3819, 0.3417, 0.3149, 0.3886, 1, 0.4087, 0.4087, 0.4824, 0.4331,
0.3782, 0.3477, 0.3111, 0.2867, 0.3538, 0.4087, 1, 0.3721, 0.4392,
0.4331, 0.3782, 0.3477, 0.3111, 0.2867, 0.3538, 0.4087, 0.3721,
1, 0.4392, 0.5112, 0.4464, 0.4104, 0.3672, 0.3384, 0.4176, 0.4824,
0.4392, 0.4392, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Kaplan1969 = structure(c(1,
0.3373, 0.1067, 0.1255, 0.2273, 0.3254, 0.1387, 0.2969, 0.2834,
0.2389, 0.3373, 1, -0.0231, 0.0316, 0.2806, 0.5858, 0.0547, 0.4678,
0.3488, 0.3118, 0.1067, -0.0231, 1, 0.5303, 0.3237, -0.0614,
0.5297, 0.1341, 0.4066, 0.2921, 0.1255, 0.0316, 0.5303, 1, 0.3152,
-0.00339999999999999, 0.4801, 0.1616, 0.3956, 0.2896, 0.2273,
0.2806, 0.3237, 0.3152, 1, 0.2554, 0.3263, 0.3074, 0.4024, 0.3194,
0.3254, 0.5858, -0.0614, -0.00339999999999999, 0.2554, 1, 0.0194,
0.4522, 0.3172, 0.2882, 0.1387, 0.0547, 0.5297, 0.4801, 0.3263,
0.0194, 1, 0.1799, 0.4094, 0.3019, 0.2969, 0.4678, 0.1341, 0.1616,
0.3074, 0.4522, 0.1799, 1, 0.3832, 0.3242, 0.2834, 0.3488, 0.4066,
0.3956, 0.4024, 0.3172, 0.4094, 0.3832, 1, 0.3992, 0.2389, 0.3118,
0.2921, 0.2896, 0.3194, 0.2882, 0.3019, 0.3242, 0.3992, 1), .Dim = c(10L,
10L), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"))), Meurer2012 = structure(c(1, 0.406364,
0.34074, 0.27764, 0.402578, 0.439176, 0.326227, 0.406364, 0.455582,
0.410781, 0.406364, 1, 0.34776, 0.28336, 0.410872, 0.448224,
0.332948, 0.414736, 0.464968, 0.419244, 0.34074, 0.34776, 1,
0.2376, 0.34452, 0.37584, 0.27918, 0.34776, 0.38988, 0.35154,
0.27764, 0.28336, 0.2376, 1, 0.28072, 0.30624, 0.22748, 0.28336,
0.31768, 0.28644, 0.402578, 0.410872, 0.34452, 0.28072, 1, 0.444048,
0.329846, 0.410872, 0.460636, 0.415338, 0.439176, 0.448224, 0.37584,
0.30624, 0.444048, 1, 0.359832, 0.448224, 0.502512, 0.453096,
0.326227, 0.332948, 0.27918, 0.22748, 0.329846, 0.359832, 1,
0.332948, 0.373274, 0.336567, 0.406364, 0.414736, 0.34776, 0.28336,
0.410872, 0.448224, 0.332948, 1, 0.464968, 0.419244, 0.455582,
0.464968, 0.38988, 0.31768, 0.460636, 0.502512, 0.373274, 0.464968,
1, 0.470022, 0.410781, 0.419244, 0.35154, 0.28644, 0.415338,
0.453096, 0.336567, 0.419244, 0.470022, 1), .Dim = c(10L, 10L
), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6", "I7",
"I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6", "I7",
"I8", "I9", "I10"))), Mimura2007a = structure(c(1, 0.4725, 0.4905,
0.4979, 0.5153, 0.406, 0.5195, 0.4427, 0.569, 0.5309, 0.4725,
1, 0.2961, 0.3563, 0.4893, 0.6776, 0.4123, 0.5999, 0.567, 0.5649,
0.4905, 0.2961, 1, 0.6246, 0.5391, 0.1647, 0.6156, 0.3033, 0.5715,
0.5013, 0.4979, 0.3563, 0.6246, 1, 0.5429, 0.2421, 0.5988, 0.3523,
0.5825, 0.5207, 0.5153, 0.4893, 0.5391, 0.5429, 1, 0.4126, 0.5633,
0.4607, 0.608, 0.5645, 0.406, 0.6776, 0.1647, 0.2421, 0.4126,
1, 0.3071, 0.5958, 0.4915, 0.5068, 0.5195, 0.4123, 0.6156, 0.5988,
0.5633, 0.3071, 1, 0.3999, 0.6095, 0.5519, 0.4427, 0.5999, 0.3033,
0.3523, 0.4607, 0.5958, 0.3999, 1, 0.53, 0.5231, 0.569, 0.567,
0.5715, 0.5825, 0.608, 0.4915, 0.6095, 0.53, 1, 0.629, 0.5309,
0.5649, 0.5013, 0.5207, 0.5645, 0.5068, 0.5519, 0.5231, 0.629,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Mimura2007b = structure(c(1,
0.3503, 0.4705, 0.4124, 0.4544, 0.386, 0.444, 0.2178, 0.3827,
0.4162, 0.3503, 1, 0.2159, 0.2376, 0.3594, 0.5266, 0.2008, 0.4686,
0.5195, 0.382, 0.4705, 0.2159, 1, 0.4856, 0.479, 0.2798, 0.5544,
0.0594, 0.2789, 0.4084, 0.4124, 0.2376, 0.4856, 1, 0.4202, 0.2854,
0.4592, 0.1056, 0.2838, 0.3678, 0.4544, 0.3594, 0.479, 0.4202,
1, 0.3955, 0.452, 0.2244, 0.3921, 0.4251, 0.386, 0.5266, 0.2798,
0.2854, 0.3955, 1, 0.2616, 0.4356, 0.5131, 0.4061, 0.444, 0.2008,
0.5544, 0.4592, 0.452, 0.2616, 1, 0.0528, 0.2608, 0.3848, 0.2178,
0.4686, 0.0594, 0.1056, 0.2244, 0.4356, 0.0528, 1, 0.429, 0.264,
0.3827, 0.5195, 0.2789, 0.2838, 0.3921, 0.5131, 0.2608, 0.429,
1, 0.4021, 0.4162, 0.382, 0.4084, 0.3678, 0.4251, 0.4061, 0.3848,
0.264, 0.4021, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Mlacic2006 = structure(c(1,
0.5325, 0.4686, 0.4331, 0.5254, 0.5112, 0.4686, 0.4047, 0.5609,
0.4473, 0.5325, 1, 0.495, 0.4575, 0.555, 0.54, 0.495, 0.4275,
0.5925, 0.4725, 0.4686, 0.495, 1, 0.4026, 0.4884, 0.4752, 0.4356,
0.3762, 0.5214, 0.4158, 0.4331, 0.4575, 0.4026, 1, 0.4514, 0.4392,
0.4026, 0.3477, 0.4819, 0.3843, 0.5254, 0.555, 0.4884, 0.4514,
1, 0.5328, 0.4884, 0.4218, 0.5846, 0.4662, 0.5112, 0.54, 0.4752,
0.4392, 0.5328, 1, 0.4752, 0.4104, 0.5688, 0.4536, 0.4686, 0.495,
0.4356, 0.4026, 0.4884, 0.4752, 1, 0.3762, 0.5214, 0.4158, 0.4047,
0.4275, 0.3762, 0.3477, 0.4218, 0.4104, 0.3762, 1, 0.4503, 0.3591,
0.5609, 0.5925, 0.5214, 0.4819, 0.5846, 0.5688, 0.5214, 0.4503,
1, 0.4977, 0.4473, 0.4725, 0.4158, 0.3843, 0.4662, 0.4536, 0.4158,
0.3591, 0.4977, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Obrien1985 = structure(c(1,
0.396, 0.4554, 0.3762, 0.4356, 0.3762, 0.5214, 0.5148, 0.495,
0.5346, 0.396, 1, 0.414, 0.342, 0.396, 0.342, 0.474, 0.468, 0.45,
0.486, 0.4554, 0.414, 1, 0.3933, 0.4554, 0.3933, 0.5451, 0.5382,
0.5175, 0.5589, 0.3762, 0.342, 0.3933, 1, 0.3762, 0.3249, 0.4503,
0.4446, 0.4275, 0.4617, 0.4356, 0.396, 0.4554, 0.3762, 1, 0.3762,
0.5214, 0.5148, 0.495, 0.5346, 0.3762, 0.342, 0.3933, 0.3249,
0.3762, 1, 0.4503, 0.4446, 0.4275, 0.4617, 0.5214, 0.474, 0.5451,
0.4503, 0.5214, 0.4503, 1, 0.6162, 0.5925, 0.6399, 0.5148, 0.468,
0.5382, 0.4446, 0.5148, 0.4446, 0.6162, 1, 0.585, 0.6318, 0.495,
0.45, 0.5175, 0.4275, 0.495, 0.4275, 0.5925, 0.585, 1, 0.6075,
0.5346, 0.486, 0.5589, 0.4617, 0.5346, 0.4617, 0.6399, 0.6318,
0.6075, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Pullmann2000 = structure(c(1,
0.4104, 0.4032, 0.4104, 0.54, 0.4392, 0.504, 0.3528, 0.5112,
0.5328, 0.4104, 1, 0.3192, 0.3249, 0.4275, 0.3477, 0.399, 0.2793,
0.4047, 0.4218, 0.4032, 0.3192, 1, 0.3192, 0.42, 0.3416, 0.392,
0.2744, 0.3976, 0.4144, 0.4104, 0.3249, 0.3192, 1, 0.4275, 0.3477,
0.399, 0.2793, 0.4047, 0.4218, 0.54, 0.4275, 0.42, 0.4275, 1,
0.4575, 0.525, 0.3675, 0.5325, 0.555, 0.4392, 0.3477, 0.3416,
0.3477, 0.4575, 1, 0.427, 0.2989, 0.4331, 0.4514, 0.504, 0.399,
0.392, 0.399, 0.525, 0.427, 1, 0.343, 0.497, 0.518, 0.3528, 0.2793,
0.2744, 0.2793, 0.3675, 0.2989, 0.343, 1, 0.3479, 0.3626, 0.5112,
0.4047, 0.3976, 0.4047, 0.5325, 0.4331, 0.497, 0.3479, 1, 0.5254,
0.5328, 0.4218, 0.4144, 0.4218, 0.555, 0.4514, 0.518, 0.3626,
0.5254, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Rojas2009 = structure(c(1,
0, 0.529505, 0.563517, 0, 0, 0.500131, 0, 0, 0.60294, 0, 1, 0,
0, 0.500226, 0.635145, 0, 0.389766, 0.525474, 0, 0.529505, 0,
1, 0.499365, 0, 0, 0.443195, 0, 0, 0.5343, 0.563517, 0, 0.499365,
1, 0, 0, 0.471663, 0, 0, 0.56862, 0, 0.500226, 0, 0, 1, 0.51037,
0, 0.313196, 0.422244, 0, 0, 0.635145, 0, 0, 0.51037, 1, 0, 0.39767,
0.53613, 0, 0.500131, 0, 0.443195, 0.471663, 0, 0, 1, 0, 0, 0.50466,
0, 0.389766, 0, 0, 0.313196, 0.39767, 0, 1, 0.329004, 0, 0, 0.525474,
0, 0, 0.422244, 0.53613, 0, 0.329004, 1, 0, 0.60294, 0, 0.5343,
0.56862, 0, 0, 0.50466, 0, 0, 1), .Dim = c(10L, 10L), .Dimnames = list(
c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"
), c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9",
"I10"))), Sarkova2006a = structure(c(1, 0.2885, 0.3096, 0.414,
0.2964, 0.2942, 0.4629, 0.1513, 0.458, 0.3395, 0.2885, 1, -0.0495,
0.2025, 0.4335, 0.514, 0.2715, 0.4265, 0.37, 0.133, 0.3096, -0.0495,
1, 0.391, 0.0298, -0.043, 0.3981, -0.1627, 0.306, 0.3493, 0.414,
0.2025, 0.391, 1, 0.235, 0.209, 0.4845, 0.0605, 0.45, 0.3745,
0.2964, 0.4335, 0.0298, 0.235, 1, 0.4358, 0.2955, 0.3419, 0.366,
0.1687, 0.2942, 0.514, -0.043, 0.209, 0.4358, 1, 0.2784, 0.426,
0.376, 0.1386, 0.4629, 0.2715, 0.3981, 0.4845, 0.2955, 0.2784,
1, 0.1143, 0.51, 0.4032, 0.1513, 0.4265, -0.1627, 0.0605, 0.3419,
0.426, 0.1143, 1, 0.218, 0.0154, 0.458, 0.37, 0.306, 0.45, 0.366,
0.376, 0.51, 0.218, 1, 0.364, 0.3395, 0.133, 0.3493, 0.3745,
0.1687, 0.1386, 0.4032, 0.0154, 0.364, 1), .Dim = c(10L, 10L), .Dimnames = list(
c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"
), c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9",
"I10"))), Sarkova2006b = structure(c(1, 0.1476, 0.3438, 0.3504,
0.1244, 0.3115, 0.3958, -0.1706, 0.282, 0.4028, 0.1476, 1, 0.0056,
0.1765, 0.3841, 0.4486, 0.1423, 0.1861, 0.4288, 0.0452, 0.3438,
0.0056, 1, 0.3008, -0.0184, 0.1538, 0.362, -0.2524, 0.1304, 0.4072,
0.3504, 0.1765, 0.3008, 1, 0.1561, 0.3274, 0.3631, -0.1259, 0.2992,
0.3572, 0.1244, 0.3841, -0.0184, 0.1561, 1, 0.4374, 0.1179, 0.2025,
0.4192, 0.018, 0.3115, 0.4486, 0.1538, 0.3274, 0.4374, 1, 0.3128,
0.1124, 0.55, 0.2188, 0.3958, 0.1423, 0.362, 0.3631, 0.1179,
0.3128, 1, -0.1861, 0.2824, 0.4228, -0.1706, 0.1861, -0.2524,
-0.1259, 0.2025, 0.1124, -0.1861, 1, 0.1192, -0.266, 0.282, 0.4288,
0.1304, 0.2992, 0.4192, 0.55, 0.2824, 0.1192, 1, 0.1904, 0.4028,
0.0452, 0.4072, 0.3572, 0.018, 0.2188, 0.4228, -0.266, 0.1904,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005a = structure(c(1,
0.5037, 0.4347, 0.4347, 0.2553, 0.4485, 0.3312, 0.3657, 0.4623,
0.4623, 0.5037, 1, 0.4599, 0.4599, 0.2701, 0.4745, 0.3504, 0.3869,
0.4891, 0.4891, 0.4347, 0.4599, 1, 0.3969, 0.2331, 0.4095, 0.3024,
0.3339, 0.4221, 0.4221, 0.4347, 0.4599, 0.3969, 1, 0.2331, 0.4095,
0.3024, 0.3339, 0.4221, 0.4221, 0.2553, 0.2701, 0.2331, 0.2331,
1, 0.2405, 0.1776, 0.1961, 0.2479, 0.2479, 0.4485, 0.4745, 0.4095,
0.4095, 0.2405, 1, 0.312, 0.3445, 0.4355, 0.4355, 0.3312, 0.3504,
0.3024, 0.3024, 0.1776, 0.312, 1, 0.2544, 0.3216, 0.3216, 0.3657,
0.3869, 0.3339, 0.3339, 0.1961, 0.3445, 0.2544, 1, 0.3551, 0.3551,
0.4623, 0.4891, 0.4221, 0.4221, 0.2479, 0.4355, 0.3216, 0.3551,
1, 0.4489, 0.4623, 0.4891, 0.4221, 0.4221, 0.2479, 0.4355, 0.3216,
0.3551, 0.4489, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005aa = structure(c(1,
0.3796, 0.3848, 0.2964, 0.364, 0.4056, 0.364, 0.0208, 0.3016,
0.3328, 0.3796, 1, 0.5402, 0.4161, 0.511, 0.5694, 0.511, 0.0292,
0.4234, 0.4672, 0.3848, 0.5402, 1, 0.4218, 0.518, 0.5772, 0.518,
0.0296, 0.4292, 0.4736, 0.2964, 0.4161, 0.4218, 1, 0.399, 0.4446,
0.399, 0.0228, 0.3306, 0.3648, 0.364, 0.511, 0.518, 0.399, 1,
0.546, 0.49, 0.028, 0.406, 0.448, 0.4056, 0.5694, 0.5772, 0.4446,
0.546, 1, 0.546, 0.0312, 0.4524, 0.4992, 0.364, 0.511, 0.518,
0.399, 0.49, 0.546, 1, 0.028, 0.406, 0.448, 0.0208, 0.0292, 0.0296,
0.0228, 0.028, 0.0312, 0.028, 1, 0.0232, 0.0256, 0.3016, 0.4234,
0.4292, 0.3306, 0.406, 0.4524, 0.406, 0.0232, 1, 0.3712, 0.3328,
0.4672, 0.4736, 0.3648, 0.448, 0.4992, 0.448, 0.0256, 0.3712,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005aaa = structure(c(1,
0.3648, 0.342, 0.3135, 0.3135, 0.3534, 0.3705, 0.1653, 0.3192,
0.3306, 0.3648, 1, 0.384, 0.352, 0.352, 0.3968, 0.416, 0.1856,
0.3584, 0.3712, 0.342, 0.384, 1, 0.33, 0.33, 0.372, 0.39, 0.174,
0.336, 0.348, 0.3135, 0.352, 0.33, 1, 0.3025, 0.341, 0.3575,
0.1595, 0.308, 0.319, 0.3135, 0.352, 0.33, 0.3025, 1, 0.341,
0.3575, 0.1595, 0.308, 0.319, 0.3534, 0.3968, 0.372, 0.341, 0.341,
1, 0.403, 0.1798, 0.3472, 0.3596, 0.3705, 0.416, 0.39, 0.3575,
0.3575, 0.403, 1, 0.1885, 0.364, 0.377, 0.1653, 0.1856, 0.174,
0.1595, 0.1595, 0.1798, 0.1885, 1, 0.1624, 0.1682, 0.3192, 0.3584,
0.336, 0.308, 0.308, 0.3472, 0.364, 0.1624, 1, 0.3248, 0.3306,
0.3712, 0.348, 0.319, 0.319, 0.3596, 0.377, 0.1682, 0.3248, 1
), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3", "I4",
"I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4",
"I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005b = structure(c(1,
0.5475, 0.5325, 0.465, 0.57, 0.5475, 0.5175, 0.5175, 0.5475,
0.5925, 0.5475, 1, 0.5183, 0.4526, 0.5548, 0.5329, 0.5037, 0.5037,
0.5329, 0.5767, 0.5325, 0.5183, 1, 0.4402, 0.5396, 0.5183, 0.4899,
0.4899, 0.5183, 0.5609, 0.465, 0.4526, 0.4402, 1, 0.4712, 0.4526,
0.4278, 0.4278, 0.4526, 0.4898, 0.57, 0.5548, 0.5396, 0.4712,
1, 0.5548, 0.5244, 0.5244, 0.5548, 0.6004, 0.5475, 0.5329, 0.5183,
0.4526, 0.5548, 1, 0.5037, 0.5037, 0.5329, 0.5767, 0.5175, 0.5037,
0.4899, 0.4278, 0.5244, 0.5037, 1, 0.4761, 0.5037, 0.5451, 0.5175,
0.5037, 0.4899, 0.4278, 0.5244, 0.5037, 0.4761, 1, 0.5037, 0.5451,
0.5475, 0.5329, 0.5183, 0.4526, 0.5548, 0.5329, 0.5037, 0.5037,
1, 0.5767, 0.5925, 0.5767, 0.5609, 0.4898, 0.6004, 0.5767, 0.5451,
0.5451, 0.5767, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005bb = structure(c(1,
0.4554, 0.3933, 0.3243, 0.3795, 0.4416, 0.4071, 0.3381, 0.4623,
0.5658, 0.4554, 1, 0.3762, 0.3102, 0.363, 0.4224, 0.3894, 0.3234,
0.4422, 0.5412, 0.3933, 0.3762, 1, 0.2679, 0.3135, 0.3648, 0.3363,
0.2793, 0.3819, 0.4674, 0.3243, 0.3102, 0.2679, 1, 0.2585, 0.3008,
0.2773, 0.2303, 0.3149, 0.3854, 0.3795, 0.363, 0.3135, 0.2585,
1, 0.352, 0.3245, 0.2695, 0.3685, 0.451, 0.4416, 0.4224, 0.3648,
0.3008, 0.352, 1, 0.3776, 0.3136, 0.4288, 0.5248, 0.4071, 0.3894,
0.3363, 0.2773, 0.3245, 0.3776, 1, 0.2891, 0.3953, 0.4838, 0.3381,
0.3234, 0.2793, 0.2303, 0.2695, 0.3136, 0.2891, 1, 0.3283, 0.4018,
0.4623, 0.4422, 0.3819, 0.3149, 0.3685, 0.4288, 0.3953, 0.3283,
1, 0.5494, 0.5658, 0.5412, 0.4674, 0.3854, 0.451, 0.5248, 0.4838,
0.4018, 0.5494, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005c = structure(c(1,
0.4692, 0.414, 0.4623, 0.4416, 0.4692, 0.3864, 0.4416, 0.4761,
0.4899, 0.4692, 1, 0.408, 0.4556, 0.4352, 0.4624, 0.3808, 0.4352,
0.4692, 0.4828, 0.414, 0.408, 1, 0.402, 0.384, 0.408, 0.336,
0.384, 0.414, 0.426, 0.4623, 0.4556, 0.402, 1, 0.4288, 0.4556,
0.3752, 0.4288, 0.4623, 0.4757, 0.4416, 0.4352, 0.384, 0.4288,
1, 0.4352, 0.3584, 0.4096, 0.4416, 0.4544, 0.4692, 0.4624, 0.408,
0.4556, 0.4352, 1, 0.3808, 0.4352, 0.4692, 0.4828, 0.3864, 0.3808,
0.336, 0.3752, 0.3584, 0.3808, 1, 0.3584, 0.3864, 0.3976, 0.4416,
0.4352, 0.384, 0.4288, 0.4096, 0.4352, 0.3584, 1, 0.4416, 0.4544,
0.4761, 0.4692, 0.414, 0.4623, 0.4416, 0.4692, 0.3864, 0.4416,
1, 0.4899, 0.4899, 0.4828, 0.426, 0.4757, 0.4544, 0.4828, 0.3976,
0.4544, 0.4899, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005cc = structure(c(1,
0.4026, 0.3498, 0.3828, 0.4554, 0.4092, 0.3564, 0.4026, 0.4356,
0.429, 0.4026, 1, 0.3233, 0.3538, 0.4209, 0.3782, 0.3294, 0.3721,
0.4026, 0.3965, 0.3498, 0.3233, 1, 0.3074, 0.3657, 0.3286, 0.2862,
0.3233, 0.3498, 0.3445, 0.3828, 0.3538, 0.3074, 1, 0.4002, 0.3596,
0.3132, 0.3538, 0.3828, 0.377, 0.4554, 0.4209, 0.3657, 0.4002,
1, 0.4278, 0.3726, 0.4209, 0.4554, 0.4485, 0.4092, 0.3782, 0.3286,
0.3596, 0.4278, 1, 0.3348, 0.3782, 0.4092, 0.403, 0.3564, 0.3294,
0.2862, 0.3132, 0.3726, 0.3348, 1, 0.3294, 0.3564, 0.351, 0.4026,
0.3721, 0.3233, 0.3538, 0.4209, 0.3782, 0.3294, 1, 0.4026, 0.3965,
0.4356, 0.4026, 0.3498, 0.3828, 0.4554, 0.4092, 0.3564, 0.4026,
1, 0.429, 0.429, 0.3965, 0.3445, 0.377, 0.4485, 0.403, 0.351,
0.3965, 0.429, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005d = structure(c(1,
0.1106, 0.6636, 0.6241, 0.5135, 0.2923, 0.6715, -0.3792, 0.4266,
0.7031, 0.1106, 1, 0.1176, 0.1106, 0.091, 0.0518, 0.119, -0.0672,
0.0756, 0.1246, 0.6636, 0.1176, 1, 0.6636, 0.546, 0.3108, 0.714,
-0.4032, 0.4536, 0.7476, 0.6241, 0.1106, 0.6636, 1, 0.5135, 0.2923,
0.6715, -0.3792, 0.4266, 0.7031, 0.5135, 0.091, 0.546, 0.5135,
1, 0.2405, 0.5525, -0.312, 0.351, 0.5785, 0.2923, 0.0518, 0.3108,
0.2923, 0.2405, 1, 0.3145, -0.1776, 0.1998, 0.3293, 0.6715, 0.119,
0.714, 0.6715, 0.5525, 0.3145, 1, -0.408, 0.459, 0.7565, -0.3792,
-0.0672, -0.4032, -0.3792, -0.312, -0.1776, -0.408, 1, -0.2592,
-0.4272, 0.4266, 0.0756, 0.4536, 0.4266, 0.351, 0.1998, 0.459,
-0.2592, 1, 0.4806, 0.7031, 0.1246, 0.7476, 0.7031, 0.5785, 0.3293,
0.7565, -0.4272, 0.4806, 1), .Dim = c(10L, 10L), .Dimnames = list(
c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"
), c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9",
"I10"))), Schmitt2005dd = structure(c(1, 0.276, 0.3312, 0.2829,
0.3864, 0.4485, 0.345, 0.3312, 0.4968, 0.4692, 0.276, 1, 0.192,
0.164, 0.224, 0.26, 0.2, 0.192, 0.288, 0.272, 0.3312, 0.192,
1, 0.1968, 0.2688, 0.312, 0.24, 0.2304, 0.3456, 0.3264, 0.2829,
0.164, 0.1968, 1, 0.2296, 0.2665, 0.205, 0.1968, 0.2952, 0.2788,
0.3864, 0.224, 0.2688, 0.2296, 1, 0.364, 0.28, 0.2688, 0.4032,
0.3808, 0.4485, 0.26, 0.312, 0.2665, 0.364, 1, 0.325, 0.312,
0.468, 0.442, 0.345, 0.2, 0.24, 0.205, 0.28, 0.325, 1, 0.24,
0.36, 0.34, 0.3312, 0.192, 0.2304, 0.1968, 0.2688, 0.312, 0.24,
1, 0.3456, 0.3264, 0.4968, 0.288, 0.3456, 0.2952, 0.4032, 0.468,
0.36, 0.3456, 1, 0.4896, 0.4692, 0.272, 0.3264, 0.2788, 0.3808,
0.442, 0.34, 0.3264, 0.4896, 1), .Dim = c(10L, 10L), .Dimnames = list(
c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"
), c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9",
"I10"))), Schmitt2005e = structure(c(1, 0.568, 0.528, 0.488,
0.608, 0.544, 0.6, 0.552, 0.6, 0.656, 0.568, 1, 0.4686, 0.4331,
0.5396, 0.4828, 0.5325, 0.4899, 0.5325, 0.5822, 0.528, 0.4686,
1, 0.4026, 0.5016, 0.4488, 0.495, 0.4554, 0.495, 0.5412, 0.488,
0.4331, 0.4026, 1, 0.4636, 0.4148, 0.4575, 0.4209, 0.4575, 0.5002,
0.608, 0.5396, 0.5016, 0.4636, 1, 0.5168, 0.57, 0.5244, 0.57,
0.6232, 0.544, 0.4828, 0.4488, 0.4148, 0.5168, 1, 0.51, 0.4692,
0.51, 0.5576, 0.6, 0.5325, 0.495, 0.4575, 0.57, 0.51, 1, 0.5175,
0.5625, 0.615, 0.552, 0.4899, 0.4554, 0.4209, 0.5244, 0.4692,
0.5175, 1, 0.5175, 0.5658, 0.6, 0.5325, 0.495, 0.4575, 0.57,
0.51, 0.5625, 0.5175, 1, 0.615, 0.656, 0.5822, 0.5412, 0.5002,
0.6232, 0.5576, 0.615, 0.5658, 0.615, 1), .Dim = c(10L, 10L), .Dimnames = list(
c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"
), c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9",
"I10"))), Schmitt2005ee = structure(c(1, 0.4032, 0.3472,
0.3528, 0.4032, 0.3416, 0.2632, -0.1904, 0.28, 0.4088, 0.4032,
1, 0.4464, 0.4536, 0.5184, 0.4392, 0.3384, -0.2448, 0.36, 0.5256,
0.3472, 0.4464, 1, 0.3906, 0.4464, 0.3782, 0.2914, -0.2108, 0.31,
0.4526, 0.3528, 0.4536, 0.3906, 1, 0.4536, 0.3843, 0.2961, -0.2142,
0.315, 0.4599, 0.4032, 0.5184, 0.4464, 0.4536, 1, 0.4392, 0.3384,
-0.2448, 0.36, 0.5256, 0.3416, 0.4392, 0.3782, 0.3843, 0.4392,
1, 0.2867, -0.2074, 0.305, 0.4453, 0.2632, 0.3384, 0.2914, 0.2961,
0.3384, 0.2867, 1, -0.1598, 0.235, 0.3431, -0.1904, -0.2448,
-0.2108, -0.2142, -0.2448, -0.2074, -0.1598, 1, -0.17, -0.2482,
0.28, 0.36, 0.31, 0.315, 0.36, 0.305, 0.235, -0.17, 1, 0.365,
0.4088, 0.5256, 0.4526, 0.4599, 0.5256, 0.4453, 0.3431, -0.2482,
0.365, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005f = structure(c(1,
0.3185, 0.416, 0.429, 0.234, 0.3965, 0.299, 0.052, 0.351, 0.4485,
0.3185, 1, 0.3136, 0.3234, 0.1764, 0.2989, 0.2254, 0.0392, 0.2646,
0.3381, 0.416, 0.3136, 1, 0.4224, 0.2304, 0.3904, 0.2944, 0.0512,
0.3456, 0.4416, 0.429, 0.3234, 0.4224, 1, 0.2376, 0.4026, 0.3036,
0.0528, 0.3564, 0.4554, 0.234, 0.1764, 0.2304, 0.2376, 1, 0.2196,
0.1656, 0.0288, 0.1944, 0.2484, 0.3965, 0.2989, 0.3904, 0.4026,
0.2196, 1, 0.2806, 0.0488, 0.3294, 0.4209, 0.299, 0.2254, 0.2944,
0.3036, 0.1656, 0.2806, 1, 0.0368, 0.2484, 0.3174, 0.052, 0.0392,
0.0512, 0.0528, 0.0288, 0.0488, 0.0368, 1, 0.0432, 0.0552, 0.351,
0.2646, 0.3456, 0.3564, 0.1944, 0.3294, 0.2484, 0.0432, 1, 0.3726,
0.4485, 0.3381, 0.4416, 0.4554, 0.2484, 0.4209, 0.3174, 0.0552,
0.3726, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005ff = structure(c(1,
0.5325, 0.48, 0.51, 0.525, 0.51, 0.495, 0.45, 0.54, 0.5925, 0.5325,
1, 0.4544, 0.4828, 0.497, 0.4828, 0.4686, 0.426, 0.5112, 0.5609,
0.48, 0.4544, 1, 0.4352, 0.448, 0.4352, 0.4224, 0.384, 0.4608,
0.5056, 0.51, 0.4828, 0.4352, 1, 0.476, 0.4624, 0.4488, 0.408,
0.4896, 0.5372, 0.525, 0.497, 0.448, 0.476, 1, 0.476, 0.462,
0.42, 0.504, 0.553, 0.51, 0.4828, 0.4352, 0.4624, 0.476, 1, 0.4488,
0.408, 0.4896, 0.5372, 0.495, 0.4686, 0.4224, 0.4488, 0.462,
0.4488, 1, 0.396, 0.4752, 0.5214, 0.45, 0.426, 0.384, 0.408,
0.42, 0.408, 0.396, 1, 0.432, 0.474, 0.54, 0.5112, 0.4608, 0.4896,
0.504, 0.4896, 0.4752, 0.432, 1, 0.5688, 0.5925, 0.5609, 0.5056,
0.5372, 0.553, 0.5372, 0.5214, 0.474, 0.5688, 1), .Dim = c(10L,
10L), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"))), Schmitt2005g = structure(c(1, 0.3213,
0.4032, 0.2583, 0.4158, 0.315, 0.3465, 0.1827, 0.4032, 0.3276,
0.3213, 1, 0.3264, 0.2091, 0.3366, 0.255, 0.2805, 0.1479, 0.3264,
0.2652, 0.4032, 0.3264, 1, 0.2624, 0.4224, 0.32, 0.352, 0.1856,
0.4096, 0.3328, 0.2583, 0.2091, 0.2624, 1, 0.2706, 0.205, 0.2255,
0.1189, 0.2624, 0.2132, 0.4158, 0.3366, 0.4224, 0.2706, 1, 0.33,
0.363, 0.1914, 0.4224, 0.3432, 0.315, 0.255, 0.32, 0.205, 0.33,
1, 0.275, 0.145, 0.32, 0.26, 0.3465, 0.2805, 0.352, 0.2255, 0.363,
0.275, 1, 0.1595, 0.352, 0.286, 0.1827, 0.1479, 0.1856, 0.1189,
0.1914, 0.145, 0.1595, 1, 0.1856, 0.1508, 0.4032, 0.3264, 0.4096,
0.2624, 0.4224, 0.32, 0.352, 0.1856, 1, 0.3328, 0.3276, 0.2652,
0.3328, 0.2132, 0.3432, 0.26, 0.286, 0.1508, 0.3328, 1), .Dim = c(10L,
10L), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"))), Schmitt2005gg = structure(c(1, 0.265,
0.3127, 0.3445, 0.2014, 0.3021, 0.3604, 0.1166, 0.3869, 0.3498,
0.265, 1, 0.295, 0.325, 0.19, 0.285, 0.34, 0.11, 0.365, 0.33,
0.3127, 0.295, 1, 0.3835, 0.2242, 0.3363, 0.4012, 0.1298, 0.4307,
0.3894, 0.3445, 0.325, 0.3835, 1, 0.247, 0.3705, 0.442, 0.143,
0.4745, 0.429, 0.2014, 0.19, 0.2242, 0.247, 1, 0.2166, 0.2584,
0.0836, 0.2774, 0.2508, 0.3021, 0.285, 0.3363, 0.3705, 0.2166,
1, 0.3876, 0.1254, 0.4161, 0.3762, 0.3604, 0.34, 0.4012, 0.442,
0.2584, 0.3876, 1, 0.1496, 0.4964, 0.4488, 0.1166, 0.11, 0.1298,
0.143, 0.0836, 0.1254, 0.1496, 1, 0.1606, 0.1452, 0.3869, 0.365,
0.4307, 0.4745, 0.2774, 0.4161, 0.4964, 0.1606, 1, 0.4818, 0.3498,
0.33, 0.3894, 0.429, 0.2508, 0.3762, 0.4488, 0.1452, 0.4818,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005h = structure(c(1,
0.3498, 0.4488, 0.3168, 0.5214, 0.297, 0.4554, 0.2442, 0.4884,
0.3564, 0.3498, 1, 0.3604, 0.2544, 0.4187, 0.2385, 0.3657, 0.1961,
0.3922, 0.2862, 0.4488, 0.3604, 1, 0.3264, 0.5372, 0.306, 0.4692,
0.2516, 0.5032, 0.3672, 0.3168, 0.2544, 0.3264, 1, 0.3792, 0.216,
0.3312, 0.1776, 0.3552, 0.2592, 0.5214, 0.4187, 0.5372, 0.3792,
1, 0.3555, 0.5451, 0.2923, 0.5846, 0.4266, 0.297, 0.2385, 0.306,
0.216, 0.3555, 1, 0.3105, 0.1665, 0.333, 0.243, 0.4554, 0.3657,
0.4692, 0.3312, 0.5451, 0.3105, 1, 0.2553, 0.5106, 0.3726, 0.2442,
0.1961, 0.2516, 0.1776, 0.2923, 0.1665, 0.2553, 1, 0.2738, 0.1998,
0.4884, 0.3922, 0.5032, 0.3552, 0.5846, 0.333, 0.5106, 0.2738,
1, 0.3996, 0.3564, 0.2862, 0.3672, 0.2592, 0.4266, 0.243, 0.3726,
0.1998, 0.3996, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005hh = structure(c(1,
0.4288, 0.2546, 0.3819, 0.3886, 0.4489, 0.2412, 0.2747, 0.3685,
0.4154, 0.4288, 1, 0.2432, 0.3648, 0.3712, 0.4288, 0.2304, 0.2624,
0.352, 0.3968, 0.2546, 0.2432, 1, 0.2166, 0.2204, 0.2546, 0.1368,
0.1558, 0.209, 0.2356, 0.3819, 0.3648, 0.2166, 1, 0.3306, 0.3819,
0.2052, 0.2337, 0.3135, 0.3534, 0.3886, 0.3712, 0.2204, 0.3306,
1, 0.3886, 0.2088, 0.2378, 0.319, 0.3596, 0.4489, 0.4288, 0.2546,
0.3819, 0.3886, 1, 0.2412, 0.2747, 0.3685, 0.4154, 0.2412, 0.2304,
0.1368, 0.2052, 0.2088, 0.2412, 1, 0.1476, 0.198, 0.2232, 0.2747,
0.2624, 0.1558, 0.2337, 0.2378, 0.2747, 0.1476, 1, 0.2255, 0.2542,
0.3685, 0.352, 0.209, 0.3135, 0.319, 0.3685, 0.198, 0.2255, 1,
0.341, 0.4154, 0.3968, 0.2356, 0.3534, 0.3596, 0.4154, 0.2232,
0.2542, 0.341, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005i = structure(c(1,
0.364, 0.3432, 0.2444, 0.3016, 0.182, 0.3536, 0.3068, 0.3484,
0.3796, 0.364, 1, 0.462, 0.329, 0.406, 0.245, 0.476, 0.413, 0.469,
0.511, 0.3432, 0.462, 1, 0.3102, 0.3828, 0.231, 0.4488, 0.3894,
0.4422, 0.4818, 0.2444, 0.329, 0.3102, 1, 0.2726, 0.1645, 0.3196,
0.2773, 0.3149, 0.3431, 0.3016, 0.406, 0.3828, 0.2726, 1, 0.203,
0.3944, 0.3422, 0.3886, 0.4234, 0.182, 0.245, 0.231, 0.1645,
0.203, 1, 0.238, 0.2065, 0.2345, 0.2555, 0.3536, 0.476, 0.4488,
0.3196, 0.3944, 0.238, 1, 0.4012, 0.4556, 0.4964, 0.3068, 0.413,
0.3894, 0.2773, 0.3422, 0.2065, 0.4012, 1, 0.3953, 0.4307, 0.3484,
0.469, 0.4422, 0.3149, 0.3886, 0.2345, 0.4556, 0.3953, 1, 0.4891,
0.3796, 0.511, 0.4818, 0.3431, 0.4234, 0.2555, 0.4964, 0.4307,
0.4891, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005ii = structure(c(1,
0.5328, 0.5032, 0.4514, 0.5328, 0.4144, 0.5032, 0.518, 0.5402,
0.5476, 0.5328, 1, 0.4896, 0.4392, 0.5184, 0.4032, 0.4896, 0.504,
0.5256, 0.5328, 0.5032, 0.4896, 1, 0.4148, 0.4896, 0.3808, 0.4624,
0.476, 0.4964, 0.5032, 0.4514, 0.4392, 0.4148, 1, 0.4392, 0.3416,
0.4148, 0.427, 0.4453, 0.4514, 0.5328, 0.5184, 0.4896, 0.4392,
1, 0.4032, 0.4896, 0.504, 0.5256, 0.5328, 0.4144, 0.4032, 0.3808,
0.3416, 0.4032, 1, 0.3808, 0.392, 0.4088, 0.4144, 0.5032, 0.4896,
0.4624, 0.4148, 0.4896, 0.3808, 1, 0.476, 0.4964, 0.5032, 0.518,
0.504, 0.476, 0.427, 0.504, 0.392, 0.476, 1, 0.511, 0.518, 0.5402,
0.5256, 0.4964, 0.4453, 0.5256, 0.4088, 0.4964, 0.511, 1, 0.5402,
0.5476, 0.5328, 0.5032, 0.4514, 0.5328, 0.4144, 0.5032, 0.518,
0.5402, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005j = structure(c(1,
0.5475, 0.4891, 0.438, 0.1752, 0.4818, 0.438, 0.3869, 0.5402,
0.5402, 0.5475, 1, 0.5025, 0.45, 0.18, 0.495, 0.45, 0.3975, 0.555,
0.555, 0.4891, 0.5025, 1, 0.402, 0.1608, 0.4422, 0.402, 0.3551,
0.4958, 0.4958, 0.438, 0.45, 0.402, 1, 0.144, 0.396, 0.36, 0.318,
0.444, 0.444, 0.1752, 0.18, 0.1608, 0.144, 1, 0.1584, 0.144,
0.1272, 0.1776, 0.1776, 0.4818, 0.495, 0.4422, 0.396, 0.1584,
1, 0.396, 0.3498, 0.4884, 0.4884, 0.438, 0.45, 0.402, 0.36, 0.144,
0.396, 1, 0.318, 0.444, 0.444, 0.3869, 0.3975, 0.3551, 0.318,
0.1272, 0.3498, 0.318, 1, 0.3922, 0.3922, 0.5402, 0.555, 0.4958,
0.444, 0.1776, 0.4884, 0.444, 0.3922, 1, 0.5476, 0.5402, 0.555,
0.4958, 0.444, 0.1776, 0.4884, 0.444, 0.3922, 0.5476, 1), .Dim = c(10L,
10L), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"))), Schmitt2005jj = structure(c(1, 0.497,
0.483, 0.455, 0.448, 0.42, 0.455, 0.42, 0.518, 0.553, 0.497,
1, 0.4899, 0.4615, 0.4544, 0.426, 0.4615, 0.426, 0.5254, 0.5609,
0.483, 0.4899, 1, 0.4485, 0.4416, 0.414, 0.4485, 0.414, 0.5106,
0.5451, 0.455, 0.4615, 0.4485, 1, 0.416, 0.39, 0.4225, 0.39,
0.481, 0.5135, 0.448, 0.4544, 0.4416, 0.416, 1, 0.384, 0.416,
0.384, 0.4736, 0.5056, 0.42, 0.426, 0.414, 0.39, 0.384, 1, 0.39,
0.36, 0.444, 0.474, 0.455, 0.4615, 0.4485, 0.4225, 0.416, 0.39,
1, 0.39, 0.481, 0.5135, 0.42, 0.426, 0.414, 0.39, 0.384, 0.36,
0.39, 1, 0.444, 0.474, 0.518, 0.5254, 0.5106, 0.481, 0.4736,
0.444, 0.481, 0.444, 1, 0.5846, 0.553, 0.5609, 0.5451, 0.5135,
0.5056, 0.474, 0.5135, 0.474, 0.5846, 1), .Dim = c(10L, 10L), .Dimnames = list(
c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"
), c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9",
"I10"))), Schmitt2005k = structure(c(1, 0.3149, 0.4087, 0.3283,
0.1072, 0.2077, 0.3618, -0.3886, 0.2345, 0.3752, 0.3149, 1, 0.2867,
0.2303, 0.0752, 0.1457, 0.2538, -0.2726, 0.1645, 0.2632, 0.4087,
0.2867, 1, 0.2989, 0.0976, 0.1891, 0.3294, -0.3538, 0.2135, 0.3416,
0.3283, 0.2303, 0.2989, 1, 0.0784, 0.1519, 0.2646, -0.2842, 0.1715,
0.2744, 0.1072, 0.0752, 0.0976, 0.0784, 1, 0.0496, 0.0864, -0.0928,
0.056, 0.0896, 0.2077, 0.1457, 0.1891, 0.1519, 0.0496, 1, 0.1674,
-0.1798, 0.1085, 0.1736, 0.3618, 0.2538, 0.3294, 0.2646, 0.0864,
0.1674, 1, -0.3132, 0.189, 0.3024, -0.3886, -0.2726, -0.3538,
-0.2842, -0.0928, -0.1798, -0.3132, 1, -0.203, -0.3248, 0.2345,
0.1645, 0.2135, 0.1715, 0.056, 0.1085, 0.189, -0.203, 1, 0.196,
0.3752, 0.2632, 0.3416, 0.2744, 0.0896, 0.1736, 0.3024, -0.3248,
0.196, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005kk = structure(c(1,
0.511, 0.5256, 0.4672, 0.3504, 0.5183, 0.4526, 0.3139, 0.5402,
0.5986, 0.511, 1, 0.504, 0.448, 0.336, 0.497, 0.434, 0.301, 0.518,
0.574, 0.5256, 0.504, 1, 0.4608, 0.3456, 0.5112, 0.4464, 0.3096,
0.5328, 0.5904, 0.4672, 0.448, 0.4608, 1, 0.3072, 0.4544, 0.3968,
0.2752, 0.4736, 0.5248, 0.3504, 0.336, 0.3456, 0.3072, 1, 0.3408,
0.2976, 0.2064, 0.3552, 0.3936, 0.5183, 0.497, 0.5112, 0.4544,
0.3408, 1, 0.4402, 0.3053, 0.5254, 0.5822, 0.4526, 0.434, 0.4464,
0.3968, 0.2976, 0.4402, 1, 0.2666, 0.4588, 0.5084, 0.3139, 0.301,
0.3096, 0.2752, 0.2064, 0.3053, 0.2666, 1, 0.3182, 0.3526, 0.5402,
0.518, 0.5328, 0.4736, 0.3552, 0.5254, 0.4588, 0.3182, 1, 0.6068,
0.5986, 0.574, 0.5904, 0.5248, 0.3936, 0.5822, 0.5084, 0.3526,
0.6068, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005l = structure(c(1,
0.5183, 0.3905, 0.3834, 0.4402, 0.5183, 0.3692, 0.4473, 0.4686,
0.5325, 0.5183, 1, 0.4015, 0.3942, 0.4526, 0.5329, 0.3796, 0.4599,
0.4818, 0.5475, 0.3905, 0.4015, 1, 0.297, 0.341, 0.4015, 0.286,
0.3465, 0.363, 0.4125, 0.3834, 0.3942, 0.297, 1, 0.3348, 0.3942,
0.2808, 0.3402, 0.3564, 0.405, 0.4402, 0.4526, 0.341, 0.3348,
1, 0.4526, 0.3224, 0.3906, 0.4092, 0.465, 0.5183, 0.5329, 0.4015,
0.3942, 0.4526, 1, 0.3796, 0.4599, 0.4818, 0.5475, 0.3692, 0.3796,
0.286, 0.2808, 0.3224, 0.3796, 1, 0.3276, 0.3432, 0.39, 0.4473,
0.4599, 0.3465, 0.3402, 0.3906, 0.4599, 0.3276, 1, 0.4158, 0.4725,
0.4686, 0.4818, 0.363, 0.3564, 0.4092, 0.4818, 0.3432, 0.4158,
1, 0.495, 0.5325, 0.5475, 0.4125, 0.405, 0.465, 0.5475, 0.39,
0.4725, 0.495, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005m = structure(c(1,
0.5159, 0.5005, 0.4851, 0.5467, 0.5467, 0.4389, 0.5313, 0.6083,
0.6391, 0.5159, 1, 0.4355, 0.4221, 0.4757, 0.4757, 0.3819, 0.4623,
0.5293, 0.5561, 0.5005, 0.4355, 1, 0.4095, 0.4615, 0.4615, 0.3705,
0.4485, 0.5135, 0.5395, 0.4851, 0.4221, 0.4095, 1, 0.4473, 0.4473,
0.3591, 0.4347, 0.4977, 0.5229, 0.5467, 0.4757, 0.4615, 0.4473,
1, 0.5041, 0.4047, 0.4899, 0.5609, 0.5893, 0.5467, 0.4757, 0.4615,
0.4473, 0.5041, 1, 0.4047, 0.4899, 0.5609, 0.5893, 0.4389, 0.3819,
0.3705, 0.3591, 0.4047, 0.4047, 1, 0.3933, 0.4503, 0.4731, 0.5313,
0.4623, 0.4485, 0.4347, 0.4899, 0.4899, 0.3933, 1, 0.5451, 0.5727,
0.6083, 0.5293, 0.5135, 0.4977, 0.5609, 0.5609, 0.4503, 0.5451,
1, 0.6557, 0.6391, 0.5561, 0.5395, 0.5229, 0.5893, 0.5893, 0.4731,
0.5727, 0.6557, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005mm = structure(c(1,
0.481, 0.4736, 0.4366, 0.3996, 0.5032, 0.481, 0.4144, 0.5328,
0.5698, 0.481, 1, 0.416, 0.3835, 0.351, 0.442, 0.4225, 0.364,
0.468, 0.5005, 0.4736, 0.416, 1, 0.3776, 0.3456, 0.4352, 0.416,
0.3584, 0.4608, 0.4928, 0.4366, 0.3835, 0.3776, 1, 0.3186, 0.4012,
0.3835, 0.3304, 0.4248, 0.4543, 0.3996, 0.351, 0.3456, 0.3186,
1, 0.3672, 0.351, 0.3024, 0.3888, 0.4158, 0.5032, 0.442, 0.4352,
0.4012, 0.3672, 1, 0.442, 0.3808, 0.4896, 0.5236, 0.481, 0.4225,
0.416, 0.3835, 0.351, 0.442, 1, 0.364, 0.468, 0.5005, 0.4144,
0.364, 0.3584, 0.3304, 0.3024, 0.3808, 0.364, 1, 0.4032, 0.4312,
0.5328, 0.468, 0.4608, 0.4248, 0.3888, 0.4896, 0.468, 0.4032,
1, 0.5544, 0.5698, 0.5005, 0.4928, 0.4543, 0.4158, 0.5236, 0.5005,
0.4312, 0.5544, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005n = structure(c(1,
0.4278, 0.4002, 0.4554, 0.483, 0.4071, 0.4554, 0.2829, 0.4002,
0.5313, 0.4278, 1, 0.3596, 0.4092, 0.434, 0.3658, 0.4092, 0.2542,
0.3596, 0.4774, 0.4002, 0.3596, 1, 0.3828, 0.406, 0.3422, 0.3828,
0.2378, 0.3364, 0.4466, 0.4554, 0.4092, 0.3828, 1, 0.462, 0.3894,
0.4356, 0.2706, 0.3828, 0.5082, 0.483, 0.434, 0.406, 0.462, 1,
0.413, 0.462, 0.287, 0.406, 0.539, 0.4071, 0.3658, 0.3422, 0.3894,
0.413, 1, 0.3894, 0.2419, 0.3422, 0.4543, 0.4554, 0.4092, 0.3828,
0.4356, 0.462, 0.3894, 1, 0.2706, 0.3828, 0.5082, 0.2829, 0.2542,
0.2378, 0.2706, 0.287, 0.2419, 0.2706, 1, 0.2378, 0.3157, 0.4002,
0.3596, 0.3364, 0.3828, 0.406, 0.3422, 0.3828, 0.2378, 1, 0.4466,
0.5313, 0.4774, 0.4466, 0.5082, 0.539, 0.4543, 0.5082, 0.3157,
0.4466, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005nn = structure(c(1,
0.5624, 0.3922, 0.4218, 0.4958, 0.5328, 0.4588, 0.444, 0.5328,
0.555, 0.5624, 1, 0.4028, 0.4332, 0.5092, 0.5472, 0.4712, 0.456,
0.5472, 0.57, 0.3922, 0.4028, 1, 0.3021, 0.3551, 0.3816, 0.3286,
0.318, 0.3816, 0.3975, 0.4218, 0.4332, 0.3021, 1, 0.3819, 0.4104,
0.3534, 0.342, 0.4104, 0.4275, 0.4958, 0.5092, 0.3551, 0.3819,
1, 0.4824, 0.4154, 0.402, 0.4824, 0.5025, 0.5328, 0.5472, 0.3816,
0.4104, 0.4824, 1, 0.4464, 0.432, 0.5184, 0.54, 0.4588, 0.4712,
0.3286, 0.3534, 0.4154, 0.4464, 1, 0.372, 0.4464, 0.465, 0.444,
0.456, 0.318, 0.342, 0.402, 0.432, 0.372, 1, 0.432, 0.45, 0.5328,
0.5472, 0.3816, 0.4104, 0.4824, 0.5184, 0.4464, 0.432, 1, 0.54,
0.555, 0.57, 0.3975, 0.4275, 0.5025, 0.54, 0.465, 0.45, 0.54,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005o = structure(c(1,
0.5226, 0.5382, 0.5304, 0.624, 0.468, 0.4992, 0.39, 0.624, 0.6318,
0.5226, 1, 0.4623, 0.4556, 0.536, 0.402, 0.4288, 0.335, 0.536,
0.5427, 0.5382, 0.4623, 1, 0.4692, 0.552, 0.414, 0.4416, 0.345,
0.552, 0.5589, 0.5304, 0.4556, 0.4692, 1, 0.544, 0.408, 0.4352,
0.34, 0.544, 0.5508, 0.624, 0.536, 0.552, 0.544, 1, 0.48, 0.512,
0.4, 0.64, 0.648, 0.468, 0.402, 0.414, 0.408, 0.48, 1, 0.384,
0.3, 0.48, 0.486, 0.4992, 0.4288, 0.4416, 0.4352, 0.512, 0.384,
1, 0.32, 0.512, 0.5184, 0.39, 0.335, 0.345, 0.34, 0.4, 0.3, 0.32,
1, 0.4, 0.405, 0.624, 0.536, 0.552, 0.544, 0.64, 0.48, 0.512,
0.4, 1, 0.648, 0.6318, 0.5427, 0.5589, 0.5508, 0.648, 0.486,
0.5184, 0.405, 0.648, 1), .Dim = c(10L, 10L), .Dimnames = list(
c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"
), c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9",
"I10"))), Schmitt2005oo = structure(c(1, 0.4148, 0.4012,
0.4216, 0.4352, 0.3468, 0.4012, 0.102, 0.4964, 0.5372, 0.4148,
1, 0.3599, 0.3782, 0.3904, 0.3111, 0.3599, 0.0915, 0.4453, 0.4819,
0.4012, 0.3599, 1, 0.3658, 0.3776, 0.3009, 0.3481, 0.0885, 0.4307,
0.4661, 0.4216, 0.3782, 0.3658, 1, 0.3968, 0.3162, 0.3658, 0.093,
0.4526, 0.4898, 0.4352, 0.3904, 0.3776, 0.3968, 1, 0.3264, 0.3776,
0.096, 0.4672, 0.5056, 0.3468, 0.3111, 0.3009, 0.3162, 0.3264,
1, 0.3009, 0.0765, 0.3723, 0.4029, 0.4012, 0.3599, 0.3481, 0.3658,
0.3776, 0.3009, 1, 0.0885, 0.4307, 0.4661, 0.102, 0.0915, 0.0885,
0.093, 0.096, 0.0765, 0.0885, 1, 0.1095, 0.1185, 0.4964, 0.4453,
0.4307, 0.4526, 0.4672, 0.3723, 0.4307, 0.1095, 1, 0.5767, 0.5372,
0.4819, 0.4661, 0.4898, 0.5056, 0.4029, 0.4661, 0.1185, 0.5767,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005p = structure(c(1,
0.444, 0.288, 0.33, 0.222, 0.342, 0.24, 0.198, 0.288, 0.27, 0.444,
1, 0.3552, 0.407, 0.2738, 0.4218, 0.296, 0.2442, 0.3552, 0.333,
0.288, 0.3552, 1, 0.264, 0.1776, 0.2736, 0.192, 0.1584, 0.2304,
0.216, 0.33, 0.407, 0.264, 1, 0.2035, 0.3135, 0.22, 0.1815, 0.264,
0.2475, 0.222, 0.2738, 0.1776, 0.2035, 1, 0.2109, 0.148, 0.1221,
0.1776, 0.1665, 0.342, 0.4218, 0.2736, 0.3135, 0.2109, 1, 0.228,
0.1881, 0.2736, 0.2565, 0.24, 0.296, 0.192, 0.22, 0.148, 0.228,
1, 0.132, 0.192, 0.18, 0.198, 0.2442, 0.1584, 0.1815, 0.1221,
0.1881, 0.132, 1, 0.1584, 0.1485, 0.288, 0.3552, 0.2304, 0.264,
0.1776, 0.2736, 0.192, 0.1584, 1, 0.216, 0.27, 0.333, 0.216,
0.2475, 0.1665, 0.2565, 0.18, 0.1485, 0.216, 1), .Dim = c(10L,
10L), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"))), Schmitt2005pp = structure(c(1, 0.5625,
0.42, 0.39, 0.525, 0.5925, 0.3675, 0.495, 0.495, 0.585, 0.5625,
1, 0.42, 0.39, 0.525, 0.5925, 0.3675, 0.495, 0.495, 0.585, 0.42,
0.42, 1, 0.2912, 0.392, 0.4424, 0.2744, 0.3696, 0.3696, 0.4368,
0.39, 0.39, 0.2912, 1, 0.364, 0.4108, 0.2548, 0.3432, 0.3432,
0.4056, 0.525, 0.525, 0.392, 0.364, 1, 0.553, 0.343, 0.462, 0.462,
0.546, 0.5925, 0.5925, 0.4424, 0.4108, 0.553, 1, 0.3871, 0.5214,
0.5214, 0.6162, 0.3675, 0.3675, 0.2744, 0.2548, 0.343, 0.3871,
1, 0.3234, 0.3234, 0.3822, 0.495, 0.495, 0.3696, 0.3432, 0.462,
0.5214, 0.3234, 1, 0.4356, 0.5148, 0.495, 0.495, 0.3696, 0.3432,
0.462, 0.5214, 0.3234, 0.4356, 1, 0.5148, 0.585, 0.585, 0.4368,
0.4056, 0.546, 0.6162, 0.3822, 0.5148, 0.5148, 1), .Dim = c(10L,
10L), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"))), Schmitt2005q = structure(c(1, 0.3876,
0.3933, 0.3192, 0.3021, 0.3078, 0.3306, 0.228, 0.2337, 0.3705,
0.3876, 1, 0.4692, 0.3808, 0.3604, 0.3672, 0.3944, 0.272, 0.2788,
0.442, 0.3933, 0.4692, 1, 0.3864, 0.3657, 0.3726, 0.4002, 0.276,
0.2829, 0.4485, 0.3192, 0.3808, 0.3864, 1, 0.2968, 0.3024, 0.3248,
0.224, 0.2296, 0.364, 0.3021, 0.3604, 0.3657, 0.2968, 1, 0.2862,
0.3074, 0.212, 0.2173, 0.3445, 0.3078, 0.3672, 0.3726, 0.3024,
0.2862, 1, 0.3132, 0.216, 0.2214, 0.351, 0.3306, 0.3944, 0.4002,
0.3248, 0.3074, 0.3132, 1, 0.232, 0.2378, 0.377, 0.228, 0.272,
0.276, 0.224, 0.212, 0.216, 0.232, 1, 0.164, 0.26, 0.2337, 0.2788,
0.2829, 0.2296, 0.2173, 0.2214, 0.2378, 0.164, 1, 0.2665, 0.3705,
0.442, 0.4485, 0.364, 0.3445, 0.351, 0.377, 0.26, 0.2665, 1), .Dim = c(10L,
10L), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"))), Schmitt2005qq = structure(c(1, 0.504,
0.322, 0.385, 0.455, 0.434, 0.427, 0.238, 0.483, 0.476, 0.504,
1, 0.3312, 0.396, 0.468, 0.4464, 0.4392, 0.2448, 0.4968, 0.4896,
0.322, 0.3312, 1, 0.253, 0.299, 0.2852, 0.2806, 0.1564, 0.3174,
0.3128, 0.385, 0.396, 0.253, 1, 0.3575, 0.341, 0.3355, 0.187,
0.3795, 0.374, 0.455, 0.468, 0.299, 0.3575, 1, 0.403, 0.3965,
0.221, 0.4485, 0.442, 0.434, 0.4464, 0.2852, 0.341, 0.403, 1,
0.3782, 0.2108, 0.4278, 0.4216, 0.427, 0.4392, 0.2806, 0.3355,
0.3965, 0.3782, 1, 0.2074, 0.4209, 0.4148, 0.238, 0.2448, 0.1564,
0.187, 0.221, 0.2108, 0.2074, 1, 0.2346, 0.2312, 0.483, 0.4968,
0.3174, 0.3795, 0.4485, 0.4278, 0.4209, 0.2346, 1, 0.4692, 0.476,
0.4896, 0.3128, 0.374, 0.442, 0.4216, 0.4148, 0.2312, 0.4692,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005r = structure(c(1,
0.366, 0.4209, 0.4148, 0.427, 0.3355, 0.4636, 0.3965, 0.4453,
0.4758, 0.366, 1, 0.414, 0.408, 0.42, 0.33, 0.456, 0.39, 0.438,
0.468, 0.4209, 0.414, 1, 0.4692, 0.483, 0.3795, 0.5244, 0.4485,
0.5037, 0.5382, 0.4148, 0.408, 0.4692, 1, 0.476, 0.374, 0.5168,
0.442, 0.4964, 0.5304, 0.427, 0.42, 0.483, 0.476, 1, 0.385, 0.532,
0.455, 0.511, 0.546, 0.3355, 0.33, 0.3795, 0.374, 0.385, 1, 0.418,
0.3575, 0.4015, 0.429, 0.4636, 0.456, 0.5244, 0.5168, 0.532,
0.418, 1, 0.494, 0.5548, 0.5928, 0.3965, 0.39, 0.4485, 0.442,
0.455, 0.3575, 0.494, 1, 0.4745, 0.507, 0.4453, 0.438, 0.5037,
0.4964, 0.511, 0.4015, 0.5548, 0.4745, 1, 0.5694, 0.4758, 0.468,
0.5382, 0.5304, 0.546, 0.429, 0.5928, 0.507, 0.5694, 1), .Dim = c(10L,
10L), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"))), Schmitt2005rr = structure(c(1, 0.5472,
0.504, 0.4536, 0.4248, 0.468, 0.5544, 0.4392, 0.5256, 0.576,
0.5472, 1, 0.532, 0.4788, 0.4484, 0.494, 0.5852, 0.4636, 0.5548,
0.608, 0.504, 0.532, 1, 0.441, 0.413, 0.455, 0.539, 0.427, 0.511,
0.56, 0.4536, 0.4788, 0.441, 1, 0.3717, 0.4095, 0.4851, 0.3843,
0.4599, 0.504, 0.4248, 0.4484, 0.413, 0.3717, 1, 0.3835, 0.4543,
0.3599, 0.4307, 0.472, 0.468, 0.494, 0.455, 0.4095, 0.3835, 1,
0.5005, 0.3965, 0.4745, 0.52, 0.5544, 0.5852, 0.539, 0.4851,
0.4543, 0.5005, 1, 0.4697, 0.5621, 0.616, 0.4392, 0.4636, 0.427,
0.3843, 0.3599, 0.3965, 0.4697, 1, 0.4453, 0.488, 0.5256, 0.5548,
0.511, 0.4599, 0.4307, 0.4745, 0.5621, 0.4453, 1, 0.584, 0.576,
0.608, 0.56, 0.504, 0.472, 0.52, 0.616, 0.488, 0.584, 1), .Dim = c(10L,
10L), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"))), Schmitt2005s = structure(c(1, 0.5325,
0.4275, 0.2775, 0.51, 0.465, 0.48, 0.36, 0.45, 0.5625, 0.5325,
1, 0.4047, 0.2627, 0.4828, 0.4402, 0.4544, 0.3408, 0.426, 0.5325,
0.4275, 0.4047, 1, 0.2109, 0.3876, 0.3534, 0.3648, 0.2736, 0.342,
0.4275, 0.2775, 0.2627, 0.2109, 1, 0.2516, 0.2294, 0.2368, 0.1776,
0.222, 0.2775, 0.51, 0.4828, 0.3876, 0.2516, 1, 0.4216, 0.4352,
0.3264, 0.408, 0.51, 0.465, 0.4402, 0.3534, 0.2294, 0.4216, 1,
0.3968, 0.2976, 0.372, 0.465, 0.48, 0.4544, 0.3648, 0.2368, 0.4352,
0.3968, 1, 0.3072, 0.384, 0.48, 0.36, 0.3408, 0.2736, 0.1776,
0.3264, 0.2976, 0.3072, 1, 0.288, 0.36, 0.45, 0.426, 0.342, 0.222,
0.408, 0.372, 0.384, 0.288, 1, 0.45, 0.5625, 0.5325, 0.4275,
0.2775, 0.51, 0.465, 0.48, 0.36, 0.45, 1), .Dim = c(10L, 10L), .Dimnames = list(
c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"
), c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9",
"I10"))), Schmitt2005ss = structure(c(1, 0.4692, 0.4485,
0.414, 0.483, 0.4692, 0.3933, 0.1725, 0.4968, 0.5106, 0.4692,
1, 0.442, 0.408, 0.476, 0.4624, 0.3876, 0.17, 0.4896, 0.5032,
0.4485, 0.442, 1, 0.39, 0.455, 0.442, 0.3705, 0.1625, 0.468,
0.481, 0.414, 0.408, 0.39, 1, 0.42, 0.408, 0.342, 0.15, 0.432,
0.444, 0.483, 0.476, 0.455, 0.42, 1, 0.476, 0.399, 0.175, 0.504,
0.518, 0.4692, 0.4624, 0.442, 0.408, 0.476, 1, 0.3876, 0.17,
0.4896, 0.5032, 0.3933, 0.3876, 0.3705, 0.342, 0.399, 0.3876,
1, 0.1425, 0.4104, 0.4218, 0.1725, 0.17, 0.1625, 0.15, 0.175,
0.17, 0.1425, 1, 0.18, 0.185, 0.4968, 0.4896, 0.468, 0.432, 0.504,
0.4896, 0.4104, 0.18, 1, 0.5328, 0.5106, 0.5032, 0.481, 0.444,
0.518, 0.5032, 0.4218, 0.185, 0.5328, 1), .Dim = c(10L, 10L), .Dimnames = list(
c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"
), c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9",
"I10"))), Schmitt2005t = structure(c(1, 0.5624, 0.4736, 0.444,
0.4514, 0.555, 0.4884, 0.5328, 0.5476, 0.5772, 0.5624, 1, 0.4864,
0.456, 0.4636, 0.57, 0.5016, 0.5472, 0.5624, 0.5928, 0.4736,
0.4864, 1, 0.384, 0.3904, 0.48, 0.4224, 0.4608, 0.4736, 0.4992,
0.444, 0.456, 0.384, 1, 0.366, 0.45, 0.396, 0.432, 0.444, 0.468,
0.4514, 0.4636, 0.3904, 0.366, 1, 0.4575, 0.4026, 0.4392, 0.4514,
0.4758, 0.555, 0.57, 0.48, 0.45, 0.4575, 1, 0.495, 0.54, 0.555,
0.585, 0.4884, 0.5016, 0.4224, 0.396, 0.4026, 0.495, 1, 0.4752,
0.4884, 0.5148, 0.5328, 0.5472, 0.4608, 0.432, 0.4392, 0.54,
0.4752, 1, 0.5328, 0.5616, 0.5476, 0.5624, 0.4736, 0.444, 0.4514,
0.555, 0.4884, 0.5328, 1, 0.5772, 0.5772, 0.5928, 0.4992, 0.468,
0.4758, 0.585, 0.5148, 0.5616, 0.5772, 1), .Dim = c(10L, 10L), .Dimnames = list(
c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"
), c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9",
"I10"))), Schmitt2005tt = structure(c(1, 0.4402, 0.4118,
0.4544, 0.3479, 0.4331, 0.3053, 0.3834, 0.5041, 0.5538, 0.4402,
1, 0.3596, 0.3968, 0.3038, 0.3782, 0.2666, 0.3348, 0.4402, 0.4836,
0.4118, 0.3596, 1, 0.3712, 0.2842, 0.3538, 0.2494, 0.3132, 0.4118,
0.4524, 0.4544, 0.3968, 0.3712, 1, 0.3136, 0.3904, 0.2752, 0.3456,
0.4544, 0.4992, 0.3479, 0.3038, 0.2842, 0.3136, 1, 0.2989, 0.2107,
0.2646, 0.3479, 0.3822, 0.4331, 0.3782, 0.3538, 0.3904, 0.2989,
1, 0.2623, 0.3294, 0.4331, 0.4758, 0.3053, 0.2666, 0.2494, 0.2752,
0.2107, 0.2623, 1, 0.2322, 0.3053, 0.3354, 0.3834, 0.3348, 0.3132,
0.3456, 0.2646, 0.3294, 0.2322, 1, 0.3834, 0.4212, 0.5041, 0.4402,
0.4118, 0.4544, 0.3479, 0.4331, 0.3053, 0.3834, 1, 0.5538, 0.5538,
0.4836, 0.4524, 0.4992, 0.3822, 0.4758, 0.3354, 0.4212, 0.5538,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005u = structure(c(1,
0.4818, 0.4964, 0.4745, 0.3796, 0.5256, 0.4234, 0.4891, 0.5621,
0.5548, 0.4818, 1, 0.4488, 0.429, 0.3432, 0.4752, 0.3828, 0.4422,
0.5082, 0.5016, 0.4964, 0.4488, 1, 0.442, 0.3536, 0.4896, 0.3944,
0.4556, 0.5236, 0.5168, 0.4745, 0.429, 0.442, 1, 0.338, 0.468,
0.377, 0.4355, 0.5005, 0.494, 0.3796, 0.3432, 0.3536, 0.338,
1, 0.3744, 0.3016, 0.3484, 0.4004, 0.3952, 0.5256, 0.4752, 0.4896,
0.468, 0.3744, 1, 0.4176, 0.4824, 0.5544, 0.5472, 0.4234, 0.3828,
0.3944, 0.377, 0.3016, 0.4176, 1, 0.3886, 0.4466, 0.4408, 0.4891,
0.4422, 0.4556, 0.4355, 0.3484, 0.4824, 0.3886, 1, 0.5159, 0.5092,
0.5621, 0.5082, 0.5236, 0.5005, 0.4004, 0.5544, 0.4466, 0.5159,
1, 0.5852, 0.5548, 0.5016, 0.5168, 0.494, 0.3952, 0.5472, 0.4408,
0.5092, 0.5852, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005uu = structure(c(1,
0.624, 0.424, 0.392, 0.456, 0.64, 0.192, 0.624, 0.424, 0.664,
0.624, 1, 0.4134, 0.3822, 0.4446, 0.624, 0.1872, 0.6084, 0.4134,
0.6474, 0.424, 0.4134, 1, 0.2597, 0.3021, 0.424, 0.1272, 0.4134,
0.2809, 0.4399, 0.392, 0.3822, 0.2597, 1, 0.2793, 0.392, 0.1176,
0.3822, 0.2597, 0.4067, 0.456, 0.4446, 0.3021, 0.2793, 1, 0.456,
0.1368, 0.4446, 0.3021, 0.4731, 0.64, 0.624, 0.424, 0.392, 0.456,
1, 0.192, 0.624, 0.424, 0.664, 0.192, 0.1872, 0.1272, 0.1176,
0.1368, 0.192, 1, 0.1872, 0.1272, 0.1992, 0.624, 0.6084, 0.4134,
0.3822, 0.4446, 0.624, 0.1872, 1, 0.4134, 0.6474, 0.424, 0.4134,
0.2809, 0.2597, 0.3021, 0.424, 0.1272, 0.4134, 1, 0.4399, 0.664,
0.6474, 0.4399, 0.4067, 0.4731, 0.664, 0.1992, 0.6474, 0.4399,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005v = structure(c(1,
0.429, 0.3894, 0.396, 0.3498, 0.4554, 0.297, 0.2046, 0.396, 0.5016,
0.429, 1, 0.3835, 0.39, 0.3445, 0.4485, 0.2925, 0.2015, 0.39,
0.494, 0.3894, 0.3835, 1, 0.354, 0.3127, 0.4071, 0.2655, 0.1829,
0.354, 0.4484, 0.396, 0.39, 0.354, 1, 0.318, 0.414, 0.27, 0.186,
0.36, 0.456, 0.3498, 0.3445, 0.3127, 0.318, 1, 0.3657, 0.2385,
0.1643, 0.318, 0.4028, 0.4554, 0.4485, 0.4071, 0.414, 0.3657,
1, 0.3105, 0.2139, 0.414, 0.5244, 0.297, 0.2925, 0.2655, 0.27,
0.2385, 0.3105, 1, 0.1395, 0.27, 0.342, 0.2046, 0.2015, 0.1829,
0.186, 0.1643, 0.2139, 0.1395, 1, 0.186, 0.2356, 0.396, 0.39,
0.354, 0.36, 0.318, 0.414, 0.27, 0.186, 1, 0.456, 0.5016, 0.494,
0.4484, 0.456, 0.4028, 0.5244, 0.342, 0.2356, 0.456, 1), .Dim = c(10L,
10L), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"))), Schmitt2005vv = structure(c(1, 0.4958,
0.5624, 0.4588, 0.4366, 0.518, 0.5254, 0.407, 0.4958, 0.5402,
0.4958, 1, 0.5092, 0.4154, 0.3953, 0.469, 0.4757, 0.3685, 0.4489,
0.4891, 0.5624, 0.5092, 1, 0.4712, 0.4484, 0.532, 0.5396, 0.418,
0.5092, 0.5548, 0.4588, 0.4154, 0.4712, 1, 0.3658, 0.434, 0.4402,
0.341, 0.4154, 0.4526, 0.4366, 0.3953, 0.4484, 0.3658, 1, 0.413,
0.4189, 0.3245, 0.3953, 0.4307, 0.518, 0.469, 0.532, 0.434, 0.413,
1, 0.497, 0.385, 0.469, 0.511, 0.5254, 0.4757, 0.5396, 0.4402,
0.4189, 0.497, 1, 0.3905, 0.4757, 0.5183, 0.407, 0.3685, 0.418,
0.341, 0.3245, 0.385, 0.3905, 1, 0.3685, 0.4015, 0.4958, 0.4489,
0.5092, 0.4154, 0.3953, 0.469, 0.4757, 0.3685, 1, 0.4891, 0.5402,
0.4891, 0.5548, 0.4526, 0.4307, 0.511, 0.5183, 0.4015, 0.4891,
1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2", "I3",
"I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005w = structure(c(1,
0.4473, 0.3465, 0.4032, 0.3906, 0.4473, 0.2835, 0.2331, 0.4347,
0.4536, 0.4473, 1, 0.3905, 0.4544, 0.4402, 0.5041, 0.3195, 0.2627,
0.4899, 0.5112, 0.3465, 0.3905, 1, 0.352, 0.341, 0.3905, 0.2475,
0.2035, 0.3795, 0.396, 0.4032, 0.4544, 0.352, 1, 0.3968, 0.4544,
0.288, 0.2368, 0.4416, 0.4608, 0.3906, 0.4402, 0.341, 0.3968,
1, 0.4402, 0.279, 0.2294, 0.4278, 0.4464, 0.4473, 0.5041, 0.3905,
0.4544, 0.4402, 1, 0.3195, 0.2627, 0.4899, 0.5112, 0.2835, 0.3195,
0.2475, 0.288, 0.279, 0.3195, 1, 0.1665, 0.3105, 0.324, 0.2331,
0.2627, 0.2035, 0.2368, 0.2294, 0.2627, 0.1665, 1, 0.2553, 0.2664,
0.4347, 0.4899, 0.3795, 0.4416, 0.4278, 0.4899, 0.3105, 0.2553,
1, 0.4968, 0.4536, 0.5112, 0.396, 0.4608, 0.4464, 0.5112, 0.324,
0.2664, 0.4968, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1",
"I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005ww = structure(c(1,
0.1037, 0.5124, 0.4636, 0.1098, 0.0732, 0.4758, -0.305, 0.0244,
0.5002, 0.1037, 1, 0.1428, 0.1292, 0.0306, 0.0204, 0.1326, -0.085,
0.0068, 0.1394, 0.5124, 0.1428, 1, 0.6384, 0.1512, 0.1008, 0.6552,
-0.42, 0.0336, 0.6888, 0.4636, 0.1292, 0.6384, 1, 0.1368, 0.0912,
0.5928, -0.38, 0.0304, 0.6232, 0.1098, 0.0306, 0.1512, 0.1368,
1, 0.0216, 0.1404, -0.09, 0.0072, 0.1476, 0.0732, 0.0204, 0.1008,
0.0912, 0.0216, 1, 0.0936, -0.06, 0.0048, 0.0984, 0.4758, 0.1326,
0.6552, 0.5928, 0.1404, 0.0936, 1, -0.39, 0.0312, 0.6396, -0.305,
-0.085, -0.42, -0.38, -0.09, -0.06, -0.39, 1, -0.02, -0.41, 0.0244,
0.0068, 0.0336, 0.0304, 0.0072, 0.0048, 0.0312, -0.02, 1, 0.0328,
0.5002, 0.1394, 0.6888, 0.6232, 0.1476, 0.0984, 0.6396, -0.41,
0.0328, 1), .Dim = c(10L, 10L), .Dimnames = list(c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"), c("I1", "I2",
"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"))), Schmitt2005x = structure(c(1,
0.3213, 0.3366, 0.2958, 0.3162, 0.3825, 0.2601, -0.0612, 0.3927,
0.3468, 0.3213, 1, 0.4158, 0.3654, 0.3906, 0.4725, 0.3213, -0.0756,
0.4851, 0.4284, 0.3366, 0.4158, 1, 0.3828, 0.4092, 0.495, 0.3366,
-0.0792, 0.5082, 0.4488, 0.2958, 0.3654, 0.3828, 1, 0.3596, 0.435,
0.2958, -0.0696, 0.4466, 0.3944, 0.3162, 0.3906, 0.4092, 0.3596,
1, 0.465, 0.3162, -0.0744, 0.4774, 0.4216, 0.3825, 0.4725, 0.495,
0.435, 0.465, 1, 0.3825, -0.09, 0.5775, 0.51, 0.2601, 0.3213,
0.3366, 0.2958, 0.3162, 0.3825, 1, -0.0612, 0.3927, 0.3468, -0.0612,
-0.0756, -0.0792, -0.0696, -0.0744, -0.09, -0.0612, 1, -0.0924,
-0.0816, 0.3927, 0.4851, 0.5082, 0.4466, 0.4774, 0.5775, 0.3927,
-0.0924, 1, 0.5236, 0.3468, 0.4284, 0.4488, 0.3944, 0.4216, 0.51,
0.3468, -0.0816, 0.5236, 1), .Dim = c(10L, 10L), .Dimnames = list(
c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"
), c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9",
"I10"))), Schmitt2005xx = structure(c(1, 0.518, 0.4958, 0.4736,
0.5106, 0.5402, 0.4588, 0.4292, 0.5846, 0.5846, 0.518, 1, 0.469,
0.448, 0.483, 0.511, 0.434, 0.406, 0.553, 0.553, 0.4958, 0.469,
1, 0.4288, 0.4623, 0.4891, 0.4154, 0.3886, 0.5293, 0.5293, 0.4736,
0.448, 0.4288, 1, 0.4416, 0.4672, 0.3968, 0.3712, 0.5056, 0.5056,
0.5106, 0.483, 0.4623, 0.4416, 1, 0.5037, 0.4278, 0.4002, 0.5451,
0.5451, 0.5402, 0.511, 0.4891, 0.4672, 0.5037, 1, 0.4526, 0.4234,
0.5767, 0.5767, 0.4588, 0.434, 0.4154, 0.3968, 0.4278, 0.4526,
1, 0.3596, 0.4898, 0.4898, 0.4292, 0.406, 0.3886, 0.3712, 0.4002,
0.4234, 0.3596, 1, 0.4582, 0.4582, 0.5846, 0.553, 0.5293, 0.5056,
0.5451, 0.5767, 0.4898, 0.4582, 1, 0.6241, 0.5846, 0.553, 0.5293,
0.5056, 0.5451, 0.5767, 0.4898, 0.4582, 0.6241, 1), .Dim = c(10L,
10L), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"))), Schmitt2005y = structure(c(1, 0.567,
0.6075, 0.5832, 0.5832, 0.5913, 0.6156, 0.4293, 0.648, 0.648,
0.567, 1, 0.525, 0.504, 0.504, 0.511, 0.532, 0.371, 0.56, 0.56,
0.6075, 0.525, 1, 0.54, 0.54, 0.5475, 0.57, 0.3975, 0.6, 0.6,
0.5832, 0.504, 0.54, 1, 0.5184, 0.5256, 0.5472, 0.3816, 0.576,
0.576, 0.5832, 0.504, 0.54, 0.5184, 1, 0.5256, 0.5472, 0.3816,
0.576, 0.576, 0.5913, 0.511, 0.5475, 0.5256, 0.5256, 1, 0.5548,
0.3869, 0.584, 0.584, 0.6156, 0.532, 0.57, 0.5472, 0.5472, 0.5548,
1, 0.4028, 0.608, 0.608, 0.4293, 0.371, 0.3975, 0.3816, 0.3816,
0.3869, 0.4028, 1, 0.424, 0.424, 0.648, 0.56, 0.6, 0.576, 0.576,
0.584, 0.608, 0.424, 1, 0.64, 0.648, 0.56, 0.6, 0.576, 0.576,
0.584, 0.608, 0.424, 0.64, 1), .Dim = c(10L, 10L), .Dimnames = list(
c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"
), c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9",
"I10"))), Schmitt2005yy = structure(c(1, 0.5621, 0.539, 0.5236,
0.5929, 0.5467, 0.5621, 0.5313, 0.5852, 0.6237, 0.5621, 1, 0.511,
0.4964, 0.5621, 0.5183, 0.5329, 0.5037, 0.5548, 0.5913, 0.539,
0.511, 1, 0.476, 0.539, 0.497, 0.511, 0.483, 0.532, 0.567, 0.5236,
0.4964, 0.476, 1, 0.5236, 0.4828, 0.4964, 0.4692, 0.5168, 0.5508,
0.5929, 0.5621, 0.539, 0.5236, 1, 0.5467, 0.5621, 0.5313, 0.5852,
0.6237, 0.5467, 0.5183, 0.497, 0.4828, 0.5467, 1, 0.5183, 0.4899,
0.5396, 0.5751, 0.5621, 0.5329, 0.511, 0.4964, 0.5621, 0.5183,
1, 0.5037, 0.5548, 0.5913, 0.5313, 0.5037, 0.483, 0.4692, 0.5313,
0.4899, 0.5037, 1, 0.5244, 0.5589, 0.5852, 0.5548, 0.532, 0.5168,
0.5852, 0.5396, 0.5548, 0.5244, 1, 0.6156, 0.6237, 0.5913, 0.567,
0.5508, 0.6237, 0.5751, 0.5913, 0.5589, 0.6156, 1), .Dim = c(10L,
10L), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"))), Schmitt2005z = structure(c(1, 0.4818,
0.5037, 0.4161, 0.365, 0.511, 0.4672, 0.3796, 0.3504, 0.5475,
0.4818, 1, 0.4554, 0.3762, 0.33, 0.462, 0.4224, 0.3432, 0.3168,
0.495, 0.5037, 0.4554, 1, 0.3933, 0.345, 0.483, 0.4416, 0.3588,
0.3312, 0.5175, 0.4161, 0.3762, 0.3933, 1, 0.285, 0.399, 0.3648,
0.2964, 0.2736, 0.4275, 0.365, 0.33, 0.345, 0.285, 1, 0.35, 0.32,
0.26, 0.24, 0.375, 0.511, 0.462, 0.483, 0.399, 0.35, 1, 0.448,
0.364, 0.336, 0.525, 0.4672, 0.4224, 0.4416, 0.3648, 0.32, 0.448,
1, 0.3328, 0.3072, 0.48, 0.3796, 0.3432, 0.3588, 0.2964, 0.26,
0.364, 0.3328, 1, 0.2496, 0.39, 0.3504, 0.3168, 0.3312, 0.2736,
0.24, 0.336, 0.3072, 0.2496, 1, 0.36, 0.5475, 0.495, 0.5175,
0.4275, 0.375, 0.525, 0.48, 0.39, 0.36, 1), .Dim = c(10L, 10L
), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6", "I7",
"I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6", "I7",
"I8", "I9", "I10"))), Schmitt2005zz = structure(c(1, 0.5625,
0.525, 0.4575, 0.51, 0.5325, 0.525, 0.495, 0.5325, 0.6, 0.5625,
1, 0.525, 0.4575, 0.51, 0.5325, 0.525, 0.495, 0.5325, 0.6, 0.525,
0.525, 1, 0.427, 0.476, 0.497, 0.49, 0.462, 0.497, 0.56, 0.4575,
0.4575, 0.427, 1, 0.4148, 0.4331, 0.427, 0.4026, 0.4331, 0.488,
0.51, 0.51, 0.476, 0.4148, 1, 0.4828, 0.476, 0.4488, 0.4828,
0.544, 0.5325, 0.5325, 0.497, 0.4331, 0.4828, 1, 0.497, 0.4686,
0.5041, 0.568, 0.525, 0.525, 0.49, 0.427, 0.476, 0.497, 1, 0.462,
0.497, 0.56, 0.495, 0.495, 0.462, 0.4026, 0.4488, 0.4686, 0.462,
1, 0.4686, 0.528, 0.5325, 0.5325, 0.497, 0.4331, 0.4828, 0.5041,
0.497, 0.4686, 1, 0.568, 0.6, 0.6, 0.56, 0.488, 0.544, 0.568,
0.56, 0.528, 0.568, 1), .Dim = c(10L, 10L), .Dimnames = list(
c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10"
), c("I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9",
"I10"))), Schmitt2055ll = structure(c(1, 0.403, 0.3286, 0.4588,
0.4092, 0.3906, 0.2852, 0.279, 0.4216, 0.434, 0.403, 1, 0.3445,
0.481, 0.429, 0.4095, 0.299, 0.2925, 0.442, 0.455, 0.3286, 0.3445,
1, 0.3922, 0.3498, 0.3339, 0.2438, 0.2385, 0.3604, 0.371, 0.4588,
0.481, 0.3922, 1, 0.4884, 0.4662, 0.3404, 0.333, 0.5032, 0.518,
0.4092, 0.429, 0.3498, 0.4884, 1, 0.4158, 0.3036, 0.297, 0.4488,
0.462, 0.3906, 0.4095, 0.3339, 0.4662, 0.4158, 1, 0.2898, 0.2835,
0.4284, 0.441, 0.2852, 0.299, 0.2438, 0.3404, 0.3036, 0.2898,
1, 0.207, 0.3128, 0.322, 0.279, 0.2925, 0.2385, 0.333, 0.297,
0.2835, 0.207, 1, 0.306, 0.315, 0.4216, 0.442, 0.3604, 0.5032,
0.4488, 0.4284, 0.3128, 0.306, 1, 0.476, 0.434, 0.455, 0.371,
0.518, 0.462, 0.441, 0.322, 0.315, 0.476, 1), .Dim = c(10L, 10L
), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6", "I7",
"I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6", "I7",
"I8", "I9", "I10"))), Sinclair2010 = structure(c(1, 0.608, 0.592,
0.528, 0.56, 0.544, 0.608, 0.584, 0.616, 0.68, 0.608, 1, 0.5624,
0.5016, 0.532, 0.5168, 0.5776, 0.5548, 0.5852, 0.646, 0.592,
0.5624, 1, 0.4884, 0.518, 0.5032, 0.5624, 0.5402, 0.5698, 0.629,
0.528, 0.5016, 0.4884, 1, 0.462, 0.4488, 0.5016, 0.4818, 0.5082,
0.561, 0.56, 0.532, 0.518, 0.462, 1, 0.476, 0.532, 0.511, 0.539,
0.595, 0.544, 0.5168, 0.5032, 0.4488, 0.476, 1, 0.5168, 0.4964,
0.5236, 0.578, 0.608, 0.5776, 0.5624, 0.5016, 0.532, 0.5168,
1, 0.5548, 0.5852, 0.646, 0.584, 0.5548, 0.5402, 0.4818, 0.511,
0.4964, 0.5548, 1, 0.5621, 0.6205, 0.616, 0.5852, 0.5698, 0.5082,
0.539, 0.5236, 0.5852, 0.5621, 1, 0.6545, 0.68, 0.646, 0.629,
0.561, 0.595, 0.578, 0.646, 0.6205, 0.6545, 1), .Dim = c(10L,
10L), .Dimnames = list(c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10"), c("I1", "I2", "I3", "I4", "I5", "I6",
"I7", "I8", "I9", "I10")))), .Names = c("Carmines1979", "Donnellan2016",
"Gnambs2017", "Hesketh2012", "Jamil2006", "Liss2008", "Liss2009",
"Liss2010", "Liss2011", "Liss2012", "Liss2013", "Liss2014", "Liss2015",
"Neps2010b", "Neps2010c", "Neps2010d", "Neps2010e", "Neps2010f",
"Opd2014a", "Opd2014b", "Opd2014c", "Opd2014d", "Opd2014e", "Opd2014f",
"Opd2014g", "Opd2014h", "Opd2014i", "Opd2014j", "Portes2012",
"Shahni1990", "Song2011a", "Song2011b", "Vasconcelos2012", "Welsh2011",
"Whiteside2003a", "Whiteside2003b", "Bagley1997a", "Bagley1997b",
"Chao2017a", "Chao2017b", "Dobson1979", "Farid2013", "Franck2008",
"Goldsmith1982", "Goldsmith1986a", "Gray1997", "Hensley1976",
"Hensley1977a", "Hensley1977b", "Kaplan1969", "Meurer2012", "Mimura2007a",
"Mimura2007b", "Mlacic2006", "Obrien1985", "Pullmann2000", "Rojas2009",
"Sarkova2006a", "Sarkova2006b", "Schmitt2005a", "Schmitt2005aa",
"Schmitt2005aaa", "Schmitt2005b", "Schmitt2005bb", "Schmitt2005c",
"Schmitt2005cc", "Schmitt2005d", "Schmitt2005dd", "Schmitt2005e",
"Schmitt2005ee", "Schmitt2005f", "Schmitt2005ff", "Schmitt2005g",
"Schmitt2005gg", "Schmitt2005h", "Schmitt2005hh", "Schmitt2005i",
"Schmitt2005ii", "Schmitt2005j", "Schmitt2005jj", "Schmitt2005k",
"Schmitt2005kk", "Schmitt2005l", "Schmitt2005m", "Schmitt2005mm",
"Schmitt2005n", "Schmitt2005nn", "Schmitt2005o", "Schmitt2005oo",
"Schmitt2005p", "Schmitt2005pp", "Schmitt2005q", "Schmitt2005qq",
"Schmitt2005r", "Schmitt2005rr", "Schmitt2005s", "Schmitt2005ss",
"Schmitt2005t", "Schmitt2005tt", "Schmitt2005u", "Schmitt2005uu",
"Schmitt2005v", "Schmitt2005vv", "Schmitt2005w", "Schmitt2005ww",
"Schmitt2005x", "Schmitt2005xx", "Schmitt2005y", "Schmitt2005yy",
"Schmitt2005z", "Schmitt2005zz", "Schmitt2055ll", "Sinclair2010"
)), n = c(340, 1127, 12437, 7097, 122, 6776, 424, 1371, 194,
1156, 173, 1556, 213, 469, 5264, 4435, 2311, 13028, 22131, 6584,
411, 2344, 2899, 1285, 460, 1073, 298, 204, 5006, 1726, 551,
380, 1763, 3066, 414, 900, 1084, 1024, 255, 269, 1332, 396, 442,
101, 87, 1234, 479, 487, 707, 500, 292, 222, 1320, 706, 206,
616, 473, 431, 519, 246, 259, 193, 485, 192, 466, 257, 145, 94,
514, 136, 179, 327, 213, 211, 93, 173, 1032, 239, 310, 272, 183,
206, 222, 59, 812, 234, 252, 183, 251, 229, 200, 159, 180, 120,
180, 130, 487, 782, 271, 229, 208, 200, 209, 200, 135, 104, 409,
389, 480, 200, 2782, 277, 503), Year = c(1979, 2016, 2017, 2012,
2006, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2010, 2010,
2010, 2010, 2010, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014,
2014, 2014, 2012, 1990, 2011, 2011, 2012, 2011, 2003, 2003, 1997,
1997, 2017, 2017, 1979, 2013, 2008, 1982, 1986, 1997, 1976, 1977,
1977, 1969, 2012, 2007, 2007, 2007, 1985, 2000, 2009, 2006, 2006,
2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005,
2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005,
2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005,
2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005,
2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2010),
Country = c("USA", "USA", "Germany", "China", "Malaysia",
"Netherlands", "Netherlands", "Netherlands", "Netherlands",
"Netherlands", "Netherlands", "Netherlands", "Netherlands",
"Germany", "Germany", "Germany", "Germany", "Germany", "USA",
"England", "Ireland", "Australia", "Canada", "India", "New Zealand",
"Philippines", "Pakistan", "Hongkong", "US Immigrants", "USA",
"USA", "China", "Portugal", "England", "USA", "USA", "Canada",
"Canada", "USA", "USA", "USA", "Pakistan", "Belgium", "USA",
"USA", "USA", "USA", "USA", "USA", "USA", "Brazil", "England",
"Japan", "Croatia", "USA", "Estonia", "Chile", "Hungary",
"Slovakia", "Argentina", "Japan", "Zimbabwe", "Australia",
"Latvia", "Austria", "Lebanon", "Bangladesh", "Lithuania",
"Belgium", "Malaysia", "Bolivia", "Malta", "Botswana", "Mexico",
"Brazil", "Morocco", "Canada", "Netherlands", "Chile", "New Zealand",
"Dem. Rep. Congo", "Peru", "Croatia", "Cyprus", "Poland",
"Czech Rep.", "Portugal", "Estonia", "Romania", "Ethiopia",
"Serbia", "Fiji", "Slovakia", "Finland", "Slovenia", "France",
"South Korea", "Germany", "Spain", "Greece", "Switzerland",
"Hongkong", "Taiwan", "India", "Tanzania", "Indonesia", "Turkey",
"Israel", "England", "Italy", "USA", "Philippenes", "USA"
), Language = c("English", "English", "German", "Chinese",
"Malay", "Dutch", "Dutch", "Dutch", "Dutch", "Dutch", "Dutch",
"Dutch", "Dutch", "German", "German", "German", "German",
"German", "English", "English", "English", "English", "English",
"English", "English", "English", "English", "English", "English",
"English", "English", "Chinese", "Portuguese", "English",
"English", "English", "English", "English", "English", "English",
"English", "English", "Dutch", "English", "English", "English",
"English", "English", "English", "English", "Portuguese",
"English", "Japanese", "Croatian", "English", "Estonian",
"Spanish", "Hungarian", "Slovak", "Spanish", "Japanese",
"English", "English", "Latvian", "German", "English", "Bangla",
"Lithuanian", "Dutch", "Malay", "Spanish", "English", "English",
"Spanish", "Portuguese", "English", "English, French", "Dutch",
"Spanish", "English", "French", "Spanish", "Croatian", "Greek",
"Polish", "Czech", "Portuguese", "Estonian", "Romanian",
"English", "Serbian", "English", "Slovak", "Finnish", "Slovenian",
"French", "Korean", "German", "Spanish", "Greek", "German",
"English", "Mandarin", "Hindi", "English", "Indonesian",
"Turkish", "Hebrew", "English", "Italian", "English", "English",
"English"), Publication = c(1, 1, 1, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1), MeanAge = c(NA, 18.31, 14.68, 28.61,
14.23, 46.02, 33.69, 48.1, 32.08, 45.33, 27.6, 40.68, 26.85,
17.52, 49.59, 10.49, 14.51, 23.47, 26.43, 28.53, 29.21, 27,
27.46, 26.26, 27.7, 21.93, 22.88, 25.96, 14.23, NA, NA, NA,
NA, 56.1, 14.8, 33, NA, NA, 20.56, 20.67, NA, NA, 36.1, NA,
40.9, NA, NA, NA, NA, NA, 67.54, 22.1, 20.6, 16.9, NA, 19.8618506493507,
NA, 11.5, 11.5, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 44.7), FemaleProp = c(NA,
3.99290150842946, 0.40202621210903, 0.745103564886572, 40.1639344262295,
0.801062573789846, 11.6816037735849, 4.04595185995624, 25.9072164948454,
4.66349480968858, 33.271676300578, 3.49293059125964, 22.3098591549296,
10.865671641791, 0.963145896656535, 1.08387824126268, 2.17092167892687,
0.463770340804421, 0.293389363336496, 0.94365127582017, 13.9464720194647,
2.78156996587031, 2.17316315971024, 3.82101167315175, 13.754347826087,
6.54147250698975, 20.7181208053691, 29.2205882352941, 1.02237315221734,
4.40324449594438, 11.978221415608, 20.7894736842105, 3.32028277741654,
1.76060013046314, 13.5265700483092, 10.7777777777778, 0,
9.765625, 25.6862745098039, 25.5762081784387, 0, 14.2842567084991,
14.9321266968326, 63.8773554774832, 79.3103448275862, NA,
NA, 0, 14.1442715700141, NA, 27.5614561831488, 39.3693693693694,
5.84090909090909, 7.64872521246459, 48.5436893203884, 10.3305785123967,
10.5931729905377, 10.9744779582367, 9.46050096339114, 22.479674796748,
15.2123552123552, 26.0621761658031, 12.0824742268041, 27.9166666666667,
11.931330472103, 20.8949416342412, 29.5172413793103, 53.1914893617021,
13.2879377431907, 47.0588235294118, 27.4860335195531, 18.1345565749235,
25.5868544600939, 23.7914691943128, 63.5483870967742, 29.0751445086705,
6.21124031007752, 21.8828451882845, 21.9677419354839, 21.2132352941176,
17.9234972677596, 23.5436893203883, 22.1171171171171, 103.389830508475,
7.75862068965517, 23.5470085470085, 22.3412698412698, 31.6939890710383,
20.3187250996016, 17.3362445414847, 25, 32.0754716981132,
30.2222222222222, 61.8333333333333, 33, 43.2307692307692,
12.3613963039014, 8.0306905370844, 24.2435424354244, 34.6724890829694,
29.375, 25, 21.2918660287081, 25, 23.6296296296296, 48.0769230769231,
12.200488997555, 13.9331619537275, 14.9375, 27, 2.30769230769231,
20.7220216606498, 10.3180914512922), Individualism = c(33,
33, 102, -31, -89, 182, 182, 182, 182, 182, 182, 182, 182,
102, 102, 102, 102, 102, 33, 93, 27, 83, 78, -101, 68, -126,
NA, -5, NA, 33, 33, -31, 30, 93, 33, 33, 78, 78, 33, 33,
33, NA, 110, 33, 33, 33, 33, 33, 33, 33, -56, 93, 42, NA,
33, NA, -8, 72, NA, -5, 42, NA, 83, NA, 95, NA, NA, NA, 110,
-89, NA, NA, NA, -63, -56, NA, 78, 182, -8, 68, NA, -117,
NA, NA, -15, 70, 30, NA, -19, NA, 58, NA, NA, 88, NA, 86,
25, 102, 58, 30, 105, -5, -43, -101, NA, -171, -18, 16, 93,
5, 33, -126, 33), CorMat = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0)), .Names = c("data", "n", "Year",
"Country", "Language", "Publication", "MeanAge", "FemaleProp",
"Individualism", "CorMat")) |
estimate.MSTT <-
function(y,X,max.iter=1000,prec=1e-4,est.var=TRUE,nu.fixed=3,nu.min=2.0001){
y.or<-y; X.or<-X
logsttnu<-function(nu,Y,X,beta0,Sigma,lambda){
n=nrow(Y)
p=ncol(Y)
B=matrix.sqrt(Sigma)
Binv=solve2(B)
mu=matrix(0,n,p)
d<-matrix(0,n,1)
res<-matrix(0,n,p)
for(i in 1:n){
mu[i,]<-X[[i]]%*%beta0
res[i,]<-Y[i,]-X[[i]]%*%beta0
d[i]<-t(res[i,])%*%Binv%*%Binv%*%res[i,]
}
A=as.vector(t(lambda)%*%solve2(B)%*%t(res))
fy=2*mvtnorm::dmvt(res, sigma = Sigma, df = nu, log = FALSE)*pt(sqrt((nu+p)/(nu+d))*A, nu+p)
return(sum(log(fy)))}
mstt.logL <- function(theta,Y,X){
n=nrow(Y)
p=ncol(Y)
q0=ncol(X[[1]])
pth=length(theta)-1
beta0=as.matrix(theta[1:q0],q0,1)
p1=p*(p+1)/2
B= xpnd(theta[(q0+1):(q0+p1)])
Sigma=B%*%B
invSigma=solve2(Sigma)
Binv=matrix.sqrt(invSigma)
lambda=as.matrix(theta[(q0+p1+1):pth],p,1)
nu=as.numeric(theta[pth+1])
mu=matrix(0,n,p)
d<-matrix(0,n,1)
res<-matrix(0,n,p)
for(i in 1:n){
mu[i,]<-X[[i]]%*%beta0
res[i,]<-Y[i,]-X[[i]]%*%beta0
d[i]<-t(res[i,])%*%Binv%*%Binv%*%res[i,]}
A=as.vector(t(lambda)%*%solve2(B)%*%t(res))
fy=2*mvtnorm::dmvt(res, sigma = Sigma, df = nu, log = FALSE)*pt(sqrt((nu+p)/(nu+d))*A, nu+p)
return(sum(log(fy)))
}
y<-as.matrix(y)
if(!is.numeric(nu.min) | nu.min<=0) stop("nu.min should be a positive number")
if(nu.fixed!=FALSE & !is.numeric(nu.fixed))
stop("nu fixed must be a number greater than 1")
if(is.numeric(nu.fixed) & as.numeric(nu.fixed)<1)
stop("nu fixed must be a number greater than 1")
if(!is.matrix(y))
stop("y must have at least one element")
if(is.null(X)){X<-array(c(diag(ncol(y))),c(ncol(y),ncol(y),nrow(y)))}
if(is.array(X)==FALSE & is.list(X)==FALSE)
stop("X must be an array or a list")
if(is.array(X))
{Xs<-list()
if(ncol(y)>1 | !is.matrix(X)){
for (i in 1:nrow(y)){
Xs[[i]]<- matrix(t(X[,,i]),nrow=ncol(y))}}
if(ncol(y)==1 & is.matrix(X)){
for (i in 1:nrow(y)){
Xs[[i]]<- matrix(t(X[i,]),nrow=1)}}
X<-Xs}
if (ncol(y) != nrow(X[[1]]))
stop("y does not have the same number of columns than X")
if (nrow(y) != length(X))
stop("y does not have the same number of observations than X")
if(!nu.fixed){
aa=system.time({
n=nrow(y)
p=ncol(y)
q=ncol(X[[n]])
b0<-matrix(0,q,q)
b1<-matrix(0,q,1)
for(i in 1:n){
b0<-b0+t(X[[i]])%*%X[[i]]
b1<-b1+t(X[[i]])%*%y[i,]
}
beta0<-solve2(b0)%*%b1
e<-matrix(0,n,p)
for(i in 1:n){
e[i,]<-y[i,]-X[[i]]%*%beta0
}
S<-cov(e)
invS<-solve2(S)
B<-matrix.sqrt(S)
lambda<-as.matrix(moments::skewness(e))
nu=5
theta0<-c(as.vector(beta0),vech(B),as.vector(lambda),nu)
log0= mstt.logL(theta0,y,X)
Sigma=B%*%B
delta=lambda/sqrt(1+sum(as.vector(lambda)^2))
Delta= matrix.sqrt(solve2(Sigma))%*%delta
a1=Sigma-Delta%*%t(Delta)
bb=eigen(a1)$values
{ if (sum(bb>0)==p) Gama=a1
else Gama=Sigma
}
criterio=1
cont=0
bb=1
mu=matrix(0,n,p)
d<-rep(0,n)
res<-matrix(0,n,p)
while((criterio>=prec)&&(cont<=max.iter)&&(bb>=0)){
cont=cont+1
Binv=solve2(B)
for (i in 1:n){
mu[i,]<-X[[i]]%*%beta0
res[i,]<-y[i,]-X[[i]]%*%beta0
d[i]<-as.numeric(t(res[i,])%*%Binv%*%Binv%*%res[i,])
}
Gamainv=solve2(Gama)
A=as.vector(t(lambda)%*%solve2(B)%*%t(res))
u=2*gamma((nu+p+2)/2)/gamma((nu+p)/2)/(nu+d)*pt(sqrt((nu+p+2)/(nu+d))*A, nu+p+2)/pt(sqrt((nu+p)/(nu+d))*A, nu+p)
eta1=1/pt(sqrt((nu+p)/(nu+d))*A, nu+p)/sqrt(pi)*gamma((nu+p+1)/2)/gamma((nu+p)/2)*((nu+d)^((nu+p)/2))/((nu+d+A^2)^((nu+p+1)/2))
MT2=1/(1+as.numeric(t(Delta)%*%Gamainv%*%Delta))
muT=MT2*as.vector(t(Delta)%*%solve2(Gama)%*%t(res))
ut = u*muT+sqrt(MT2)*eta1
ut2=u*(muT^2)+MT2+muT*sqrt(MT2)*eta1
beta01=matrix(0,q,q)
beta02=matrix(0,q,1)
Delta1=matrix(0,p,1)
Gama0=matrix(0,p,p)
for (i in 1:n){
yi=as.matrix(y[i,])
Xi=X[[i]]
resi=as.matrix(res[i,])
beta01=beta01+u[i]*t(Xi)%*%Gamainv%*%Xi
beta02=beta02+t(Xi)%*%Gamainv%*%(u[i]*yi-ut[i]*Delta)
Delta1=Delta1+ut[i]*resi
Gama0=Gama0+u[i]*resi%*%t(resi)-ut[i]*(Delta%*%t(resi)+resi%*%t(Delta))+ut2[i]*Delta%*%t(Delta)
}
beta0=solve2(beta01)%*%beta02
Delta=Delta1/sum(ut2)
Gama=Gama0/n
Sigma=Gama+Delta%*%t(Delta)
B=matrix.sqrt(Sigma)
Binv=solve2(B)
delta=Binv%*%Delta
lambda=delta/sqrt(1-as.numeric(t(delta)%*%delta))
nu=optimize(logsttnu,c(nu.min,100),y,X,beta0,Sigma,lambda,maximum=T)
nu=as.numeric(nu$maximum)
theta=c(as.vector(beta0),vech(B),as.vector(lambda),nu)
logL=mstt.logL(theta,y,X)
criterio=abs(logL-log0)
bb=sum(eigen(Gama)$values>0)-p
theta0=theta
log0=logL
}
})}
if(is.numeric(nu.fixed)){
aa=system.time({
n=nrow(y)
p=ncol(y)
q=ncol(X[[n]])
b0<-matrix(0,q,q)
b1<-matrix(0,q,1)
for(i in 1:n){
b0<-b0+t(X[[i]])%*%X[[i]]
b1<-b1+t(X[[i]])%*%y[i,]
}
beta0<-solve2(b0)%*%b1
e<-matrix(0,n,p)
for(i in 1:n){
e[i,]<-y[i,]-X[[i]]%*%beta0
}
S<-cov(e)
invS<-solve2(S)
B<-matrix.sqrt(S)
lambda<-as.matrix(moments::skewness(e))
nu=nu.fixed
theta0<-c(as.vector(beta0),vech(B),as.vector(lambda),nu)
log0= mstt.logL(theta0,y,X)
Sigma=B%*%B
delta=lambda/sqrt(1+sum(as.vector(lambda)^2))
Delta= matrix.sqrt(solve2(Sigma))%*%delta
a1=Sigma-Delta%*%t(Delta)
bb=eigen(a1)$values
{ if (sum(bb>0)==p) Gama=a1
else Gama=Sigma
}
criterio=1
cont=0
bb=1
mu=matrix(0,n,p)
d<-rep(0,n)
res<-matrix(0,n,p)
while((criterio>=prec)&&(cont<=max.iter)&&(bb>=0)){
cont=cont+1
Binv=solve2(B)
for (i in 1:n){
mu[i,]<-X[[i]]%*%beta0
res[i,]<-y[i,]-X[[i]]%*%beta0
d[i]<-as.numeric(t(res[i,])%*%Binv%*%Binv%*%res[i,])
}
Gamainv=solve2(Gama)
A=as.vector(t(lambda)%*%solve2(B)%*%t(res))
u=2*gamma((nu+p+2)/2)/gamma((nu+p)/2)/(nu+d)*pt(sqrt((nu+p+2)/(nu+d))*A, nu+p+2)/pt(sqrt((nu+p)/(nu+d))*A, nu+p)
eta1=1/pt(sqrt((nu+p)/(nu+d))*A, nu+p)/sqrt(pi)*gamma((nu+p+1)/2)/gamma((nu+p)/2)*((nu+d)^((nu+p)/2))/((nu+d+A^2)^((nu+p+1)/2))
MT2=1/(1+as.numeric(t(Delta)%*%Gamainv%*%Delta))
muT=MT2*as.vector(t(Delta)%*%solve2(Gama)%*%t(res))
ut = u*muT+sqrt(MT2)*eta1
ut2=u*(muT^2)+MT2+muT*sqrt(MT2)*eta1
beta01=matrix(0,q,q)
beta02=matrix(0,q,1)
Delta1=matrix(0,p,1)
Gama0=matrix(0,p,p)
for (i in 1:n){
yi=as.matrix(y[i,])
Xi=X[[i]]
resi=as.matrix(res[i,])
beta01=beta01+u[i]*t(Xi)%*%Gamainv%*%Xi
beta02=beta02+t(Xi)%*%Gamainv%*%(u[i]*yi-ut[i]*Delta)
Delta1=Delta1+ut[i]*resi
Gama0=Gama0+u[i]*resi%*%t(resi)-ut[i]*(Delta%*%t(resi)+resi%*%t(Delta))+ut2[i]*Delta%*%t(Delta)
}
beta0=solve2(beta01)%*%beta02
Delta=Delta1/sum(ut2)
Gama=Gama0/n
Sigma=Gama+Delta%*%t(Delta)
B=matrix.sqrt(Sigma)
Binv=solve2(B)
delta=Binv%*%Delta
lambda=delta/sqrt(1-as.numeric(t(delta)%*%delta))
theta=c(as.vector(beta0),vech(B),as.vector(lambda),nu)
logL=mstt.logL(theta,y,X)
criterio=abs(logL-log0)
bb=sum(eigen(Gama)$values>0)-p
theta0=theta
log0=logL
}
})}
npar=length(theta)
AIC=-2*logL+2*npar
BIC=-2*logL+log(n)*npar
tempo=as.numeric(aa[3])
conv<-ifelse(cont<=max.iter & criterio<=prec, 0, 1)
aux=as.list(sapply(1:p,seq,by=1,to=p))
indices=c()
for(j in 1:p)
{indices=c(indices,paste(j,aux[[j]],sep=""))}
P<-matrix(theta[-length(theta)],ncol=1)
nu<-theta[length(theta)]
rownames(P)<-c(paste("beta",1:q,sep=""),paste("alpha",indices,sep=""),paste("lambda",1:p,sep=""))
colnames(P)<-c("estimate")
conv.problem=1
if(est.var)
{
MI.obs<- FI.MSTT(P,y,X,nu)
test=try(solve2(MI.obs),silent=TRUE)
se=c()
if(is.numeric(test) & max(diag(test))<0)
{
conv.problem=0
se=sqrt(-diag(test))
P<-cbind(P,se)
colnames(P)<-c("estimate","s.e.")
}
}
if(conv.problem==0) ll<-list(coefficients=P[,1],se=P[,2],nu=nu,logLik=logL,AIC=AIC,BIC=BIC,iterations=cont,time=tempo,conv=conv,dist="MSTT",class="MSMSN",n=nrow(y))
else{
ll<-list(coefficients=P[,1],nu=nu,logLik=logL,AIC=AIC,BIC=BIC,iterations=cont,time=tempo,conv=conv,dist="MSTT",class="MSMSN",n=nrow(y))
ll$warnings="Standard errors can't be estimated: Numerical problems with the inversion of the information matrix"
}
object.out<-ll
class(object.out) <- "skewMLRM"
object.out$y<-y.or
object.out$X<-X.or
object.out$"function"<-"estimate.MSTT"
object.out
} |
cpCommunityGraph <- function(list.of.communities, node.size.method = c("proportional","normal"),
max.node.size = 10, ...){
if (length(list.of.communities) < 2) {
stop("Less than two communities. Thus, no network is plotted.")
}
if (node.size.method != "proportional" & node.size.method != "normal") {
stop("node.size.method must be 'proportional' or 'normal'.")
}
if (length(list.of.communities) > 1) {
W <- matrix(c(0), nrow = length(list.of.communities), ncol = length(list.of.communities),
byrow = TRUE)
for (i in 1:(length(list.of.communities) - 1)) {
for (j in (i + 1):length(list.of.communities)) {
overlap <- Reduce(intersect, list(list.of.communities[[i]],list.of.communities[[j]]))
if (length(overlap) > 0) {
W[i,j] <- length(overlap)
W[j,i] <- length(overlap)
}
}
}
if (node.size.method == "proportional") {
size_communities <- c()
for (i in 1:length(list.of.communities)) {
size_communities[i] <- length(list.of.communities[[i]])
}
divider <- max(size_communities) / max.node.size
qgraph::qgraph(W, vsize = size_communities/divider, ...)
}
if (node.size.method == "normal") {
qgraph::qgraph(W, ...)
}
invisible(list(community.weights.matrix = W))
}
} |
mmenubd.mae<-function(){
fontHeading<- tkfont.create(family="times",size=40,weight="bold")
fontHeading3<-tkfont.create(family="times",size=10,weight="bold")
AMVDEopt.top<-tktoplevel()
tkwm.title(AMVDEopt.top,"Optimal Block Designs For Microarray Experiments")
tkgrid(tklabel(AMVDEopt.top,text=" optbdmaeAT 1.0.1 ",font=fontHeading))
tkgrid(tklabel(AMVDEopt.top,text="",font=fontHeading))
Fixp.butA<-tkbutton(AMVDEopt.top,text="A-Optimal Block Design",font=fontHeading3,command=function()fixparbd.mae("A"),width=30)
Fixp.butMV<-tkbutton(AMVDEopt.top,text="MV-Optimal Block Design",font=fontHeading3,command=function() fixparbd.mae("MV"),width=30)
Fixp.butD<-tkbutton(AMVDEopt.top,text="D-Optimal Block Design",font=fontHeading3,command=function() fixparbd.mae("D"),width=30)
Fixp.butE<-tkbutton(AMVDEopt.top,text="E-Optimal Block Design",font=fontHeading3,command=function() fixparbd.mae("E"),width=30)
ExitWind.1<-function(){ tkmessageBox(title="Bye...", message=paste("Bye..., Enjoy your optimal design"))
tkdestroy(AMVDEopt.top)
}
ExitWin.but<-tkbutton(AMVDEopt.top,text="Exit",font=fontHeading3,command=ExitWind.1,width=15)
tkgrid(Fixp.butA)
tkgrid(Fixp.butMV)
tkgrid(Fixp.butD)
tkgrid(Fixp.butE)
tkgrid(ExitWin.but)
tkgrid(tklabel(AMVDEopt.top,text="",font=fontHeading)) }
mmenubd.mae() |
rd <- lsa[which(lsa[,"domain"] == "reading"),]
rdN1 <- rd[which(rd[,"nest"] == 1),]
rdN1y10<- rdN1[which(rdN1[,"year"] == 2010),]
test_that("No se_correction for jk2.table", {
suppressMessages(tab1_old <- repTable(datL = rdN1y10, ID = "idstud", wgt = "wgt", imp="imp",
type = "JK2", PSU = "jkzone", repInd = "jkrep", groups = "country", group.splits = 0:1,
group.differences.by = "country", dependent = "comp", chiSquare = FALSE, cross.differences = TRUE,
verbose=FALSE, progress = FALSE, crossDiffSE = "old"))
mess <- capture_messages(tab1_wec <- repTable(datL = rdN1y10, ID = "idstud", wgt = "wgt", imp="imp",
type = "JK2", PSU = "jkzone", repInd = "jkrep", groups = "country", group.splits = 0:1,
group.differences.by = "country", dependent = "comp", chiSquare = FALSE, cross.differences = TRUE,
crossDiffSE = "wec", verbose=FALSE, progress = FALSE))
expect_equal(mess, "To date, only method 'old' is applicable for cross level differences in frequency tables.\n")
expect_equal(tab1_old$SE_correction[[1]], NULL)
expect_equal(tab1_wec$SE_correction[[1]], NULL)
}) |
test_that("autotest", {
with_seed(1, {
learner = mlr_learners$get("surv.ranger")
expect_learner(learner)
learner$param_set$values = list(importance = "impurity")
result = run_autotest(learner, check_replicable = FALSE)
expect_true(result, info = result$error)
})
})
test_that("importance", {
learner = mlr_learners$get("surv.ranger")
expect_error(learner$importance(), "No model stored")
expect_error(learner$train(tsk("rats"))$importance(), "No importance stored")
})
test_that("mtry.ratio", {
task = mlr3::tsk("rats")
learner = mlr3::lrn("surv.ranger", mtry.ratio = 0.5)
res = convert_ratio(learner$param_set$values, "mtry", "mtry.ratio", length(task$feature_names))
expect_equal(
res$mtry,
2
)
expect_null(res$mtry.ratio)
learner$train(task)
expect_equal(
learner$model$mtry,
2
)
}) |
library(testthat)
library(recipes)
library(modeldata)
library(modeldata)
data(credit_data)
set.seed(342)
in_training <- sample(1:nrow(credit_data), 2000)
credit_tr <- credit_data[ in_training, ]
credit_te <- credit_data[-in_training, ]
test_that('simple mean', {
rec <- recipe(Price ~ ., data = credit_tr)
impute_rec <- rec %>%
step_impute_mean(Age, Assets, Income, id = "")
imputed <- prep(impute_rec, training = credit_tr, verbose = FALSE)
te_imputed <- bake(imputed, new_data = credit_te)
expect_equal(te_imputed$Age, credit_te$Age)
assets_pred <- mean(credit_tr$Assets, na.rm = TRUE)
assets_pred <- recipes:::cast(assets_pred, credit_tr$Assets)
expect_equal(te_imputed$Assets[is.na(credit_te$Assets)],
rep(assets_pred, sum(is.na(credit_te$Assets))))
inc_pred <- mean(credit_tr$Income, na.rm = TRUE)
inc_pred <- recipes:::cast(inc_pred, credit_tr$Assets)
expect_equal(te_imputed$Income[is.na(credit_te$Income)],
rep(inc_pred, sum(is.na(credit_te$Income))))
means <- vapply(credit_tr[, c("Age", "Assets", "Income")],
mean, numeric(1), na.rm = TRUE)
means <- purrr::map2(means, credit_tr[, c("Age", "Assets", "Income")], recipes:::cast)
means <- unlist(means)
imp_tibble_un <-
tibble(terms = c("Age", "Assets", "Income"),
model = rep(NA_real_, 3),
id = "")
imp_tibble_tr <-
tibble(terms = c("Age", "Assets", "Income"),
model = means,
id = "")
expect_equal(as.data.frame(tidy(impute_rec, 1)), as.data.frame(imp_tibble_un))
expect_equal(tidy(imputed, 1), imp_tibble_tr)
})
test_that('trimmed mean', {
rec <- recipe(Price ~ ., data = credit_tr)
impute_rec <- rec %>%
step_impute_mean(Assets, trim = .1)
imputed <- prep(impute_rec, training = credit_tr, verbose = FALSE)
te_imputed <- bake(imputed, new_data = credit_te)
mean_val <- mean(credit_tr$Assets, na.rm = TRUE, trim = .1)
mean_val <- recipes:::cast(mean_val, credit_tr$Assets)
expect_equal(te_imputed$Assets[is.na(credit_te$Assets)],
rep(mean_val, sum(is.na(credit_te$Assets))))
})
test_that('non-numeric', {
rec <- recipe(Price ~ ., data = credit_tr)
impute_rec <- rec %>%
step_impute_mean(Assets, Job)
expect_error(prep(impute_rec, training = credit_tr, verbose = FALSE))
})
test_that('all NA values', {
rec <- recipe(Price ~ ., data = credit_tr)
impute_rec <- rec %>%
step_impute_mean(Age, Assets)
imputed <- prep(impute_rec, training = credit_tr, verbose = FALSE)
imputed_te <- bake(imputed, new_data = credit_te %>% mutate(Age = NA))
expect_equal(unique(imputed_te$Age), imputed$steps[[1]]$means$Age)
})
test_that('printing', {
impute_rec <- recipe(Price ~ ., data = credit_tr) %>%
step_impute_mean(Age, Assets, Income)
expect_output(print(impute_rec))
expect_output(prep(impute_rec, training = credit_tr, verbose = TRUE))
})
test_that('tunable', {
rec <-
recipe(~ ., data = iris) %>%
step_impute_mean(all_predictors())
rec_param <- tunable.step_impute_mean(rec$steps[[1]])
expect_equal(rec_param$name, c("trim"))
expect_true(all(rec_param$source == "recipe"))
expect_true(is.list(rec_param$call_info))
expect_equal(nrow(rec_param), 1)
expect_equal(
names(rec_param),
c('name', 'call_info', 'source', 'component', 'component_id')
)
}) |
add_cow_alliance <- function(data) {
if (length(attributes(data)$ps_data_type) > 0 && attributes(data)$ps_data_type %in% c("dyad_year", "leader_dyad_year")) {
if (!all(i <- c("ccode1", "ccode2") %in% colnames(data))) {
stop("add_cow_alliance() merges on two Correlates of War codes (ccode1, ccode2), which your data don't have right now. Make sure to run create_dyadyears() at the top of the pipe. You'll want the default option, which returns Correlates of War codes.")
} else {
cow_alliance %>%
left_join(data, .) %>%
mutate_at(vars("cow_defense", "cow_neutral", "cow_nonagg", "cow_entente"), ~ifelse(is.na(.), 0, .)) -> data
}
} else if (length(attributes(data)$ps_data_type) > 0 && attributes(data)$ps_data_type == "state_year") {
stop("Right now, there is only support for dyad-year data.")
} else {
stop("add_cow_alliance() requires a data/tibble with attributes$ps_data_type of dyad_year. Try running create_dyadyears() at the start of the pipe.")
}
return(data)
} |
discrepancyPlot <- function(object, observed, simulated, ...) {
objName <- deparse(substitute(object))
object <- mcmcOutput(object)
nms <- colnames(object)
if(!(observed %in% nms))
stop("Can't find the node ", sQuote(observed), " in ", sQuote(objName), call.=FALSE )
if(!(simulated %in% nms))
stop("Can't find the node ", sQuote(simulated), " in ", sQuote(objName), call.=FALSE )
obs <- object[, observed]
sim <- object[, simulated]
lims <- range(obs, sim)
pval <- mean(sim > obs)
dots <- list(...)
if(length(dots) == 1 && class(dots[[1]]) == "list")
dots <- dots[[1]]
defaultArgs <- list(
xlim=lims, ylim=lims, pch=16, cex=0.8, col=rgb(0, 0, 0, 0.3), bty='l',
las=1, cex.lab=1.2,
xlab=paste("Observed:", sQuote(observed)),
ylab=paste("Simulated:", sQuote(simulated)),
main="Posterior Predictive GOF check")
useArgs <- modifyList(defaultArgs, dots)
useArgs$x <- obs
useArgs$y <- sim
do.call(graphics::plot, useArgs)
abline(0, 1, lwd = 2)
where <- if (pval < 0.5) {
"topleft"
} else {
"bottomright"
}
graphics::legend(where, paste("P =", round(pval, 2)),
bty = "n", cex = 1.5)
return(pval)
} |
isLetter <- function(ch) isUppercase(ch) || isLowercase(ch) |
normalizeWeight.details <- function(normalize,weight,data){
message("\n This function normalizes weight values. \n")
if(!is.null(weight)){
message("\n This are the initial weights: \n")
for (i in c(1:length(weight))) {
message(" ", weight[i])
}
}
message("\n It checks if there is a weights vector. If not, it creates a vector with ", ncol(data), " '1's. \n")
if(is.null(weight)){
weight <- c()
value <- 1
for (j in c(1:ncol(data))) {
weight <- c(weight, value)
}
}
res <- c()
if(normalize){
message("\n Due to the fact that 'normalize' = TRUE, weight vector changes every weight as the \n initial value divided between the total sum of the vector. \n")
message("\n FinalWeight[i] = WeightValue[i]/TotalSum \n")
total <- sum(weight)
for (index in c(1:length(weight))) {
currentValue <- weight[index]
normalizedValue <- currentValue/total
res <- c(res, normalizedValue)
}
} else {
message("\n Due to the fact that 'normalize' = FALSE, weight vector does not change. \n")
res <- weight
}
message("\n These are the new weights: \n")
for (i in c(1:length(res))) {
message(" ", res[[i]])
}
res
} |
bprobgHsCont3 <- function(params, respvec, VC, ps, AT = FALSE){
p1 <- p2 <- pdf1 <- pdf2 <- c.copula.be2 <- c.copula.be1 <- c.copula2.be1be2 <- NA
eta1 <- VC$X1%*%params[1:VC$X1.d2]
eta2 <- VC$X2%*%params[(VC$X1.d2+1):(VC$X1.d2+VC$X2.d2)]
etad <- etas <- etan <- NULL
if(is.null(VC$X3)){
sigma2.st <- etas <- params[(VC$X1.d2 + VC$X2.d2 + 1)]
nu.st <- etan <- params[(VC$X1.d2 + VC$X2.d2 + 2)]
teta.st <- etad <- params[(VC$X1.d2 + VC$X2.d2 + 3)]
}
if(!is.null(VC$X3)){
sigma2.st <- etas <- VC$X3%*%params[(VC$X1.d2+VC$X2.d2+1):(VC$X1.d2+VC$X2.d2+VC$X3.d2)]
nu.st <- etan <- VC$X4%*%params[(VC$X1.d2+VC$X2.d2+VC$X3.d2+1):(VC$X1.d2+VC$X2.d2+VC$X3.d2+VC$X4.d2)]
teta.st <- etad <- VC$X5%*%params[(VC$X1.d2+VC$X2.d2+VC$X3.d2+VC$X4.d2+1):(VC$X1.d2+VC$X2.d2+VC$X3.d2+VC$X4.d2+VC$X5.d2)]
}
sstr1 <- esp.tr(sigma2.st, VC$margins[2])
sigma2.st <- sstr1$vrb.st
sigma2 <- sstr1$vrb
sstr1 <- enu.tr(nu.st, VC$margins[2])
nu.st <- sstr1$vrb.st
nu <- sstr1$vrb
eta2 <- eta.tr(eta2, VC$margins[2])
dHs <- distrHs(respvec$y2, eta2, sigma2, sigma2.st, nu, nu.st, margin2=VC$margins[2], naive = FALSE, min.dn = VC$min.dn, min.pr = VC$min.pr, max.pr = VC$max.pr)
pdf2 <- dHs$pdf2
p2 <- dHs$p2
derpdf2.dereta2 <- dHs$derpdf2.dereta2
derpdf2.dersigma2.st <- dHs$derpdf2.dersigma2.st
derp2.dersigma.st <- dHs$derp2.dersigma.st
derpdf2.dernu.st <- dHs$derpdf2.dernu.st
derp2.dernu.st <- dHs$derp2.nu.st
derp2.dereta2 <- dHs$derp2.dereta2
der2p2.dereta2eta2 <- dHs$der2p2.dereta2eta2
der2pdf2.dereta2 <- dHs$der2pdf2.dereta2
der2p2.dersigma2.st2 <- dHs$der2p2.dersigma2.st2
der2pdf2.dersigma2.st2 <- dHs$der2pdf2.dersigma2.st2
der2p2.dernu.st2 <- dHs$der2p2.dernu.st2
der2pdf2.dernu.st2 <- dHs$der2pdf2.dernu.st2
der2p2.dereta2dersigma2.st <- dHs$der2p2.dereta2dersigma2.st
der2pdf2.dereta2dersigma2.st <- dHs$der2pdf2.dereta2dersigma2.st
der2p2.dereta2dernu.st <- dHs$der2p2.dereta2dernu.st
der2pdf2.dereta2dernu.st <- dHs$der2pdf2.dereta2dernu.st
der2p2.dersigma2.stdernu.st <- dHs$der2p2.dersigma2.stdernu.st
der2pdf2.dersigma2.stdernu.st <- dHs$der2pdf2.sigma2.st2dernu.st
pd1 <- probm(eta1, VC$margins[1], bc = TRUE, min.dn = VC$min.dn, min.pr = VC$min.pr, max.pr = VC$max.pr)
p1 <- 1 - pd1$pr
resT <- teta.tr(VC, teta.st)
teta.st1 <- teta.st2 <- teta.st <- resT$teta.st
teta1 <- teta2 <- teta <- resT$teta
Cop1 <- Cop2 <- VC$BivD
teta.ind1 <- as.logical(c(1,0,round(runif(VC$n-2))) )
teta.ind2 <- teta.ind1 == FALSE
if(!(VC$BivD %in% VC$BivD2) && length(teta.st) > 1){
teta.st1 <- teta.st[teta.ind1]
teta.st2 <- teta.st[teta.ind2]
teta1 <- teta[teta.ind1]
teta2 <- teta[teta.ind2]
}
if(VC$BivD %in% VC$BivD2){
if(VC$BivD %in% VC$BivD2[c(1:4,13:16)]) teta.ind1 <- ifelse(VC$my.env$signind*teta > exp(VC$zerov), TRUE, FALSE)
if(VC$BivD %in% VC$BivD2[5:12]) teta.ind1 <- ifelse(VC$my.env$signind*teta > exp(VC$zerov) + 1, TRUE, FALSE)
teta.ind2 <- teta.ind1 == FALSE
VC$my.env$signind <- ifelse(teta.ind1 == TRUE, 1, -1)
teta1 <- teta[teta.ind1]
teta2 <- -teta[teta.ind2]
teta.st1 <- teta.st[teta.ind1]
teta.st2 <- teta.st[teta.ind2]
if(length(teta) == 1) teta.ind2 <- teta.ind1 <- rep(TRUE, VC$n)
Cop1Cop2R <- Cop1Cop2(VC$BivD)
Cop1 <- Cop1Cop2R$Cop1
Cop2 <- Cop1Cop2R$Cop2
}
if( length(teta1) != 0) dH1 <- copgHs(p1[teta.ind1], p2[teta.ind1], eta1=NULL, eta2=NULL, teta1, teta.st1, Cop1, VC$dof, min.dn = VC$min.dn, min.pr = VC$min.pr, max.pr = VC$max.pr)
if( length(teta2) != 0) dH2 <- copgHs(p1[teta.ind2], p2[teta.ind2], eta1=NULL, eta2=NULL, teta2, teta.st2, Cop2, VC$dof, min.dn = VC$min.dn, min.pr = VC$min.pr, max.pr = VC$max.pr)
h <- NA
if( length(teta1) != 0) h[teta.ind1] <- dH1$c.copula.be2
if( length(teta2) != 0) h[teta.ind2] <- dH2$c.copula.be2
l.par <- VC$weights*( respvec$cy*log(h) + respvec$y1*log(1 - h) + log(pdf2) )
c.copula2.be2 <- c.copula2.be1be2 <- c.copula2.be2th <- NA
if( length(teta1) != 0){
c.copula2.be2[teta.ind1] <- dH1$c.copula2.be2
c.copula2.be1be2[teta.ind1] <- dH1$c.copula2.be1be2
c.copula2.be2th[teta.ind1] <- dH1$c.copula2.be2th
}
if( length(teta2) != 0){
c.copula2.be2[teta.ind2] <- dH2$c.copula2.be2
c.copula2.be1be2[teta.ind2] <- dH2$c.copula2.be1be2
c.copula2.be2th[teta.ind2] <- dH2$c.copula2.be2th
}
derp1.dereta1 <- pd1$derp1.dereta1
derh.dereta1 <- c.copula2.be1be2 * derp1.dereta1
derh.dereta2 <- c.copula2.be2 * derp2.dereta2
dl.dbe1 <- VC$weights*( derh.dereta1 *(respvec$cy/h - respvec$y1/(1-h)) )
dl.dbe2 <- VC$weights*( derh.dereta2 * (respvec$cy/h - respvec$y1/(1-h)) + derpdf2.dereta2/pdf2 )
dl.dsigma.st <- VC$weights*( c.copula2.be2 * derp2.dersigma.st *(respvec$cy/h - respvec$y1/(1-h)) + derpdf2.dersigma2.st/pdf2 )
dl.dnu.st <- VC$weights*( c.copula2.be2 * derp2.dernu.st *(respvec$cy/h - respvec$y1/(1-h)) + derpdf2.dernu.st/pdf2 )
dl.dteta.st <- VC$weights*( c.copula2.be2th*(respvec$cy/h - respvec$y1/(1-h)) )
der2h.derp2p2 <- der2h.derteta.teta.st <- derteta.derteta.st <- der2teta.derteta.stteta.st <- der2h.derp1p2 <- der2h.derp1teta <- der2h.derp2teta <- der2h.derp1p1 <- NA
if( length(teta1) != 0) BITS1 <- copgHsCont(p1[teta.ind1], p2[teta.ind1], teta1, teta.st1, Cop1, par2 = VC$dof, nu.st = log(VC$dof-2))
if( length(teta2) != 0) BITS2 <- copgHsCont(p1[teta.ind2], p2[teta.ind2], teta2, teta.st2, Cop2, par2 = VC$dof, nu.st = log(VC$dof-2))
if( length(teta1) != 0){
der2h.derp2p2[teta.ind1] <- BITS1$der2h.derp2p2
der2h.derteta.teta.st[teta.ind1] <- BITS1$der2h.derteta.teta.st
derteta.derteta.st[teta.ind1] <- BITS1$derteta.derteta.st
der2teta.derteta.stteta.st[teta.ind1] <- BITS1$der2teta.derteta.stteta.st
der2h.derp1p2[teta.ind1] <- BITS1$der2h.derp1p2
der2h.derp1teta[teta.ind1] <- BITS1$der2h.derp1teta
der2h.derp2teta[teta.ind1] <- BITS1$der2h.derp2teta
der2h.derp1p1[teta.ind1] <- BITS1$der2h.derp1p1
}
if( length(teta2) != 0){
der2h.derp2p2[teta.ind2] <- BITS2$der2h.derp2p2
der2h.derteta.teta.st[teta.ind2] <- BITS2$der2h.derteta.teta.st
derteta.derteta.st[teta.ind2] <- BITS2$derteta.derteta.st
der2teta.derteta.stteta.st[teta.ind2] <- BITS2$der2teta.derteta.stteta.st
der2h.derp1p2[teta.ind2] <- BITS2$der2h.derp1p2
der2h.derp1teta[teta.ind2] <- BITS2$der2h.derp1teta
der2h.derp2teta[teta.ind2] <- BITS2$der2h.derp2teta
der2h.derp1p1[teta.ind2] <- BITS2$der2h.derp1p1
}
der2p1.dereta1eta1 <- pd1$der2p1.dereta1eta1
der2h.dereta2.dereta2 <- der2h.derp2p2*derp2.dereta2^2 + c.copula2.be2*der2p2.dereta2eta2
der2h.derteta.st2 <- der2h.derteta.teta.st*derteta.derteta.st^2 + c.copula2.be2th/derteta.derteta.st* der2teta.derteta.stteta.st
der2h.derp2dersigma2.st <- der2h.derp2p2*derp2.dersigma.st
der2h.derp2dernu.st <- der2h.derp2p2*derp2.dernu.st
der2h.dersigma2.st2 <- der2h.derp2dersigma2.st*derp2.dersigma.st + c.copula2.be2*der2p2.dersigma2.st2
der2h.dernu.st2 <- der2h.derp2dernu.st*derp2.dernu.st + c.copula2.be2*der2p2.dernu.st2
derh.dersigma2.st <- c.copula2.be2 * derp2.dersigma.st
derh.dernu.st <- c.copula2.be2 * derp2.dernu.st
der2h.dereta1.dereta2 <- der2h.derp1p2*derp1.dereta1*derp2.dereta2
der2h.dereta1.derteta.st <- der2h.derp1teta*derp1.dereta1*derteta.derteta.st
der2h.dereta1.dersigma2.st <- der2h.derp1p2 * derp2.dersigma.st*derp1.dereta1
der2h.dereta1.dernu.st <- der2h.derp1p2 * derp2.dernu.st*derp1.dereta1
der2h.dereta2.derteta.st <- der2h.derp2teta*derp2.dereta2*derteta.derteta.st
der2h.derteta.st.dersigma2.st <- der2h.derp2teta* derteta.derteta.st*derp2.dersigma.st
der2h.derteta.st.dernu.st <- der2h.derp2teta* derteta.derteta.st*derp2.dernu.st
der2h.dersigma2.st.dernu.st <- der2h.derp2dernu.st*derp2.dersigma.st + c.copula2.be2*der2p2.dersigma2.stdernu.st
der2h.dereta2.dersigma2.st <- der2h.derp2dersigma2.st*derp2.dereta2 + c.copula2.be2*der2p2.dereta2dersigma2.st
der2h.dereta2.dernu.st <- der2h.derp2dernu.st*derp2.dereta2 + c.copula2.be2*der2p2.dereta2dernu.st
der2h.dereta1.dereta1 <- der2h.derp1p1*derp1.dereta1^2 + c.copula2.be1be2*der2p1.dereta1eta1
d2l.be1.be1 <- -VC$weights*(der2h.dereta1.dereta1 *(respvec$cy/h - respvec$y1/(1-h)) - derh.dereta1^2 * (respvec$cy/h^2 + respvec$y1/(1-h)^2) )
d2l.be2.be2 <- -VC$weights*(der2h.dereta2.dereta2 *(respvec$cy/h - respvec$y1/(1-h)) - derh.dereta2^2 * (respvec$cy/h^2 + respvec$y1/(1-h)^2) + (der2pdf2.dereta2*pdf2-(derpdf2.dereta2)^2)/(pdf2)^2 )
d2l.rho.rho <- -VC$weights*(der2h.derteta.st2*(respvec$cy/h - respvec$y1/(1-h)) - c.copula2.be2th^2 * (respvec$cy/h^2 + respvec$y1/(1-h)^2) )
d2l.sigma.sigma <- -VC$weights*(der2h.dersigma2.st2 *(respvec$cy/h - respvec$y1/(1-h)) - derh.dersigma2.st^2 * (respvec$cy/h^2 + respvec$y1/(1-h)^2) + (der2pdf2.dersigma2.st2*pdf2-(derpdf2.dersigma2.st)^2)/(pdf2)^2 )
d2l.nu.nu <- -VC$weights*(der2h.dernu.st2 *(respvec$cy/h - respvec$y1/(1-h)) - derh.dernu.st^2 * (respvec$cy/h^2 + respvec$y1/(1-h)^2) + (der2pdf2.dernu.st2*pdf2-(derpdf2.dernu.st)^2)/(pdf2)^2 )
d2l.be1.be2 <- -VC$weights*(der2h.dereta1.dereta2 *(respvec$cy/h - respvec$y1/(1-h)) - derh.dereta1*derh.dereta2 * (respvec$cy/h^2 + respvec$y1/(1-h)^2) )
d2l.be1.rho <- -VC$weights*(der2h.dereta1.derteta.st *(respvec$cy/h - respvec$y1/(1-h)) - derh.dereta1 * c.copula2.be2th* (respvec$cy/h^2 + respvec$y1/(1-h)^2) )
d2l.be1.sigma <- -VC$weights*(der2h.dereta1.dersigma2.st *(respvec$cy/h - respvec$y1/(1-h)) - derh.dereta1 * derh.dersigma2.st* (respvec$cy/h^2 + respvec$y1/(1-h)^2) )
d2l.be1.nu <- -VC$weights*(der2h.dereta1.dernu.st *(respvec$cy/h - respvec$y1/(1-h)) - derh.dereta1 * derh.dernu.st* (respvec$cy/h^2 + respvec$y1/(1-h)^2) )
d2l.be2.rho <- -VC$weights*(der2h.dereta2.derteta.st *(respvec$cy/h - respvec$y1/(1-h)) - derh.dereta2*c.copula2.be2th * (respvec$cy/h^2 + respvec$y1/(1-h)^2) )
d2l.be2.sigma <- -VC$weights*(der2h.dereta2.dersigma2.st *(respvec$cy/h - respvec$y1/(1-h)) - derh.dereta2*derh.dersigma2.st * (respvec$cy/h^2 + respvec$y1/(1-h)^2) + (der2pdf2.dereta2dersigma2.st*pdf2-(derpdf2.dereta2*derpdf2.dersigma2.st))/(pdf2)^2 )
d2l.be2.nu <- -VC$weights*(der2h.dereta2.dernu.st *(respvec$cy/h - respvec$y1/(1-h)) - derh.dereta2*derh.dernu.st * (respvec$cy/h^2 + respvec$y1/(1-h)^2) + (der2pdf2.dereta2dernu.st*pdf2-(derpdf2.dereta2*derpdf2.dernu.st))/(pdf2)^2 )
d2l.rho.sigma <- -VC$weights*(der2h.derteta.st.dersigma2.st *(respvec$cy/h - respvec$y1/(1-h)) - derh.dersigma2.st * c.copula2.be2th* (respvec$cy/h^2 + respvec$y1/(1-h)^2) )
d2l.rho.nu <- -VC$weights*(der2h.derteta.st.dernu.st *(respvec$cy/h - respvec$y1/(1-h)) - derh.dernu.st * c.copula2.be2th* (respvec$cy/h^2 + respvec$y1/(1-h)^2) )
d2l.sigma.nu <- -VC$weights*(der2h.dersigma2.st.dernu.st *(respvec$cy/h - respvec$y1/(1-h)) - derh.dersigma2.st * derh.dernu.st * (respvec$cy/h^2 + respvec$y1/(1-h)^2) + (der2pdf2.dersigma2.stdernu.st*pdf2-(derpdf2.dersigma2.st*derpdf2.dernu.st))/(pdf2)^2 )
if( is.null(VC$X3) ){
be1.be1 <- crossprod(VC$X1*c(d2l.be1.be1),VC$X1)
be2.be2 <- crossprod(VC$X2*c(d2l.be2.be2),VC$X2)
be1.be2 <- crossprod(VC$X1*c(d2l.be1.be2),VC$X2)
be1.rho <- t(t(rowSums(t(VC$X1*c(d2l.be1.rho)))))
be1.sigma <- t(t(rowSums(t(VC$X1*c(d2l.be1.sigma)))))
be2.rho <- t(t(rowSums(t(VC$X2*c(d2l.be2.rho)))))
be2.sigma <- t(t(rowSums(t(VC$X2*c(d2l.be2.sigma)))))
be2.nu <- t(t(rowSums(t(VC$X2*c(d2l.be2.nu)))))
be1.nu <- t(t(rowSums(t(VC$X1*c(d2l.be1.nu)))))
H <- rbind( cbind( be1.be1 , be1.be2 , be1.sigma , be1.nu, be1.rho ),
cbind( t(be1.be2) , be2.be2 , be2.sigma , be2.nu, be2.rho ),
cbind( t(be1.sigma), t(be2.sigma), sum(d2l.sigma.sigma) , sum(d2l.sigma.nu), sum(d2l.rho.sigma) ),
cbind( t(be1.nu), t(be2.nu), sum(d2l.sigma.nu) , sum(d2l.nu.nu), sum(d2l.rho.nu) ),
cbind( t(be1.rho) , t(be2.rho) , sum(d2l.rho.sigma), sum(d2l.rho.nu), sum(d2l.rho.rho) )
)
G <- -c( colSums( c(dl.dbe1)*VC$X1 ) ,
colSums( c(dl.dbe2)*VC$X2 ) ,
sum( dl.dsigma.st ),
sum( dl.dnu.st ),
sum( dl.dteta.st ) )
}
if( !is.null(VC$X3) ){
be1.be1 <- crossprod(VC$X1*c(d2l.be1.be1),VC$X1)
be2.be2 <- crossprod(VC$X2*c(d2l.be2.be2),VC$X2)
be1.be2 <- crossprod(VC$X1*c(d2l.be1.be2),VC$X2)
be1.rho <- crossprod(VC$X1*c(d2l.be1.rho), VC$X5)
be1.sigma <- crossprod(VC$X1*c(d2l.be1.sigma),VC$X3)
be1.nu <- crossprod(VC$X1*c(d2l.be1.nu),VC$X4)
be2.rho <- crossprod(VC$X2*c(d2l.be2.rho), VC$X5)
be2.sigma <- crossprod(VC$X2*c(d2l.be2.sigma),VC$X3)
be2.nu <- crossprod(VC$X2*c(d2l.be2.nu),VC$X4)
sigma.sigma <- crossprod(VC$X3*c(d2l.sigma.sigma),VC$X3)
sigma.nu <- crossprod(VC$X3*c(d2l.sigma.nu),VC$X4)
sigma.rho <- crossprod(VC$X3*c(d2l.rho.sigma),VC$X5)
rho.rho <- crossprod(VC$X5*c(d2l.rho.rho), VC$X5)
rho.nu <- crossprod(VC$X4*c(d2l.rho.nu), VC$X5)
nu.nu <- crossprod(VC$X4*c(d2l.nu.nu), VC$X4)
H <- rbind( cbind( be1.be1 , be1.be2 , be1.sigma , be1.nu , be1.rho ),
cbind( t(be1.be2) , be2.be2 , be2.sigma , be2.nu , be2.rho ),
cbind( t(be1.sigma), t(be2.sigma), sigma.sigma , sigma.nu , sigma.rho ),
cbind( t(be1.nu) , t(be2.nu) , t(sigma.nu) , nu.nu , rho.nu ),
cbind( t(be1.rho) , t(be2.rho) , t(sigma.rho), t(rho.nu) , rho.rho )
)
G <- -c( colSums( c(dl.dbe1)*VC$X1 ) ,
colSums( c(dl.dbe2)*VC$X2 ) ,
colSums( c(dl.dsigma.st)*VC$X3 ) ,
colSums( c(dl.dnu.st)*VC$X4 ) ,
colSums( c(dl.dteta.st)*VC$X5 ) )
}
res <- -sum(l.par)
if(VC$extra.regI == "pC") H <- regH(H, type = 1)
S.h <- ps$S.h
if( length(S.h) != 1){
S.h1 <- 0.5*crossprod(params,S.h)%*%params
S.h2 <- S.h%*%params
} else S.h <- S.h1 <- S.h2 <- 0
S.res <- res
res <- S.res + S.h1
G <- G + S.h2
H <- H + S.h
if(VC$extra.regI == "sED") H <- regH(H, type = 2)
list(value=res, gradient=G, hessian=H, S.h=S.h, S.h1=S.h1, S.h2=S.h2, l=S.res, l.par=l.par, ps = ps, etas = etas,
eta1 = eta1, eta2 = eta2, etad = etad, etan = etan,
dl.dbe1=dl.dbe1, dl.dbe2=dl.dbe2, dl.dsigma.st = dl.dsigma.st,
dl.dnu.st = dl.dnu.st, dl.dteta.st = dl.dteta.st,
BivD=VC$BivD, theta.star = teta.st,
p1 = 1-p1, p2 = p2, pdf1 = pdf1, pdf2 = pdf2,
c.copula.be2 = c.copula.be2,
c.copula.be1 = c.copula.be1,
c.copula2.be1be2 = c.copula2.be1be2,
teta.ind2 = teta.ind2, teta.ind1 = teta.ind1,
Cop1 = Cop1, Cop2 = Cop2, teta1 = teta1, teta2 = teta2)
}
|
summary.BayesMassBal <- function(object, export = NA,...){
ybal <- object$ybal
ans <- list()
components <- names(ybal)
components <- c(components, "Total")
locations <- nrow(ybal[[1]])
ybal_total <- Reduce("+", ybal)
ybal[["Total"]] <- ybal_total
ans$`Mass Flow Rates` <- list()
template_df <- data.frame(matrix(NA, ncol = 4, nrow = locations))
names(template_df) <- c("Sampling Location", "Expected Value", "95% LB", "95% UB")
template_df[,1] <- 1:locations
cat("Mass Flow Rates:\n")
for(i in 1:(length(components))){
cat(paste("\n",components[i],":\n", sep = ""))
temp <- template_df
temp[,2] <- apply(ybal[[components[i]]],1,mean)
temp[,3:4] <- unname(t(apply(ybal[[components[[i]]]],1,hdi)))
cat(paste(c(rep("-", times = 20),"\n"), sep = "", collapse = ""))
print(temp, row.names = FALSE)
ans[[1]][[components[i]]] <- temp
}
cat("\n\nlog-marginal likelihood:\n")
cat(paste(c(object$lml,"\n")))
if(is.character(export)){
csv.check <- strsplit(export, split ="[.]")[[1]]
if(length(csv.check) == 1){
export <- paste(export,"csv", sep = ".")
csv.check <- strsplit(export, split ="[.]")[[1]]
}
if(csv.check[[2]] != "csv"){warning("Only a .csv format can be output. Output not saved. Check spelling of export argument", immediate. = TRUE)}
if(length(csv.check) == 2 & csv.check[2] == "csv"){
export.df <- do.call("rbind",ans[[1]])
export.df <- cbind.data.frame(`Sample Component` = rep(components, each = locations), export.df)
write.csv(export.df, file = export, row.names = FALSE)
}
}else if(!is.na(export) & !is.character(export)){
warning("\nPlease specify a character string or NA for the export argument.")
}
} |
"lamp.generate_tau" <- function(object) {
lambda <- object@lambda
alpha <- object@alpha
n <- [email protected]
if (object@beta==1 & lambda<=2) stop("lambda=2 beta=1 is not supported")
sd.factor <- if ([email protected]==0) lamp.sd_factor(object) else 1
g <- if (alpha < 1) cos(pi*alpha/2)^(1/alpha) else 1
if (alpha==1) g <- 1/8
if (object@beta==1) {
rs <- rstable(n, alpha, 1, gamma=g/sd.factor, pm=object@pm)
bi <- sign(runif(n)-0.5)
object@tau <- rs*bi
object@tm <- Sys.time()
return(object)
}
object@tau <- rstable(n, alpha, object@beta, gamma=g/sd.factor, pm=object@pm)
object@tau_i <- 1
object@tm <- Sys.time()
return(object)
} |
test_that('ppv', {
lst <- data_altman()
pathology <- lst$pathology
path_tbl <- lst$path_tbl
expect_equal(
ppv(pathology, truth = "pathology", estimate = "scan")[[".estimate"]],
0.87832,
tolerance = .001
)
expect_equal(
ppv(path_tbl)[[".estimate"]],
0.87832,
tolerance = .001
)
expect_equal(
ppv(pathology, truth = pathology, estimate = "scan_na")[[".estimate"]],
0.87744,
tolerance = .001
)
expect_equal(
ppv(pathology, truth = pathology, estimate = "scan", prevalence = .5)[[".estimate"]],
0.70642,
tolerance = .001
)
})
test_that("`event_level = 'second'` works", {
lst <- data_altman()
df <- lst$pathology
df_rev <- df
df_rev$pathology <- relevel(df_rev$pathology, "norm")
df_rev$scan <- relevel(df_rev$scan, "norm")
expect_equal(
ppv_vec(df$pathology, df$scan),
ppv_vec(df_rev$pathology, df_rev$scan, event_level = "second")
)
})
test_that('Three class', {
multi_ex <- data_three_by_three()
micro <- data_three_by_three_micro()
micro$prev <- (micro$tp + micro$fn) / (micro$p + micro$n)
expect_equal(
ppv(multi_ex, estimator = "macro")[[".estimate"]],
macro_metric(ppv_binary)
)
expect_equal(
ppv(multi_ex, estimator = "macro_weighted")[[".estimate"]],
macro_weighted_metric(ppv_binary)
)
expect_equal(
ppv(multi_ex, estimator = "micro")[[".estimate"]],
precision(multi_ex, estimator = "micro")[[".estimate"]]
)
expect_equal(
ppv(multi_ex, estimator = "micro")[[".estimate"]],
with(micro,
((sum(tp) / sum(p)) * sum(prev)) /
( (sum(tp) / sum(p)) * sum(prev) + ((1 - sum(tn) / sum(n)) * sum((1 - prev))) )
)
)
expect_equal(
ppv(multi_ex, estimator = "micro", prevalence = .4)[[".estimate"]],
with(micro,
((sum(tp) / sum(p)) * sum(.4)) /
( (sum(tp) / sum(p)) * sum(.4) + ((1 - sum(tn) / sum(n)) * sum((1 - .4))) )
)
)
})
test_that("Binary `ppv()` returns `NA` with a warning when `sens()` is undefined (tp + fn = 0) (
levels <- c("a", "b")
truth <- factor(c("b", "b"), levels = levels)
estimate <- factor(c("a", "b"), levels = levels)
expect_snapshot(
out <- ppv_vec(truth, estimate)
)
expect_identical(out, NA_real_)
}) |
run.models <-
function(model.list=NULL,type=NULL, save=TRUE, ...)
{
lx=ls(envir=parent.frame())
model.list=collect.model.names(lx, type)
if(is.null(model.list)) stop("No models need to be run")
run=FALSE
for(i in 1:length(model.list))
{
model=eval(parse(text=model.list[i]),envir=parent.frame())
if(is.null(model$output))
{
run=TRUE
eval(parse(text=paste(model.list[i],"=run.mark.model(",model.list[i],"...)")),envir=parent.frame())
if(save)save.image()
}
}
if(!run)message("All defined models have been run\n")
invisible()
} |
string_2_matrix <- function(new_matrix, supplied_string, self = 0){
result.matrix = new_matrix
for (i in 1:length(colnames(new_matrix))){
result.matrix[,i] = string_2_matrix_x(new_matrix, supplied_string, coord_x = i, self = self)
}
return(result.matrix)
} |
context("geom_hex")
test_that("density and value summaries are available", {
df <- data_frame(x = c(1, 1, 1, 2), y = c(1, 1, 1, 2))
base <- ggplot(df, aes(x, y)) +
geom_hex()
out <- layer_data(base)
expect_equal(nrow(out), 2)
expect_equal(out$density, c(0.75, 0.25), tolerance = 1e-7)
expect_equal(out$count, c(3, 1), tolerance = 1e-7)
})
test_that("size and linetype are applied", {
df <- data_frame(x = c(1, 1, 1, 2), y = c(1, 1, 1, 2))
plot <- ggplot(df, aes(x, y)) +
geom_hex(color = "red", size = 4, linetype = 2)
gpar <- layer_grob(plot)[[1]]$children[[1]]$gp
expect_equal(gpar$lwd, c(4, 4) * .pt, tolerance = 1e-7)
expect_equal(gpar$lty, c(2, 2), tolerance = 1e-7)
}) |
dashboardSidebar <- function(..., disable = FALSE, width = NULL, collapsed = FALSE,
minified = TRUE, id = NULL) {
width <- shiny::validateCssUnit(width)
if (is.null(id)) id <- "sidebarCollapsed"
custom_css <- NULL
if (!is.null(width)) {
custom_css <- shiny::tags$head(shiny::tags$style(shiny::HTML(gsub("_WIDTH_", width, fixed = TRUE, '
.main-sidebar, .left-side {
width: _WIDTH_;
}
@media (min-width: 768px) {
.content-wrapper,
.right-side,
.main-footer {
margin-left: _WIDTH_;
}
.main-sidebar,
.left-side {
width: _WIDTH_;
}
}
@media (max-width: 767px) {
.sidebar-open .content-wrapper,
.sidebar-open .right-side,
.sidebar-open .main-footer {
-webkit-transform: translate(_WIDTH_, 0);
-ms-transform: translate(_WIDTH_, 0);
-o-transform: translate(_WIDTH_, 0);
transform: translate(_WIDTH_, 0);
}
}
@media (max-width: 767px) {
.main-sidebar,
.left-side {
-webkit-transform: translate(-_WIDTH_, 0);
-ms-transform: translate(-_WIDTH_, 0);
-o-transform: translate(-_WIDTH_, 0);
transform: translate(-_WIDTH_, 0);
}
}
@media (min-width: 768px) {
.sidebar-collapse .main-sidebar,
.sidebar-collapse .left-side {
-webkit-transform: translate(-_WIDTH_, 0);
-ms-transform: translate(-_WIDTH_, 0);
-o-transform: translate(-_WIDTH_, 0);
transform: translate(-_WIDTH_, 0);
}
}
'))))
}
dataValue <- shiny::restoreInput(id = id, default = collapsed)
if (disable) dataValue <- TRUE
dataValueString <- if (dataValue) "true" else "false"
shiny::tags$aside(
id = id,
class = "main-sidebar",
`data-minified` = if (minified) "true" else "false",
`data-collapsed` = dataValueString,
custom_css,
shiny::tags$section(
id = "sidebarItemExpanded",
class = "sidebar",
`data-disable` = if (disable) 1 else NULL,
list(...)
)
)
}
updateSidebar <- function(id, session = shiny::getDefaultReactiveDomain()) {
message <- list(value = !session$input[[id]])
session$sendInputMessage(id, message)
} |
mvJointModelBayes <- function (mvglmerObject, survObject, timeVar,
Formulas = list(NULL), Interactions = list(NULL),
transFuns = NULL, priors = NULL, multiState = FALSE,
data_MultiState = NULL, idVar_MultiState = "id",
control = NULL, ...) {
cl <- match.call()
con <- list(temps = 1.0, n_iter = 300, n_burnin = 1000,
n_block = 50, n_thin = 300, target_acc = 0.234, c0 = 1, c1 = 0.8,
eps1 = 1e-06, eps2 = 1e-05, eps3 = 1e04, adaptCov = FALSE,
knots = NULL, ObsTimes.knots = TRUE,
lng.in.kn = 15L, ordSpline = 4L, diff = 2L, speed_factor = 0.6,
GQsurv = "GaussKronrod", GQsurv.k = 15L, seed = 1L,
n_cores = max(1, parallel::detectCores() - 1), update_RE = TRUE,
light = FALSE, equal.strata.knots = FALSE,
equal.strata.bound.knots = FALSE,
lng.in.kn.multiState = 5L)
control <- c(control, list(...))
namC <- names(con)
con[(namc <- names(control))] <- control
if (length(noNms <- namc[!namc %in% namC]) > 0)
warning("unknown names in control: ", paste(noNms, collapse = ", "))
if (is.null(survObject$model)) {
stop("'survObject' must be a 'coxph' or 'survreg' object fitted with argument 'model'",
" set to TRUE.\n")
}
dataS <- survObject$model
Terms <- attr(dataS, "terms")
environment(Terms) <- NULL
SurvInf <- model.response(dataS)
typeSurvInf <- attr(SurvInf, "type")
TimeVar <- all.vars(Terms)[1L]
if (typeSurvInf == "right") {
if (class(survObject)[1L] == 'survreg') {
stop("Please refit the survival submodel using coxph().\n")
}
Time <- SurvInf[, "time"]
Time[Time < 1e-04] <- 1e-04
nT <- length(Time)
event <- SurvInf[, "status"]
LongFormat <- FALSE
TimeLl <- rep(0.0, length(Time))
}
if (typeSurvInf == "counting" && !multiState) {
if (class(survObject) == 'survreg') {
stop("Please refit the survival submodel using coxph().\n")
}
if (is.null(survObject$model$`(cluster)`)) {
stop("you need to refit the Cox and include in the right hand side of the ",
"formula the 'cluster()' function using as its argument the subjects' ",
"id indicator. These ids need to be the same as the ones used to fit ",
"the mixed effects model.\n")
}
idT <- survObject$model$`(cluster)`
LongFormat <- length(idT) > length(unique(idT))
TimeL <- TimeLl <- SurvInf[, "start"]
fidT <- factor(idT, levels = unique(idT))
TimeL <- tapply(TimeL, fidT, head, n = 1)
anyLeftTrunc <- any(TimeL > 1e-07)
TimeR <- SurvInf[, "stop"]
TimeR[TimeR < 1e-04] <- 1e-04
Time <- tapply(TimeR, fidT, tail, n = 1)
nT <- length(Time)
eventLong <- SurvInf[, "status"]
event <- c(tapply(eventLong, fidT, tail, n = 1))
}
if (typeSurvInf == "counting" && multiState) {
if (class(survObject) == 'survreg') {
stop("Please refit the survival submodel using coxph(). \n")
}
if (is.null(survObject$model$`(cluster)`)) {
stop("you need to refit the Cox and include in the right hand side of the ",
"formula the 'cluster()' function using as its argument the subjects' ",
"id indicator. These ids need to be the same as the ones used in the ",
"data_MultiState dataset. \n")
}
con$lng.in.kn <- con$lng.in.kn.multiState
idT <- survObject$model$`(cluster)`
LongFormat <- length(idT) > length(unique(idT))
TimeL <- TimeLl <- SurvInf[, "start"]
fidT <- factor(idT, levels = unique(idT))
anyLeftTrunc <- any(TimeL > 1e-07)
TimeR <- SurvInf[, "stop"]
nT <- length(unique(fidT))
nT.long <- length(idT)
event <- eventLong <- SurvInf[, "status"]
nRisks <- length(unique(survObject$strata))
state.id <- gsub("^strata*\\((.*)\\).*", "\\1",
colnames(dataS)[grep("^strata", colnames(dataS))])
state.id2 <- colnames(dataS)[grep("^strata", colnames(dataS))]
}
if (typeSurvInf == "interval") {
Time1 <- SurvInf[, "time1"]
Time2 <- SurvInf[, "time2"]
Time <- Time1
Time[Time2 != 1] <- Time2[Time2 != 1]
TimeL <- Time1
TimeL[Time2 == 1] <- 0.0
Time[Time < 1e-04] <- 1e-04
nT <- length(Time)
event <- SurvInf[, "status"]
LongFormat <- FALSE
TimeLl <- rep(0.0, length(Time))
}
GQsurv <- if (con$GQsurv == "GaussKronrod") gaussKronrod() else gaussLegendre(con$GQsurv.k)
wk <- GQsurv$wk
sk <- GQsurv$sk
K <- length(sk)
if (typeSurvInf == "counting" && !multiState) {
P <- (Time - TimeL) / 2
} else if (typeSurvInf == "counting" && multiState) {
P <- (TimeR - TimeL) / 2
} else {
P <- Time / 2
}
st <- if (typeSurvInf == "counting" && !multiState) {
outer(P, sk) + c(Time + TimeL) / 2
} else if (typeSurvInf == "counting" && multiState) {
outer(P, sk) + c(TimeR + TimeL) / 2
} else {
outer(P, sk + 1)
}
if (typeSurvInf == "interval") {
P_int <- TimeL / 2
st_int <- outer(P_int, sk + 1)
}
if (typeSurvInf == "counting" && multiState) {
idGK <- rep(seq_along(TimeR), each = K)
strat <- survObject$strata
n.strat <- length(levels(strat))
split.TimeR <- split(TimeR, strat)
split.TimeL <- split(TimeL, strat)
ind.t <- unlist(tapply(idT, idT,
FUN = function(x)
c(as.logical(data_MultiState[data_MultiState[, idVar_MultiState] %in% x, "status"]))))
Time <- TimeR
idGK_fast <- c(idGK[-length(idGK)] != idGK[-1L], TRUE)
} else {
idGK <- rep(seq_len(nT), each = K)
idGK_fast <- c(idGK[-length(idGK)] != idGK[-1L], TRUE)
}
if (typeSurvInf == "counting" && multiState) {
kn <- if (con$equal.strata.knots) {
kk <- if (is.null(con$knots)) {
tt <- if (con$ObsTimes.knots) Time else Time[ind.t]
pp <- quantile(tt, c(0.05, 0.95), names = FALSE)
tail(head(seq(pp[1L], pp[2L], length.out = con$lng.in.kn), -1L), -1L)
} else {
con$knots
}
kk <- kk[kk < max(Time)]
if (!con$equal.strata.bound.knots) {
st.split <- split(st, strat)
rr <- mapply(FUN = function(x, y) sort(c(rep(range(x, y), con$ordSpline), kk)),
split.TimeR, st.split, SIMPLIFY = FALSE)
} else {
rr <- rep(list(sort(c(rep(range(Time, st), con$ordSpline), kk))), n.strat)
}
names(rr) <- names(split.TimeR)
con$knots <- rr
} else {
sptt <- if (con$ObsTimes.knots) {
split(TimeR[event == 1], strat[event == 1])
} else {
mapply(function(x, y) {x[y]}, split.TimeR, split(ind.t, strat))
}
if (!con$equal.strata.bound.knots) {
st.split <- split(st, strat)
rr <- mapply(FUN =function (t, y){
kk <- if (is.null(con$knots)) {
pp <- quantile(t, c(0.05, 0.95), names = FALSE)
tail(head(seq(pp[1L], pp[2L], length.out = con$lng.in.kn), -1L), -1L)
} else {
con$knots
}
kk <- kk[kk < max(t)]
sort(c(rep(range(t, y), con$ordSpline), kk))
}, sptt, st.split, SIMPLIFY = FALSE)
} else {
rr <- lapply(sptt, function(t) {
kk <- if (is.null(con$knots)) {
pp <- quantile(t, c(0.05, 0.95), names = FALSE)
tail(head(seq(pp[1L], pp[2L], length.out = con$lng.in.kn), -1L), -1L)
} else {
con$knots
}
kk <- kk[kk < max(t)]
sort(c(rep(range(Time, st), con$ordSpline), kk))
})
names(rr) <- names(split.TimeR)
}
con$knots <- rr
}
} else {
kn <- if (is.null(con$knots)) {
tt <- if (con$ObsTimes.knots) Time else Time[event == 1]
pp <- quantile(tt, c(0.05, 0.95), names = FALSE)
tail(head(seq(pp[1L], pp[2L], length.out = con$lng.in.kn), -1L), -1L)
} else {
con$knots
}
kn <- kn[kn < max(Time)]
rr <- sort(c(rep(range(Time, st), con$ordSpline), kn))
con$knots <- rr
}
dataL <- mvglmerObject$data
components <- mvglmerObject$components
families <- mvglmerObject$families
n_outcomes <- length(families)
seq_n_outcomes <- seq_len(n_outcomes)
idL <- components[paste0("id", seq_n_outcomes)]
y <- components[paste0("y", seq_n_outcomes)]
X <- components[paste0("X", seq_n_outcomes)]
Z <- components[paste0("Z", seq_n_outcomes)]
idVar <- components$idVar1
if (is.null(dataL[[timeVar]])) {
stop("variable '", timeVar, "' not in the data.frame extracted from 'mvglmerObject'.\n")
}
dataL <- dataL[order(dataL[[idVar]], dataL[[timeVar]]), ]
if (typeSurvInf == "counting" && multiState) {
dataL.id <- right_rows_mstate(dataL, dataL[[timeVar]], dataL[[idVar]], as.matrix(TimeR), idT)
dataL.id[[state.id]] <- data_MultiState$trans
} else {
dataL.id <- last_rows(dataL, dataL[[idVar]])
}
dataL.id[[timeVar]] <- Time
if (typeSurvInf == "interval") {
dataL_int.id <- dataL.id
dataL_int.id[[timeVar]] <- TimeL
}
if (typeSurvInf == "counting" && multiState) {
dataL.id2 <- right_rows_mstate(dataL, dataL[[timeVar]], dataL[[idVar]], st, idT)
dataL.id2[[timeVar]] <- c(t(st))
} else {
dataL.id2 <- right_rows(dataL, dataL[[timeVar]], dataL[[idVar]], st)
dataL.id2[[timeVar]] <- c(t(st))
}
if (typeSurvInf == "interval") {
dataL_int.id2 <- right_rows(dataL, dataL[[timeVar]], dataL[[idVar]], st_int)
dataL_int.id2[[timeVar]] <- c(t(st_int))
}
if (typeSurvInf == "right" || typeSurvInf == "interval") {
idT <- dataS[[idVar]] <- unique(dataL[[idVar]])
} else {
if (!all(idT %in% unique(dataL[[idVar]]))) {
stop("it seems there are some ids in the survival data set that cannot be ",
"found in the longitudinal data set.\n")
}
dataS[[idVar]] <- idT
}
if (typeSurvInf == "counting" & multiState) {
dataS.id <- data_MultiState
dataS.split <- split(dataS, strat)
st.strat.split <- split(rownames(st), strat)
dataS.id.long <- NULL
for (i in 1:n.strat) {
dataS.id.long[[i]] <- right_rows(dataS.split[[i]], split.TimeL[[i]], dataS.split[[i]][[idVar_MultiState]],
st[st.strat.split[[i]], ])
}
dataS.id2 <- do.call(rbind, dataS.id.long)
dataS.id2 <- dataS.id2[order(dataS.id2[[idVar_MultiState]]), ]
survVars_notin_long <- survVars_notin_long2 <- !names(dataS) %in% names(dataL)
survVars_notin_long[names(dataS) == idVar] <- TRUE
dataS.id.long2 <- lapply(dataS.split, FUN = function (x) x[survVars_notin_long])
dataL.id.split <- split(dataL.id, dataL.id[[state.id]])
dataLS.id <- mapply(merge, dataL.id.split, dataS.id.long2, by = idVar,
all = FALSE, SIMPLIFY = FALSE, sort = FALSE)
dataLS.id <- do.call(rbind, dataLS.id)
dataLS.id <- dataLS.id[order(dataLS.id[[idVar]]), ]
dataLS.id[[TimeVar]] <- dataLS.id[[timeVar]]
dataS.id2[["id2merge"]] <- paste(dataS.id2[[idVar]], round(c(t(st)), 8), sep = ":")
dataL.id2[["id2merge"]] <- paste(dataL.id2[[idVar]], round(c(t(st)), 8), sep = ":")
dataS.id2.split <- split(dataS.id2, dataS.id2[[state.id2]])
dataS.id2.split <- lapply(dataS.id2.split, FUN = function (x) x[survVars_notin_long])
dataL.id2[[state.id2]] <- rep(dataS.id[[state.id]], each = K)
dataL.id2.split <- split(dataL.id2, dataL.id2[[state.id2]])
dataLS.id2 <- mapply(merge, dataL.id2.split, dataS.id2.split, by = "id2merge",
all = FALSE, SIMPLIFY = FALSE, sort = FALSE)
dataLS.id2 <- do.call(rbind, dataLS.id2)
col.rm1 <- colnames(dataLS.id2)[grep(paste0(state.id2, "*"), colnames(dataLS.id2))]
col.rm2 <- colnames(dataLS.id2)[grep(paste0(idVar, ".", "[x | y]"), colnames(dataLS.id2))]
col.rm.x <- c(col.rm1[grep("*.x", col.rm1)], col.rm2[grep("*.x", col.rm2)])
col.rm.y <- c(col.rm1[grep("*.y", col.rm1)], col.rm2[grep("*.y", col.rm2)])
col.rm <- unname(sapply(col.rm.y, FUN = function (x) gsub(".y", "", x)))
dataLS.id2 <- dataLS.id2[, !colnames(dataLS.id2) %in% col.rm.x]
colnames(dataLS.id2)[colnames(dataLS.id2) %in% col.rm.y] <- col.rm
dataLS.id2 <- dataLS.id2[order(dataLS.id2[[idVar]]), ]
colnames(dataLS.id2) <- gsub("^strata*\\((.*)\\).*", "\\1", colnames(dataLS.id2))
dataLS.id2[[TimeVar]] <- dataLS.id2[[timeVar]]
} else {
dataS.id <- last_rows(dataS, dataS[[idVar]])
dataS.id2 <- right_rows(dataS, TimeLl, idT, st)
survVars_notin_long <- survVars_notin_long2 <- !names(dataS) %in% names(dataL)
survVars_notin_long[names(dataS) == idVar] <- TRUE
dataLS <- merge(dataL, dataS.id[survVars_notin_long], all = TRUE, sort = FALSE)
dataLS.id <- merge(dataL.id, dataS.id[survVars_notin_long], by = idVar,
all = TRUE, sort = FALSE)
dataLS.id[[TimeVar]] <- dataLS.id[[timeVar]]
dataS.id2[["id2merge"]] <- paste(dataS.id2[[idVar]], round(c(t(st)), 8), sep = ":")
dataL.id2[["id2merge"]] <- paste(dataL.id2[[idVar]], round(c(t(st)), 8), sep = ":")
dataLS.id2 <- merge(dataL.id2, dataS.id2[survVars_notin_long2], by = "id2merge",
sort = FALSE, all = FALSE)
dataLS.id2[[TimeVar]] <- dataLS.id2[[timeVar]]
}
if (typeSurvInf == "interval") {
dataS_int.id <- last_rows(dataS, dataS[[idVar]])
dataS_int.id2 <- right_rows(dataS, TimeLl, idT, st_int)
dataLS_int <- merge(dataL, dataS_int.id[survVars_notin_long], all = TRUE,
sort = FALSE)
dataLS_int.id <- merge(dataL_int.id, dataS_int.id[survVars_notin_long], by = idVar,
all = TRUE, sort = FALSE)
uu <- runif(length(st_int))
dataS_int.id2[["id2merge"]] <- paste(dataS_int.id2[[idVar]], uu, sep = ":")
dataL_int.id2[["id2merge"]] <- paste(dataL.id2[[idVar]], uu, sep = ":")
dataLS_int.id2 <- merge(dataL_int.id2, dataS_int.id2[survVars_notin_long2],
by = "id2merge", sort = FALSE, all = FALSE)
dataLS_int.id2[[TimeVar]] <- dataLS_int.id2[[timeVar]]
}
if (typeSurvInf == "counting" && multiState) {
W1 <- mapply(FUN = function (x, y) splines::splineDesign(x, y, ord = con$ordSpline, outer.ok = TRUE),
con$knots, split.TimeR, SIMPLIFY = FALSE)
W1 <- mapply(FUN = function (w1, ind) {
out <- matrix(0, length(Time), ncol(w1))
out[strat == ind, ] <- w1
out
}, W1, levels(strat), SIMPLIFY = FALSE)
knots_strat <- lapply(W1, ncol)
knots_strat <- do.call(c, knots_strat)
W1 <- do.call(cbind, W1)
strat_GQ <- rep(strat, each = con$GQsurv.k)
split.TimeR_GQ <- split(c(t(st)), strat_GQ)
W1s <- mapply(FUN = function (x, y) splines::splineDesign(x, y, ord = con$ordSpline, outer.ok = TRUE),
con$knots, split.TimeR_GQ, SIMPLIFY = FALSE)
W1s <- mapply(FUN = function (w1s, ind) {
out <- matrix(0, length(Time) * con$GQsurv.k, ncol(w1s))
out[strat_GQ == ind, ] <- w1s
out
}, W1s, levels(strat), SIMPLIFY = FALSE)
knots_strat_GQ <- lapply(W1s, ncol)
knots_strat_GQ <- do.call(c, knots_strat_GQ)
W1s <- do.call(cbind, W1s)
dataS.id.clone <- dataS
Terms <- drop.terms(Terms, attr(Terms, "specials")$strata - 1,
keep.response = TRUE)
W2 <- model.matrix(Terms, data = dataS.id.clone)[, -1, drop = FALSE]
W2s <- model.matrix(Terms, data = dataS.id2)[, -1, drop = FALSE]
} else {
W1 <- splines::splineDesign(con$knots, Time, ord = con$ordSpline, outer.ok = TRUE)
W1s <- splines::splineDesign(con$knots, c(t(st)), ord = con$ordSpline, outer.ok = TRUE)
knots_strat <- ncol(W1)
W2 <- model.matrix(Terms, data = dataS.id)[, -1, drop = FALSE]
W2s <- model.matrix(Terms, data = dataS.id2)[, -1, drop = FALSE]
}
if (typeSurvInf == "interval") {
W1_int <- splines::splineDesign(con$knots, TimeL, ord = con$ordSpline,
outer.ok = TRUE)
W1s_int <- splines::splineDesign(con$knots, c(t(st_int)), ord = con$ordSpline,
outer.ok = TRUE)
W2_int <- model.matrix(Terms, data = dataS_int.id)[, -1, drop = FALSE]
W2s_int <- model.matrix(Terms, data = dataS_int.id2)[, -1, drop = FALSE]
}
extract_component <- function (component, fixed = TRUE) {
components[grep(component, names(components), fixed = fixed)]
}
respVars <- unlist(extract_component("respVar"), use.names = FALSE)
if (any(!names(Formulas) %in% respVars)) {
stop("unknown names in the list provided in the 'Formulas' argument; as names ",
"of the elements of this list you need to use the response variables from ",
"the multivariate mixed model.\n")
}
not_specified <- !respVars %in% names(Formulas)
Formulas_ns <- rep(list("value"), length = sum(not_specified))
names(Formulas_ns) <- respVars[not_specified]
Formulas <- c(Formulas, Formulas_ns)
Formulas <- Formulas[order(match(names(Formulas), respVars))]
Formulas <- Formulas[!sapply(Formulas, is.null)]
TermsX <- extract_component("TermsX")
X <- extract_component("^X[1-9]", FALSE)
TermsZ <- extract_component("TermsZ")
Z <- extract_component("^Z[1-9]", FALSE)
names(TermsX) <- names(X) <- names(TermsZ) <- names(Z) <- respVars
which_value <- sapply(Formulas, function (x) any(x == "value"))
names_which_value <- names(which_value)[which_value]
replace_value <- function (termsx, x, termsz, z) {
list(fixed = formula(termsx), indFixed = seq_len(ncol(x)),
random = formula(termsz), indRandom = seq_len(ncol(z)),
name = "value")
}
Formulas[which_value] <- mapply(replace_value, TermsX[names_which_value],
X[names_which_value], TermsZ[names_which_value],
Z[names_which_value], SIMPLIFY = FALSE)
names_alphas <- function (Form) {
name_term <- ifelse(!sapply(Form, is.list), "value", "extra")
ind_extra <- name_term == "extra"
user_names <- lapply(Form[ind_extra], "[[", "name")
ind_usernames <- !sapply(user_names, is.null)
name_term[ind_extra][ind_usernames] <- unlist(user_names[ind_usernames],
use.names = FALSE)
out <- paste0(names(Form), "_", name_term)
which_dupl <- unique(out[duplicated(out)])
replc <- function (x) {
paste(x, seq_along(x), sep = ".")
}
replacement <- unlist(lapply(which_dupl, function (dbl) replc(out[out == dbl])),
use.names = FALSE)
out[out %in% which_dupl] <- replacement
out
}
outcome <- match(names(Formulas), respVars)
names(Formulas) <- names_alphas(Formulas)
TermsFormulas <- function (input_terms, dataOrig, which) {
out <- vector("list", length(input_terms))
for (i in seq_along(input_terms)) {
MF <- model.frame.default(terms(input_terms[[i]][[which]]), dataOrig)
out[[i]] <- terms(MF)
}
out
}
TermsFormulas_fixed <- TermsFormulas(Formulas, dataL, "fixed")
TermsFormulas_random <- TermsFormulas(Formulas, dataL, "random")
XX <- build_model_matrix(Formulas, dataL, dataL.id, "fixed")
XXs <- build_model_matrix(Formulas, dataL, dataL.id2, "fixed")
ZZ <- build_model_matrix(Formulas, dataL, dataL.id, "random")
ZZs <- build_model_matrix(Formulas, dataL, dataL.id2, "random")
if (typeSurvInf == "interval") {
XXs_int <- build_model_matrix(Formulas, dataL, dataL_int.id2, "fixed")
ZZs_int <- build_model_matrix(Formulas, dataL, dataL_int.id2, "random")
}
possible_names <- unique(c(respVars, paste0(respVars, "_value"), names(Formulas)))
if (any(!names(Interactions) %in% possible_names)) {
stop("unknown names in the list provided in the 'Interactions' argument; as names ",
"of the elements of this list you need to use the response variables from ",
"the multivariate mixed model or the induced names from the 'Formulas' ",
"argument; these are: ", paste(names(Formulas), collapse = ", "), ".\n")
}
ind_nams <- unlist(lapply(respVars, function (nam) which(names(Interactions) == nam)))
names(Interactions)[ind_nams] <- paste0(names(Interactions)[ind_nams], "_value")
if (any(duplicated(names(Interactions)))) {
stop("duplicated names in argument 'Interactions'; check the help page.\n")
}
not_specified <- !names(Formulas) %in% names(Interactions)
Interactions_ns <- rep(list(~ 1), length = sum(not_specified))
names(Interactions_ns) <- names(Formulas)[not_specified]
Interactions <- c(Interactions, Interactions_ns)
Interactions <- Interactions[order(match(names(Interactions), names(Formulas)))]
Interactions <- Interactions[!sapply(Interactions, is.null)]
TermsU <- lapply(Interactions, function (form) {
MF <- model.frame.default(terms(form), data = dataLS.id)
terms(MF)
})
Interactions <- lapply(Interactions, function (x) {environment(x) <- NULL; x})
U <- lapply(TermsU, function (term) {
model.matrix(term, data = dataLS.id)
})
Us <- lapply(TermsU, function (term) {
model.matrix(term, data = dataLS.id2)
})
if (typeSurvInf == "interval") {
Us_int <- lapply(Interactions, function (form) {
MF <- model.frame.default(terms(form), data = dataLS.id)
Terms <- terms(MF)
model.matrix(Terms, data = dataLS_int.id2)
})
}
id <- lapply(seq_len(n_outcomes), function (i) seq_len(nT))
ids <- rep(list(idGK), n_outcomes)
betas <- mvglmerObject$mcmc[grep("betas", names(mvglmerObject$mcmc), fixed = TRUE)]
colmns_HC <- components[grep("colmns_HC", names(components), fixed = TRUE)]
RE_inds <- mapply(function (sq, incr) seq_len(sq) + incr,
sq = components[grep("ncz", names(components), fixed = TRUE)],
incr = cumsum(c(0, head(sapply(colmns_HC, length), -1))),
SIMPLIFY = FALSE)
bb <- mvglmerObject$mcmc$b
b <- lapply(RE_inds, function (ind) bb[, , ind, drop = FALSE])
inv_D <- mvglmerObject$mcmc[grep("inv_D", names(mvglmerObject$mcmc), fixed = TRUE)]
sigmas <- vector("list", n_outcomes)
if (any(which_gaussian <- sapply(families, "[[", "family") == "gaussian")) {
sigmas[which_gaussian] <- mvglmerObject$mcmc[grep("sigma",
names(mvglmerObject$mcmc),
fixed = TRUE)]
}
trans_Funs <- rep("identity", length(XX))
names(trans_Funs) <- names(Formulas)
if (!is.null(transFuns)) {
if (is.null(names(transFuns)) || !all(names(transFuns) %in% names(trans_Funs))) {
stop("unknown names in 'transFuns'; valid names are the ones induced by the 'Formulas' ",
"argument; these are:\n", paste(names(Formulas), collapse = ", "))
}
valid_funs <- c("identity", "expit", "exp", "log", "log2", "log10", "sqrt")
if (!is.character(transFuns) || !all(transFuns %in% valid_funs)) {
stop("invalid functions names in 'transFuns'; the functions currently supported are: ",
paste(valid_funs, collapse = ", "), ".\nThese should be provided as character vector.")
}
trans_Funs[names(transFuns)] <- transFuns
}
indFixed <- lapply(Formulas, "[[", "indFixed")
indRandom <- lapply(Formulas, "[[", "indRandom")
RE_inds2 <- mapply(function (ind, select) ind[select], RE_inds[outcome], indRandom,
SIMPLIFY = FALSE)
postMean_betas <- lapply(betas, colMeans, na.rm = TRUE)
postMean_b <- lapply(b, function (m) apply(m, 2:3, mean, na.rm = TRUE))
postMean_inv_D <- lapply(inv_D, function (m) apply(m, 2:3, mean, na.rm = TRUE))
mean_null <- function (x) if (is.null(x)) as.numeric(NA) else mean(x)
postMean_sigmas <- lapply(sigmas, mean_null)
Xbetas <- Xbetas_calc(X, postMean_betas)
XXbetas <- Xbetas_calc(XX, postMean_betas, indFixed, outcome)
XXsbetas <- Xbetas_calc(XXs, postMean_betas, indFixed, outcome)
if (typeSurvInf == "interval") {
XXsbetas_int <- Xbetas_calc(XXs_int, postMean_betas, indFixed, outcome)
}
fams <- sapply(families, "[[", "family")
links <- sapply(families, "[[", "link")
idL2 <- lapply(idL, function (x) {
x <- c(x[-length(x)] != x[-1L], TRUE)
which(x) - 1
})
if (typeSurvInf == "counting" && multiState) {
idT.list <- rep(list(idT), times = n_outcomes)
Wlong <- designMatLong(XX, postMean_betas, ZZ, postMean_b, idT.list, outcome,
indFixed, indRandom, U, trans_Funs)
idTs <- rep(idT, each = K)
idTs.list <- rep(list(idTs), times = n_outcomes)
Wlongs <- designMatLong(XXs, postMean_betas, ZZs, postMean_b, idTs.list, outcome,
indFixed, indRandom, Us, trans_Funs)
idT_rsum <- c(idT[-length(idT)] != idT[-1L], TRUE)
idT_rsum <- which(idT_rsum) - 1
rows_wlong <- tapply(which(idT == idT), idT, c)
rows_wlongs <- tapply(which(idTs == idTs), idTs, c)
} else {
Wlong <- designMatLong(XX, postMean_betas, ZZ, postMean_b, id, outcome,
indFixed, indRandom, U, trans_Funs)
Wlongs <- designMatLong(XXs, postMean_betas, ZZs, postMean_b, ids, outcome,
indFixed, indRandom, Us, trans_Funs)
idT.u <- unique(idT)
idT_rsum <- c(idT.u[-length(idT.u)] != idT.u[-1L], TRUE)
idT_rsum <- which(idT_rsum) - 1
idTs <- rep(idT.u, each = K)
rows_wlong <- tapply(which(idT.u == idT.u), idT.u, c)
rows_wlongs <- tapply(which(idTs == idTs), idTs, c)
}
if (typeSurvInf == "interval") {
Wlongs_int <- designMatLong(XXs_int, postMean_betas, ZZs_int, postMean_b, ids,
outcome, indFixed, indRandom, Us_int, trans_Funs)
}
if (typeSurvInf == "counting" && multiState) {
DD <- lapply(knots_strat, diag)
Tau_Bs_gammas.strt <- lapply(DD, FUN = function(x) {
crossprod(diff(x, differences = con$diff)) + 1e-06 * x
})
Tau_Bs_gammas <- matrix(0, nrow = sum(knots_strat), ncol = sum(knots_strat))
for (i in 1:length(knots_strat)) {
tmp.first <- cumsum(knots_strat) - knots_strat + 1
tmp.last <- cumsum(knots_strat)
Tau_Bs_gammas[tmp.first[i]:tmp.last[i], tmp.first[i]:tmp.last[i]] <- Tau_Bs_gammas.strt[[i]]
}
} else {
DD <- diag(ncol(W1))
Tau_Bs_gammas <- crossprod(diff(DD, differences = con$diff)) + 1e-06 * DD
}
find_td_cols <- function (x) grep('tve(', colnames(x), fixed = TRUE)
td_cols <- lapply(U, find_td_cols)
Tau_alphas <- lapply(U, function (x) 0.01 * diag(NCOL(x)))
pen_matrix <- function (td_cols, Tau_alphas) {
if (ncol(Tau_alphas) == length(td_cols)) {
DD <- diag(ncol(Tau_alphas))
crossprod(diff(DD, differences = con$diff)) + 1e-06 * DD
} else Tau_alphas
}
Tau_alphas <- bdiag(mapply(pen_matrix, td_cols, Tau_alphas, SIMPLIFY = FALSE))
which_td <- as.logical(sapply(td_cols, length))
td_cols <- mapply(seq, from = c(1, head(cumsum(sapply(U, ncol)), -1) + 1),
to = cumsum(sapply(U, ncol)), SIMPLIFY = FALSE)[which_td]
prs <- list(mean_Bs_gammas = rep(0, ncol(W1)), Tau_Bs_gammas = Tau_Bs_gammas,
mean_gammas = rep(0, ncol(W2)), Tau_gammas = 0.01 * diag(ncol(W2)),
mean_alphas = rep(0, ncol(Wlong)), Tau_alphas = Tau_alphas,
td_cols = unname(td_cols),
rank_Tau_td_alphas = if (length(td_cols)) length(td_cols[[1]]) else 0,
A_tau_Bs_gammas = 1, B_tau_Bs_gammas = 0.01,
rank_Tau_Bs_gammas = qr(Tau_Bs_gammas)$rank,
A_phi_Bs_gammas = 1, B_phi_Bs_gammas = 0.01, shrink_Bs_gammas = FALSE,
A_tau_gammas = 0.1, B_tau_gammas = 0.1, rank_Tau_gammas = ncol(W2),
A_phi_gammas = 0.5, B_phi_gammas = 0.01, shrink_gammas = FALSE,
A_tau_alphas = 0.5, B_tau_alphas = 0.1, rank_Tau_alphas = ncol(Wlong),
shrink_alphas = FALSE, A_phi_alphas = 0.5, B_phi_alphas = 0.01,
double_gamma_alphas = FALSE, A_nu_alphas = 0.5, B_nu_alphas = 1,
A_xi_alphas = 0.5, B_xi_alphas = 1)
if (!is.null(priors)) {
lngths <- lapply(prs[(nam.prs <- names(priors))], length)
if (!is.list(priors) || !isTRUE(all.equal(lngths, lapply(priors, length)))) {
warning("'priors' is not a list with elements numeric vectors of appropriate ",
"length; default priors are used instead.\n")
} else {
prs[nam.prs] <- priors
}
}
if (mvglmerObject$engine == "JAGS") {
tau_betas <- mvglmerObject$priors[grep("tau_betas", names(mvglmerObject$priors),
fixed = TRUE)]
prs$Tau_betas <- diag(rep(unlist(tau_betas, use.names = FALSE),
sapply(betas, ncol)))
} else {
scale_betas <- mvglmerObject$priors[grep("scale_betas", names(mvglmerObject$priors),
fixed = TRUE)]
prs$Tau_betas <- diag(rep(1 / unlist(scale_betas, use.names = FALSE)^2,
sapply(betas, ncol)))
}
prs$priorK_D <- mvglmerObject$priors$priorK_D
if (typeSurvInf == "counting" && multiState) {
Data <- list(y = y, Xbetas = Xbetas, X = X, Z = Z, RE_inds = RE_inds,
RE_inds2 = RE_inds2, idL = idL, idL2 = idL2, sigmas = postMean_sigmas,
invD = postMean_inv_D[[1]], fams = fams, links = links, Time = Time,
event = event, idGK_fast = which(idGK_fast) - 1, W1 = W1, W1s = W1s,
event_colSumsW1 = colSums(event * W1), W2 = W2, W2s = W2s,
event_colSumsW2 = if (ncol(W2)) colSums(event * W2),
Wlong = Wlong, Wlongs = Wlongs,
event_colSumsWlong = colSums(event * Wlong),
U = U, Us = Us, col_inds = attr(Wlong, "col_inds"),
row_inds_U = seq_len(nrow(Wlong)), row_inds_Us = seq_len(nrow(Wlongs)),
XXbetas = XXbetas, XXsbetas = XXsbetas, XX = XX, XXs = XXs, ZZ = ZZ,
ZZs = ZZs, P = P[ids[[1]]], w = rep(wk, nT.long),
Pw = P[ids[[1]]] * rep(wk, nT.long), idT = id[outcome], idTs = ids[outcome],
idT2 = idT.list[outcome], idT2s = idTs.list[outcome], idT_rsum = idT_rsum,
outcome = outcome, indFixed = indFixed, indRandom = indRandom,
trans_Funs = trans_Funs, nRisks = nRisks,
kn_strat_last = cumsum(knots_strat) - 1,
kn_strat_first = cumsum(knots_strat) - knots_strat,
rows_wlong = rows_wlong, rows_wlongs = rows_wlongs)
} else {
Data <- list(y = y, Xbetas = Xbetas, X = X, Z = Z, RE_inds = RE_inds,
RE_inds2 = RE_inds2, idL = idL, idL2 = idL2, sigmas = postMean_sigmas,
invD = postMean_inv_D[[1]], fams = fams, links = links, Time = Time,
event = event, idGK_fast = which(idGK_fast) - 1, W1 = W1, W1s = W1s,
event_colSumsW1 = colSums(event * W1), W2 = W2, W2s = W2s,
event_colSumsW2 = if (ncol(W2)) colSums(event * W2),
Wlong = Wlong, Wlongs = Wlongs,
event_colSumsWlong = colSums(event * Wlong),
U = U, Us = Us, col_inds = attr(Wlong, "col_inds"),
row_inds_U = seq_len(nrow(Wlong)), row_inds_Us = seq_len(nrow(Wlongs)),
XXbetas = XXbetas, XXsbetas = XXsbetas, XX = XX, XXs = XXs, ZZ = ZZ,
ZZs = ZZs, P = P[ids[[1]]], w = rep(wk, nT),
Pw = P[ids[[1]]] * rep(wk, nT), idT = id[outcome], idTs = ids[outcome],
outcome = outcome, indFixed = indFixed, indRandom = indRandom,
trans_Funs = trans_Funs, nRisks = 1,
kn_strat_last = cumsum(knots_strat) - 1,
kn_strat_first = cumsum(knots_strat) - knots_strat,
idT_rsum = idT_rsum, idT2 = id[outcome], idT2s = ids[outcome],
rows_wlong = rows_wlong, rows_wlongs = rows_wlongs)
}
if (typeSurvInf == "interval") {
Data <- c(Data, list(Levent1 = event == 1,
Levent01 = event == 1 | event == 0,
Levent2 = event == 2, Levent3 = event == 3,
W1s_int = W1s_int, W2s_int = W2s_int, Wlongs_int = Wlongs_int,
Us_int = Us_int, XXsbetas_int = XXsbetas_int,
XXs_int = XXs_int, ZZs_int = ZZs_int,
P_int = P_int[ids[[1]]],
Pw_int = P_int[ids[[1]]] * rep(wk, nT)))
} else {
Data <- c(Data, list(Levent1 = logical(0), Levent01 = logical(0),
Levent2 = logical(0), Levent3 = logical(0),
W1s_int = matrix(nrow = 0, ncol = 0),
W2s_int = matrix(nrow = 0, ncol = 0),
Wlongs_int = matrix(nrow = 0, ncol = 0),
Us_int = list(matrix(nrow = 0, ncol = 0)),
XXsbetas_int = list(numeric(0)),
XXs_int = list(matrix(nrow = 0, ncol = 0)),
ZZs_int = list(matrix(nrow = 0, ncol = 0)),
P_int = numeric(0),
Pw_int = numeric(0)))
}
inits <- list(Bs_gammas = rep(0, ncol(W1)), tau_Bs_gammas = 200, phi_Bs_gammas = rep(1, ncol(W1)),
gammas = rep(0, ncol(W2)), tau_gammas = 1, phi_gammas = rep(1, ncol(W2)),
alphas = rep(0, ncol(Wlong)), tau_alphas = 1, phi_alphas = rep(1, ncol(Wlong)),
tau_td_alphas = rep(200, length(td_cols)))
inits2 <- marglogLik2(inits[c("Bs_gammas", "gammas", "alphas", "tau_Bs_gammas")],
Data, prs, fixed_tau_Bs_gammas = TRUE)
inits[names(attr(inits2, "inits"))] <- attr(inits2, "inits")
if (multiState) {
inits$tau_Bs_gammas <- rep(inits$tau_Bs_gammas, nRisks)
}
Cvs <- attr(inits2, "Covs")
nRE <- sum(sapply(Z, ncol))
Cvs$b <- array(0.0, c(nRE, nRE, nT))
for (i in seq_len(nT)) Cvs$b[, , i] <- chol(var(bb[, i, ]))
if (is.null(Cvs$gammas)) Cvs$gammas <- matrix(nrow = 0, ncol = 0)
inits$b <- do.call("cbind", postMean_b)
scales <- list(b = rep(5.76 / nRE, nT), Bs_gammas = 5.76 / ncol(W1),
gammas = 5.76 / ncol(W2), alphas = 5.76 / ncol(Wlong))
sampl <- function (x, m) {
lapply(x, function (obj) {
d <- dim(obj)
if (is.null(d)) {
obj[m]
} else {
if (is.matrix(obj)) obj[m, ] else obj[m, , ]
}
})
}
runParallel <- function (block, betas, b, sigmas, inv_D, inits, data, priors,
scales, Covs, control, interval_cens, multiState) {
M <- length(block)
LogLiks <- numeric(M)
out <- vector("list", M)
new_scales <- vector("list", M)
inits_Laplace <- inits[c("Bs_gammas", "gammas", "alphas", "tau_Bs_gammas")]
inits_Laplace[["tau_Bs_gammas"]] <- log(inits_Laplace[["tau_Bs_gammas"]])
inits_Laplace[["b"]] <- NULL
any_gammas <- as.logical(length(priors[["mean_gammas"]]))
set.seed(control$seed)
on.exit(rm(list = ".Random.seed", envir = globalenv()))
for (i in seq_len(M)) {
ii <- block[i]
if (control$update_RE) {
betas. <- sampl(betas, ii)
data$Xbetas <- Xbetas_calc(data$X, betas.)
outcome <- data$outcome
indFixed <- data$indFixed
data$XXbetas <- Xbetas_calc(data$XX, betas., indFixed, outcome)
data$XXsbetas <- Xbetas_calc(data$XXs, betas., indFixed, outcome)
if (interval_cens) {
data$XXsbetas_int <- Xbetas_calc(data$XXs_int, betas., indFixed, outcome)
}
data$sigmas <- sampl(sigmas, ii)
data$invD <- as.matrix(sampl(inv_D, ii)[[1]])
oo <- lap_rwm_C(inits, data, priors, scales, Covs, control, interval_cens, multiState)
current_betas <- unlist(betas., use.names = FALSE)
n_betas <- length(current_betas)
pr_betas <- c(dmvnorm2(rbind(current_betas), rep(0, n_betas),
priors$Tau_betas, logd = TRUE))
pr_invD <- dwish(data$invD, diag(nrow(data$invD)),
priors$priorK_D, log = TRUE)
LogLiks[i] <- c(oo$logWeights) - pr_betas - pr_invD
out[[i]] <- oo$mcmc
new_scales[[i]] <- oo$scales$sigma
} else {
betas. <- sampl(betas, ii)
b. <- sampl(b, ii)
outcome <- data$outcome
indFixed <- data$indFixed
indRandom <- data$indRandom
data$Wlong <- designMatLong(data$XX, betas., data$ZZ, b., data$idT,
outcome, indFixed, indRandom, data$U, trans_Funs)
data$Wlongs <- designMatLong(data$XXs, betas., data$ZZs, b., data$idTs,
outcome, indFixed, indRandom, data$Us, trans_Funs)
data$event_colSumsWlong <- colSums(data$event * data$Wlong)
LogLiks[i] <- marglogLik2(inits_Laplace, data, priors)
oo <- if (any_gammas) {
lap_rwm_C_woRE(inits, data, priors, scales, Covs, control)
} else {
lap_rwm_C_woRE_nogammas(inits, data, priors, scales, Covs, control)
}
out[[i]] <- oo$mcmc
new_scales[[i]] <- oo$scales$sigma
}
}
out <- lapply(unlist(out, recursive = FALSE), drop)
new_scales <- lapply(unlist(new_scales, recursive = FALSE), drop)
nams <- names(out)
if (!is.null(out$b)) {
b_out <- array(0.0, c(dim(as.matrix(out$b)), M))
for (i in seq_len(M)) b_out[, , i] <- out[nams == "b"][[i]]
} else b_out <- NULL
out <- list("b" = b_out,
"Bs_gammas" = do.call("rbind", out[nams == "Bs_gammas"]),
"gammas" = if (any_gammas) do.call("rbind", out[nams == "gammas"]),
"alphas" = do.call("rbind", out[nams == "alphas"]),
"tau_Bs_gammas" = do.call("rbind", out[nams == "tau_Bs_gammas"]),
"tau_gammas" = if (any_gammas)do.call("rbind", out[nams == "tau_gammas"]),
"tau_alphas" = do.call("rbind", out[nams == "tau_alphas"]),
"tau_td_alphas" = do.call("rbind", out[nams == "tau_td_alphas"]),
"phi_Bs_gammas" = do.call("rbind", out[nams == "phi_Bs_gammas"]),
"phi_gammas" = if (any_gammas) do.call("rbind", out[nams == "phi_gammas"]),
"phi_alphas" = do.call("rbind", out[nams == "phi_alphas"]))
out$LogLiks <- LogLiks
nams <- names(scales)
out$scales <- list("b" = do.call("rbind", new_scales[nams == "b"]),
"Bs_gammas" = do.call("rbind", new_scales[nams == "Bs_gammas"]),
"gammas" = if (any_gammas) do.call("rbind", new_scales[nams == "gammas"]),
"alphas" = do.call("rbind", new_scales[nams == "alphas"]) )
out <- out[!sapply(out, is.null)]
list(mcmc = out)
}
any_gammas <- ncol(W2)
combine <- function(lis) {
f <- function (lis, nam) {
if (nam == "LogLiks") {
lis <- unlist(lis, recursive = FALSE)
nam <- paste0("mcmc.", nam)
unname(do.call("c", lis[names(lis) == nam]))
} else {
lis <- unlist(lis[names(lis) == "mcmc"], recursive = FALSE)
nam <- paste0("mcmc.", nam)
if (nam == "mcmc.b")
abind(lis[names(lis) == nam])
else
unname(do.call("rbind", lis[names(lis) == nam]))
}
}
list("b" = f(lis, "b"),
"Bs_gammas" = f(lis, "Bs_gammas"), "tau_Bs_gammas" = f(lis, "tau_Bs_gammas"),
"phi_Bs_gammas" = f(lis, "phi_Bs_gammas"),
"gammas" = if (any_gammas) f(lis, "gammas"),
"tau_gammas" = if (any_gammas) f(lis, "tau_gammas"),
"phi_gammas" = if (any_gammas) f(lis, "phi_gammas"),
"alphas" = f(lis, "alphas"), "tau_alphas" = f(lis, "tau_alphas"),
"tau_td_alphas" = f(lis, "tau_td_alphas"),
"phi_alphas" = f(lis, "phi_alphas"),
"LogLiks" = f(lis, "LogLiks"))
}
M <- nrow(betas[[1L]])
blocks <- split(seq_len(M),
rep(seq_len(con$n_cores + 1L), each = ceiling(M / (con$n_cores + 1L)),
length.out = M))
block1 <- split(blocks[[1L]],
rep(seq_len(con$n_cores), each = ceiling(length(blocks[[1L]]) / con$n_cores),
length.out = length(blocks[[1L]])))
blocks <- blocks[-1L]
elapsed_time <- system.time({
registerDoParallel(con$n_cores)
out1 <- foreach(i = block1, .packages = "JMbayes", .combine = c) %dopar% {
runParallel(i, betas, b, sigmas, inv_D, inits, Data, prs, scales, Cvs, con,
typeSurvInf == "interval", multiState)
}
stopImplicitCluster()
if (con$speed_factor < 1) {
calc_new_scales <- function (parm) {
if (parm == "b") {
apply(do.call("rbind", lapply(new_scales, "[[", "b")), 2L, median)
} else {
median(do.call("c", lapply(new_scales, "[[", parm)))
}
}
new_scales <- lapply(out1, "[[", "scales")
new_scales <- list("b" = if (con$update_RE) calc_new_scales("b"),
"Bs_gammas" = calc_new_scales("Bs_gammas"),
"gammas" = if (any_gammas) calc_new_scales("gammas") else Inf,
"alphas" = calc_new_scales("alphas"))
con$n_burnin <- round(ceiling(con$speed_factor *
con$n_burnin / con$n_block) * con$n_block)
} else {
new_scales <- scales
}
registerDoParallel(con$n_cores)
out <- foreach(i = blocks, .packages = "JMbayes", .combine = c) %dopar% {
runParallel(i, betas, b, sigmas, inv_D, inits, Data, prs, new_scales, Cvs,
con, typeSurvInf == "interval", multiState)
}
stopImplicitCluster()
out <- c(out1, out)
})["elapsed"]
mcmc <- mvglmerObject$mcmc
keep <- unlist(sapply(c("betas", "sigma", "D"), grep, x = names(mcmc), fixed = TRUE))
mcmc <- c(mcmc[keep], combine(out))
colnames(mcmc$Bs_gammas) <- paste0("bs", seq_len(ncol(mcmc$Bs_gammas)))
colnames(mcmc$gammas) <- colnames(W2)
get_U_colnames <- unlist(lapply(U, function (u)
gsub("(Intercept)", "", colnames(u), fixed = TRUE)))
nam_alph <- names(U)
trans_Funs <- trans_Funs[names(U)]
ind <- trans_Funs != "identity"
nam_alph[ind] <- paste0(trans_Funs[ind], "(", nam_alph, ")")
colnames(mcmc$alphas) <- paste0(rep(nam_alph, sapply(U, ncol)),
ifelse(get_U_colnames == "", "", ":"),
get_U_colnames)
summary_fun <- function (FUN, ...) {
fun <- function (x, ...) {
res <- try(FUN(x, ...), silent = TRUE)
if (!inherits(res, "try-error")) res else NA
}
out <- lapply(mcmc, function (x) {
d <- dim(x)
if (!is.null(d) && length(d) > 1) {
dd <- if (length(d) == 2) 2L else if (d[2L] == d[3L]) c(2L, 3L)
else c(1L, 2L)
apply(x, dd, fun, ...)
} else if (!is.null(x)) {
fun(x, ...)
}
})
out[!sapply(out, is.null)]
}
stand <- function (x) {
n <- length(x)
upp <- max(x, na.rm = TRUE) + log(n)
w <- exp(x - upp)
w / sum(w)
}
LogLiks <- combine(out)$LogLiks
weights <- stand(LogLiks)
wmean <- function (x, weights, na.rm = FALSE) sum(x * weights, na.rm = na.rm)
wsd <- function (x, weights) sqrt(drop(cov.wt(cbind(x[!is.na(x)]), wt = weights)$cov))
res <- list(call = cl, mcmc = mcmc, weights = weights,
mcmc_info = list(
elapsed_mins = elapsed_time / 60,
n_burnin = con$n_burnin,
n_iter = con$n_iter + con$n_burnin, n_thin = con$n_thin,
priors = prs
),
statistics = list(
postMeans = summary_fun(mean, na.rm = TRUE),
postwMeans = summary_fun(wmean, weights = weights, na.rm = TRUE),
postModes = summary_fun(modes),
EffectiveSize = summary_fun(effectiveSize),
StDev = summary_fun(sd, na.rm = TRUE),
wStDev = summary_fun(wsd, weights = weights),
StErr = summary_fun(stdErr),
CIs = summary_fun(quantile, probs = c(0.025, 0.975)),
wCIs = summary_fun(Hmisc::wtd.quantile, weights = weights,
probs = c(0.025, 0.975), type = "i/(n+1)",
na.rm = TRUE),
Pvalues = summary_fun(computeP)
),
model_info = list(
families = families,
timeVar = timeVar,
TimeVar = TimeVar,
Formulas = Formulas,
Interactions = Interactions,
RE_inds = RE_inds,
RE_inds2 = RE_inds2,
transFuns = trans_Funs,
multiState = multiState,
mvglmer_components = c(components, list(data = dataL)),
coxph_components = list(data = dataS, Terms = Terms, Time = Time,
event = event, TermsU = TermsU,
TermsFormulas_fixed = TermsFormulas_fixed,
TermsFormulas_random = TermsFormulas_random)
),
control = con)
if (con$light) {
res$mcmc[["b"]] <- NULL
}
class(res) <- "mvJMbayes"
res
} |
setOldClass("request")
setClass(Class = "MovebankLogin",
contains="request",
validity = function(object){
if(nchar(object$headers['user'])==0 || nchar(object$headers['password']==0))
return(TRUE)
}
)
setGeneric("movebankLogin", function(username, password,...) standardGeneric("movebankLogin"))
setMethod(f="movebankLogin",
signature=c(username="character", password="character"),
definition = function(username, password){
return(new("MovebankLogin", add_headers(user=username, password=password)))
})
setMethod(f="movebankLogin",
signature=c(username="character", password="missing"),
definition = function(username, password){
pwd<-readline("password:")
return(movebankLogin(username=username, password=pwd))
})
setMethod(f="movebankLogin",
signature=c(username="missing", password="missing"),
definition = function(username, password){
user<-readline("username:")
return(movebankLogin(username=user))
})
setGeneric("getMovebank", function(entity_type, login,...) standardGeneric("getMovebank"))
setMethod(f="getMovebank",
signature=c(entity_type="character", login="MovebankLogin"),
definition = function(entity_type, login, ...){
tmp <- list(...)
if("timestamp_start" %in% names(tmp)){
if(inherits(tmp[['timestamp_start']], "POSIXt")){
tmp[['timestamp_start']]<- sub('\\.','',strftime(format="%Y%m%d%H%M%OS3", tmp[['timestamp_start']] , tz="UTC"))
}
}
if("timestamp_end" %in% names(tmp)){
if(inherits(tmp[['timestamp_end']], "POSIXt")){
tmp[['timestamp_end']]<- sub('\\.','',strftime(format="%Y%m%d%H%M%OS3", tmp[['timestamp_end']] , tz="UTC"))
}
}
url <- paste("https://www.movebank.org/movebank/service/direct-read?entity_type=",entity_type ,sep="")
if(length(tmp)!=0){
tmp <- lapply(tmp, paste, collapse='%2C')
url <- paste(url, sep="&",paste(names(tmp),tmp, collapse="&", sep="="))
}
f<-GET(url, config = login)
if(grepl("location_long", url)){cols<-c(location_long='numeric', location_lat='numeric')}else{cols<-NA}
cont<-content(f, as='text', encoding = "UTF-8")
if(grepl(pattern="The requested download may contain copyrighted material. You may only download it if you agree with the terms listed below. If study-specific terms have not been specified, read the \"General Movebank Terms of Use\".",
cont[1])) stop("You need a permission to access this data set. Go to www.movebank.org and accept the license terms when downloading the data set (you only have to do this once per data set).")
data <- read.csv(textConnection(cont), colClasses=cols)
if(any(grepl(pattern = 'The.request.has.not.been.applied.because.it.lacks.valid.authentication.credentials.for.the.target.resource', x=colnames(data)))) stop("There are no credentials")
if(any(grepl(pattern = 'The.server.understood.the.request.but.refuses.to.authorize', x=colnames(data)))) stop("There are no valid credentials")
if(any(grepl(pattern="You.may.only.download.it.if.you.agree.with.the.terms", x=colnames(data)))) stop("You need a permission to access this data set. Go to www.movebank.org and accept the license terms when downloading the data set (you only have to do this once per data set).")
if (any(grepl(pattern="X.html..head..title.Apache.Tomcat", colnames(data)))) stop("It looks like you are not allowed to download this data set, either by permission but maybe also an invalid password. Or there is a sensor for which no attributes are available.")
if (any(grepl(pattern="are.not.available.for.download", colnames(data)))) stop("You have no permission to download this data set.")
if (any(grepl(pattern="503 Service Temporarily Unavailable", unlist(head(data))))) stop("Movebank is (temporarily) unavailable")
if (any(grepl(pattern="No.data.are.available.for.download", colnames(data)))) stop("Api reports: No data are available for download")
if (any(grepl(pattern="By accepting this document the user agrees to the following", data[,1]))) stop("It looks like you are not allowed to download this data set, have you agreed to the license terms in the web interface?")
if (any(grepl(pattern="The requested URL.s length exceeds the capacity", data[,1]))) stop("The requested URL's length exceeds the capacity limit for this server. This can for example occur when too many indviduals are requested")
return(data)
})
setMethod(f="getMovebank",
signature=c(entity_type="character", login="missing"),
definition = function(entity_type, login, ...){
d<-movebankLogin()
getMovebank(entity_type=entity_type, login=d,...)
})
setGeneric("searchMovebankStudies", function(x,login) standardGeneric("searchMovebankStudies"))
setMethod(f="searchMovebankStudies",
signature=c(x="character",login="MovebankLogin"),
definition = function(x,login){
data <- getMovebank("study", login, sort="name", attributes="id%2Cname%2Ci_am_owner%2Ci_can_see_data%2Cthere_are_data_which_i_cannot_see")
res <- as.character(data$name)[grepl(x,data$name,useBytes=TRUE)]
if(length(res)>0){return(res)}else{"No study matches your search criteria"}
})
setMethod(f="searchMovebankStudies",
signature=c(x="character",login="missing"),
definition = function(x,login){
login=movebankLogin()
searchMovebankStudies(x=x,login=login)
})
setGeneric("getMovebankStudies", function(login) standardGeneric("getMovebankStudies"))
setMethod(f="getMovebankStudies",
signature=c(login="missing"),
definition = function(login){
login <- movebankLogin()
getMovebankStudies(login=login)
})
setMethod(f="getMovebankStudies",
signature=c(login="MovebankLogin"),
definition = function(login){
data <- getMovebank("study", login, sort="name", attributes="id%2Cname%2Ci_am_owner%2Ci_can_see_data%2Cthere_are_data_which_i_cannot_see")
return(data$name)
})
setGeneric("getMovebankSensors", function(study, login) standardGeneric("getMovebankSensors"))
setMethod(f="getMovebankSensors",
signature=c(study="ANY",login="missing"),
definition = function(study,login){
login <- movebankLogin()
getMovebankSensors(study=study, login=login)
})
setMethod(f="getMovebankSensors",
signature=c(study="missing",login="missing"),
definition = function(study,login){
login <- movebankLogin()
getMovebankSensors(login=login)
})
setMethod(f="getMovebankSensors",
signature=c(study="missing",login="MovebankLogin"),
definition = function(study,login){
data <- getMovebank("tag_type", login)
return(data)
})
setMethod(f="getMovebankSensors",
signature=c(study="character",login="MovebankLogin"),
definition = function(study,login){
study <- getMovebankID(study, login)
callGeneric()
})
setMethod(f="getMovebankSensors",
signature=c(study="numeric",login="MovebankLogin"),
definition = function(study,login){
data <- getMovebank("sensor", login, tag_study_id=study)
return(data)
})
setGeneric("getMovebankSensorsAttributes", function(study, login, ...) standardGeneric("getMovebankSensorsAttributes"))
setMethod(f="getMovebankSensorsAttributes",
signature=c(study="ANY",login="missing"),
definition = function(study,login,...){
login<-movebankLogin()
getMovebankSensorsAttributes(study=study, login=login,...)
})
setMethod(f="getMovebankSensorsAttributes",
signature=c(study="character",login="MovebankLogin"),
definition = function(study,login,...){
study<-getMovebankID(study, login,... )
callGeneric()
})
setMethod(f="getMovebankSensorsAttributes",
signature=c(study="numeric",login="MovebankLogin"),
definition = function(study,login,...){
data <- getMovebank("sensor", login, tag_study_id=study,...)
studySensors <- unique(data$sensor_type_id)
data2 <- lapply(studySensors, function(y, login, study) {try(getMovebank("study_attribute", login, study_id=study, sensor_type_id=y), silent=T)} ,login=login, study=study)
data2<-data2[(lapply(data2, class))!='try-error']
return(as.data.frame(do.call(rbind, data2)))
})
setGeneric("getMovebankID", function(study, login) standardGeneric("getMovebankID"))
setMethod(f="getMovebankID",
signature=c(study="character", login="missing"),
definition = function(study, login){
login <- movebankLogin()
getMovebankID(study=study, login=login)
})
setMethod(f="getMovebankID",
signature=c(study="character", login="MovebankLogin"),
definition = function(study=NA, login){
data <- getMovebank("study", login, sort="name", attributes="id%2Cname%2Ci_am_owner%2Ci_can_see_data%2Cthere_are_data_which_i_cannot_see")
if (is.na(study)) {
return(data[ ,c("id","name")])
} else {
studyNUM <- data[gsub(" ","", data$name)==gsub(" ","", study),c("id")]
if (length(studyNUM)>1) stop(paste("There was more than one study with the name:",study))
return(studyNUM)
}
})
setGeneric("getMovebankStudy", function(study, login) standardGeneric("getMovebankStudy"))
setMethod(f="getMovebankStudy",
signature=c(study="numeric", login="MovebankLogin"),
definition = function(study, login){
data <- getMovebank("study", login, id=study)
return(data)
})
setMethod(f="getMovebankStudy",
signature=c(study="character", login="MovebankLogin"),
definition = function(study, login){
study<- getMovebankID(study, login)
callGeneric()
})
setMethod(f="getMovebankStudy",
signature=c(study="ANY", login="missing"),
definition = function(study, login){
login <- movebankLogin()
getMovebankStudy(study=study,login=login)
})
setGeneric("getMovebankAnimals", function(study, login) standardGeneric("getMovebankAnimals"))
setMethod(f="getMovebankAnimals",
c(study="character", login="MovebankLogin"),
definition = function(study, login){
study <- getMovebankID(study,login)
callGeneric()
})
setMethod(f="getMovebankAnimals",
c(study="numeric", login="MovebankLogin"),
definition = function(study, login){
tags <- getMovebank(entity_type="sensor", login, tag_study_id=study)
tagNames <- getMovebank(entity_type="tag", login, study_id=study)[,c("id", "local_identifier")]
colnames(tagNames) <- c("tag_id","tag_local_identifier")
tags <- merge.data.frame(x=tags, y=tagNames, by="tag_id")
animalID <- getMovebank("individual", login, study_id=study)
deploymentID <- getMovebank("deployment", login=login, study_id=study, attributes="individual_id%2Ctag_id%2Cid")
names(deploymentID) <- sub('^id$','deployment_id', names(deploymentID))
if (nrow(tags)!=0){
tagdep <- merge.data.frame(x=tags, y=deploymentID, by.x="tag_id", by.y="tag_id", all=TRUE)
tagdepid <- merge.data.frame(x=tagdep, y=animalID, by.x="individual_id", by.y="id", all.y=TRUE)[,-3]
tagdepid$animalName<-tagdepid$local_identifier
if (any(duplicated(tagdepid$individual_id)|duplicated(tagdepid$tag_id))){
tagdepid$animalName <- paste(tagdepid$animalName, tagdepid$deployment_id, sep="_")
}
return(tagdepid)
} else {
return(merge.data.frame(x=deploymentID, y=animalID, by.x="individual_id", by.y="id", all.y=TRUE))
}
})
setMethod(f="getMovebankAnimals",
c(study="ANY", login="missing"),
definition = function(study, login){
login <- movebankLogin()
getMovebankAnimals(study=study,login=login)
})
setGeneric("getMovebankData", function(study,animalName,login, ...) standardGeneric("getMovebankData"))
setMethod(f="getMovebankData",
signature=c(study="ANY",animalName="missing", login="missing"),
definition = function(study, animalName, login=login, ...){
login <- movebankLogin()
getMovebankData(study = study, login = login, ...)
})
setMethod(f="getMovebankData",
signature=c(study="ANY",animalName="ANY", login="missing"),
definition = function(study, animalName, login=login, ...){
login <- movebankLogin()
getMovebankData(study = study, animalName = animalName, login = login, ...)
})
setMethod(f="getMovebankData",
signature=c(study="character",animalName="ANY", login="MovebankLogin"),
definition = function(study, animalName, login, ...){
study <- getMovebankID(study, login)
callGeneric()
})
setMethod(f="getMovebankData",
signature=c(study="numeric",animalName="missing", login="MovebankLogin"),
definition = function(study, animalName, login, ...){
d<- getMovebank("individual", login=login, study_id=study, attributes=c('id'))$id
getMovebankData(study=study, login=login, ..., animalName=d)
})
setMethod(f="getMovebankData",
signature=c(study="numeric",animalName="character", login="MovebankLogin"),
definition = function(study, animalName, login, ...){
d<- getMovebank("individual", login=login, study_id=study, attributes=c('id','local_identifier'))
animalName<-d[as.character(d$local_identifier)%in%animalName,'id']
callGeneric()
})
setMethod(
f = "getMovebankData",
signature = c(
study = "numeric",
animalName = "numeric",
login = "MovebankLogin"
),
definition = function(study,
animalName,
login,
removeDuplicatedTimestamps = FALSE,
includeExtraSensors = FALSE,
deploymentAsIndividuals = FALSE,
includeOutliers = FALSE,
...) {
idData <-do.call('rbind', lapply(split(animalName, ceiling((1:length(animalName))/200)), function(x,...)
{
getMovebank(
"individual",
login = login,
study_id = study,
id = x,
...
)},...))
colnames(idData)[which(names(idData) == "id")] <-
"individual_id"
if (deploymentAsIndividuals) {
dep <-do.call('rbind', lapply(split(animalName, ceiling((1:length(animalName))/200)), function(x,...)
getMovebank(
"deployment",
login = login,
study_id = study,
individual_id = x,
...
),...))
dep <-do.call('rbind', lapply(split(animalName, ceiling((1:length(animalName))/200)), function(x,...)
getMovebank(
"deployment",
login = login,
study_id = study,
individual_id = x,
attributes = c("individual_id",
names(which(
!unlist(lapply(lapply(dep, is.na), all))
))),
...
),...))
colnames(dep)[which(names(dep) == "id")] <- "deployment_id"
if(any(colnames(dep)=='local_identifier')){
colnames(dep)[which(names(dep) == "local_identifier")] <-
"deployment_local_identifier"
}else{
dep$deployment_local_identifier<-dep$deployment_id
}
idData <- merge.data.frame(idData, dep, by = "individual_id")
}else{
if(all(is.na(idData$local_identifier))){
if(any(duplicated(idData$local_identifier))){
stop('This needs checking')
}
idData$local_identifier<- idData$individual_id
}
}
sensorTypes <- getMovebank("tag_type", login = login)
rownames(sensorTypes) <- sensorTypes$id
locSen <-
sensorTypes[as.logical(sensorTypes$is_location_sensor), "id"]
attribs <-
unique(
c(
as.character(getMovebankSensorsAttributes(study, login, ...)$short_name),
"sensor_type_id",
'visible',
"deployment_id",
'event_id',
'individual_id',
'tag_id'
)
)
trackDF <-do.call('rbind',
lapply(split(animalName, ceiling(1:length(animalName)/200)), function(x,...)
getMovebank(
"event",
login = login,
study_id = study,
attributes = attribs ,
individual_id = x,
sensor_type_id = locSen,
...
), ...))
if (includeExtraSensors) {
otherSen <-
sensorTypes[!as.logical(sensorTypes$is_location_sensor), "id"]
otherDF <-do.call('rbind',
lapply(split(animalName, ceiling(1:length(animalName)/200)), function(x,...)
getMovebank(
"event",
login = login,
study_id = study,
attributes = attribs ,
individual_id = x,
sensor_type_id = otherSen,
...
), ...))
trackDF <- rbind(trackDF, otherDF)
}
if (nrow(trackDF) == 0) {
stop('No records found for this individual/study combination')
}
trackDF <-
merge.data.frame(trackDF, sensorTypes[, c("id", "name")], by.x = "sensor_type_id", by.y =
"id")
colnames(trackDF)[which(names(trackDF) == "name")] <-
"sensor_type"
if(!is.factor(trackDF$sensor_type))
trackDF$sensor_type<-factor(trackDF$sensor_type)
trackDF$sensor_type <- droplevels(trackDF$sensor_type)
trackDF <-
merge.data.frame(trackDF, unique(idData[, c("individual_id", "local_identifier")]), by =
"individual_id")
trackDF$individual_id <-
NULL
tagID <- getMovebank("tag", login, study_id=study)[,c("id", "local_identifier")]
colnames(tagID) <- c("tag_id","tag_local_identifier")
trackDF <- merge.data.frame(trackDF,tagID,by="tag_id", all.x=T)
if (deploymentAsIndividuals) {
trackDF <-
merge.data.frame(trackDF, idData[, c("deployment_id", "deployment_local_identifier")], by =
"deployment_id")
trackDF$deployment_id <-
NULL
}
trackDF$timestamp <-
as.POSIXct(strptime(
as.character(trackDF$timestamp),
format = "%Y-%m-%d %H:%M:%OS",
tz = "UTC"
),
tz = "UTC")
if (!deploymentAsIndividuals) {
if (any(tapply(trackDF$sensor_type_id, trackDF$local_identifier, length) !=
1)) {
trackDF <-
trackDF[with(trackDF, order(trackDF$local_identifier, timestamp)) ,]
}
trackDF$local_identifier <- as.factor(trackDF$local_identifier)
levels(trackDF$local_identifier) <-
validNames(levels((trackDF$local_identifier)))
rownames(idData) <- validNames(idData$local_identifier)
} else{
if (any(
tapply(
trackDF$sensor_type_id,
trackDF$deployment_local_identifier,
length
) != 1
)) {
trackDF <-
trackDF[with(trackDF,
order(trackDF$deployment_local_identifier, timestamp)) ,]
}
trackDF$deployment_local_identifier <-
as.factor(trackDF$deployment_local_identifier)
levels(trackDF$deployment_local_identifier) <-
validNames(levels((
trackDF$deployment_local_identifier
)))
rownames(idData) <-
validNames(idData$deployment_local_identifier)
}
outliers <- is.na(trackDF$location_long)
stopifnot('visible'%in%colnames(trackDF))
if(!includeOutliers){outliers[trackDF$visible == "false"] <- T}
if (all(outliers))
stop("There not observed records for this study/individual")
spdf <-
SpatialPointsDataFrame(
trackDF[!outliers, c('location_long', 'location_lat')],
data = trackDF[!outliers, ],
proj4string = CRS("+proj=longlat +datum=WGS84"),
match.ID = T
)
if (!deploymentAsIndividuals) {
idCol <- "local_identifier"
} else{
idCol <- "deployment_local_identifier"
}
id <-
paste(format(trackDF$timestamp, "%Y %m %d %H %M %OS4"),
trackDF[[idCol]],
trackDF$sensor_type_id)
if(!is.factor(spdf[[idCol]]))
spdf[[idCol]]<-factor(spdf[[idCol]])
trackId <- droplevels(spdf[[idCol]])
spdf[[idCol]] <- NULL
if (anyDuplicated(id)) {
if (any(s <- id[outliers] %in% id[!outliers]))
{
warning(
"There are timestamps ",
sum(s),
" in the unused data that are also in the real data, those records are omitted"
)
outliers[outliers][s] <- F
}
if (any(s <- duplicated(id[outliers])))
{
warning(
"There are ",
sum(s),
" duplicated timestamps in the unused that those will be removed"
)
outliers[outliers][s] <- F
}
}
unUsed <-
new(
'.unUsedRecordsStack',
dataUnUsedRecords = trackDF[outliers, ],
timestampsUnUsedRecords = trackDF$timestamp[outliers],
sensorUnUsedRecords = trackDF[outliers, 'sensor_type'],
trackIdUnUsedRecords = trackDF[outliers, idCol]
)
if (any(!(s <-
(
as.character(unUsed@trackIdUnUsedRecords) %in% levels(trackId)
))))
{
warning('Omiting individual(s) (n=',
length(unique(unUsed@trackIdUnUsedRecords[!s])),
') that have only unUsedRecords')
unUsed <- unUsed[s, ]
}
unUsed@trackIdUnUsedRecords <-
factor(unUsed@trackIdUnUsedRecords, levels = levels(trackId))
if (removeDuplicatedTimestamps) {
message(
"removeDupilcatedTimestamps was set to TRUE, this will retain the first of multiple records with the same animal ID and timestamp, and remove any subsequent duplicates"
)
dupsDf <-
(data.frame(
format(spdf$timestamp, "%Y %m %d %H %M %OS4"),
spdf$sensor_type_id,
trackId
))
dups <- duplicated(dupsDf)
spdf <- spdf[!dups, ]
trackId <- trackId[!dups]
warning(sum(dups),
" location(s) is/are removed by removeDuplicatedTimestamps")
}
s <- getMovebankStudy(study, login)
if(is.na(s$license_terms)){s$license_terms <- s$license_type}else{s$license_terms <- paste0(s$license_type," - ", s$license_terms)}
res <- new(
"MoveStack",
spdf,
timestamps = spdf$timestamp,
sensor = spdf$sensor_type,
unUsed,
trackId = trackId,
idData = idData[as.character(unique(trackId)), ],
study = ifelse(is.na(s$name), character(), as.character(s$name)),
citation = ifelse(is.na(s$citation), character(), as.character(s$citation)),
license = ifelse(
is.na(s$license_terms),
character(),
as.character(s$license_terms)
)
)
if (length(n.locs(res)) == 1)
res <- as(res, 'Move')
return(res)
}
)
setGeneric("getMovebankNonLocationData", function(study,sensorID,animalName,login, ...) standardGeneric("getMovebankNonLocationData"))
setMethod(f="getMovebankNonLocationData",
signature=c(study="ANY",sensorID="missing",animalName="missing", login="missing"),
definition = function(study, sensorID, animalName, login=login, ...){
login <- movebankLogin()
getMovebankNonLocationData(study = study, login=login,...)
})
setMethod(f="getMovebankNonLocationData",
signature=c(study="ANY",sensorID="ANY",animalName="ANY", login="missing"),
definition = function(study, sensorID, animalName, login=login, ...){
login <- movebankLogin()
getMovebankNonLocationData(study = study, sensorID = sensorID, animalName = animalName, login=login,...)
})
setMethod(f="getMovebankNonLocationData",
signature=c(study="ANY",sensorID="ANY",animalName="missing", login="missing"),
definition = function(study, sensorID, animalName, login=login, ...){
login <- movebankLogin()
getMovebankNonLocationData(study = study, sensorID = sensorID, login=login,...)
})
setMethod(f="getMovebankNonLocationData",
signature=c(study="character", sensorID="ANY",animalName="ANY",login="MovebankLogin"),
definition = function(study, sensorID, animalName, login, ...){
study <- getMovebankID(study, login)
callGeneric()
})
setMethod(f="getMovebankNonLocationData",
signature=c(study="numeric", sensorID="missing",animalName="ANY",login="MovebankLogin"),
definition = function(study, sensorID, animalName, login, ...){
allsens <- getMovebank("tag_type", login=login)[(c("id","is_location_sensor"))]
allNL <- allsens$id[allsens$is_location_sensor=="false"]
sensStudy <- unique(getMovebankSensors(study=study, login=login)$sensor_type_id)
sensorID <- sensStudy[sensStudy%in%allNL]
if(missing(animalName)){
getMovebankNonLocationData(study=study, sensorID=sensorID, login=login, ...)
}else{
getMovebankNonLocationData(study=study, sensorID=sensorID, login=login, animalName=animalName, ...)}
})
setMethod(f="getMovebankNonLocationData",
signature=c(study="numeric", sensorID="character",animalName="ANY",login="MovebankLogin"),
definition = function(study, sensorID, animalName, login, ...){
ss <- getMovebank("tag_type", login=login)[c("name","id")]
sensorID<-ss[as.character(ss$name)%in%sensorID,'id']
callGeneric()
})
setMethod(f="getMovebankNonLocationData",
signature=c(study="numeric",sensorID="numeric",animalName="missing", login="MovebankLogin"),
definition = function(study, sensorID, animalName, login, ...){
d<- getMovebank("individual", login=login, study_id=study, attributes=c('id'))$id
getMovebankNonLocationData(study=study, sensorID=sensorID, login=login, ..., animalName=d)
})
setMethod(f="getMovebankNonLocationData",
signature=c(study="numeric",sensorID="numeric",animalName="character",login="MovebankLogin"),
definition = function(study, sensorID, animalName, login, ...){
d<- getMovebank("individual", login=login, study_id=study, attributes=c('id','local_identifier'))
animalName<-d[as.character(d$local_identifier)%in%animalName,'id']
callGeneric()
})
setMethod(f="getMovebankNonLocationData",
signature=c(study="numeric",sensorID="numeric", animalName="numeric", login="MovebankLogin"),
definition = function(study, sensorID, animalName, login,...){
idData <-do.call('rbind', lapply(split(animalName, ceiling((1:length(animalName))/200)), function(x,...){
getMovebank("individual", login=login, study_id=study, id=x,...)},...))
colnames(idData)[which(names(idData) == "id")] <- "individual_id"
if(length(study)>1){stop("Download only possible for a single study")}
sensorTypes <- getMovebank("tag_type", login=login)
if(length(sensorID)==0 | length(sensorID[!sensorID%in%sensorTypes$id])>0){stop("Sensor name(s) not valid. See 'getMovebankSensors(login)' for valid sensor names")}
if(any(as.logical(sensorTypes$is_location_sensor[sensorTypes$id%in%sensorID]))){
stop("The selected sensor(s): '",paste0(sensorTypes$name[sensorTypes$id%in%sensorID & sensorTypes$is_location_sensor=="true"],collapse = ", "),"' is a/are location sensor(s). Only non location data can be downloaded with this function. Use 'getMovebankData' to download location data.")}
sensorAnim <- getMovebankAnimals(study, login)[c("individual_id","sensor_type_id")]
if(length(sensorID[!sensorID%in%unique(sensorAnim$sensor_type_id)])>0){
NoSens <- as.character(sensorTypes$name[sensorTypes$id%in%sensorID[!sensorID%in%unique(sensorAnim$sensor_type_id)]])
stop("Sensor(s): '",paste0(NoSens,collapse = ", "), "' is/are not available for this study")}
NoDat <- idData$local_identifier[!unlist(lapply(1:nrow(idData), function(x){is.element(sensorID, sensorAnim$sensor_type_id[sensorAnim$individual_id==idData$individual_id[x]])}))]
if(length(NoDat)>0){
animalName <- animalName[!animalName%in%idData$individual_id[as.character(idData$local_identifier)%in%as.character(NoDat)]]
if(length(NoDat)<=90){
warning("Individual(s): '", paste0(as.character(NoDat),collapse = ", "),"' do(es) not have data for one or more of the selected sensor(s). Data for this/these individual(s) are not downloaded.")
}else{
warning("Individual(s): '", paste0(as.character(NoDat[1:90]),collapse = ", "), "' ... and ", (length(NoDat)-90) ," more (total ",length(NoDat), ") do not have data for one or more of the selected sensor(s). Data for these individuals are not downloaded.")}
}
NonLocData <-do.call('rbind',
lapply(split(animalName, ceiling(1:length(animalName)/200)), function(x,...){
getMovebank("event", login=login, study_id=study, sensor_type_id=sensorID, individual_id=x, attributes="all",...)}, ...))
if(nrow(NonLocData)==0){
stop("This Individual/All Individuals has/have 0 data points for the selected sensor(s)." )}
IndivWithData <- unique(NonLocData$individual_id)
if(!setequal(animalName, IndivWithData)){
indivNoData <- idData$local_identifier[!idData$individual_id%in%IndivWithData]
if(length(indivNoData)<=90){
warning("Individual(s): '",paste0(as.character(indivNoData),collapse = ", "), "' have 0 data points for one or more of the selected sensor(s).")
}else{
warning("Individuals: '", paste0(as.character(indivNoData[1:90]),collapse = ", "), "' ... and ", (length(indivNoData)-90) ," more (total ",length(indivNoData), ") have 0 data points for one or more of the selected sensor(s).")}
}
NonLocData$timestamp <- as.POSIXct(strptime(as.character(NonLocData$timestamp), format = "%Y-%m-%d %H:%M:%OS",tz="UTC"), tz="UTC")
NonLocData$study_name <- as.character(getMovebankStudy(study, login)$name)
for(i in unique(NonLocData$sensor_type_id)){
NonLocData$sensor_type[NonLocData$sensor_type_id==i] <- as.character(sensorTypes$name[sensorTypes$id==i])
}
return(NonLocData)
})
setGeneric("getMovebankLocationData", function(study,sensorID,animalName,login,...) standardGeneric("getMovebankLocationData"))
setMethod(f="getMovebankLocationData",
signature=c(study="ANY",sensorID="missing",animalName="missing", login="missing"),
definition = function(study, sensorID, animalName, login=login, ...){
login <- movebankLogin()
getMovebankLocationData(study = study, login=login,...)
})
setMethod(f="getMovebankLocationData",
signature=c(study="ANY",sensorID="ANY",animalName="ANY", login="missing"),
definition = function(study, sensorID, animalName, login=login, ...){
login <- movebankLogin()
getMovebankLocationData(study = study, sensorID = sensorID, animalName = animalName, login=login,...)
})
setMethod(f="getMovebankLocationData",
signature=c(study="ANY",sensorID="ANY",animalName="missing", login="missing"),
definition = function(study, sensorID, animalName, login=login, ...){
login <- movebankLogin()
getMovebankLocationData(study = study, sensorID = sensorID, login=login,...)
})
setMethod(f="getMovebankLocationData",
signature=c(study="character", sensorID="ANY",animalName="ANY",login="MovebankLogin"),
definition = function(study, sensorID, animalName, login, ...){
study <- getMovebankID(study, login)
callGeneric()
})
setMethod(f="getMovebankLocationData",
signature=c(study="numeric", sensorID="missing",animalName="ANY",login="MovebankLogin"),
definition = function(study, sensorID, animalName, login, ...){
allsens <- getMovebank("tag_type", login=login)[(c("id","is_location_sensor"))]
allNL <- allsens$id[allsens$is_location_sensor=="true"]
sensStudy <- unique(getMovebankSensors(study=study, login=login)$sensor_type_id)
sensorID <- sensStudy[sensStudy%in%allNL]
if(missing(animalName)){
getMovebankLocationData(study=study, sensorID=sensorID, login=login, ...)
}else{
getMovebankLocationData(study=study, sensorID=sensorID, login=login, animalName=animalName, ...)}
})
setMethod(f="getMovebankLocationData",
signature=c(study="numeric", sensorID="character",animalName="ANY",login="MovebankLogin"),
definition = function(study, sensorID, animalName, login, ...){
ss <- getMovebank("tag_type", login=login)[c("name","id")]
sensorID<-ss[as.character(ss$name)%in%sensorID,'id']
callGeneric()
})
setMethod(f="getMovebankLocationData",
signature=c(study="numeric",sensorID="numeric",animalName="missing", login="MovebankLogin"),
definition = function(study, sensorID, animalName, login, ...){
d<- getMovebank("individual", login=login, study_id=study, attributes=c('id'))$id
getMovebankLocationData(study=study, sensorID=sensorID, login=login, ..., animalName=d)
})
setMethod(f="getMovebankLocationData",
signature=c(study="numeric",sensorID="numeric",animalName="character",login="MovebankLogin"),
definition = function(study, sensorID, animalName, login, ...){
d<- getMovebank("individual", login=login, study_id=study, attributes=c('id','local_identifier'))
animalName<-d[as.character(d$local_identifier)%in%animalName,'id']
callGeneric()
})
setMethod(f="getMovebankLocationData",
signature=c(study="numeric",sensorID="numeric", animalName="numeric", login="MovebankLogin"),
definition = function(study, sensorID, animalName, login, includeOutliers=FALSE, underscoreToDots=TRUE, ...){
idData <-do.call('rbind', lapply(split(animalName, ceiling((1:length(animalName))/200)), function(x,...){
getMovebank("individual", login=login, study_id=study, id=x ,...)}, ...))
colnames(idData)[which(names(idData) == "id")] <- "individual_id"
if(length(study)>1){stop("Download only possible for a single study")}
sensorTypes <- getMovebank("tag_type", login=login)
if(length(sensorID)==0 | length(sensorID[!sensorID%in%sensorTypes$id])>0){stop("Sensor name(s) not valid. See 'getMovebankSensors(login)' for valid sensor names")}
if(!(as.logical(sensorTypes$is_location_sensor[sensorTypes$id%in%sensorID]))){
stop("The selected sensor(s): '",paste0(sensorTypes$name[sensorTypes$id%in%sensorID & sensorTypes$is_location_sensor=="false"],collapse = ", "),"' is a/are non-location sensor(s). Only location data can be downloaded with this function. Use 'getMovebankNonLocationData' to download non-location data.")}
sensorAnim <- getMovebankAnimals(study, login)[c("individual_id","sensor_type_id","taxon_canonical_name","local_identifier")]
if(length(sensorID[!sensorID%in%unique(sensorAnim$sensor_type_id)])>0){
NoSens <- as.character(sensorTypes$name[sensorTypes$id%in%sensorID[!sensorID%in%unique(sensorAnim$sensor_type_id)]])
stop("Sensor(s): '",paste0(NoSens,collapse = ", "), "' is/are not available for this study" )}
NoDat <- idData$local_identifier[!unlist(lapply(1:nrow(idData),function(x){is.element(sensorID,sensorAnim$sensor_type_id[sensorAnim$individual_id==idData$individual_id[x]])}))]
if(length(NoDat)>0){
animalName <- animalName[!animalName%in%idData$individual_id[as.character(idData$local_identifier)%in%as.character(NoDat)]]
if(length(NoDat)<=90){
warning("Individual(s): '", paste0(as.character(NoDat),collapse = ", "),"' do(es) not have data for one or more of the selected sensor(s). Data for this/these individual(s) are not downloaded.")
}else{
warning("Individual(s): '", paste0(as.character(NoDat[1:90]),collapse = ", "), "' ... and ", (length(NoDat)-90) ," more (total ",length(NoDat), ") do not have data for one or more of the selected sensor(s). Data for these individuals are not downloaded.")}
}
LocData <-do.call('rbind',
lapply(split(animalName, ceiling(1:length(animalName)/200)), function(x,...){
getMovebank("event", login=login, study_id=study, sensor_type_id=sensorID, individual_id=x, attributes="all",...)}, ...))
if(nrow(LocData)==0){
stop("This Individual/All Individuals has/have 0 data points for the selected sensor(s)." )}
WithData <- unique(LocData$individual_id)
if(!setequal(animalName, WithData)){
withNoData <- idData$local_identifier[!idData$individual_id%in%WithData]
if(length(withNoData)<=90){
warning("Individual(s): '",paste0(as.character(withNoData),collapse = ", "), "' have 0 data points for one or more of the selected sensor(s).")
}else{
warning("Individuals: '", paste0(as.character(withNoData[1:90]),collapse = ", "), "' ... and ", (length(withNoData)-90) ," more (total ",length(withNoData), ") have 0 data points for one or more of the selected sensor(s).")}
}
attbsFrist <- c("event_id","visible","timestamp" ,"location_long","location_lat")
attribsAll <- colnames(LocData)
attribs <- c(attbsFrist,attribsAll[!attribsAll%in%attbsFrist])
LocData <- LocData[, attribs]
LocData$timestamp <- as.POSIXct(strptime(as.character(LocData$timestamp), format = "%Y-%m-%d %H:%M:%OS",tz="UTC"), tz="UTC")
LocData$study_name <- as.character(getMovebankStudy(study, login)$name)
for(i in unique(LocData$sensor_type_id)){
LocData$sensor_type[LocData$sensor_type_id==i] <- as.character(sensorTypes$name[sensorTypes$id==i])
}
if(!includeOutliers ){
LocDataOutl <- LocData[LocData$visible=="true",]
if(underscoreToDots){
names(LocDataOutl) <- gsub("_",".",names(LocDataOutl))
return(LocDataOutl)
}else{return(LocDataOutl)}
}
if(includeOutliers){
if(underscoreToDots){
names(LocData) <- gsub("_",".",names(LocData))
return(LocData)
}else{return(LocData)}
}
})
setGeneric("getMovebankReferenceTable", function(study, login, allAttributes=FALSE) standardGeneric("getMovebankReferenceTable"))
setMethod(f="getMovebankReferenceTable",
c(study="character", login="MovebankLogin"),
definition = function(study, login, allAttributes){
study <- getMovebankID(study,login)
callGeneric()
})
setMethod(f="getMovebankReferenceTable",
c(study="numeric", login="MovebankLogin"),
definition = function(study, login, allAttributes){
tags <- getMovebank(entity_type="sensor", login, tag_study_id=study)
tags$id <- NULL
tagNames <- getMovebank(entity_type="tag", login, study_id=study)
colnames(tagNames)[colnames(tagNames)%in%colnames(tagNames)[-grep("tag",colnames(tagNames))]] <- paste0("tag_",colnames(tagNames)[-grep("tag",colnames(tagNames))])
tagAtrb <- merge.data.frame(x=tags, y=tagNames, by="tag_id",all=T)
animalAtrb <- getMovebank("individual", login, study_id=study)
colnames(animalAtrb) <- paste0("animal_",colnames(animalAtrb))
deploymentID <- getMovebank("deployment", login=login, study_id=study, attributes="individual_id%2Ctag_id%2Cid")
names(deploymentID) <- sub('^id$','deployment_id', names(deploymentID))
names(deploymentID) <- sub('^individual_id$','animal_id', names(deploymentID))
deploymentAtrb <- getMovebank("deployment", login=login, study_id=study)
colnames(deploymentAtrb)[colnames(deploymentAtrb)%in%c("comments","id","local_identifier")] <- paste0("deployment_",c("comments","id","local_identifier"))
deploymentAtrbs <- merge.data.frame(x=deploymentAtrb, y=deploymentID, by="deployment_id",all=T)
tagdep <- merge.data.frame(tagAtrb,deploymentAtrbs, by="tag_id",all=T)
animtagdep <- merge.data.frame(animalAtrb,tagdep, by="animal_id",all=T)
colnames(animtagdep)[which(names(animtagdep) == "animal_number_of_events")] <- "number_of_location_events"
Sens <- getMovebankSensors(login=login)[c("id","is_location_sensor")]
nonLocSens <- Sens$id[Sens$is_location_sensor=="false"]
animtagdep$number_of_location_events[animtagdep$sensor_type_id%in%nonLocSens] <- NA
if(nrow(animtagdep)==0){stop("Reference data are not available: maybe you have no permission to download this dataset, or maybe password is invalid.")}
if(study=="character"){animtagdep$study_id <- getMovebankID(study,login)}else{animtagdep$study_id <- study}
RefData <- animtagdep[,c("animal_local_identifier","tag_local_identifier","sensor_type_id", names(animtagdep)[!names(animtagdep)%in%c("animal_local_identifier","tag_local_identifier","sensor_type_id")])]
if(allAttributes){
return(RefData)
}else{
RefDataRed <- RefData[, colSums(is.na(RefData)) != nrow(RefData)]
return(RefDataRed)
}
})
setMethod(f="getMovebankReferenceTable",
c(study="ANY", login="missing"),
definition = function(study, login, allAttributes){
login <- movebankLogin()
getMovebankReferenceTable(study=study,login=login,allAttributes=FALSE)
}) |
context("search_common")
test_that("search_common basic functionality works", {
vcr::use_cassette("search_common", {
aa <- search_common(x = "american bullfrog")
})
expect_is(aa, "data.frame")
expect_is(aa, "tbl_df")
expect_is(aa$tsn, "character")
expect_gt(NROW(aa), 0)
})
test_that("search_common - xml works", {
vcr::use_cassette("search_common-xml", {
aa <- search_common(x = "american bullfrog", wt = "xml")
})
expect_is(aa, "character")
expect_true(grepl("xmlns", aa))
})
test_that("search_common - raw JSON works", {
vcr::use_cassette("search_common-json", {
aa <- search_common(x = "american bullfrog", raw = TRUE)
})
expect_is(aa, "character")
expect_false(grepl("xmlns", aa))
})
test_that("search_common fails well", {
expect_error(search_common(), "\"x\" is missing")
expect_error(search_common("asdfadf", wt = "ffa"), "'wt' must be one of")
vcr::use_cassette("search_common-fails-well", {
tmp <- search_common(x = "asdfadf")
expect_is(tmp, "tbl_df")
expect_equal(NROW(tmp), 0)
})
}) |
PMPcomplement<-function(results){
Nhypo <- length(results$hypotheses)
varnames <- names(results$estimates)
equal <- vector(mode = "integer",length = Nhypo)
equal[1:Nhypo] <- 0
temphypo <- results$hypotheses
temphypo <- gsub("=~", "~", temphypo)
for (t in 1:Nhypo){
if (!grepl("=", temphypo[t], fixed = TRUE)) equal[t] <- 1
}
hypo <- results$hypotheses
for (t in 1:Nhypo){
if (equal[t] == 1){
check <- checkconsist(varnames,hypo[t])
if (check == 1) equal[t] <- -1
}
}
Nineq <- sum(equal == 1)
Ncombi <- 0
if (Nineq > 1){
for (t in 2:Nineq){
Ncombi <- Ncombi + choose(Nineq,t)
}
}
Hcombi <- vector(mode = "character",length = Ncombi)
combitel <- 0
if (Nineq > 1) {
for (combi in 2:Nineq) {
combies <- combn(Nhypo,combi)
for (tc in 1:dim(combies)[2]){
hit <- 1
for (tr in 1:combi){
if (equal[combies[tr,tc]] != 1) hit <-0
}
if (hit == 1) {
combitel <- combitel + 1
Hcombi[combitel] <- paste(results$hypotheses[combies[1:combi,tc]], collapse="&")
}
}
}
}
if (combitel > 0){
Process <- vector(mode = "integer",length = length(Hcombi))
Process[1:length(Hcombi)] <-1
for (t in 1:combitel){
check <- checkconsist(varnames,Hcombi[t])
if (check == 1) Process[t] <- 0
}
}
fit <- vector(mode = "numeric",length = (Nhypo + combitel))
com <- vector(mode = "numeric",length = (Nhypo + combitel))
fit[1:Nhypo] <- results$fit$Fit[1:Nhypo]
com[1:Nhypo] <- results$fit$Com[1:Nhypo]
if (combitel > 0){
Hcombisubset <- vector(mode = "character",length = sum(Process))
Subtel <- 1
for (Htel in 1:combitel){
if (Process[Htel] == 0){fit[Nhypo+Htel] <- 0
com[Nhypo+Htel] <- 0}
if (Process[Htel] == 1){
Hcombisubset[Subtel] <- Hcombi[Htel]
Subtel <- Subtel + 1
}
}
if (sum(Process) > 0) {
subforbain <- paste0(Hcombisubset, collapse=";")
resultscombi <-bain(results$estimates,Sigma=results$Sigma,n=results$n, subforbain,
group_parameters = results$group_parameters,
joint_parameters = results$joint_parameters,
fraction = results$fraction,gocomplement = FALSE)
Subtel <- 1
for (Htel in 1:combitel){
if (Process[Htel] == 1){
fit[Nhypo + Htel] <- resultscombi$fit$Fit[Subtel]
com[Nhypo + Htel] <- resultscombi$fit$Com[Subtel]
Subtel <- Subtel + 1
}
}
}
order <- vector(mode = "integer",length = (combitel))
loctel <- 1
for (ordertel in 2:sum(equal == 1)){
numord <- choose(sum(equal == 1),ordertel)
order[loctel:(loctel + numord -1)] <- ordertel
loctel <- loctel + numord
}
}
jointfit <- 0
for (tel in 1:Nhypo){
if (equal[tel] == 1){jointfit <- jointfit + fit[tel]}
}
if (combitel > 0){
for (tel in 1:combitel){
if (order[tel] %% 2 == 0) {jointfit <- jointfit - fit[Nhypo + tel]}
if (order[tel] %% 2 == 1) {jointfit <- jointfit + fit[Nhypo + tel]}
}
}
jointcom <- 0
for (tel in 1:Nhypo){
if (equal[tel] == 1){jointcom <- jointcom + com[tel]}
}
if (combitel > 0){
for (tel in 1:combitel){
if (order[tel] %% 2 == 0) {jointcom <- jointcom - com[Nhypo + tel]}
if (order[tel] %% 2 == 1) {jointcom <- jointcom + com[Nhypo + tel]}
}
}
BF <- vector(mode = "numeric", length = (Nhypo + 1))
PMPc <- vector(mode = "numeric",length = (Nhypo + 1))
results$fit["Hc",]<-NA
results$fit[,"PMPc"]<-NA
results <- results[names(results)!="gocomplement"]
results <- results[names(results)!="fraction"]
complf <- 1 - jointfit
if (complf < 0){complf <- 0}
complc <- 1 - jointcom
if (complc < 0){complc <- 0}
if (complc < .05) {
BF[1:Nhypo] <- results$fit$BF.u[1:Nhypo]
BF[Nhypo + 1] <- NA
PMPc[1:(Nhypo + 1)] <- NA
results$fit[,"PMPc"] <- c(PMPc[1:Nhypo], NA, PMPc[Nhypo+1])
results$fit["Hc","BF.u"] <- BF[Nhypo + 1]
results$fit["Hc","Fit"] <- complf
results$fit["Hc","Com"] <- complc
}
if (combitel > 0 & complc >= .05){
BF[1:Nhypo] <- results$fit$BF.u[1:Nhypo]
BF[Nhypo + 1] <- complf / complc
PMPc <- BF/sum(BF)
results$fit[,"PMPc"] <- c(PMPc[1:Nhypo], NA, PMPc[Nhypo+1])
results$fit["Hc","BF.u"] <- BF[Nhypo + 1]
results$fit["Hc","Fit"] <- complf
results$fit["Hc","Com"] <- complc
}
if (combitel == 0 & Nineq == 0 & complc >= .05){
BF[1:Nhypo] <- results$fit$BF.u[1:Nhypo]
BF[Nhypo + 1] <- NA
PMPc <- results$fit$PMPb
complf <- NA
complc <- NA
results$fit[,"PMPc"] <- c(PMPc[1:Nhypo], NA, PMPc[Nhypo+1])
results$fit["Hc","BF.u"] <- BF[Nhypo + 1]
results$fit["Hc","Fit"] <- complf
results$fit["Hc","Com"] <- complc
}
if (combitel ==0 & Nineq == 1 & complc >= .05){
BF[1:Nhypo] <- results$fit$BF.u[1:Nhypo]
BF[Nhypo + 1] <- complf/complc
PMPc <- BF/sum(BF)
results$fit[,"PMPc"] <- c(PMPc[1:Nhypo], NA, PMPc[Nhypo+1])
results$fit["Hc","BF.u"] <- BF[Nhypo + 1]
results$fit["Hc","Fit"] <- complf
results$fit["Hc","Com"] <- complc
}
return(results)
}
checkconsist <- function(varnames,hypo){
Rrres <- parse_hypothesis(varnames,hypo)
Rexclc <- Rrres$hyp_mat[[1]][,1:dim(Rrres$hyp_mat[[1]])[2]-1]
Rinclc <- Rrres$hyp_mat[[1]][,1:dim(Rrres$hyp_mat[[1]])[2]]
check <- 0
Rexabout <- split(Rexclc,Rinclc)$Rexabout
Rexnone <- split(Rexclc,Rinclc)$Rexnone
Rinabout <- split(Rexclc,Rinclc)$Rinabout
Rinnone <- split(Rexclc,Rinclc)$Rinnone
if (qr(Rexclc)$rank < Rrres$n_constraints[2] & nrow(Rinabout) > 1){
for (r1 in 1:(nrow(Rinabout)-1)){
for (r2 in (r1+1):nrow(Rinabout)){
tworow <- Rexabout[c(r1,r2),]
if (qr(tworow)$rank == 1 &
!identical(Rexabout[r1,],Rexabout[r2,])&
(Rinabout[r1,dim(Rinabout)[2]] + Rinabout[r2,dim(Rinabout)[2]]) >= 0)
{check <- 1}
if (check == 1){break}
}
if (check == 1){break}
}
}
if (!is.null(nrow(Rexnone))){
if (nrow(Rexnone) > 1 & check == 0){
if (qr(Rexnone)$rank < nrow(Rexnone)){
for (t in 1:nrow(Rexnone)){
allbutone <- Rexnone[(-1*t),]
if (!is.null(dim(allbutone)[1])) {allbutone <- makefullrank(allbutone)}
one <- Rexnone[t,]
allbutoneplusone <- rbind(allbutone,one)
if (qr(allbutoneplusone)$rank < nrow(allbutoneplusone)){
lincoef <- 0
if (is.null(dim(allbutone)[1])) {lincoef <- qr.solve(allbutone,one)} else {lincoef <- qr.solve(t(allbutone),one)}
lincoef <- round(lincoef,2)
if (all(lincoef <= 0)) {check <- 1
break}
}
}
}
}
}
return(check)
}
makefullrank <- function(consmat){
s <- 1
repeat{
if(dim(consmat)[1] == qr(consmat)$rank) {
break
}
removeone <- consmat[(-1*s),]
if (qr(consmat)$rank == qr(removeone)$rank){
consmat <- removeone
} else {s <- s+1}
if (is.null(dim(consmat)[1])){break}
}
return(consmat)
}
split <- function(Rexclc,Rinclc){
if (is.null(dim(Rexclc)[1])){
Ncol <- length(Rexclc)
Nrows <- 1
} else {
Ncol <- dim(Rexclc)[2]
Nrows <- nrow(Rexclc)
}
abrows <- vector(mode = "integer",length = Nrows)
abrows[1:Nrows] <- 0
rowcount <- 0
if (Nrows > 1){
for (r in 1:(Nrows-1)){
for (t in (r+1):Nrows){
if (!(r %in% abrows) & !(t %in% abrows)){
lincoef <- 1
for (h in 1: Ncol){
if (Rexclc[r,h] != 0 & Rexclc[t,h] != 0){
lincoef <- abs(Rexclc[r,h]/Rexclc[t,h])
}
}
Rtemp <- lincoef * Rexclc[r,]
if (identical(Rtemp,-1*Rexclc[t,]) == TRUE){
abrows[rowcount+1] <- r
abrows[rowcount+2] <- t
rowcount <- rowcount + 2
}
}
}
}
}
if (sum(abrows) == 0){Rexabout <- t(Rexclc)[0,]
Rexnone <- Rexclc} else
{ Rexabout <- Rexclc[abrows,]
Rexnone <- Rexclc[-1*abrows,]}
if (sum(abrows) == 0){Rinabout <- t(Rinclc)[0,]
Rinnone <- Rinclc} else
{ Rinabout <- Rinclc[abrows,]
Rinnone <- Rinclc[-1*abrows,]}
if (sum(abrows)>0){
Ncol <- dim(Rinabout)[2]
Nrows <- nrow(Rinabout)
abrowsub <- vector(mode = "integer",length = Nrows)
abrowsub <- c(1:Nrows)
if (Nrows > 2){
rowcount <- 0
for (r in 1:(Nrows-1)){
for (t in (r+1):Nrows){
lincoef <- 1
for (h in 1:(Ncol-1)){
if (Rinabout[r,h] != 0 & Rinabout[t,h] != 0){
lincoef <- abs(Rinabout[r,h]/Rinabout[t,h])
}
}
Rintemp <- lincoef * Rinabout[r,]
if (identical(Rintemp,Rinabout[t,]) == TRUE){
abrowsub <- replace(abrowsub, abrowsub==t, 0)
}
}
}
Rexabout <- Rexabout[abrowsub,]
Rinabout <- Rinabout[abrowsub,]
}
}
splitres <- list("Rexabout" = Rexabout, "Rexnone" = Rexnone,
"Rinabout" = Rinabout, "Rinnone" = Rinnone)
return(splitres)
} |
ic_spTran_copula <- function(data, var_list, l=0, u, copula = "Copula2", m = 3, r = 3,
method = "BFGS", iter=300, stepsize=1e-6, hes = TRUE,
control = list()){
if (!is.data.frame(data)) {
stop('data must be a data frame')
}
if ((!"id" %in% colnames(data)) |
(!"ind" %in% colnames(data)) |
(!"Left" %in% colnames(data)) |
(!"Right" %in% colnames(data)) |
(!"status" %in% colnames(data))) {
stop('data must have id, ind, Left, Right and status')
}
if (!copula %in% c("Clayton","Gumbel","Copula2","Frank","Joe","AMH")) {
stop('copula must be one of "Clayton","Gumbel","Copula2","Frank","Joe","AMH"')
}
if (l<0 | u <= max(data$Left[is.finite(data$Left)],data$Right[is.finite(data$Right)])) {
stop('l must be >= 0 and u greater than non-infinite values of Left and Right')
}
if (r <= 0) {
stop('r must be a positive number')
}
if (m != round(m)) {
stop('m must be a positive integer')
}
if (!method %in% c("Newton","Nelder-Mead","BFGS","CG","SANN")) {
stop('m.dist must be one of "Newton","Nelder-Mead","BFGS","CG","SANN"')
}
data_processed <- data_process_sieve(data, l, u, var_list, m)
indata1 <- data_processed$indata1
indata2 <- data_processed$indata2
t1_left <- data_processed$t1_left
t1_right <- data_processed$t1_right
t2_left <- data_processed$t2_left
t2_right <- data_processed$t2_right
n <- data_processed$n
p <- data_processed$p
x1 <- data_processed$x1
x2 <- data_processed$x2
var_list <- data_processed$var_list
bl1 <- data_processed$bl1
br1 <- data_processed$br1
bl2 <- data_processed$bl2
br2 <- data_processed$br2
if (method == "Newton") {
model_step1a <- nlm(estimate_sieve_step1a, rep(0, (p+m+1)), hessian = FALSE,
iterlim = iter, steptol = stepsize,
p, m = m, x1 = x1, x2 = x2, bl1 = bl1, br1 = br1, bl2 = bl2,
br2 = br2, indata1 = indata1, indata2 = indata2, r = r)
beta <- model_step1a$estimate[1:p]
phi <- model_step1a$estimate[(p+1):(p+1+m)]
ep<-cumsum(exp(phi))
}
if (method != "Newton") {
model_step1a <- optim(par = rep(0,(p+m+1)), estimate_sieve_step1a,
method = method, hessian = FALSE,
p = p, m = m, x1 = x1, x2 = x2, bl1 = bl1, br1 = br1,
bl2 = bl2, br2 = br2, indata1 = indata1, indata2 = indata2,
r = r, control = control)
beta <- model_step1a$par[1:p]
phi <- model_step1a$par[(p+1):(p+1+m)]
ep <- cumsum(exp(phi))
}
if (copula == "AMH") {
eta_ini <- 0
}
else if (copula == "Copula2") {
eta_ini <- c(0, 0)
}
else {
eta_ini <- 0
}
if (method == "Newton") {
model_step1b <- nlm(ic_copula_log_lik_sieve_eta, eta_ini, hessian = FALSE,
beta = beta, ep = ep, x1 = x1, x2 = x2, bl1 = bl1,
br1 = br1, bl2 = bl2, br2 = br2, indata1 = indata1,
indata2 = indata2, r = r, copula = copula)
eta_ini <- exp(model_step1b$estimate)
} else {
model_step1b <- optim(par = eta_ini, ic_copula_log_lik_sieve_eta,
method = method, control = control, hessian = FALSE,
beta = beta, ep = ep, x1 = x1, x2 = x2, bl1 = bl1,
br1 = br1, bl2 = bl2, br2 = br2, indata1 = indata1,
indata2 = indata2, r = r, copula = copula)
eta_ini <- exp(model_step1b$par)
}
if (copula == "AMH" & eta_ini[1] > 1) {eta_ini <- 0.5}
if (copula == "Gumbel" & eta_ini[1] < 1) {eta_ini <- 1}
if (copula == "Joe" & eta_ini[1] < 1) {eta_ini <- 1}
if (copula == "Copula2" & eta_ini[1] > 1) {eta_ini[1] <- 0.5}
if (method == "Newton") {
model_step2 <- nlm(ic_copula_log_lik_sieve, c(model_step1a$estimate,eta_ini),
hessian = hes, iterlim = iter ,steptol = stepsize,
p, m = m, x1 = x1, x2 = x2, bl1 = bl1, br1 = br1, bl2 = bl2,
br2 = br2, indata1 = indata1, indata2 = indata2, r = r,
copula = copula)
if (isTRUE(hes)) {
inv_info <- pseudoinverse(model_step2$hessian)
dih <- diag(inv_info)
dih[dih < 0] <- 0
dih <- sqrt(dih)
se <- if (copula != "Copula2") dih[c(1:p,length(dih))] else dih[c(1:p,length(dih)-1,length(dih))]
beta <- if (copula != "Copula2") model_step2$estimate[c(1:p,length(dih))] else model_step2$estimate[c(1:p,length(dih)-1,length(dih))]
llk <- -1 * model_step2$minimum
AIC <- 2 * length(model_step2$estimate) - 2 * llk
stat <- (beta-0)^2/se^2
pvalue <- pchisq(stat, 1, lower.tail=F)
summary <- cbind(beta, se, stat, pvalue)
tmp_name2 <- if (copula != "Copula2") c("eta") else c("alpha","kappa")
rownames(summary) <- c(var_list, tmp_name2)
colnames(summary) <- c("estimate","SE","stat","pvalue")
code <- model_step2$code
}
if (!isTRUE(hes)) {
inv_info = NULL
beta <- if (copula != "Copula2") model_step2$estimate[c(1:p,length(model_step2$estimate))] else model_step2$estimate[c(1:p,length(model_step2$estimate)-1,length(model_step2$estimate))]
llk <- -1 * model_step2$minimum
AIC <- 2 * length(model_step2$estimate) - 2 * llk
summary = cbind(beta)
tmp_name2 <- if (copula != "Copula2") c("eta") else c("alpha","kappa")
rownames(summary) <- c(var_list, tmp_name2)
colnames(summary) <- c("estimate")
code <- model_step2$code
}
output <- list(code = code, summary = summary, llk = llk, AIC = AIC, copula = copula,
m = m, r = r, indata1 = indata1, indata2 = indata2, var_list = var_list,
l = l, u = u, bl1 = bl1, br1 = br1, bl2 = bl2, br2 = br2,
estimates = model_step2$estimate, x1 = x1, x2 = x2,inv_info = inv_info)
}
if (method != "Newton") {
model_step2 <- optim(par = c(model_step1a$par,eta_ini), ic_copula_log_lik_sieve,
method = method, hessian = hes, control = control,
p = p, m = m, x1 = x1, x2 = x2, bl1 = bl1, br1 = br1,
bl2 = bl2, br2 = br2, indata1 = indata1, indata2 = indata2,
r = r, copula = copula)
if (isTRUE(hes)) {
inv_info <- pseudoinverse(model_step2$hessian)
dih <- diag(inv_info)
dih[dih < 0] = 0
dih <- sqrt(dih)
se <- if (copula != "Copula2") dih[c(1:p,length(dih))] else dih[c(1:p,length(dih)-1,length(dih))]
beta <- if (copula != "Copula2") model_step2$par[c(1:p,length(dih))] else model_step2$par[c(1:p,length(dih)-1,length(dih))]
llk <- -1 * model_step2$value
AIC <- 2 * length(model_step2$par) - 2 * llk
stat = (beta-0)^2/se^2
pvalue = pchisq(stat, 1, lower.tail=F)
summary = cbind(beta, se, stat, pvalue)
tmp_name2 <- if (copula != "Copula2") c("eta") else c("alpha","kappa")
rownames(summary) <- c(var_list, tmp_name2)
colnames(summary) <- c("estimate","SE","stat","pvalue")
code <- model_step2$convergence
}
if (!isTRUE(hes)) {
inv_info = NULL
beta <- if (copula != "Copula2") model_step2$par[c(1:p,length(model_step2$par))] else model_step2$par[c(1:p,length(model_step2$par)-1,length(model_step2$par))]
llk <- -1 * model_step2$value
AIC <- 2 * length(model_step2$par) - 2 * llk
summary <- cbind(beta)
tmp_name2 <- if (copula != "Copula2") c("eta") else c("alpha","kappa")
rownames(summary) <- c(var_list, tmp_name2)
colnames(summary) <- c("estimate")
code <- model_step2$convergence
}
output <- list(code = code, summary = summary, llk = llk, AIC = AIC, copula = copula,
m = m, r = r, indata1 = indata1, indata2 = indata2, var_list = var_list,
l = l, u = u, bl1 = bl1, br1 = br1, bl2 = bl2, br2 = br2,
estimates = model_step2$par, x1 = x1, x2 = x2, inv_info = inv_info)
}
class(output) <- "CopulaCenR"
return(output)
} |
expected <- eval(parse(text="c(\"1\", NA, \"3\", \"4\", \"5\", \"6\", \"7\")"));
test(id=0, code={
argv <- eval(parse(text="list(structure(c(0.434200949779115, NA, 0.907914219551846, 0.907914219551846, 0.907914219551846, 0.434200949779115, 0.434200949779115), .Names = c(\"1\", NA, \"3\", \"4\", \"5\", \"6\", \"7\")))"));
do.call(`names`, argv);
}, o=expected); |
context("tests the processSSE function")
test_that("processes SSE traces", {
bisse_file <- system.file("extdata",
"sse/primates_BiSSE_activity_period_mini.p",
package="RevGadgets")
pdata <- processSSE(bisse_file)
expect_equal(class(pdata), "data.frame")
expect_equal(ncol(pdata), 6)
expect_equal(colnames(pdata), c("value", "rate", "hidden_state", "label",
"observed_state", "Iteration" ))
}) |
'
Authors
Torsten Pook, [email protected]
Copyright (C) 2017 -- 2020 Torsten Pook
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
'
find.chromo <- function(position, length.total){
chromo <- min(sum(position<=length.total), length(length.total)-1)
return(chromo)
} |
add_atop_alliance <- function(data) {
if (length(attributes(data)$ps_data_type) > 0 && attributes(data)$ps_data_type %in% c("dyad_year", "leader_dyad_year")) {
if (!all(i <- c("ccode1", "ccode2") %in% colnames(data))) {
stop("add_atop_alliance() merges on two Correlates of War codes (ccode1, ccode2), which your data don't have right now. Make sure to run create_dyadyears() at the top of the pipe. You'll want the default option, which returns Correlates of War codes.")
} else {
atop_alliance %>%
left_join(data, .) %>%
mutate_at(vars("atop_defense", "atop_offense", "atop_neutral", "atop_nonagg", "atop_consul"), ~ifelse(is.na(.) & year <= 2018, 0, .)) -> data
}
} else if (length(attributes(data)$ps_data_type) > 0 && attributes(data)$ps_data_type %in% c("state_year", "leader_year")) {
stop("Right now, there is only support for dyad-year data.")
} else {
stop("add_atop_alliance() requires a data/tibble with attributes$ps_data_type of dyad_year or leader_dyad_year. Try running create_dyadyears() or create_leaderdyadyears() at the start of the pipe.")
}
return(data)
} |
getClonalityWithError<-function(integerCN,
beta,
adm.global.thisZone,
adm.global.thisZone.min,
adm.global.thisZone.max,
clonalityThreshold,
local.error,
roundDec=3){
if(integerCN == 0){
if (beta==0){
betaCorr <- NA
zone.ctm.local <- NA
clonality <- NA
clonality.int <- interval(NULL,NULL)
clonality.status <- "not.analysed"
}else{
betaCorr <- beta
zone.ctm.local <- beta / (2 - beta)
G <- adm.global.thisZone
L <- zone.ctm.local
clonality <- setBetween0and1(1- ((G - ( L * G)) / ( L * ( 1 - G))))
zone.ctm.local.min <- zone.ctm.local - local.error
zone.ctm.local.max <- zone.ctm.local + local.error
G.int <- interval(adm.global.thisZone.min,adm.global.thisZone.max)
L.int <- interval(zone.ctm.local.min,zone.ctm.local.max )
clonality.int <- 1 - ((G.int - ( L.int * G.int)) / ( L.int * ( 1 - G.int)))
clonality.int <- interval(setBetween0and1(min(clonality.int)),setBetween0and1(max(clonality.int)))
}
}
if (integerCN == 1){
betaCorr <- beta
zone.ctm.local <- beta / (2 - beta)
clonality <- setBetween0and1((1 - zone.ctm.local) / (1 - adm.global.thisZone))
zone.ctm.local.min <- zone.ctm.local - local.error
zone.ctm.local.max <- zone.ctm.local + local.error
zone.ctm.local.int <- interval(zone.ctm.local.min,zone.ctm.local.max)
adm.global.thisZone.int <- interval(adm.global.thisZone.min,adm.global.thisZone.max)
clonality.int <- ( 1 - zone.ctm.local.int) / (1 - adm.global.thisZone.int)
clonality.int <- interval(setBetween0and1(min(clonality.int)),setBetween0and1(max(clonality.int)))
}
if (integerCN == 2){
betaCorr <- beta
zone.ctm.local <- betaCorr
clonality <- zone.ctm.local
zone.ctm.local.min <- zone.ctm.local - local.error
zone.ctm.local.max <- zone.ctm.local + local.error
clonality.int <- interval(zone.ctm.local.min,zone.ctm.local.max)
clonality.int <- interval(setBetween0and1(min(clonality.int)),setBetween0and1(max(clonality.int)))
}
if (integerCN == 3){
betaCorr <- 1 - (3 * (1 - beta) )
if ( betaCorr > 0){
zone.ctm.local <- ( 3 * betaCorr ) / (( 3 - 2 ) * betaCorr + 2)
clonality <- setBetween0and1((1 - zone.ctm.local) / (1 - adm.global.thisZone))
zone.ctm.local.min <- zone.ctm.local - local.error
zone.ctm.local.max <- zone.ctm.local + local.error
zone.ctm.local.int <- interval(zone.ctm.local.min,zone.ctm.local.max)
adm.global.thisZone.int <- interval(adm.global.thisZone.min,adm.global.thisZone.max)
clonality.int <- ( 1 - zone.ctm.local.int) / (1 - adm.global.thisZone.int)
clonality.int <- interval(setBetween0and1(min(clonality.int)),setBetween0and1(max(clonality.int)))
}else{
betaCorr <- NA
zone.ctm.local <- NA
clonality <- NA
clonality.int <- interval(NULL,NULL)
clonality.status <- "not.analysed"
}
}
if (integerCN == 4){
betaCorr <- beta
zone.ctm.local <- ( 4 * betaCorr ) / ((4-2) * betaCorr +2 )
clonality <- setBetween0and1(zone.ctm.local )
zone.ctm.local.min <- zone.ctm.local - local.error
zone.ctm.local.max <- zone.ctm.local + local.error
clonality.int <- interval(zone.ctm.local.min,zone.ctm.local.max)
clonality.int <- interval(setBetween0and1(min(clonality.int)),setBetween0and1(max(clonality.int)))
}
if (integerCN == 5){
betaCorr <- 1 - (5 * (1 - beta) )
if ( betaCorr > 0){
zone.ctm.local <- ( 5 * betaCorr ) / (( 5 - 2 ) * betaCorr + 2)
clonality <- setBetween0and1((1 - zone.ctm.local) / (1 - adm.global.thisZone))
zone.ctm.local.min <- zone.ctm.local - local.error
zone.ctm.local.max <- zone.ctm.local + local.error
zone.ctm.local.int <- interval(zone.ctm.local.min,zone.ctm.local.max)
adm.global.thisZone.int <- interval(adm.global.thisZone.min,adm.global.thisZone.max)
clonality.int <- ( 1 - zone.ctm.local.int) / (1 - adm.global.thisZone.int)
clonality.int <- interval(setBetween0and1(min(clonality.int)),setBetween0and1(max(clonality.int)))
}else{
betaCorr <- NA
zone.ctm.local <- NA
clonality <- NA
clonality.int <- interval(NULL,NULL)
clonality.status <- "not.analysed"
}
}
if (integerCN > 5){
betaCorr <- NA
zone.ctm.local <- NA
clonality <- NA
clonality.int <- interval(NULL,NULL)
clonality.status <- "not.analysed"
}
if (interval_is_empty(clonality.int)){
clonality.min <- NA
clonality.max <- NA
}else{
clonality <- round(clonality,roundDec)
clonality.min <- round(min(clonality.int),roundDec)
clonality.max <- round(max(clonality.int),roundDec)
if ( clonality.min >= clonalityThreshold ){ clonality.status <- "clonal"}
if ( clonality.max <= clonalityThreshold ){ clonality.status <- "subclonal"}
if ( clonality.min <= clonalityThreshold && clonality.max >= clonalityThreshold && clonality < clonalityThreshold ) { clonality.status <- "uncertain.subclonal" }
if ( clonality.min <= clonalityThreshold && clonality.max >= clonalityThreshold && clonality >= clonalityThreshold ){ clonality.status <- "uncertain.clonal"}
}
data<-data.frame(row.names=1,stringsAsFactors=F)
data$betaCorr <- betaCorr
data$zone.ctm.local <- zone.ctm.local
data$clonality <- clonality
data$clonality.min <- clonality.min
data$clonality.max <- clonality.max
data$clonality.status <- clonality.status
return(data)
}
compute_clonality <- function(betaTable,errorTable,clonalityThreshold,betaThreshold=NULL,roundDec = 3,n_cores=1){
if (is.null(betaThreshold)){betaThreshold<-clonalityThreshold}
betaTable$integerCN <- NA
betaTable$clonality <- NA
betaTable$clonality.min <- NA
betaTable$clonality.max <- NA
betaTable$clonality.status <- "not.analysed"
getIndexClonality <- function(i){
zone <- betaTable[i,,drop=F]
zone$adm.global <- round(zone$adm,roundDec)
zone$adm.global.min <- round(zone$adm.min,roundDec)
zone$adm.global.max <- round(zone$adm.max,roundDec)
if (is.na(zone$beta) || is.na(zone$log2.corr) || is.na( zone$adm.global.min) || is.na(zone$adm.global.max)){
return(zone)
}
nsnps <- zone$nsnp
cov <- zone$cov
idxError <- which(errorTable$n.info.snps <= nsnps & errorTable$mean.cov <= cov)
if (length(idxError) == 0 ){idxError <- 1}
local.error <- errorTable$adm.estimation.error[max(idxError)]
cn <- 2*2^zone$log2.corr
clonCNlow <- getClonalityWithError(integerCN=floor(cn),
beta=zone$beta,
adm.global.thisZone=zone$adm.global,
adm.global.thisZone.min=zone$adm.global.min,
adm.global.thisZone.max=zone$adm.global.max,
clonalityThreshold,
local.error,
roundDec)
clonCNhigh <- getClonalityWithError(integerCN=ceiling(cn),
beta=zone$beta,
adm.global.thisZone=zone$adm.global,
adm.global.thisZone.min=zone$adm.global.min,
adm.global.thisZone.max=zone$adm.global.max,
clonalityThreshold,
local.error,
roundDec)
if (is.null(clonCNlow) | is.null(clonCNhigh) | is.na(clonCNlow$clonality) | is.na(clonCNhigh$clonality) ){
return(zone)
}
if (cn >= 0 & cn < 1){
if ( zone$beta >= betaThreshold ){
zone$integerCN <- 0
zone$clonality <- clonCNlow$clonality
zone$clonality.min <- clonCNlow$clonality.min
zone$clonality.max <- clonCNlow$clonality.max
zone$clonality.status <- "clonal"
}else if (cn <= 0.8) {
zone$integerCN <- floor(cn)
zone$clonality <- clonCNlow$clonality
zone$clonality.min <- clonCNlow$clonality.min
zone$clonality.max <- clonCNlow$clonality.max
zone$clonality.status <- clonCNlow$clonality.status
}else{
zone$integerCN <- ceiling(cn)
zone$clonality <- clonCNhigh$clonality
zone$clonality.min <- clonCNhigh$clonality.min
zone$clonality.max <- clonCNhigh$clonality.max
zone$clonality.status <- clonCNhigh$clonality.status
}
}
if (cn >= 1 & cn < 2){
if (zone$beta <= betaThreshold){
zone$integerCN <- floor(cn)
zone$clonality <- clonCNlow$clonality
zone$clonality.min <- clonCNlow$clonality.min
zone$clonality.max <- clonCNlow$clonality.max
zone$clonality.status <- clonCNlow$clonality.status
}else{
zone$integerCN <- ceiling(cn)
zone$clonality <- clonCNhigh$clonality
zone$clonality.min <- clonCNhigh$clonality.min
zone$clonality.max <- clonCNhigh$clonality.max
zone$clonality.status <- "not.analysed"
}
}
if (cn >= 2 & cn <= 3){
if (zone$beta <= betaThreshold){
zone$integerCN <- ceiling(cn)
zone$clonality <- clonCNhigh$clonality
zone$clonality.min <- clonCNhigh$clonality.min
zone$clonality.max <- clonCNhigh$clonality.max
zone$clonality.status <- clonCNhigh$clonality.status
}else{
zone$integerCN <- floor(cn)
zone$clonality <- clonCNlow$clonality
zone$clonality.min <- clonCNlow$clonality.min
zone$clonality.max <- clonCNlow$clonality.max
zone$clonality.status <- "not.analysed"
}
}
return(zone)
}
clonalityTable.list <- mclapply(seq(1,nrow(betaTable),1), getIndexClonality, mc.preschedule = T, mc.cores = n_cores)
clonalityTable <- fromListToDF(clonalityTable.list)
return(clonalityTable)
}
compute_scna_clonality_table<-function(beta_table,
ploidy_table,
admixture_table,
error_tb = error_table,
clonality_threshold = 0.85,
beta_threshold = 0.90,
n_digits=3,
n_cores=1,
debug=F){
sample_id <- unique(beta_table$sample)
if (length(sample_id) != 1){stop(paste("[",Sys.time() ,"] beta_table must contain exactly one sample\n",sep=""))}
if (nrow(ploidy_table) !=1 || nrow(admixture_table) !=1 || (pls = ploidy_table$sample) != sample_id || (ads = admixture_table$sample) != sample_id){
stop(paste("[",Sys.time() ,"] ploidy_table and admixture_table must contain only sample ",sample_id,"\n",sep=""))
}
beta_table <- merge(beta_table, ploidy_table, by="sample")
beta_table$log2shift <- round(-log2(beta_table$ploidy/2),n_digits)
beta_table$log2.plCorr <- round(beta_table$log2 - beta_table$log2shift, n_digits)
beta_table <- merge(x = beta_table, y = admixture_table, by="sample")
beta_table$log2.corr <- suppressWarnings(log2(pmax(( 2 ^ (beta_table$log2.plCorr ) - admixture_table$adm[1] ) / (1 - admixture_table$adm[1]), 0)))
clonality_table <- compute_clonality(betaTable = beta_table,
errorTable = error_tb,
clonalityThreshold = clonality_threshold,
betaThreshold = beta_threshold,
roundDec = n_digits,
n_cores = n_cores )
if (!debug){
cols_to_save <- c("sample","chr","start","end","num.mark","log2","beta","nsnp","cov","n_beta","clonality","clonality.min","clonality.max","clonality.status")
clonality_table <- clonality_table[,intersect(colnames(clonality_table),cols_to_save)]
}
return(clonality_table)
} |
"pairData" |
test_that(
"test.is_empty_character.a_character_vector.returns_true_when_string_is_missing_or_empty",
{
x <- c(missing = NA_character_, empty = "", non_empty = "a", space = " ",
not_missing1 = "NA", not_missing2 = "<NA>")
expected <- c(FALSE, TRUE, FALSE, FALSE, FALSE, FALSE)
expect_equal(
strip_attributes(actual <- is_empty_character(x)),
expected
)
expect_equal(names(actual), unname(x))
expect_equal(
cause(actual),
noquote(rep.int(c("missing", "", "nonempty"), c(1, 1, 4)))
)
}
)
test_that(
"test.is_non_empty_character.a_character_vector.returns_true_when_string_is_missing_or_empty",
{
x <- c(missing = NA_character_, empty = "", non_empty = "a", space = " ",
not_missing1 = "NA", not_missing2 = "<NA>")
expected <- c(TRUE, FALSE, TRUE, TRUE, TRUE, TRUE)
expect_equal(
strip_attributes(actual <- is_non_empty_character(x)),
expected
)
expect_equal(names(actual), unname(x))
expect_equal(
cause(actual),
noquote(rep.int(c("", "empty", ""), c(1, 1, 4)))
)
}
)
test_that(
"test.is_missing_or_empty_character.a_character_vector.returns_true_when_string_is_missing_or_empty",
{
x <- c(missing = NA_character_, empty = "", non_empty = "a", space = " ",
not_missing1 = "NA", not_missing2 = "<NA>")
expected <- c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE)
expect_equal(
strip_attributes(actual <- is_missing_or_empty_character(x)),
expected
)
expect_equal(names(actual), unname(x))
expect_equal(
cause(actual),
noquote(rep.int(c("", "nonempty"), c(2, 4)))
)
}
)
test_that(
"test.is_non_missing_nor_empty_character.a_character_vector.returns_true_when_string_is_not_missing_nor_empty",
{
x <- c(missing = NA_character_, empty = "", non_empty = "a", space = " ",
not_missing1 = "NA", not_missing2 = "<NA>")
expected <- c(FALSE, FALSE, TRUE, TRUE, TRUE, TRUE)
expect_equal(
strip_attributes(actual <- is_non_missing_nor_empty_character(x)),
expected
)
expect_equal(names(actual), unname(x))
expect_equal(
cause(actual),
noquote(rep.int(c("missing", "empty", ""), c(1, 1, 4)))
)
}
) |
sir_ratio <- function(x, y, digits = 3, alternative = 'two.sided',
conf.level = 0.95, type = 'exact') {
if(inherits(x = x, what = 'sir')){
O1 <- sum(x$observed)
E1 <- sum(x$expected)
}
else if(is.vector(x) && length(x) == 2) {
O1 <- x[1]
E1 <- x[2]
}
else{
stop('Input x is not correct: x is neighter a vector of 2 nor sir-object')
}
if(inherits(y,'sir')){
O2 <- sum(y$observed)
E2 <- sum(y$expected)
}
else if(is.vector(y) && length(y) == 2) {
O2 <- y[1]
E2 <- y[2]
}
else{
stop('Input y is not correct: y is neighter a vector of 2 nor sir-object')
}
type <- match.arg(type, c('asymptotic', 'exact'), several.ok = FALSE)
alternative <- match.arg(alternative, c('two.sided','less', 'greater'), several.ok = FALSE)
p <- O1/(O1+O2)
if(type == 'asymptotic') {
alpha <- (1 - conf.level)/2
Ex <- p + c(-qnorm(1-alpha),qnorm(1-alpha)) * sqrt((1/(O1+O2))*p*(1-p))
if( alternative != 'two.sided') {
message('Test changed to two.sided when asymptotic.')
alternative <- 'two.sided'
}
}
if(type == 'exact') {
Ex <- binom.test(c(O1,O2), p = 0.5, alternative = alternative, conf.level = conf.level)$conf.int
}
B = Ex/(1-Ex)
res <- round(c(sir_ratio = (O1/E1)/(O2/E2), lower=(B*(E2/E1))[1], upper = (B*(E2/E1))[2]), digits = digits)
return(res)
} |
plot.amlps <- function(x, xp, smoo.index, cred.int = 0.95, plot.cred = TRUE,
np = 100, fit.col = "blue", shade.col = "gray75",
show.plot = TRUE, show.info = TRUE, ...){
if (smoo.index < 1 || smoo.index > x$q)
stop("smoo.index wrongly specified")
smoo.index <- as.integer(smoo.index)
if (!is.vector(cred.int, mode = "numeric") || length(cred.int) > 1 ||
is.na(cred.int) || is.infinite(cred.int) || cred.int <= 0 ||
cred.int >= 1)
stop("cred.int must be between 0 and 1")
if (!is.logical(plot.cred))
stop("plot.cred must be either TRUE or FALSE")
if(np < 20 || np > 200)
stop("choose np between 20 and 200")
if(is.null(x$data)) {
mf <- stats::model.frame(x$formula)
X <- stats::model.matrix(mf)
colXnames <- colnames(X)
smterms <- grepl("sm(", colnames(X), fixed = TRUE)
X <- cbind(X[, as.logical(1 - smterms)], X[, smterms])
colnames(X) <- colXnames
} else{
mf <- stats::model.frame(x$formula, data = x$data)
X <- stats::model.matrix(mf, data = x$data)
colXnames <- colnames(X)
smterms <- grepl("sm(", colnames(X), fixed = TRUE)
X <- cbind(X[, as.logical(1 - smterms)], X[, smterms])
colnames(X) <- colXnames
}
q <- x$q
p <- ncol(X) - q
n <- x$n
K <- x$K
splines <- x$spline.estim
j <- smoo.index
xj <- as.numeric(X[, p + j])
min.xgrid <- min(xj)
max.xgrid <- max(xj)
if(!missing(xp)){
if (any(xp < min.xgrid) || any(xp > max.xgrid))
stop("values in xp not in the range of observed covariates")
}
xgrid <- seq(min.xgrid, max.xgrid, length = np)
xj.fine <- seq(min.xgrid, max.xgrid, length = 1000)
Bj.fine <- cubicbs(xj.fine, lower = min.xgrid, upper = max.xgrid,
K = K)$Bmatrix
Bj.fine.mean <- colMeans(Bj.fine)
Bxgrid <- cubicbs(xgrid, lower = min.xgrid,
upper = max.xgrid, K = K)$Bmatrix
Bxgrid.centered <- Bxgrid - matrix(rep(Bj.fine.mean, np), nrow = np,
byrow = TRUE)
Bx <- Bxgrid.centered[, -K]
fhat <- as.numeric(Bx %*% splines[[j]])
alpha <- 1 - cred.int
latmaximum <- x$latmaximum
Covmaximum <- x$Covmaximum
thetaj.max <- latmaximum[((p + 1) + (j - 1) * (K - 1)) : (p + j * (K - 1))]
Sigj.max <- Covmaximum[((p + 1) + (j - 1) * (K - 1)):(p + j * (K - 1)),
((p + 1) + (j - 1) * (K - 1)):(p + j * (K - 1))]
postfj.mean <- as.numeric(Bx %*% thetaj.max)
postfj.sd <- sqrt(diag(Bx %*% Sigj.max %*% t(Bx)))
fj.lb <- fhat - stats::qnorm((1 - (alpha * .5))) * postfj.sd
fj.ub <- fhat + stats::qnorm((1 - (alpha * .5))) * postfj.sd
minf <- min(fj.lb)
maxf <- max(fj.ub)
shift.frame <- 0.3 * (maxf - minf)
covariate.name <- colnames(X)[(p + 1):(p + q)][smoo.index]
nchar.covariate <- nchar(covariate.name)
covariate.name <- substr(covariate.name, 4, nchar.covariate - 1)
if(show.plot == TRUE){
graphics::plot(xgrid, fhat, type = "l", col = fit.col, xlab = covariate.name,
ylab = paste0("sm(", covariate.name, ",",
format(round(x$EDf[smoo.index], 2), nsmall = 2),
")"), ...)
if(plot.cred == TRUE) {
graphics::polygon(x = c(xgrid, rev(xgrid)), y = c(fj.lb, rev(fj.ub)),
col = shade.col, border = NA)
}
graphics::lines(xgrid, fhat, type="l", lwd=2, col = fit.col)
graphics::rug(X[, p + smoo.index])
}
if (!missing(xp)) {
xxgrid <- xp
xlen <- length(xp)
Bxxgrid <- cubicbs(xp, lower = min.xgrid, upper = max.xgrid, K = K)$Bmatrix
Bxxgrid.centered <- Bxxgrid - matrix(rep(Bj.fine.mean, xlen), nrow = xlen,
byrow = TRUE)
Bxx <- Bxxgrid.centered[, -K]
fhatxx <- as.numeric(Bxx %*% splines[[j]])
postfjxx.mean <- as.numeric(Bxx %*% thetaj.max)
postfjxx.sd <- sqrt(diag(Bxx %*% Sigj.max %*% t(Bxx)))
fjxx.lb <- fhatxx - stats::qnorm((1 - (alpha * .5))) * postfjxx.sd
fjxx.ub <- fhatxx + stats::qnorm((1 - (alpha * .5))) * postfjxx.sd
ftable <- matrix(0, nrow = xlen, ncol = 4)
colnames(ftable) <- c("xp", "sm", "sm.low", "sm.up")
ftable[, 1] <- xp
ftable[, 2] <- fhatxx
ftable[, 3] <- fjxx.lb
ftable[, 4] <- fjxx.ub
ftable <- round(ftable, 4)
if(show.info == TRUE){
cat("Estimated smooth function", paste0("sm(", covariate.name,")"),
"at specified grid points (*): \n")
cat("\n")
print.table(format(ftable, nsmall = 4), right = TRUE)
cat("--- \n")
cat("* Bounds correspond to a", paste(format(round(cred.int * 100, 2),
nsmall = 2), "%", sep = ""), "credible interval. \n")
}
listout <- list(xp = xp,
sm.xp = fhatxx,
sm.low = fjxx.lb,
sm.up = fjxx.ub,
cred.int = cred.int,
smoo.index = smoo.index)
return(invisible(listout))
}
} |
SL.xgboost = function(Y, X, newX, family, obsWeights, id, ntrees = 1000,
max_depth = 4, shrinkage = 0.1, minobspernode = 10,
params = list(),
nthread = 1,
verbose = 0,
save_period = NULL,
...) {
.SL.require("xgboost")
if(packageVersion("xgboost") < 0.6) stop("SL.xgboost requires xgboost version >= 0.6, try help(\'SL.xgboost\') for details")
if (!is.matrix(X)) {
X = model.matrix(~ . - 1, X)
}
xgmat = xgboost::xgb.DMatrix(data = X, label = Y, weight = obsWeights)
if (family$family == "gaussian") {
if(packageVersion("xgboost") >= "1.1.1.1") {
objective <- 'reg:squarederror'
} else {
objective <- 'reg:linear'
}
model = xgboost::xgboost(data = xgmat, objective=objective, nrounds = ntrees,
max_depth = max_depth, min_child_weight = minobspernode, eta = shrinkage,
verbose = verbose, nthread = nthread, params = params,
save_period = save_period)
}
if (family$family == "binomial") {
model = xgboost::xgboost(data = xgmat, objective="binary:logistic", nrounds = ntrees,
max_depth = max_depth, min_child_weight = minobspernode, eta = shrinkage,
verbose = verbose, nthread = nthread, params = params,
save_period = save_period, eval_metric = "logloss")
}
if (family$family == "multinomial") {
model = xgboost::xgboost(data = xgmat, objective="multi:softmax", nrounds = ntrees,
max_depth = max_depth, min_child_weight = minobspernode, eta = shrinkage,
verbose = verbose, num_class = length(unique(Y)), nthread = nthread,
params = params,
save_period = save_period)
}
if (!is.matrix(newX)) {
newX = model.matrix(~ . - 1, newX)
}
pred = predict(model, newdata = newX)
fit = list(object = model)
class(fit) = c("SL.xgboost")
out = list(pred = pred, fit = fit)
return(out)
}
predict.SL.xgboost <- function(object, newdata, family, ...) {
.SL.require("xgboost")
if(packageVersion("xgboost") < 0.6) stop("SL.xgboost requires xgboost version >= 0.6, try help(\'SL.xgboost\') for details")
if (!is.matrix(newdata)) {
newdata = model.matrix(~ . - 1, newdata)
}
pred = predict(object$object, newdata = newdata)
return(pred)
}
create.SL.xgboost = function(tune = list(ntrees = c(1000), max_depth = c(4), shrinkage = c(0.1),
minobspernode = c(10)), detailed_names = F, env = .GlobalEnv,
name_prefix = "SL.xgb") {
tuneGrid = expand.grid(tune, stringsAsFactors=F)
names = rep("", nrow(tuneGrid))
for (i in seq(nrow(tuneGrid))) {
g = tuneGrid[i,]
if (detailed_names) {
name = paste(name_prefix, g$ntrees, g$max_depth, g$shrinkage, g$minobspernode, sep=".")
} else {
name = paste(name_prefix, i, sep=".")
}
names[i] = name
eval(parse(text = paste0(name, "= function(..., ntrees = ", g$ntrees, ", max_depth = ", g$max_depth, ", shrinkage=", g$shrinkage, ", minobspernode=", g$minobspernode, ") SL.xgboost(..., ntrees = ntrees, max_depth = max_depth, shrinkage=shrinkage, minobspernode=minobspernode)")), envir = env)
}
results = list(grid = tuneGrid, names = names)
invisible(results)
} |
{
library(vroom)
data <- vroom(file, col_types = c(pickup_datetime = "c"))
vroom:::vroom_materialize(data, replace = TRUE)
}
data.table::fwrite(data, tempfile(fileext = ".tsv"), sep = "\t") |
pool.means <- function (m, se, na.rm = FALSE) {
if(is.list(m)) {if(length(m) == 1) { stopifnot(length(se)==1); m <- unlist(m); se <- unlist(se)}}
if(!is.list(m)) {
pooled <- mice::pool.scalar(Q=m, U=se^2)
pooled <- data.frame ( m.pooled = pooled$qbar, se.pooled = sqrt(pooled$t), df = pooled$df, stringsAsFactors = FALSE)
} else {
if(!all(unlist(lapply(m, length)) == unlist(lapply(se, length)) ) ) {
if(!all ( unlist(lapply(se,length)) == 0)) {
cat(paste("Some coefficients without standard error estimates. Standard errors won't be pooled.\n"))
}
se <- lapply(m, FUN = function ( x ) { rep(NA,length(x)) })
}
M <- length(m)
N <- length(m[[1]])
Q.m <- lapply(m,mean)
Qbar <- mean(unlist(Q.m))
U <- mean(unlist(lapply(se, FUN = function ( x ) { mean(x^2) } )))
MS.b <- N/(M-1) * sum((unlist(Q.m) - Qbar)^2)
MS.omeg<- 1/(M*(N-1)) * sum(unlist(lapply(m, FUN = function ( x ) { sum((x-mean(x))^2) })))
varT <- U+1/N*(1+1/M)*MS.b + (1-1/N)*MS.omeg
dfN <- 1 / ( (1/N*(1+1/M)*MS.b / varT)^2 * 1/(M-1) + ( ((1-1/N)*MS.omeg )/varT)^2 * 1/ (M * (N-1)) )
pooled <- data.frame ( m.pooled = Qbar, se.pooled = sqrt(varT), df = dfN, stringsAsFactors = FALSE)
}
return(list(summary=pooled))}
pool.R2 <- function ( r2, N, quiet = FALSE ) {
if(!is.list(r2)) {r2 <- list(r2)}
if (missing(N)) {
if(quiet == FALSE ) {cat("No sample size given. Will not compute standard error of pooled R squared.\n")}
N <- lapply(r2, FUN = function (x) { rep ( 1000, length( x ) ) } )
mis.N <- TRUE
}
if(!is.list(N)) {N <- list(N)}
if (!missing(N)) {
stopifnot(length(N) == length(r2) )
mis.N <- FALSE
stopifnot( all ( sapply(N, length) == sapply(r2, length) ) )
}
Q.i <- lapply(r2, FUN = function (x) {0.5*log( (1 + sqrt(x)) / (1-sqrt(x)) )})
Q.i.err <- lapply(N, FUN = function (n) {1 / (n-3)})
untransformed <- pool.means(m = Q.i, se = Q.i.err)$summary[c("m.pooled","se.pooled")]
transformed <- as.data.frame ( ((exp(2*untransformed)-1) / (exp(2*untransformed)+1) )^2)
if(mis.N) {return(transformed[1])} else {return(transformed)} }
jk2.pool <- function ( datLong, allNam, forceSingularityTreatment, modus ) {
retList <- do.call("rbind", by(data = datLong, INDICES = datLong[, c("group","parameter")], FUN = function ( u ) {
comp <- table(u[,"comparison"], useNA="ifany")
stopifnot(length(comp)==1)
if(u[1,"parameter"] == "chiSquareTest") {
chi <- by(u, INDICES = u[,c(allNam[["nest"]] )], FUN = function ( uN ) { uN[which(uN[,"coefficient"] == "chi2"),"value"]})
degFr<- by(u, INDICES = u[,c(allNam[["nest"]] )], FUN = function ( uN ) { uN[which(uN[,"coefficient"] == "df"),"value"]})
if ( length(table(degFr)) != 1 ) {
cat(paste0("Warning for '",u[1,"group"],"': degrees of freedom vary between imputations. Min: ",min(unlist(degFr)),"; Max: ", max(unlist(degFr)),". Chi-square test will be skipped.\n"))
}
degFr<- unique(unlist(degFr))[1]
pool <- miceadds::micombine.chisquare ( dk = unlist(chi), df=degFr, display = FALSE)
ret <- data.frame ( group = names(table(u[,"group"])), depVar = allNam[["dependent"]], modus=modus, comparison = names(comp), parameter = names(table(u[,"parameter"])), coefficient = c("D2statistic","chi2Approx", "df1", "df2", "p", "pApprox"), value = pool[c("D", "chisq.approx", "df", "df2", "p", "p.approx")], u[1,allNam[["group"]],drop=FALSE], stringsAsFactors = FALSE, row.names=NULL)
} else {
uM <- by(u, INDICES = u[,c(allNam[["nest"]] )], FUN = function ( uN ) { uN[which(uN[,"coefficient"] == "est"),"value"]})
uSE <- by(u, INDICES = u[,c(allNam[["nest"]] )], FUN = function ( uN ) { uN[which(uN[,"coefficient"] == "se"),"value"]})
if ( "es" %in% u[,"coefficient"] ) {
uES <- by(u, INDICES = u[,c(allNam[["nest"]] )], FUN = function ( uN ) { uN[which(uN[,"coefficient"] == "es"),"value"]})
esP <- mean(unlist(lapply(uES, mean)))
}
if(u[1,"parameter"] %in% c("R2", "R2nagel")) {
getNvalid <- datLong[ intersect( intersect( which(datLong[,"group"] == u[1,"group"]), which( datLong[,"parameter"] == "Nvalid")), which( datLong[,"coefficient"] == "est") ) ,]
if(nrow(getNvalid)==0) {
pooled <- t(pool.R2(r2 = u[,"value"]))
} else {
if (forceSingularityTreatment == TRUE) {
if(nrow(getNvalid) != nrow(u) ) {
paste("Inconsistent number of sample size replications and/or R^2 estimates. Try workaround.\n")
u <- u[which(u[,"coefficient"] == "est"),]
stopifnot(nrow(getNvalid) == nrow(u))
pooled <- t(pool.R2(r2 = u[,"value"], N = getNvalid[,"value"]))
} else {
pooled <- t(pool.R2(r2 = u[,"value"], N = getNvalid[,"value"]))
}
} else {
pooled <- t(pool.R2(r2 = u[,"value"], N = getNvalid[,"value"]))
}
}
} else {
pooled <- pool.means(m = uM, se = uSE)$summary[c("m.pooled","se.pooled")]
}
ret <- data.frame ( group = names(table(u[,"group"])), depVar = allNam[["dependent"]], modus=modus, comparison = names(comp), parameter = names(table(u[,"parameter"])), coefficient = c("est","se"), value = unlist(pooled), u[1,allNam[["group"]],drop=FALSE], stringsAsFactors = FALSE, row.names=NULL)
if ( "es" %in% u[,"coefficient"] ) {
retI <- ret[1,]
retI[,"coefficient"] <- "es"
retI[,"value"] <- esP
ret <- rbind(ret, retI)
}
}
return(ret)}))
return(retList)}
pool.corr <- function( corrs , N , conf.level = .05){
fisher.corrs <- 1/2*log( ( 1 + corrs) / ( 1 - corrs ) )
var.fisher <- rep( 1/(N-3) , length(corrs) )
fisher.cor.combine <- mice::pool.scalar( fisher.corrs , var.fisher)
zr <- fisher.cor.combine$qbar
zr.se <- sqrt( fisher.cor.combine$t )
t.zr <- zr / zr.se
fisher2cor <- function(z){ ( exp(2*z) - 1 )/ ( exp(2*z) + 1 ) }
res <- c( "r" = fisher2cor(zr) ,
"fisher_r" = zr ,
"fisher_rse" = zr.se ,
"t" = t.zr ,
"p" = 2 * pnorm( abs(t.zr) , lower.tail = FALSE ) ,
fisher2cor( zr + qnorm( ( 1 - conf.level ) / 2 ) * zr.se ) ,
fisher2cor( zr - qnorm( ( 1 - conf.level ) / 2 ) * zr.se ) )
names(res)[6] <- paste( "lower" , round(100*conf.level,2),sep="")
names(res)[7] <- paste( "upper" , round(100*conf.level,2),sep="")
res <- c( res , ( res[6] - res[7] ) / ( 2* qnorm( ( 1 - conf.level )/2 ) ) )
names(res)[8] <- "rse"
res <- res[ c(1,8,2:7) ]
res <- round(res, 6)
return(res) } |
response.BTLLasso <- function(response, first.object = NULL, second.object = NULL,
subject = NULL, with.order = rep(TRUE, length(response))) {
if(inherits(response, "paircomp")){
response <- as.matrix(response)
model_names <- str_split(colnames(response),pattern=":")
model_names <- matrix(unlist(model_names),nrow=2)
subject <- paste0("Subject",rep(1:nrow(response),ncol(response)))
first.object <- rep(model_names[1,],each=nrow(response))
second.object <- rep(model_names[2,],each=nrow(response))
}
withS <- FALSE
if (!is.null(subject)) {
withS <- TRUE
if (!is.character(subject))
stop("Argument subject has to be a character vector")
}
if (!withS) {
subject <- 1:length(response)
}
ly <- length(response)
lo1 <- length(first.object)
lo2 <- length(second.object)
ls <- length(subject)
lorder <- length(with.order)
if (!all(sapply(list(lo1, lo2, ls,lorder), identical, ly)))
stop("The arguments response, first.object, second.object and (if specified) subject and with.order
have to be of the same length")
all.objects <- as.factor(as.character(unlist(list(first.object,
second.object))))
object.names <- levels(all.objects)
first.object <- as.numeric(all.objects[1:ly])
second.object <- as.numeric(all.objects[(ly + 1):(2 * ly)])
m <- length(object.names)
response <- as.ordered(response)
q <- length(levels(response)) - 1
k <- q + 1
subject.names <- levels(as.factor(subject))
n <- length(subject.names)
RET <- list(response = response, first.object = first.object,
second.object = second.object, subject = subject, withS = withS,
subject.names = subject.names, object.names = object.names,
n = n, m = m, k = k, q = q, with.order = with.order)
class(RET) <- "responseBTLLasso"
RET
} |
ClassMDplot <- function(Data, Cls, ColorSequence = DataVisualizations::DefaultColorSequence,
ClassNames = NULL, PlotLegend = TRUE,Ordering = "Columnwise",
main = 'MDplot for each Class',
xlab = 'Classes', ylab = 'PDE of Data per Class',
MinimalAmoutOfData=40,MinimalAmoutOfUniqueData=12,SampleSize=1e+05,...) {
NoNanInd <- which(!is.nan(Data))
Data <- Data[NoNanInd]
Cls <- Cls[NoNanInd]
AnzData = length(Data)
uniqueData=unique(Data)
TrainInd <- c()
if(AnzData>SampleSize){
UniqueClasses=unique(Cls)
Percentage=round(SampleSize/AnzData,2)
for(i in UniqueClasses){
ClassInd <- which(Cls==i)
nclass=round(length(ClassInd)* Percentage,0)
if(nclass>SampleSize)
sampleInd <- sample(ClassInd,nclass)
else
sampleInd = ClassInd
TrainInd=c(TrainInd,sampleInd)
}
Data=Data[TrainInd]
Cls=Cls[TrainInd]
AnzData=length(Data)
}
if(AnzData<3e+03){
Cls=checkCls(Cls,AnzData,Normalize=TRUE)
}else{
Cls=checkCls(Cls,AnzData,Normalize=FALSE)
}
UniqueClasses = unique(Cls)
NrOfClasses = length(UniqueClasses)
if (is.null(ClassNames)) {
ClassNames = unique(Cls)
names(ClassNames)=paste("Class ", ClassNames, sep = "")
}else{
if(!is.numeric(ClassNames)){
warning('ClassNames should be a numeric vector. Ignoring input and setting to default.')
ClassNames = unique(Cls)
names(ClassNames) = paste("Class ", ClassNames, sep = "")
}
if(is.null(names(ClassNames))){
warning('Numeric vector "ClassNames" does not have names specified. Ignoring input and setting to default.')
ClassNames = unique(Cls)
names(ClassNames) = paste("Class ", ClassNames, sep = "")
}
}
if (NrOfClasses != length(ClassNames))
warning("Number of classes does not equal number of ClassNames!
This might result in a wrong plot")
ColorsUnique=ColorSequence[1:NrOfClasses]
indMatched=match(table = ClassNames,UniqueClasses,nomatch = 0)
inNomatch=which(indMatched==0)
if(length(inNomatch)>0){
warning("Not all classes could be matched, not matched classes are named automatically.")
ClassNamesNew=UniqueClasses
names(ClassNamesNew) = paste("Class ", ClassNamesNew, sep = "")
ClassNamesNew[match(table = ClassNamesNew,ClassNames)]=ClassNames
ClassNames=ClassNamesNew
ClassNames=ClassNames[match(table = ClassNames,UniqueClasses,nomatch = 0)]
}else{
ClassNames=ClassNames[indMatched]
}
Colors=rep(NaN,length(Cls))
ClassNamesVec=rep(NaN,length(Cls))
for(i in 1:NrOfClasses){
Colors[Cls==UniqueClasses[i]]=ColorsUnique[i]
ClassNamesVec[Cls==UniqueClasses[i]]=names(ClassNames)[i]
}
DataPerClassList=vector(mode="list",length = NrOfClasses)
for(i in 1:NrOfClasses){
DataPerClassList[[i]]=Data[Cls==UniqueClasses[i]]
}
DataPerClass=as.matrix(do.call(CombineCols,DataPerClassList))
ggobject=MDplot(Data = DataPerClass,Names = names(ClassNames),Ordering = Ordering,
QuantityThreshold = MinimalAmoutOfData,
UniqueValuesThreshold = MinimalAmoutOfUniqueData,SampleSize = SampleSize,OnlyPlotOutput = TRUE,...)
ggobject=ggobject+ylab(ylab) + xlab(xlab) +
ggtitle(main)+ theme(axis.text.x = element_text(angle = 45, hjust = 1,size = rel(1.2)))
if (isFALSE(PlotLegend)){
ggobject <- ggobject + theme(legend.position = "none",legend.title = NULL,legend.text = element_text(inherit.blank = T))
}
print(ggobject)
return(invisible(list(ClassData = DataPerClass, ggobject = ggobject)))
} |
computeStatistic_t <- function(var1, var2, conf.level=.95,
var.equal=TRUE, ...) {
if (nlevels(as.factor(var1)) == 2) {
dichotomous <- factor(var1);
interval <- var2;
} else if (nlevels(as.factor(var2)) == 2) {
dichotomous <- factor(var2);
interval <- var1;
} else {
stop("Error: none of the two variables has only two levels!");
}
res <- list();
res$object <- stats::t.test(interval ~ dichotomous,
var.equal = var.equal,
conf.level=conf.level);
res$statistic <- res$object$statistic;
res$statistic.type <- "t";
res$parameter <- res$object$parameter;
res$p.raw <- res$object$p.value;
return(res);
}
computeStatistic_r <- function(var1, var2, conf.level=.95,
...) {
res <- list();
res$object <- stats::cor.test(var1, var2, use="complete.obs",
conf.level=conf.level);
res$statistic <- res$object$statistic;
res$statistic.type <- "r";
res$parameter <- res$object$parameter;
res$p.raw <- res$object$p.value;
return(res);
}
computeStatistic_f <- function(var1, var2, conf.level=.95,
...) {
if (is.factor(var1) & is.numeric(var2)) {
factor <- var1;
dependent <- var2;
} else if (is.factor(var2) & is.numeric(var1)) {
factor <- var2;
dependent <- var1;
} else if (nlevels(as.factor(var1)) < nlevels(as.factor(var2))) {
factor <- factor(var1);
dependent <- as.numeric(var2);
}
else {
factor <- factor(var2);
dependent <- as.numeric(var1);
}
res <- list();
res$object <- stats::aov(dependent ~ factor);
res$statistic <- summary(res$object)[[1]][['F value']][1];
res$statistic.type <- "f";
res$parameter <- c(summary(res$object)[[1]][['Df']]);
res$p.raw <- summary(res$object)[[1]][['Pr(>F)']][1];
return(res);
}
computeStatistic_chisq <- function(var1, var2, conf.level=.95,
...) {
res <- list();
res$object <- stats::chisq.test(var1, var2, correct=FALSE);
res$statistic <- res$object$statistic;
res$statistic.type <- "chisq";
res$parameter <- res$object$parameter;
res$p.raw <- res$object$p.value;
return(res);
}
computeEffectSize_d <- function(var1, var2, conf.level=.95,
var.equal=TRUE, ...) {
if (length(unique(stats::na.omit(var1))) == 2) {
dichotomous <- factor(var1);
interval <- var2;
}
else if (length(unique(stats::na.omit(var2))) == 2) {
dichotomous <- factor(var2);
interval <- var1;
}
else {
stop("Error: none of the two variables has only two levels!");
}
res <- list();
tTest <- stats::t.test(interval ~ dichotomous,
var.equal = var.equal)$statistic;
dValue <- ufs::convert.t.to.d(tTest,
n1 = sum(as.numeric(dichotomous)==min(as.numeric(dichotomous),
na.rm=TRUE), na.rm=TRUE),
n2 = sum(as.numeric(dichotomous)==max(as.numeric(dichotomous),
na.rm=TRUE), na.rm=TRUE));
res$object <- ufs::confIntD(dValue,
n=sum(!is.na(interval)),
conf.level=conf.level);
res$es <- dValue;
res$es.type <- "d";
res$ci <- c(res$object[1],
res$object[2]);
return(res);
}
computeEffectSize_r <- function(var1, var2, conf.level=.95,
...) {
res <- list();
res$object <- stats::cor.test(var1, var2, use="complete.obs",
conf.level=conf.level);
res$es <- res$object$estimate;
res$es.type <- "r";
res$ci <- res$object$conf.int;
return(res);
}
computeEffectSize_etasq <- function(var1, var2, conf.level=.95,
...) {
if (is.factor(var1) & is.numeric(var2)) {
factor <- var1;
dependent <- var2;
}
else if (is.factor(var2) & is.numeric(var1)) {
factor <- var2;
dependent <- var1;
} else if (nlevels(as.factor(var1)) < nlevels(as.factor(var2))) {
factor <- factor(var1);
dependent <- as.numeric(var2);
}
else {
factor <- factor(var2);
dependent <- as.numeric(var1);
}
res <- list();
res$realConfidence <- 1 - ((1-conf.level) * 2);
res$object.aov <- stats::aov(dependent ~ factor);
df_num <- summary(res$object.aov)[[1]][1,1];
df_den <- summary(res$object.aov)[[1]][2,1];
f_val <- summary(res$object.aov)[[1]][1,4];
res$es <- df_num*f_val/(df_den + df_num*f_val);
res$es.type <- "etasq";
utils::capture.output(res$object <-
from_MBESS_ci.pvaf(F.value=f_val, df.1=df_num, df.2=df_den,
N=(df_den+df_num+1), conf.level=res$realConfidence));
res$ci <- c(res$object$Lower.Limit.Proportion.of.Variance.Accounted.for,
res$object$Upper.Limit.Proportion.of.Variance.Accounted.for);
return(res);
}
computeEffectSize_omegasq <- function(var1, var2, conf.level=.95,
...) {
res$object <- ufs::confIntOmegaSq(var1, var2, conf.level=conf.level);
res$es <- res$object$output$es;
res$es.type <- "omegasq";
res$ci <- res$object$output$ci;
return(res);
}
computeEffectSize_v <- function(var1, var2, conf.level=.95,
bootstrap=FALSE, samples=5000,
...) {
res <- list();
if (bootstrap) {
res$object <- ufs::confIntV(var1, var2,
method="bootstrap",
samples=samples,
conf.level=conf.level);
res$ci <- res$object$output$confIntV.bootstrap;
} else {
res$object <- ufs::confIntV(var1, var2, method="fisher");
res$ci <- res$object$output$confIntV.fisher;
}
res$es <- res$object$intermediate$cramersV$output$cramersV
res$es.type <- "V";
return(res);
}
associationMatrixStatDefaults <- list(dichotomous =
list(dichotomous = "computeStatistic_chisq",
nominal = "computeStatistic_chisq",
ordinal = "computeStatistic_chisq",
numeric = "computeStatistic_t"),
nominal =
list(dichotomous = "computeStatistic_chisq",
nominal = "computeStatistic_chisq",
ordinal = "computeStatistic_chisq",
numeric = "computeStatistic_f"),
ordinal =
list(dichotomous = "computeStatistic_chisq",
nominal = "computeStatistic_chisq",
ordinal = "computeStatistic_chisq",
numeric = "computeStatistic_f"),
numeric =
list(dichotomous = "computeStatistic_t",
nominal = "computeStatistic_f",
ordinal = "computeStatistic_f",
numeric = "computeStatistic_r"));
associationMatrixESDefaults <- list(dichotomous =
list(dichotomous = "computeEffectSize_v",
nominal = "computeEffectSize_v",
ordinal = "computeEffectSize_v",
numeric = "computeEffectSize_d"),
nominal =
list(dichotomous = "computeEffectSize_v",
nominal = "computeEffectSize_v",
ordinal = "computeEffectSize_v",
numeric = "computeEffectSize_etasq"),
ordinal =
list(dichotomous = "computeEffectSize_v",
nominal = "computeEffectSize_v",
ordinal = "computeEffectSize_v",
numeric = "computeEffectSize_etasq"),
numeric =
list(dichotomous = "computeEffectSize_d",
nominal = "computeEffectSize_etasq",
ordinal = "computeEffectSize_etasq",
numeric = "computeEffectSize_r"));
associationMatrix <- function(dat=NULL, x=NULL, y=NULL, conf.level = .95,
correction = "fdr", bootstrapV=FALSE,
info=c("full", "ci", "es"),
includeSampleSize = "depends",
bootstrapV.samples = 5000, digits = 2,
pValueDigits=digits + 1, colNames = FALSE,
type=c("R", "html", "latex"), file="",
statistic = associationMatrixStatDefaults,
effectSize = associationMatrixESDefaults,
var.equal = TRUE) {
res <- list(input = as.list(environment()),
intermediate = list(),
output = list());
res$intermediate$statistics <- list();
res$intermediate$effectSizes <- list();
res$intermediate$sampleSizes <- list();
if (is.null(dat)) {
dat <- getData(errorMessage=paste0("No dataframe specified, and no valid datafile selected in ",
"the dialog I then showed to allow selection of a dataset.",
"Original error:\n\n[defaultErrorMessage]"),
use.value.labels=FALSE);
res$input$dat.name <- paste0("SPSS file imported from ", attr(dat, "filename"));
}
else {
if (!is.data.frame(dat)) {
stop("Argument 'dat' must be a dataframe or NULL! Class of ",
"provided argument: ", class(dat));
}
res$input$dat.name <- deparse(substitute(dat));
}
if (is.null(x) && is.null(y)) {
x <- names(dat);
}
if (is.null(x) && !is.null(y)) {
x <- y;
}
if (length(x) < 1) {
stop(paste0("Error: x vector has 0 elements or less; ",
"make sure to specify at least one variable name!."));
}
measurementLevelsX <- vector();
xCounter <- 1;
for(curXvar in x) {
if (stats::var(as.numeric(dat[,curXvar]), na.rm=TRUE) == 0) {
stop("Variable '", curXvar, "' has no variance (everybody scores the same)! ",
"This prohibits the calculation of effect size measures, so I'm aborting.");
}
if (is.numeric(dat[,curXvar])) {
measurementLevelsX[xCounter] <- "numeric";
}
else if (is.factor(dat[,curXvar])) {
if (length(levels(dat[,curXvar])) == 2) {
measurementLevelsX[xCounter] <- "dichotomous";
}
else if (is.ordered(dat[,curXvar])) {
measurementLevelsX[xCounter] <- "ordinal";
}
else {
measurementLevelsX[xCounter] <- "nominal";
}
}
else {
stop(paste0("Error: variable '", curXvar, "'' does not have ",
"nominal, ordinal, or interval measurement level!"));
}
xCounter <- xCounter + 1;
}
if (!is.null(y)) {
if (length(y) < 1) {
stop(paste0("Error: y vector has 0 elements or less; ",
"make sure to specify at least one variable name!."));
}
symmetric <- FALSE;
measurementLevelsY <- vector();
yCounter <- 1;
for(curYvar in y) {
if (stats::var(as.numeric(dat[,curYvar]), na.rm=TRUE) == 0) {
stop("Variable '", curYvar, "' has no variance (everybody scores the same)! ",
"This prohibits the calculation of effect size measures, so I'm aborting.");
}
if (is.numeric(dat[,curYvar])) {
measurementLevelsY[yCounter] <- "numeric";
}
else if (is.factor(dat[,curYvar])) {
if (length(levels(dat[,curYvar])) == 2) {
measurementLevelsY[yCounter] <- "dichotomous";
}
else if (is.ordered(dat[,curYvar])) {
measurementLevelsY[yCounter] <- "ordinal";
}
else {
measurementLevelsY[yCounter] <- "nominal";
}
}
else {
stop(paste0("Error: variable '", curYvar, "'' does not have ",
"nominal, ordinal, or interval measurement level!"));
}
yCounter <- yCounter + 1;
}
}
else {
symmetric <- TRUE;
y <- x;
measurementLevelsY <- measurementLevelsX;
}
if (colNames) {
rowNames <- x;
columnNames <- y;
}
else {
rowNames <- paste(1:length(x), x, sep=". ");
columnNames <- paste0(1:length(y), ".");
}
res$output$matrix <- list();
res$output$matrix$es <- matrix(nrow = length(x), ncol = length(y));
rownames(res$output$matrix$es) <- rowNames;
colnames(res$output$matrix$es) <- columnNames;
res$output$matrix$sampleSizes <- matrix(nrow = length(x), ncol = length(y));
rownames(res$output$matrix$sampleSizes) <- rowNames;
colnames(res$output$matrix$sampleSizes) <- columnNames;
res$output$matrix$ci <- matrix(nrow = length(x), ncol = length(y));
rownames(res$output$matrix$ci) <- rowNames;
colnames(res$output$matrix$ci) <- columnNames;
res$output$matrix$full <- matrix(nrow = 2 * length(x), ncol = length(y));
rownames(res$output$matrix$full) <- rep("", 2*length(rowNames));
rownames(res$output$matrix$full)[seq(1, (2*length(rowNames)) - 1, by=2)] <- rowNames;
colnames(res$output$matrix$full) <- columnNames;
res$output$raw <- list();
res$output$raw$es <- matrix(nrow = length(x), ncol = length(y));
rownames(res$output$raw$es) <- rowNames;
colnames(res$output$raw$es) <- columnNames;
res$output$raw$esType <- matrix(nrow = length(x), ncol = length(y));
rownames(res$output$raw$esType) <- rowNames;
colnames(res$output$raw$esType) <- columnNames;
res$output$raw$ci.lo <- matrix(nrow = length(x), ncol = length(y));
rownames(res$output$raw$ci.lo) <- rowNames;
colnames(res$output$raw$ci.lo) <- columnNames;
res$output$raw$ci.hi <- matrix(nrow = length(x), ncol = length(y));
rownames(res$output$raw$ci.hi) <- rowNames;
colnames(res$output$raw$ci.hi) <- columnNames;
res$output$raw$n <- matrix(nrow = length(x), ncol = length(y));
rownames(res$output$raw$n) <- rowNames;
colnames(res$output$raw$n) <- columnNames;
res$output$raw$p <- matrix(nrow = length(x), ncol = length(y));
rownames(res$output$raw$p) <- rowNames;
colnames(res$output$raw$p) <- columnNames;
xCounter <- 1;
for(curXvar in x) {
res$intermediate$statistics[[curXvar]] <- list();
res$intermediate$effectSizes[[curXvar]] <- list();
res$intermediate$sampleSizes[[curXvar]] <- list();
yCounter <- 1;
for(curYvar in y) {
if (!symmetric | (yCounter < xCounter)) {
statisticFunctionName <-
statistic[[measurementLevelsX[xCounter]]][[measurementLevelsY[yCounter]]];
tmpFun <-
get(statisticFunctionName, envir=environment(eval(parse(text=statisticFunctionName))));
res$intermediate$statistics[[curXvar]][[curYvar]] <-
tmpFun(dat[,curXvar], dat[,curYvar], conf.level = conf.level);
effectSizeFunctioName <-
effectSize[[measurementLevelsX[xCounter]]][[measurementLevelsY[yCounter]]];
tmpFun <-
get(effectSizeFunctioName, envir=environment(eval(parse(text=effectSizeFunctioName))));
res$intermediate$effectSizes[[curXvar]][[curYvar]] <-
tmpFun(dat[,curXvar], dat[,curYvar], conf.level = conf.level,
var.equal = var.equal);
res$intermediate$sampleSizes[[curXvar]][[curYvar]] <- nrow(stats::na.omit(dat[,c(curXvar, curYvar)]));
}
yCounter <- yCounter + 1;
}
xCounter <- xCounter + 1;
}
res$intermediate$pvalMatrix <- matrix(nrow=length(x), ncol=length(y), dimnames=list(x, y));
for(curXvar in x) {
for(curYvar in y) {
if (!is.null(res$intermediate$statistics[[curXvar]][[curYvar]]$p.raw)) {
res$intermediate$pvalMatrix[curXvar, curYvar] <- res$intermediate$statistics[[curXvar]][[curYvar]]$p.raw;
}
}
}
res$intermediate$pvalMatrix.adj <- matrix(stats::p.adjust(res$intermediate$pvalMatrix, method=correction),
nrow(res$intermediate$pvalMatrix), ncol(res$intermediate$pvalMatrix),
dimnames=dimnames(res$intermediate$pvalMatrix));
for(curXvar in x) {
for(curYvar in y) {
if (!is.null(res$intermediate$statistics[[curXvar]][[curYvar]]$p.raw)) {
res$intermediate$statistics[[curXvar]][[curYvar]]$p.adj <-
res$intermediate$pvalMatrix.adj[curXvar, curYvar];
}
}
}
for(rowVar in 1:length(x)) {
for(colVar in 1:length(y)) {
if (!symmetric | (colVar < rowVar)) {
res$output$matrix$ci[rowVar, colVar] <- paste0(
substr(res$intermediate$effectSizes[[rowVar]][[colVar]]$es.type, 1, 1), "=[",
round(res$intermediate$effectSizes[[rowVar]][[colVar]]$ci[1], digits), "; ",
round(res$intermediate$effectSizes[[rowVar]][[colVar]]$ci[2], digits), "]");
res$output$raw$ci.lo[rowVar, colVar] <-
res$intermediate$effectSizes[[rowVar]][[colVar]]$ci[1];
res$output$raw$ci.hi[rowVar, colVar] <-
res$intermediate$effectSizes[[rowVar]][[colVar]]$ci[2];
res$output$matrix$es[rowVar, colVar] <-
paste0(substr(res$intermediate$effectSizes[[rowVar]][[colVar]]$es.type, 1, 1), "=",
round(res$intermediate$effectSizes[[rowVar]][[colVar]]$es, digits), ", ",
formatPvalue(res$intermediate$statistics[[rowVar]][[colVar]]$p.adj, digits=pValueDigits, spaces=FALSE));
res$output$raw$es[rowVar, colVar] <-
res$intermediate$effectSizes[[rowVar]][[colVar]]$es;
res$output$raw$esType[rowVar, colVar] <-
res$intermediate$effectSizes[[rowVar]][[colVar]]$es.type;
res$output$raw$p[rowVar, colVar] <-
res$intermediate$statistics[[rowVar]][[colVar]]$p.adj;
res$output$matrix$sampleSizes[rowVar, colVar] <-
res$intermediate$sampleSizes[[rowVar]][[colVar]];
res$output$raw$n[rowVar, colVar] <-
res$intermediate$sampleSizes[[rowVar]][[colVar]];
res$output$matrix$full[(rowVar*2)-1, colVar] <-
res$output$matrix$ci[rowVar, colVar];
res$output$matrix$full[(rowVar*2), colVar] <-
res$output$matrix$es[rowVar, colVar];
if (((includeSampleSize == "depends") &&
(length(unique(unlist(res$intermediate$sampleSizes))) > 1)) ||
(includeSampleSize == "always")) {
res$output$matrix$full[(rowVar*2), colVar] <-
paste0(res$output$matrix$full[(rowVar*2), colVar],
", n=", res$output$matrix$sampleSizes[rowVar, colVar]);
}
}
else {
res$output$matrix$es[rowVar, colVar] <- "";
res$output$matrix$ci[rowVar, colVar] <- "";
res$output$matrix$full[(rowVar*2)-1, colVar] <- "";
res$output$matrix$full[rowVar*2, colVar] <- "";
}
}
}
class(res) <- c("associationMatrix");
return(res);
}
print.associationMatrix <- function (x, type = x$input$type,
info = x$input$info,
file = x$input$file, ...) {
matrixToPrint <- x$output$matrix[[info[1]]];
if (toupper(type[1])=="R") {
if (file=="") {
print(matrixToPrint, quote=FALSE);
} else {
utils::write.table(matrixToPrint, file=file, sep="\t",
quote=FALSE, row.names=TRUE, col.names=TRUE);
}
}
else {
if ((tolower(type[1])=="latex") && (info[1]=='full')) {
rownames(matrixToPrint)[seq(2, nrow(matrixToPrint), by=2)] <-
paste0("%%% Variable ", 1:(nrow(matrixToPrint)/2), "\n");
} else if (info[1]=='full') {
rownames(matrixToPrint)[seq(2, nrow(matrixToPrint), by=2)] <-
paste0("<!-- Variable ", 1:(nrow(matrixToPrint)/2), " -->");
}
print(matrixToPrint);
}
invisible();
}
pander.associationMatrix <- function (x,
info = x$input$info,
file = x$input$file, ...) {
pander(x$output$matrix[[info[1]]],
missing="");
invisible();
} |
expected <- TRUE
test(id=678, code={
argv <- list(function (x, format = "", usetz = FALSE, ...)
{
if (!inherits(x, "POSIXlt"))
stop("wrong class")
if (format == "") {
times <- unlist(unclass(x)[1L:3L])
secs <- x$sec
secs <- secs[!is.na(secs)]
np <- getOption("digits.secs")
if (is.null(np))
np <- 0L
else np <- min(6L, np)
if (np >= 1L)
for (i in seq_len(np) - 1L) if (all(abs(secs - round(secs,
i)) < 1e-06)) {
np <- i
break
}
format <- if (all(times[!is.na(times)] == 0))
"%Y-%m-%d"
else if (np == 0L)
"%Y-%m-%d %H:%M:%S"
else paste0("%Y-%m-%d %H:%M:%OS", np)
}
y <- .Internal(format.POSIXlt(x, format, usetz))
names(y) <- names(x$year)
y
})
do.call('is.function', argv);
}, o = expected);
|
get_predicted.clm <- function(x, predict = "expectation", data = NULL, ...) {
dots <- list(...)
if (!is.null(predict)) {
valid <- c("expectation", "classification")
predict <- match.arg(predict, choices = valid)
type_arg <- c("prob", "class")[match(predict, valid)]
} else {
if (!"type" %in% names(dots)) {
stop("Please specify the `predict` argument.")
} else {
type_arg <- match.arg(dots$type, choices = c("prob", "class"))
}
}
if (is.null(data)) {
data <- get_data(x)
}
resp <- find_response(x)
data <- data[, setdiff(colnames(data), resp), drop = FALSE]
vars <- as.character(attr(x$terms, "variables"))[-1]
vars[attr(x$terms, "response")] <- resp
s <- paste0("list(", paste(vars, collapse = ", "), ")")
new_call <- parse(text = s, keep.source = FALSE)[[1L]]
attr(x$terms, "variables") <- new_call
args <- list(
object = x,
newdata = data,
type = type_arg,
se.fit = (type_arg == "prob")
)
pred <- do.call("predict", args)
out <- .get_predicted_out(pred$fit)
if (type_arg == "prob") {
se <- pred$se.fit
se <- as.data.frame(se)
se$Row <- 1:nrow(se)
se <- stats::reshape(se,
direction = "long",
varying = setdiff(colnames(se), "Row"),
times = setdiff(colnames(se), "Row"),
v.names = "SE",
timevar = "Response",
idvar = "Row"
)
row.names(se) <- NULL
attr(out, "ci_data") <- se
}
return(out)
}
get_predicted.multinom <- function(x, predict = "expectation", data = NULL, ...) {
dots <- list(...)
if (!is.null(predict)) {
type_arg <- match.arg(predict, choices = c("classification", "expectation"))
type_arg <- c("class", "probs")[c("classification", "expectation") == type_arg]
} else if ("type" %in% names(dots)) {
type_arg <- match.arg(dots$type, choices = c("class", "probs"))
} else {
stop('The `predict` argument must be either "expectation" or "classification".')
}
args <- c(list(x, "data" = data), list(...))
if (is.null(data)) {
out <- stats::predict(x, type = type_arg)
} else {
out <- stats::predict(x, newdata = data, type = type_arg)
}
.get_predicted_out(out, args = args)
}
get_predicted.rlm <- function(x, predict = "expectation", ...) {
if (!is.null(predict)) {
predict <- match.arg(predict, choices = "expectation")
get_predicted.lm(x, predict = predict, ...)
} else {
dots <- list(...)
if (!"type" %in% names(dots)) {
stop("Please specify the `predict` argument.")
}
dots[["type"]] <- match.arg(dots$type, choices = "response")
dots[["x"]] <- x
dots <- c(dots, list("predict" = NULL))
do.call("get_predicted.lm", dots)
}
}
get_predicted.polr <- get_predicted.multinom |
acronym <- function(input, dictionary = NULL, acronym_length = 3, ignore_articles = TRUE, alnum_only = TRUE, timeout = 60, bow = FALSE, bow_prop = 0.5, to_tibble = FALSE) {
if(is.null(dictionary)) {
dictpath <- system.file("dict", "en_US.dic", package = "hunspell")
stopifnot(file.exists(dictpath))
dictionary <-
dictpath %>%
readr::read_lines() %>%
grep("^[A-Z]", ., value = TRUE) %>%
gsub("/[A-Z]*.", "", .) %>%
tolower()
}
tmp <- mince(input = input,
ignore_articles = ignore_articles,
alnum_only = alnum_only,
bow = bow,
bow_prop = bow_prop)
first_char_ind <- abs(tmp$words_len - cumsum(tmp$words_len)) + 1
probs <- rep(0.1, nchar(tmp$collapsed))
probs[first_char_ind] <- 0.9
probs[1] <- 0.95
tryCatch({
R.utils::withTimeout({
res <- find_candidate(collapsed = tmp$collapsed,
acronym_length = acronym_length,
probs = probs,
dictionary = dictionary,
words_len = tmp$words_len)
if(to_tibble) {
res_tibble <-
dplyr::tibble(
formatted = res$formatted,
prefix = res$prefix,
suffix = res$suffix,
original = paste0(tmp$words, collapse = " ")
)
return(res_tibble)
} else {
return(res$formatted)
}
}, timeout = timeout)
}, TimeoutException = function(ex) {
message(sprintf("Unable to find viable acronym in 'timeout' specified (%d seconds) ... ", timeout))
})
}
initialism <- function(input, ignore_articles = TRUE, alnum_only = TRUE, bow = FALSE, bow_prop = 0.5, to_tibble = FALSE) {
tmp <- mince(input = input,
ignore_articles = ignore_articles,
alnum_only = alnum_only,
bow = bow,
bow_prop = bow_prop)
candidate <- paste0(toupper(tmp$first_chars), collapse = "")
tmp_collapsed_split <-
tmp$collapsed %>%
strsplit(., split = "") %>%
unlist(.)
first_char_ind <- abs(tmp$words_len - cumsum(tmp$words_len)) + 1
tmp_collapsed_split <- tolower(tmp_collapsed_split)
tmp_collapsed_split[first_char_ind] <- toupper(tmp_collapsed_split[first_char_ind])
last_letter_ind <- cumsum(tmp$words_len)
tmp_collapsed_split[last_letter_ind[-length(last_letter_ind)]] <- paste0(tmp_collapsed_split[last_letter_ind[-length(last_letter_ind)]], " ")
name <- paste0(tmp_collapsed_split, collapse = "")
formatted <- paste0(toupper(candidate), ": ", name)
if(to_tibble) {
res_tibble <-
dplyr::tibble(
formatted = formatted,
prefix = candidate,
suffix = name,
original = paste0(tmp$words, collapse = " ")
)
return(res_tibble)
} else {
return(formatted)
}
} |
source("utils.R")
test_that("add img into placeholder", {
skip_on_os("windows")
img.file <- file.path( R.home("doc"), "html", "logo.jpg" )
doc <- read_pptx()
doc <- add_slide(doc, "Title and Content", "Office Theme")
doc <- ph_with(doc, value = external_img(img.file), location = ph_location(left = 1, top = 1,
height = 1.06, width = 1.39) )
sm <- slide_summary(doc)
expect_equal(nrow(sm), 1)
expect_equal(sm$cx, 1.39)
expect_equal(sm$cy, 1.06)
expect_equal(sm$offx, 1)
expect_equal(sm$offy, 1)
}) |
library(gsheet)
context('Test gsheet2text')
test_that('Works correctly with and without sheet id', {
a <- gsheet2text('docs.google.com/spreadsheets/d/1I9mJsS5QnXF2TNNntTy-HrcdHmIF9wJ8ONYvEJTXSNo')
b <- gsheet2text('docs.google.com/spreadsheets/d/1I9mJsS5QnXF2TNNntTy-HrcdHmIF9wJ8ONYvEJTXSNo', sheetid=0)
expect_equal(a, b)
})
test_that('Throws informative error when share by link is turned off', {
expect_error({gsheet2text('https://docs.google.com/spreadsheets/d/1zMvLM_dWvIHeTFi8Sct9QMmrr7Roo2tav2SE4Wt7vBQ/edit')},
"Unable to retrieve document. Is 'share by link' enabled for this sheet?"
)
}) |
aprof <- function(src=NULL,output=NULL){
if(is.null(src)){
warning("src is empty, no source code file defined")} else {
if(!file.exists(src)) {stop(paste("The specified source ",
src, " does not appear to exist"))
}
if(is.na(file.info(src)$size)|file.info(src)$size<1){
stop("specified source file appears to be empty")}
}
if(!is.null(output)){
CallsInt <- readOutput(output)
if(is.null(CallsInt$calls)|length(CallsInt$calls)==0){
stop(paste("Rprof outputs appears to be empty,",
"were enough samples made by the profiler?"))}
} else { stop("No profiling output files defined")}
if(!is.null(CallsInt$mem)) {
aprofobject<-list(sourcefile=src,
calls=CallsInt$calls,
mem=CallsInt$mem,
interval=CallsInt$interval)
class(aprofobject) <- c("aprof","mem.aprof","list")
} else {
aprofobject<-list(sourcefile=src,calls=CallsInt$calls,
interval=CallsInt$interval)
class(aprofobject) <- c("aprof","list")
}
return(aprofobject)
}
readOutput<-function(outputfilename="Rprof.out"){
RprofSamples<-readLines(outputfilename)
if(length(grep("line profiling",RprofSamples[1]))==0){
stop(paste("Line profiling is required.",
"\nPlease run the profiler with line profiling enabled"))}
Mem <- grepl("memory profiling",RprofSamples[1])
if(Mem){
tosplit <- grepl("
splPos<-regexpr(pattern = "^:[0-9]+:[0-9]+:[0-9]+:[0-9]+:",
text =RprofSamples[-1][tosplit])
meminfo <- !splPos==(-1)
cutlength <- attr(splPos,"match.length")
mem <- substr(RprofSamples[-1][tosplit][meminfo],1,cutlength[meminfo])
mem <- t(sapply(strsplit(mem,":"),function(X) as.numeric(X[-1])))
mem <- as.data.frame(mem)
colnames(mem) <- c("sm_v_heap","lrg_v_heap","mem_in_node")
mem$mb<-rowSums(mem)/1024^2
splPosReg <- regexpr(pattern = "\\\"|:.
text =RprofSamples[-1][tosplit])
regular <- substring(RprofSamples[-1][tosplit],splPosReg)
regular <- gsub(":","",regular)
RprofSamples <- c(RprofSamples[1],regular)
mem$calllines <- which(meminfo)
}
splitCalls<- sapply(RprofSamples[-1],
function(X) strsplit(X, split = " "),USE.NAMES=FALSE)
calls<-sapply(splitCalls, function(x) rev(gsub("\"", "", x)))
Samp.Int<-as.numeric(strsplit(RprofSamples[1],"=")[[1]][2])
if(Mem){
return(list(calls=calls,mem=mem,interval=Samp.Int*1e-6))
} else {
return(list(calls=calls,interval=Samp.Int*1e-6))
}
}
readLineDensity<-function(aprofobject=NULL,Memprof=FALSE){
if(!"aprof"%in%class(aprofobject)){ stop("no aprof object found,
check function inputs")}
calls <- aprofobject$calls
interval <- aprofobject$interval
TargetFile <- aprofobject$sourcefile
idfiles<-sapply(calls,function(X) length(grep("
CallFiles <- sapply(calls[idfiles],function(X) X[1])
if(is.null(TargetFile))
{
FileNumber<-"1:"
warning(paste("sourcefile is null", " assuming first file in
call stack is the source: ", CallFiles[1],sep=""))
if(!exists(CallFiles[1])){stop("source file was not defined and
does not seem to exist in the working directory.")}
} else{
unlistedCalls <- unlist(calls)
if(sum(unlistedCalls==TargetFile)==0){
if(sum(unlistedCalls==basename(TargetFile))>0){
TargetFile <- basename(TargetFile) } else {
warning(paste("specified source
file ", TargetFile, " is not in the list of files in the
profiler output: \n ", CallFiles,sep=""))
}
}
FileNumber<-unlistedCalls[which(unlistedCalls==TargetFile)+1]
FileCheck<-unlistedCalls[which(unlistedCalls==TargetFile)]
if(length(FileCheck)==0){
warning(paste("Some aprof functions may fail -->",
" user supplied source file",
TargetFile,
" does not seem to correspond to any",
" file in the profiler output.\n",
" Possible causes: \n" ,
"1) Source file was not profiled?\n",
"2) Spelling?\n",sep=""))
}
}
FileNumber <- substr(FileNumber,1,1)
cleancalls<-sapply(calls[!idfiles],
function(x) gsub("
LineCalls<- lapply(cleancalls, function(X)
unique(X[grep(paste(FileNumber,"
USE.NAMES=FALSE))
if(any(sapply(LineCalls,length)>1)){
LineCalls <- sapply(LineCalls,function(X) X[1])
warning("Some line calls stripped - BUGCODE: 02022016")
}
LineCalls <- unlist(LineCalls)
Pathways<-unique(sapply(LineCalls, paste,collapse="-"))
Pathways<-Pathways[grep("
filehash <- paste(FileNumber,"
LineDensity<-table(unlist(sapply(LineCalls,unique)))
names(LineDensity)<-gsub(filehash,"", names(LineDensity))
Line.Numbers<-as.numeric(names(LineDensity))
Call.Density<-as.numeric(LineDensity)
Time.Density<-Call.Density*interval
if(Memprof) {
MemLines <- as.integer(gsub(filehash,"", LineCalls))
TotalMem <- tapply(c(0,diff(aprofobject$mem$mb)),
MemLines,function(X) sum(abs(X)))
Finallist <-list(Line.Numbers=as.numeric(names(LineDensity)),
Call.Density=as.numeric(LineDensity),
Time.Density=Call.Density*interval,
Total.Calls=sum(as.numeric(LineDensity))+1,
Total.Time=sum(Call.Density*interval+interval),
Files=CallFiles,Total.Mem=TotalMem)
} else {
Finallist <-list(Line.Numbers=as.numeric(names(LineDensity)),
Call.Density=as.numeric(LineDensity),
Time.Density=Call.Density*interval,
Total.Calls=sum(as.numeric(LineDensity))+1,
Total.Time=sum(Call.Density*interval+interval),
Files=CallFiles)
}
return(Finallist)
}
print.aprof <- function(x,...){
aprofobject<-x
if(!is.aprof(aprofobject)){
stop("Input does not appear to be of the class \"aprof\"")}
if(!is.null(aprofobject$sourcefile)){
cat(paste0("\nSource file:\n",aprofobject$sourcefile," (",
length(readLines(aprofobject$sourcefile))
," lines).\n"))
}
if(!is.null(aprofobject$calls)){
interval <- aprofobject$interval
Finallist <- readLineDensity(aprofobject,Memprof=FALSE)
CallTable<-cbind(as.character(Finallist$Line.Numbers),
Finallist$Call.Density,
Finallist$Time.Density)
if(nrow(CallTable)>1) {CallTable<-CallTable[order(CallTable[,2]),]}
rownames(CallTable)<-NULL
dimnames(CallTable)<-list(NULL, c("Line","Call Density",
"Time Density (s)"))
cat("\n Call Density and Execution time per line number:\n\n")
print.default(format(CallTable,digits = 3),print.gap = 2L,
quote = FALSE)
cat(paste("\n Totals:\n",
"Calls\t\t",Finallist$Total.Calls,"\n",
"Time (s)\t",Finallist$Total.Time,
"\t(interval = \t",interval,"(s))\n"))
if(length(Finallist$Files)>1) {
cat("\n Note: multiple files in the profiler output: \n")
print.default(Finallist$Files,print.gap = 2L,quote = FALSE)
}
if(!is.null(aprofobject$mem)){
cat("\n Memory statistics per line number:\n\n")
memtable <- readLineDensity(aprofobject,Memprof=TRUE)$Total.Mem
prettymem <- cbind(Line=names(memtable),
MB=round(as.double(memtable),3))
print.default(format(prettymem),print.gap = 2L,
quote = FALSE)
cat(paste("\n Total MBs (allocated and released).\n\n"))
}
} else {
stop("No profiler sampling information (removed?). Recreate aprof object.")
}
}
MakeBranchPlot<-function(calls,interval){
nlevel<-sapply(calls,length)
minlev<-min(nlevel)
maxlev<-max(nlevel)
pipes<-unique(sapply(calls, paste,collapse=" ",sep=" "))
pipesize<-table(sapply(calls, paste,collapse=" ",sep=" "))
branches<-vector(maxlev,mode="list")
for (i in seq_len(maxlev)){
branches[[i]]<-table(sapply(calls,function(X) X[i]))
}
branTh<-sapply(branches,sum)
branchPropSize<-sapply(branches,function(X) X/max(branTh)*1.5)
branchSize<-sapply(branchPropSize,
function(X) ifelse(X<0.45,0.45,X))
xpos<-sapply(branches, function(x)
if(length(x)>1){seq(-1,1,length.out=length(x))}
else{0}
)
tmppos<-seq(-1,1,length.out=maxlev)
ypos<-sapply(1:maxlev,function(x)
rep(tmppos[x],length(xpos[[x]]))
)
graphics::par(mar=c(0,0,0,0))
graphics::plot(0,0,type='n')
for(i in seq_len(maxlev)){
graphics::text(xpos[[i]],ypos[[i]], names(branches[[i]]),
cex=branchSize[[i]])
}
}
PlotSourceCode<-function(SourceFilename){
CodeLines<-readLines(SourceFilename)
NCodeLines<-length(CodeLines)
CleanLines<-sapply(CodeLines,function(x)
gsub("\t", " ",x,fixed=TRUE),USE.NAMES=FALSE)
Nchar<-sapply(CleanLines,function(x)
strsplit(x,""),USE.NAMES=FALSE)
Nchar<-sapply(Nchar,function(x)
length(x),USE.NAMES=FALSE)
graphics::par(mar=c(0,0,0,0))
graphics::plot(0,0,xlim=c(-graphics::strwidth("M"),
max(Nchar)+graphics::strwidth("M")),
ylim=c(0,NCodeLines+0.5),
type='n',xaxt='n',yaxt='n',bty='n',xlab='',ylab='')
graphics::abline(h=seq_len(NCodeLines),col='white')
Codewidth<-sapply(CleanLines,graphics::strwidth,USE.NAMES=FALSE)
Codeheight<-sapply(CleanLines,graphics::strheight,USE.NAMES=FALSE)
SizeText<-0.98*min(c(
diff(graphics::par("usr")[3:4])/(sum(Codeheight)*1.5),
diff(graphics::par("usr")[1:2])/(max(Codewidth)*1.1))
)
ypos<-length(CodeLines):1
graphics::text(1+graphics::strwidth("M"),ypos,
labels=CleanLines,adj=c(0,0),
cex=SizeText)
graphics::text(0+0.5*graphics::strwidth("M"),ypos,
labels=seq_len(length(CleanLines)),
adj=c(1,0),
cex=SizeText*0.90)
}
plot.aprof<-function(x,y,...){
aprofobject<-x
if(!is.aprof(aprofobject)){
stop("Input does not appear to be of the class \"aprof\"")}
AddMemProf<-!is.null(aprofobject$mem)
SourceFilename <- aprofobject$sourcefile
if(is.null(SourceFilename)){
stop("aprof object requires a defined source code file for plotting")}
NCodeLines<-length(readLines(SourceFilename))
LineDensity<-readLineDensity(aprofobject,Memprof=AddMemProf)
DensityData<-list(Lines=NCodeLines:1,
Time.Density=rep(0,NCodeLines))
DensityData$Time.Density[LineDensity$Line.Numbers]<-LineDensity$Time.Density
layoutmat<-matrix(c(
1,1,1,1,3,3, rep(c(2,2,2,2,4,4),10)),
byrow=TRUE,ncol=6)
graphics::layout(layoutmat)
opar<-graphics::par("mar","bg")
graphics::par(mar=c(0,0,0,0),bg='grey90')
graphics::plot(0,0,type='n',xaxt='n',yaxt='n',bty='n',xlab='',ylab='')
graphics::text(0,0.55,SourceFilename,cex=2)
graphics::segments(-.75,0,.75,0,lwd=1.2)
graphics::segments(c(-.75,.75),c(0,0),c(-.75,.75),c(-0.1,-0.1),lwd=1.2)
PlotSourceCode(SourceFilename)
graphics::plot(0,0,type='n',xaxt='n',yaxt='n',bty='n',xlab='',ylab='')
graphics::plot(DensityData$Time.Density,DensityData$Lines,
ylim=c(0,NCodeLines+0.5),
type='n',xaxt='n',yaxt='n',bty='n',xlab='',ylab='')
graphics::abline(h=seq_len(NCodeLines),col='white')
graphics::axis(3)
graphics::mtext("Density in execution time(s)",3,cex=.85,padj=-2.5)
graphics::segments(0, DensityData$Lines,
DensityData$Time.Density,DensityData$Lines
,lwd=4,col=grDevices::rgb(0,0,1,alpha=1))
graphics::points(DensityData$Time.Density,DensityData$Lines, pch=20)
if(AddMemProf){
graphics::axis(3,col="blue",lwd=2)
DensityData$MemStats <- rep(0,NCodeLines)
MemLines <- as.integer(names(LineDensity$Total.Mem))
DensityData$MemStats[MemLines]<-LineDensity$Total.Mem
DensityData$PlotStats <- DensityData$MemStats/max(DensityData$MemStats)
DensityData$PlotStats <- DensityData$PlotStats*
max(DensityData$Time.Density)
graphics::segments(0,DensityData$Lines+0.1,
DensityData$PlotStats,DensityData$Lines+0.1
,lwd=4,col=grDevices::rgb(1,0,0,alpha=1))
graphics::par(xaxt="s")
xloc <- range(DensityData$Time.Density)
graphics::axis(1,
at=c(xloc[1],xloc[2]/2,xloc[2]),
labels=round(c(0,max(DensityData$MemStats)/2,
max(DensityData$MemStats)),1),
line=-3.5,col='red',lwd=2,cex.lab=0.9)
graphics::mtext("Total memory usage (MB)",1,cex=.8,padj=-1.5)
graphics::points(DensityData$PlotStats,DensityData$Lines+.1, pch=20)
}
graphics::par(opar)
graphics::layout(1)
}
profileplot <- function(aprofobject){
if(!is.aprof(aprofobject)){
stop("Input does not appear to be of the class \"aprof\"")}
SourceFilename <- aprofobject$sourcefile
if(is.null(SourceFilename)){
stop("aprof object requires a defined source code file for plotting")
}
TargetFile <- aprofobject$sourcefile
calls<-aprofobject$calls
interval <- aprofobject$interval
FileNumber<-unlist(calls)[which(unlist(calls)==TargetFile)+1]
FileNumber <- substr(FileNumber,1,1)
NCodeLines<-length(readLines(SourceFilename))
cleancalls<-sapply(calls, function(x)
gsub("
LineCalls<- unlist(sapply(cleancalls,
function(X) X[grep(paste(FileNumber,
"
,USE.NAMES=FALSE))
nLineCalls<-as.numeric(sapply(LineCalls,function(X)
strsplit(X,"1
timesteps<-seq(0,length(nLineCalls)*interval,interval)
callhistory <- c(1,nLineCalls)
LineDensity<-readLineDensity(aprofobject)
opar<-graphics::par("mar","bg")
maxtimesteps <- max(timesteps)
layoutmat<-matrix(c(rep(c(1,1,1,1,2,2),10)), byrow=TRUE,ncol=6)
graphics::layout(layoutmat)
graphics::par(mar=c(4,4,0.1,0.1),bg='grey90')
graphics::plot(0,0,xlim=c(0,maxtimesteps),ylim=c(1,NCodeLines),
type='n',xaxt='s',yaxt='s', xlab='',ylab='')
graphics::abline(h=1:NCodeLines,col='white')
graphics::mtext("Run time(s)",1,cex=.9,padj=3.4)
graphics::mtext("Line",2,cex=.9,padj=-3.4)
graphics::lines(c(timesteps,maxtimesteps), c(callhistory,NCodeLines),
lwd=2,col=grDevices::rgb(0,0,1,alpha=0.6))
graphics::text(0,1,"Start",col='red',adj=0,cex=1.2)
graphics::text(maxtimesteps,NCodeLines,"End",col='darkgreen',cex=1.2)
callcounts<-table(callhistory)
maxcalls<-as.numeric(names(which(callcounts==max(callcounts))))
graphics::axis(2,at=maxcalls,labels=maxcalls,col.axis='red',
lwd=1.2,col.ticks='red')
graphics::plot(0,0,ylim=c(1,NCodeLines),
xlim = c(0,max(LineDensity$Call.Density/LineDensity$Total.Calls)*1.1),
type='n',xaxt='s',yaxt='s', xlab='',ylab='')
graphics::abline(h = 1:NCodeLines, col = "white")
PerLineDensity <- numeric(NCodeLines)
PerLineDensity[LineDensity$Line.Numbers]<-LineDensity$Call.Density/
LineDensity$Total.Calls
connectedlines <- c(1:NCodeLines)-c(0,rep(.5,NCodeLines-2),0)
graphics::lines(y=connectedlines,x=PerLineDensity,type = "S",lwd=1.3)
graphics::abline(v=0,col='grey30',lty=3)
graphics::axis(4)
graphics::mtext("Line Density", 1, cex = .9, padj = 2.7)
graphics::par(opar)
graphics::layout(1)
}
is.aprof <- function(object) {
inherits(object, "aprof")
}
AmLaw<-function(P=1,S=2){
1/((1-P)+P/S)
}
summary.aprof<-function(object,...){
aprofobject<-object
LineProf<-readLineDensity(aprofobject)
PropLines<-LineProf$Time.Density/LineProf$Total.Time
Speedups<-2^c(0:4)
SpeedTable<-sapply(Speedups,function(X) AmLaw(P=PropLines,S=X))
if(is.null(nrow(SpeedTable))) SpeedTable <- matrix(SpeedTable,nrow=1)
ExecTimeTable<-LineProf$Total.Time/SpeedTable
ExecTimeTable<-rbind(ExecTimeTable,LineProf$Total.Time/Speedups)
SpeedTable<-cbind(SpeedTable,1/(1-PropLines))
dimnames(SpeedTable)<-list(paste("Line*:",
LineProf$Line.Numbers,":"),
c(Speedups,"S -> Inf**"))
SpeedTable<-SpeedTable[order(PropLines,decreasing=TRUE),]
dimnames(ExecTimeTable)<-list(c(paste("Line*:",
LineProf$Line.Numbers,":"),
"All lines"),Speedups)
ExecTimeTable<-ExecTimeTable[order(
c(PropLines,sum(PropLines)),
decreasing=TRUE),]
cat("Largest attainable speed-up factor for the entire program\n
when 1 line is sped-up with factor (S): \n\n")
cat("\t Speed up factor (S) of a line \n")
print.default(format(SpeedTable,digits = 3),print.gap = 2L,
quote = FALSE)
cat("\nLowest attainable execution time for the entire program when\n
lines are sped-up with factor (S):\n\n")
cat("\t Speed up factor (S) of a line \n")
print.default(format(ExecTimeTable,digits = 3),print.gap = 2L,
quote = FALSE)
cat("\n Total sampling time: ",round(LineProf$Total.Time,2) ,
" seconds")
cat("\n * Expected improvement at current scaling")
cat("\n ** Asymtotic max. improvement at current scaling\n\n")
invisible(SpeedTable)
}
targetedSummary<-function(target=NULL,aprofobject=NULL,findParent=FALSE){
if(is.null(target)){stop("Function requires target line number")}
if(is.null(aprofobject$calls)){
stop(paste("Calls appear empty - no call stack samples.",
"Did the program run too fast? ")) }
calls <- aprofobject$calls
interval <- aprofobject$interval
if(is.null(aprofobject$sourcefile)) {
TargetFile<-"1
warning("sourcefile empty, assumed first file in callstack is the source")
} else {
sourcefile <- aprofobject$sourcefile
FileNumber<-unlist(calls)[which(unlist(calls)==sourcefile)+1]
TargetFile <- paste(substr(FileNumber,1,1),"
}
FileNames<-unlist(calls)[which(unlist(calls)=="
TotalTime<-length(calls)*interval
Lcalls<-sapply(calls,function(x) gsub(TargetFile,"L",x),USE.NAMES=FALSE)
for(i in seq_len(length(FileNames))){
Lcalls<-sapply(Lcalls,function(x) gsub(paste(i,"
,paste(FileNames[i],
'
x),USE.NAMES=FALSE)
}
tlines <- sapply(Lcalls,function(X) paste("L",target,sep='')%in%X)
TargetCalls<-Lcalls[tlines]
if(sum(tlines)==0){stop("Target line not found in profiler output.\n
Confirm target line and run again") }
trimmedTargetCalls<-lapply(TargetCalls,function(X)
X[1+max(grep(paste("L",target,sep=''),
X)):length(X)])
CallCounts<-table(stats::na.omit(unlist(trimmedTargetCalls)))
if(findParent==TRUE) {
parentCalls <- vector(mode="character", length=
length(CallCounts))
for(i in seq_len(length(CallCounts))){
parentCalls[i]<-names(
sort(table(unlist(
lapply(TargetCalls,
function(X) X[which(names(CallCounts)[i]==X)[1]-1]
))),decreasing=TRUE)[1])
}
CallOrder <- order(CallCounts,decreasing=TRUE)
CallCounts <- CallCounts[CallOrder]
parentCalls <- parentCalls[CallOrder]
FinalTable<-data.frame(Function=names(CallCounts),
Parent=parentCalls, Calls=CallCounts,
Time=CallCounts*interval)
} else {
CallCounts <- sort(CallCounts,decreasing=TRUE)
FinalTable <- data.frame(Function=names(CallCounts),
Calls=CallCounts,
Time=CallCounts*interval)
}
row.names(FinalTable) <- NULL
return(FinalTable)
} |
library(testthat)
context("Test matrix inversion")
test_that("Matrix inversion gives acceptable result", {
mata <- matrix(c(2,1,1,0), nrow = 2, ncol = 2, byrow = T)
matb <- matrix(c(0,1,1,-2), nrow = 2, ncol = 2, byrow = T)
expect_equal(ginv(mata), matb)
}) |
"afgen" <-
function (xgrid = seq(0, 1, length = 21), ygrid = seq(0, 1, length = 21),
samples = 1000, binsize = 32)
{
af1vals <- array(0, c(length(xgrid), length(ygrid), samples))
ansc1vals <- array(0, c(length(xgrid), length(ygrid), samples))
free1vals<-ansc1vals
for (i in 1:length(xgrid)) {
for (j in 1:length(ygrid)) {
x1vals <- rbinom(samples, binsize, xgrid[i])
x2vals <- rbinom(samples, binsize, ygrid[j])
x1x2 <- rbind(x1vals, x2vals)
maxi <- which.max(c(xgrid[i], ygrid[j]))
ansc1vals[i, j, ] <- ansc(x1x2[maxi, ], binsize)
free1vals[i, j, ] <- free(x1x2[maxi, ], binsize)
af1vals[i, j, ] <- (x2vals - x1vals)/sqrt((x1vals +
x2vals) * ((2 * binsize) - (x1vals + x2vals))/(2 *
binsize))
}
}
af1vals[which(abs(af1vals) == Inf)] <- 0
af1vals[which(is.na(af1vals))] <- 0
ansc1vals[which(abs(ansc1vals) == Inf)] <- 0
ansc1vals[which(is.na(ansc1vals))] <- 0
free1vals[which(abs(free1vals) == Inf)] <- 0
free1vals[which(is.na(free1vals))] <- 0
return(list(a = af1vals, b = ansc1vals, c = free1vals))
} |
prettify_FCA <- function(contents = NA, language = NA){
if(http_error("http://www.google.com")){
stop(
"This function requires an Internet connection."
)
}
language <- tolower(language)
languages <- Languages()[["FCA"]]
if(isNA(contents) && isAvailable()){
context <- RStudioContext()
if(is.na(language)){
ext <- tolower(fileExt(context[["path"]]))
if(ext %in% names(languages)){
language <- languages[[ext]]
}else{
stop("Unrecognized or unsupported language.")
}
}else{
if(!is.element(language, languages)){
stop("Unrecognized or unsupported language.")
}
}
contents <- context[["contents"]]
}else if(isNA(contents)){
stop("You have to provide something for the `contents` argument.")
}else{
if(is.na(language)){
if(!isFile(contents)){
stop("You have to set a language.")
}
ext <- tolower(fileExt(contents))
if(ext %in% names(languages)){
language <- languages[[ext]]
}else{
stop("Unrecognized or unsupported language.")
}
}else if(!isFile(contents) && !is.element(language, languages)){
stop("Unrecognized or unsupported language.")
}
}
if(isFile(contents)){
contents <- suppressWarnings(readLines(contents))
}
code <- paste0(contents, collapse = "\n")
url <- switch(
language,
java = "http://aozozo.com:600/java",
json = "http://aozozo.com:600/json",
ruby = "http://www.zafuswitchout.com:3001/ruby"
)
request <- POST(url, content_type("text/plain; charset=UTF-8"), body = code)
if(request$status_code == 200){
prettyCode <- URLdecode(content(request, "text"))
}else{
stop("Failed to prettify.")
}
prettyCode
} |
p.grm <-
function(theta, params){
p <- .Call("pgrm", theta, params)
return(p)
} |
set.seed(5)
test_data <- data.frame(patient_id = rep(1:15, each = 4),
visit = rep(1:4, 15),
var_1 = c(rnorm(20, -1), rnorm(20, 3), rnorm(20, 0.5)) +
rep(seq(from = 0, to = 1.5, length.out = 4), 15),
var_2 = c(rnorm(20, 0.5, 1.5), rnorm(20, -2, 0.3),
rnorm(20, 4, 0.5)) +
rep(seq(from = 1.5, to = 0, length.out = 4), 15))
model_list <- list(flexmix::FLXMRmgcv(as.formula("var_1 ~ .")),
flexmix::FLXMRmgcv(as.formula("var_2 ~ .")))
clustering <- longitudinal_consensus_cluster(
data = test_data,
id_column = "patient_id",
max_k = 3,
reps = 3,
model_list = model_list
)
save_png <- function(code, width = 400, height = 3200) {
path <- tempfile(fileext = ".png")
png(path, width = width, height = height)
op <- par(mfrow = c(8, 1))
on.exit(dev.off())
on.exit(par(op), add = TRUE)
code
path
}
test_that("a plot is generated in the CI", {
skip_if_not(isTRUE(as.logical(Sys.getenv("CI"))),
message = "simple plot generation only tested on CI")
test_plot <- plot(clustering)
expect_equal(test_plot, matrix(c(0.7, 1.9, 3.1, 4.3, 5.5, 6.7, 7.9),
nrow = 7))
})
test_that("the plots stay the same", {
skip_on_ci()
expect_snapshot_file(save_png(plot(clustering)), "plot_lcc_output.png")
})
test_that("plot.lcc only uses lcc objects", {
expect_error(plot.lcc(1:10))
})
test_that("the color_palette argument is correct", {
expect_error(plot(clustering, color_palette = 1:10),
regexp = "Assertion on 'color_palette' failed")
expect_silent(plot(clustering,
color_palette = c("
}) |
port <- Sys.getenv("CI_ES_PORT", "9200")
Sys.setenv(TEST_ES_PORT = port)
stop_es_version <- function(conn, ver_check, fxn) {
ver <- es_version(conn)
if (ver < ver_check) {
stop(fxn, " is not available for this Elasticsearch version",
call. = FALSE)
}
}
es_version <- function(conn, ver_check, fxn) {
xx <- conn$info()$version$number
xx <- gsub("[A-Za-z]", "", xx)
as.numeric(gsub("\\.|-", "", xx))
}
load_shakespeare <- function(conn) {
if (conn$es_ver() < 600) {
shakespeare <- system.file("examples", "shakespeare_data.json",
package = "elastic")
} else if (conn$es_ver() >= 700) {
shakespeare <- system.file("examples", "shakespeare_data_.json",
package = "elastic")
shakespeare <- type_remover(shakespeare)
} else {
shakespeare <- system.file("examples", "shakespeare_data_.json",
package = "elastic")
}
if (index_exists(conn, 'shakespeare')) index_delete(conn, 'shakespeare')
invisible(suppressWarnings(elastic::docs_bulk(conn, shakespeare)))
}
load_plos <- function(conn) {
plos <- system.file("examples", "plos_data.json", package = "elastic")
if (conn$es_ver() >= 700) plos <- type_remover(plos)
if (index_exists(conn, 'plos')) index_delete(conn, 'plos')
invisible(suppressWarnings(elastic::docs_bulk(conn, plos)))
}
load_omdb <- function(conn) {
omdb <- system.file("examples", "omdb.json", package = "elastic")
if (!index_exists(conn, 'omdb'))
invisible(suppressWarnings(elastic::docs_bulk(conn, omdb)))
} |
tdlnre.lnre.gigp <- function (model, x, ...)
{
if (! inherits(model, "lnre.gigp")) stop("first argument must be object of class 'lnre.gigp'")
gamma <- model$param$gamma
b <- model$param$B
c <- model$param$C
C <- (2 / (b*c))^(gamma+1) / (2 * besselK(b, gamma+1))
d <- C * x^(gamma-1) * exp(- x/c - (b*b*c)/(4*x))
d
}
dlnre.lnre.gigp <- function (model, x, ...)
{
if (! inherits(model, "lnre.gigp")) stop("first argument must be object of class 'lnre.gigp'")
gamma <- model$param$gamma
b <- model$param$B
c <- model$param$C
C <- (2 / (b*c))^(gamma+1) / (2 * besselK(b, gamma+1))
d <- C * x^gamma * exp(- x/c - (b*b*c)/(4*x))
d
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.