code
stringlengths 1
13.8M
|
---|
print.summary.aftreg <- function(x,
digits = max(getOption("digits") - 3, 3),
short = FALSE, ...){
if (!("summary.aftreg" %in% class(x))){
stop("Only for 'summary.aftreg' ojects.")
}
if (!is.null(x$fail)) {
if (x$fail != 0){
cat(" coxreg failed with: ")
stop(x$fail)
}
}
if (x$nullModel){
cat("Null model\n")
return()
}
savedig <- options(digits = digits)
on.exit(options(savedig))
coef <- x$coefficients[, 1]
se <- x$coefficients[, 3]
wald.p <- formatC(pchisq((coef / se)^2, 1, lower.tail = FALSE),
digits = digits,
width = 9, format = "f")
if(is.null(coef) | is.null(se))
stop("Input is not valid")
lp <- !is.null(x$dr)
if (lp){
dr <- x$dr[rownames(x$dr) %in% x$covars, ]
lpval <- formatC(dr[, 4], digits = digits, width = 9, format = "f")
}
ord <- attr(x$terms, "order")
if (any(ord > 1)){
lp <- FALSE
if (!is.null(x$dr)){
print(x$dr)
cat("\n")
}
}
if (x$param == "lifeAcc"){
cat("Covariate W.mean Coef Time-Accn se(Coef) LR p\n")
}else{
cat("Covariate W.mean Coef Life-Expn se(Coef) LR p\n")
}
e.coef <- formatC(exp(coef), width = 9, digits = 3, format = "f")
coef <- formatC(coef, width = 9, digits = 3, format = "f")
se <- formatC(se, width = 9, digits = 3, format = "f")
ett <- formatC(1, width = 9, digits = 0, format = "f")
noll <- formatC(0, width = 5, digits = 0, format = "f")
factors <- attr(x$terms, "factors")
resp <- attr(x$terms, "response")
row.strata <- attr(x$terms, "specials")$strata
if (!is.null(row.strata)){
col.strata <- which(factors[row.strata, ] == 1)
}else{
col.strata <- NULL
}
if (!is.null(col.strata)){
factors <-
attr(x$terms, "factors")[-c(resp, row.strata), -col.strata,
drop = FALSE]
}else{
factors <-
attr(x$terms, "factors")[-c(resp, row.strata), ,
drop = FALSE]
}
covar.names <- x$covars
term.names <- colnames(factors)
isF <- x$isF
if (!is.null(col.strata)) ord <- ord[-col.strata]
index <- 0
lpindx <- 0
for (term.no in 1:length(term.names)){
if (ord[term.no] == 1){
covar.no <- which(factors[, term.no] == 1)
if (isF[covar.no]){
if (lp){
lpindx <- lpindx + 1
outp <- formatC(covar.names[covar.no], width = 56,
flag = "-")
cat(outp, lpval[lpindx], "\n")
}else{
cat(covar.names[covar.no], "\n")
}
no.lev <- length(x$levels[[covar.no]])
x$levels[[covar.no]] <-
substring(x$levels[[covar.no]], 1, 16)
cat(formatC(x$levels[[covar.no]][1], width = 16, flag = "+"),
formatC(x$w.means[[covar.no]][1],
width = 10, digits = 3, format = "f"),
noll,
ett,
" (reference)\n")
for (lev in 2:no.lev){
index <- index + 1
cat(formatC(x$levels[[covar.no]][lev], width = 16,
flag = "+"),
formatC(x$w.means[[covar.no]][lev],
width = 10, digits = 3, format = "f"),
coef[index],
e.coef[index],
se[index])
if (lp){
cat("\n")
}else{
cat(formatC(wald.p[index],
digits = 3,
width = digits + 2,
format = "f"),
"\n")
}
}
}else{
index <- index + 1
xxx <- x$w.means[[covar.no]]
if (inherits(xxx, "Date")){
xxx <- as.character(xxx)
}else{
xxx <- formatC(xxx,
width = 10, digits = 3, format = "f")
}
cat(formatC(substr(covar.names[covar.no], 1, 16),
width = 16, flag = "-"),
xxx,
coef[index],
e.coef[index],
se[index])
if (lp){
lpindx <- lpindx + 1
ppv <- lpval[lpindx]
}else{
ppv <- wald.p[index]
}
cat(formatC(ppv,
digits = 3,
width = digits + 2,
format = "f"), "\n")
}
}else if (ord[term.no] > 1){
cat(formatC(term.names[term.no], width = 16, flag = "-"), "\n")
niv <- numeric(ord[term.no])
covar.no <- which(factors[, term.no] == 1)
for (i in 1:ord[term.no]){
if (isF[covar.no[i]]){
niv[i] <- length(x$levels[[covar.no[i]]]) - 1
}else{
niv[i] <- 1
}
}
stt <- index + 1
for (index in stt:(stt + prod(niv) - 1)){
vn <- sub(covar.names[covar.no[1]], "", names(coef)[index])
for (i in 1:ord[term.no]){
vn <- sub(covar.names[covar.no[i]], "", vn)
}
cat(formatC(" ", width = 2),
formatC(substring(vn, 1, 22), width = 22, flag = "-"),
coef[index],
e.coef[index],
se[index],
formatC(wald.p[index],
digits = 3,
width = digits + 2,
format = "f"),
"\n")
}
}
}
if(FALSE){
tmp <- cbind(coef, exp(coef), se,
signif(1 - pchisq((coef/ se)^2, 1), digits - 1))
dimnames(tmp) <- list(names(coef), c("coef", "rel. risk",
"se(coef)", "p"))
cat("\n")
prmatrix(tmp)
}
if (!is.null(x$frailty)){
cat("\nFrailty standard deviation = ", x$sigma, "\n")
cat(" S.E. = ", x$sigma.sd, "\n\n")
}
logtest <- -2 * (x$loglik[1] - x$loglik[2])
if (is.null(x$df)){
df <- sum(!is.na(coef))
}else{
df <- round(sum(x$df),2)
}
if (!short){
cat("\n")
cat(formatC("Events", width = 25, flag = "-"), x$n.events, "\n")
cat(formatC("Total time at risk", width = 25, flag = "-"),
formatC(x$ttr, digits = 5, format = "fg"), "\n")
cat(formatC("Max. log. likelihood", width = 25, flag = "-"),
formatC(x$loglik[2], digits = 5, format = "fg"), "\n")
cat(formatC("LR test statistic", width = 25, flag = "-"),
format(round(logtest, 2), nsmall = 2), "\n")
cat(formatC("Degrees of freedom", width = 25, flag = "-"),
formatC(df, digits = 0, format = "f"), "\n")
cat(formatC("Overall p-value", width = 25, flag = "-"),
format.pval(1 - pchisq(logtest, df), digits = 6, "\n"))
cat("\n")
if (length(x$icc))
cat(" number of clusters=", x$icc[1],
" ICC=", format(x$icc[2:3]), "\n")
}
invisible(x)
}
|
rm(list=ls())
library(quadrupen)
seed <- 8527
cat("\nseed
set.seed(seed)
mu <- 3
sigma <- 10
beta <- rep(c(0,1,0,-1,0), c(25,10,25,10,25))
Soo <- matrix(0.75,25,25)
Sww <- matrix(0.75,10,10)
Sigma <- bdiag(Soo,Sww,Soo,Sww,Soo) + 0.2
diag(Sigma) <- 1
n <- 100
x <- as.matrix(matrix(rnorm(95*n),n,95) %*% chol(Sigma))
y <- mu + x %*% beta + rnorm(n,0,10)
fit01 <- bounded.reg(x,y, lambda2=0,min.ratio=1e-4, control=list(bulletproof=FALSE))
fit11 <- bounded.reg(x,y, lambda2=0,min.ratio=1e-4)
fit02 <- bounded.reg(x,y, lambda2=0.1,min.ratio=1e-4, control=list(bulletproof=FALSE))
fit12 <- bounded.reg(x,y, lambda2=0.1,min.ratio=1e-4)
|
averaged.network.backend = function(strength, threshold) {
nodes = attr(strength, "nodes")
e = empty.graph(nodes)
significant = (strength$strength > threshold) | (strength$strength == 1)
if ("direction" %in% names(strength))
significant = significant & (strength$direction >= 0.5)
if (!any(significant))
return(e)
candidate.arcs = as.matrix(strength[significant, c("from", "to"), drop = FALSE])
if (all(which.undirected(candidate.arcs))) {
e$arcs = candidate.arcs
}
else {
e$arcs = .Call(call_smart_network_averaging,
arcs = candidate.arcs,
nodes = nodes,
weights = strength$strength[significant])
}
e$nodes = cache.structure(nodes, arcs = e$arcs)
if ("illegal" %in% names(attributes(strength)))
e$learning$illegal = attr(strength, "illegal")
return(e)
}
threshold = function(strength, method = "l1") {
if (nrow(strength) == 0)
return(0)
e = ecdf(strength$strength)
u = knots(e)
if (method == "l1") {
norm = function(p)
sum( diff(unique(c(0, u, 1))) * abs(e(unique(c(0, u[u < 1]))) - p))
}
p0 = optimize(f = norm, interval = c(0, 1))$minimum
if (norm(1) < norm(p0))
p0 = 1
if (norm(0) < norm(p0))
p0 = 0
quantile(strength$strength, p0, type = 1, names = FALSE)
}
|
predValues <- function(sens, spec, prev){
if(all(sens < 0 | sens > 1))
stop("'sens' has to be in [0,1]")
if(all(spec < 0 | spec > 1))
stop("'spec' has to be in [0,1]")
if(length(sens) != length(spec))
stop("lengths of 'sens' and 'spec' have to be identical")
if(length(prev) > 1)
stop("'pre' has to be of length 1")
if(prev < 0 | prev > 1)
stop("'pre' has to be in [0,1]")
ppv <- sens*prev/(sens*prev + (1-spec)*(1-prev))
npv <- spec*(1-prev)/(spec*(1-prev) + (1-sens)*prev)
if(length(sens) > 1)
res <- cbind("PPV" = ppv, "NPV" = npv)
else
res <- c("PPV" = ppv, "NPV" = npv)
res
}
|
with_fake_input <- function(input, expr) {
with_mock(
`crunch:::is.interactive` = function() return(TRUE),
`crunch:::read_input` = function(...) input,
eval.parent(expr)
)
}
with_interactive <- function(expr) {
with_mock(
`crunch:::is.interactive` = function() return(TRUE),
eval.parent(expr)
)
}
without_interactive <- function(expr) {
with_mock(
`crunch:::is.interactive` = function() return(FALSE),
eval.parent(expr)
)
}
uniqueDatasetName <- now
objects_to_purge <- c()
new.dataset.with.setup <- function(df = NULL, ...) {
unique.name <- uniqueDatasetName()
if (is.dataset(df)) {
out <- df
} else if (is.null(df)) {
out <- createDataset(name = unique.name, ...)
} else {
out <- suppressMessages(newDataset(df, name = unique.name, ...))
}
objects_to_purge <<- c(objects_to_purge, self(out))
return(out)
}
purge.object <- function() {
len <- length(objects_to_purge)
if (len) {
try(crDELETE(objects_to_purge[len]), silent = TRUE)
objects_to_purge <<- objects_to_purge[-len]
}
}
test.dataset <- function(df = NULL, obj.name = "ds", ...) {
return(ContextManager(
function() new.dataset.with.setup(df, ...),
purge.object,
as = obj.name
))
}
reset.option <- function(opts) {
old <- sapply(opts, getOption, simplify = FALSE)
return(ContextManager(
null,
function() do.call(options, old)
))
}
uniqueEmail <- function() paste0("test+", as.numeric(Sys.time()), "@crunch.io")
testUser <- function(email = uniqueEmail(), name = paste("Ms.", email, "User"), ...) {
u.url <- invite(email, name = name, notify = FALSE, ...)
return(UserEntity(crGET(u.url)))
}
|
q.cor <-
function(x, set, sex, fem=1, male=2, tails=2, sims=1000, seed=2) {
new.data <- data.frame(cbind(sex, x, set))
Comb.N <- nrow(subset(new.data, complete.cases(new.data)))
female <- subset(new.data, sex == fem)
Fem.N <- nrow(subset(female, complete.cases(female)))
fem.cols <- female[,-1:-2]
male <- subset(new.data, sex == male)
Male.N <- nrow(subset(male, complete.cases(male)))
male.cols <- male[,-1:-2]
Ns <- cbind(Comb.N, Fem.N, Male.N)
rownames(Ns) <- c("N")
colnames(Ns) <- c("Combined", "Female", "Male")
comb.cor <- data.frame(t(cor(x, set, use="pairwise")))
names(comb.cor) <- c("Combined")
comb.sig <- data.frame(sig.r(abs(comb.cor$Combined), Comb.N, tails))
names(comb.sig) <- c("p.C")
comb.out <- data.frame(cbind(comb.cor, comb.sig))
fem.cor <- data.frame(t(cor(female[,2], fem.cols, use="pairwise")))
names(fem.cor) <- c("Female")
fem.sig <- data.frame(sig.r(abs(fem.cor$Female), Fem.N, tails))
names(fem.sig) <- c("p.F")
fem.out <- data.frame(cbind(fem.cor, fem.sig))
male.cor <- data.frame(t(cor(male[,2], male.cols, use="pairwise")))
names(male.cor) <- c("Male")
male.sig <- data.frame(sig.r(abs(male.cor$Male), Male.N, tails))
names(male.sig) <- c("p.M")
male.out <- data.frame(cbind(male.cor, male.sig))
cortable <- data.frame(cbind(comb.out, fem.out, male.out))
vec.corr <- cor(cortable$Female, cortable$Male)
cortable.order <- cortable[order(cortable$Combined, cortable$Female, cortable$Male, decreasing=T),]
comb.order.sig <- data.frame(sig.r(abs(cortable.order$Combined), Comb.N, tails))
fem.order.sig <- data.frame(sig.r(abs(cortable.order$Female), Fem.N, tails))
male.order.sig <- data.frame(sig.r(abs(cortable.order$Male), Male.N, tails))
names(comb.order.sig) <- c("p.C")
names(fem.order.sig) <- c("p.F")
names(male.order.sig) <- c("p.M")
sort.out <- data.frame(cbind(cortable.order$Combined, comb.order.sig, cortable.order$Female, fem.order.sig, cortable.order$Male, male.order.sig))
names(sort.out) <- c("Combined", "p.C", "Female", "p.F", "Male", "p.M")
rownames(sort.out) <- rownames(cortable.order)
if (sims != FALSE) {
all.test <- rand.test(data.frame(x), set, sims=1000, graph=F, seed=seed)
fem.test <- rand.test(data.frame(female[,2]), fem.cols, sims=sims, graph=F, seed=seed)
male.test <- rand.test(data.frame(male[,2]), male.cols, sims=sims, graph=F, seed=seed)
result <- list("N"=Ns, "corrs"=cortable, "sorted"=sort.out, "vector.cor"=vec.corr, "combined"=all.test, "fem.test"=fem.test, "male.test"=male.test)
}
if (sims == FALSE) {
result <- list("N"=Ns, "corrs"=cortable, "sorted"=sort.out, "vector.cor"=vec.corr)
}
class(result) <- c("q.cor")
return(result)
}
|
stat_pde_density <- function(mapping = NULL,
data = NULL,
geom = "violin",
position = "dodge",
...,
trim = TRUE,
scale = "area",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE) {
scale <- match.arg(scale, c("area", "count", "width"))
ggplot2::layer(
data = data,
mapping = mapping,
stat = StatPDEdensity,
geom = geom,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(
trim = trim,
scale = scale,
na.rm = na.rm,
...
)
)
}
compute_pdedensity <- function(x) {
nx <- length(x)
if (nx < 2) {
warning("stat_pde_density: Groups with fewer than two data points have been dropped.",
call. = FALSE)
return(
data.frame(
x = NA_real_,
density = NA_real_,
scaled = NA_real_,
count = NA_real_,
n = NA_integer_
)
)
}
Flag <- FALSE
if (length(unique(x)) ==1) {
warning('stat_pde_density: Only one unique value in Data.')
if(unique(x)!=0)
x <- c(unique(x), head(x, 1) * runif(1, 0.999, 1.001))
else
x <- c(unique(x), head(x, 1) + runif(1, 0.999, 1.001))
Flag <- TRUE
}
dens <- ParetoDensityEstimation(Data = x)
if (Flag) {
dens$kernels <- dens$kernels * runif(length(dens$kernels), 0.998, 1.002)
x <- max(dens$kernels) - min(dens$kernels)
dens$paretoDensity[1:length(dens$paretoDensity)] <- 1 / x
}
data.frame(
x = dens$kernels,
density = dens$paretoDensity,
scaled = dens$paretoDensity / max(dens$paretoDensity, na.rm = TRUE),
count = dens$paretoDensity * nx,
n = nx
)
}
StatPDEdensity <- ggproto("StatPDEdensity",
Stat,
required_aes = c("x", "y"),
compute_group = function(data,
scales,
width = NULL,
trim = TRUE,
na.rm = FALSE) {
if (nrow(data) < 3)
return(data.frame())
range <- range(data$y, na.rm = TRUE)
modifier <- if (trim) 0 else 3
dens <- compute_pdedensity(data$y)
dens$y <- dens$x
dens$x <- mean(range(data$x))
if (length(unique(data$x)) > 1) {
width <- diff(range(data$x)) * 0.9
}
dens$width <- width
dens
},
compute_panel = function(self,
data,
scales,
width = NULL,
trim = TRUE,
na.rm = FALSE,
scale = "area") {
data <- ggproto_parent(Stat, self)$compute_panel(
data,
scales,
width = width,
trim = trim,
na.rm = na.rm
)
data$violinwidth <- switch(
scale,
area = data$density / max(data$density),
count = data$density / max(data$density) * data$n / max(data$n),
width = data$scaled
)
data
}
)
|
dskt<-function(x,df,gamma=1)
{
result<-rep(NA,length(x))
result[x<0]<-2/(gamma+1/gamma)*dt(gamma*x[x<0],df)
result[x>=0]<-2/(gamma+1/gamma)*dt(x[x>=0]/gamma,df)
result
}
pskt<-function(x,df,gamma=1)
{
result<-rep(NA,length(x))
result[x<0]<-2/(gamma^2+1)*pt(gamma*x[x<0],df)
result[x>=0]<-1/(gamma^2+1) + 2/(1+(1/gamma^2))*(pt(x[x>=0]/gamma,df) - 1/2)
result
}
qskt<-function(p,df,gamma)
{
result2<-rep(NA,length(p))
probzero<-pskt(0,df,gamma)
result2[p<probzero]<-1/gamma*qt(((gamma^2+1)*p[p<probzero])/2,df)
result2[p>=probzero]<-gamma*qt((1+1/gamma^2)/2*(p[p>=probzero]-probzero)+1/2,df)
result2
}
rskt<-function(n,df,gamma)
{
u<-runif(n)
result3<-qskt(u,df,gamma)
result3
}
|
{}
spikeAndSlab <- function(
y,
X,
family = c("gaussian", "binomial", "poisson"),
hyperparameters = list(),
model = list(),
mcmc = list(),
start = list()
) {
startTime <- Sys.time()
if (is.null(X) || is.null(y)) stop("Need X and y.")
familystr <- match.arg(family)
family <- as.integer(switch(familystr,
"gaussian" = 0,
"binomial" = 1,
"poisson" = 2
))
if ((family != 0) && (any(y < 0))) {
stop("non-gaussian responses must be non-negative.\n")
}
if ((family == 1) && (any(y > 1))) {
stop("binomial responses must be between 0 and 1.\n")
}
if ((family == 2) && (any(y %% 1 != 0))) {
stop("poisson reponses must be integers.")
}
y <- as.matrix(y)
X <- as.matrix(X)
n <- nrow(y)
if (nrow(X) != n) {
stop(simpleError("X doesn't have same length as y."))
}
q <- ncol(X)
defaultMcmc <-
list(
nChains = 3,
chainLength = 500,
burnin = 100,
thin = 5,
verbose = TRUE,
returnSamples = TRUE,
sampleY = FALSE,
useRandomStart = TRUE,
blocksize = if (family == 0) {
50
} else {
c(5, 15)
} ,
scalemode = 1,
allKsi = TRUE,
modeSwitching = 0.05,
reduceRet = FALSE
)
mcmc <- modifyList(defaultMcmc, mcmc)
if (length(mcmc$blocksize) == 2) {
mcmc$blocksizeAlpha <- mcmc$blocksize[1]
mcmc$blocksizeKsi <- mcmc$blocksize[2]
} else {
mcmc$blocksizeAlpha <- mcmc$blocksizeKsi <- mcmc$blocksize
}
mcmc$chainLength <- as.integer(mcmc$chainLength)
mcmc$burnin <- as.integer(mcmc$burnin)
mcmc$thin <- as.integer(mcmc$thin)
with(
mcmc,
stopifnot(
all(c(chainLength, burnin, thin) >= c(1, 0, 1)),
scalemode %in% c(-1, 0, 1, 2)
)
)
mcmc$totalLength <- with(mcmc, burnin + thin * chainLength)
H <- diag(q - 1)
colnames(H) <- rownames(H) <- seq_len(q - 1)
defaultModel <-
list(
groupIndicators = c("u", seq_len(q - 1)),
H = H,
n = n,
q = q,
scale = rep(1, n),
offset = rep(0, n)
)
model <- modifyList(defaultModel, as.list(model))
if (length(model$groupIndicators) != model$q) {
oldGroupIndicators <- model$groupIndicators
model$groupIndicators <- rep(model$groupIndicators, length.out = q)
warning(simpleWarning(paste(
"Length of model$groupIndicators did not equal",
"the number of columns in design matrix X.\n",
"Expanded to\n",
paste(model$groupIndicators, collapse = " "),
"\nfrom \n",
paste(oldGroupIndicators, collapse = " ")
)))
}
model$groupIndicatorsOrig <- model$groupIndicators
unpen <- which(model$groupIndicators == "u")
pUnpen <- length(unpen)
unpenLevels <- if (pUnpen) paste("u.", 1:length(unpen), sep = "") else c()
model$groupIndicators[unpen] <- unpenLevels
d1Levels <- if (pUnpen) {
model$groupIndicators[which(!(model$groupIndicators %in%
c("u", names(table(model$groupIndicators[-unpen]))[
table(model$groupIndicators[-unpen]) > 1
])))]
} else {
model$groupIndicators[which(!(model$groupIndicators %in%
c(names(table(model$groupIndicators))[table(model$groupIndicators) > 1])))]
}
d1Levels <- setdiff(d1Levels, unpenLevels)
grpLevels <- unique(model$groupIndicators[which(!(model$groupIndicators %in%
c(unpenLevels, d1Levels)))])
model$groupIndicators <- factor(model$groupIndicators,
levels = c(unpenLevels, d1Levels, grpLevels), ordered = T
)
properOrder <- order(model$groupIndicators)
properPenOrder <- order(model$groupIndicators[!(model$groupIndicators %in%
unpenLevels)])
reverseOrder <- order(properOrder)
reversePenOrder <- order(properPenOrder)
model$groupIndicators <- model$groupIndicators[properOrder]
model$H <- model$H[c(d1Levels, grpLevels), c(d1Levels, grpLevels)]
model$hierarchy <- apply(model$H * upper.tri(model$H), 1, function(x) {
ind <- max(0, which(x != 0) - 1)
})
model$properOrder <- properOrder
model$reverseOrder <- reverseOrder
model$d <- table(model$groupIndicators)
model$nGroups <- length(model$d)
model$G <- if (nlevels(model$groupIndicators) > 1) {
with(model,
model.matrix(~0 + groupIndicators,
contrasts.arg = list(groupIndicators = contr.treatment)))
} else {
matrix(1, nrow = length(model$groupIndicators), ncol = 1)
}
model$nUnpenGrps <- pUnpen
model$nPenGrps <- model$nGroups - pUnpen
if (!mcmc$allKsi) {
model$updateKsiGrps <- which(!(unique(model$groupIndicators) %in%
names(model$d)[model$d == 1]))
model$updateKsi <- which(!(model$groupIndicators %in%
names(model$d)[model$d == 1]))
} else {
model$updateKsiGrps <- 1:model$nGroups
model$updateKsi <- 1:q
}
model$qKsiUpdate <- length(model$updateKsi)
model$qKsiNoUpdate <- model$q - model$qKsiUpdate
X <- X[, model$properOrder]
defaultHyperparameters <-
list(
w = c(alphaW = 1, betaW = 1),
tau2 = c(a1 = 5, a2 = 25),
gamma = c(v0 = 0.00025),
sigma2 = c(b1 = 1e-4, b2 = 1e-4),
varKsi = rep(1, model$qKsiUpdate),
ksiDF = 0
)
hyperparameters <- modifyList(defaultHyperparameters, as.list(hyperparameters))
if (length(hyperparameters$varKsi) == 1) {
hyperparameters$varKsi <- rep(hyperparameters$varKsi, model$qKsiUpdate)
}
with(
hyperparameters,
stopifnot(
all(w > 0),
all(tau2 > 0),
gamma >= 0,
sigma2 > 0
),
ksiDF >= 0,
all(varKsi > 0),
length(varKsi) == model$qKsiUpdate
)
hyperparameters$gamma["v1"] <- 1
names(hyperparameters$w) <- c("alpha", "beta")
names(hyperparameters$tau2) <- c("a1", "a2")
names(hyperparameters$gamma) <- c("v0", "v1")
names(hyperparameters$sigma2) <- c("b1", "b2")
if (!length(start$seed)) start$seed <- as.integer(round(1e6 * runif(1)))
set.seed(start$seed)
gamma <- matrix(if (mcmc$useRandomStart) {
replicate(mcmc$nChains, as.vector(sample(hyperparameters$gamma,
size = model$nPenGrps,
replace = TRUE,
prob = c(1, 0) + c(-1, 1) *
rbeta(
1, hyperparameters$w[1],
hyperparameters$w[2]
)
)))
} else {
replicate(mcmc$nChains, rep(1, model$nPenGrps))
}, ncol = mcmc$nChains)
tau2 <- matrix(if (mcmc$useRandomStart) {
replicate(mcmc$nChains, as.vector(1 / rgamma(
model$nPenGrps,
hyperparameters$tau2[1], hyperparameters$tau2[2]
)))
} else {
replicate(mcmc$nChains, rep(
hyperparameters$tau2[2] / hyperparameters$tau2[1],
model$nPenGrps
))
}, ncol = mcmc$nChains)
sigma2 <- if (mcmc$useRandomStart) {
replicate(mcmc$nChains, as.vector(1 / rgamma(
1,
model$n / 2 + hyperparameters$sigma2[1],
var(y) / 2 + hyperparameters$sigma2[2]
)))
} else {
replicate(mcmc$nChains, var(y) / model$nPenGrps)
}
w <- if (mcmc$useRandomStart) {
replicate(mcmc$nChains, as.vector(rbeta(
1, hyperparameters$w[1],
hyperparameters$w[2]
)))
} else {
replicate(mcmc$nChains, hyperparameters$w[1] / (hyperparameters$w[1] +
hyperparameters$w[2]))
}
if (is.null(start$beta) || (family > 0)) {
betaM <- switch(as.character(family),
"0" = as.vector(solve(
crossprod(sqrt(model$scale) * X) + diag(q),
crossprod(X, y)
)),
"1" = iwls.start(X, y, 1, model$scale, model$offset),
"2" = iwls.start(X, y, 2, model$scale, model$offset)
)
beta <- matrix(if (mcmc$useRandomStart) {
tmp <- replicate(mcmc$nChains, betaM + rnorm(q))
gammaLong <- model$G %*% rbind(matrix(1,
ncol = ncol(gamma),
nrow = model$nUnpenGrps
), gamma)
sapply(1:mcmc$nChains, function(i) tmp[, i] * gammaLong[
,
i
])
}
else {
replicate(mcmc$nChains, betaM)
}, ncol = mcmc$nChains)
} else {
beta <- NULL
}
defaultStart <- list(
beta = beta,
gamma = gamma,
tau2 = tau2,
sigma2 = sigma2,
w = w,
seed = as.integer(start$seed)
)
if (!is.null(start$beta)) {
if (sum(abs(start$beta)) == 0) {
start$beta <- matrix(runif(
q * mcmc$nChains,
-.01, .01
), nrow = q)
}
}
start <- modifyList(defaultStart, start)
with(
start,
stopifnot(
nrow(beta) == model$q,
nrow(gamma) == model$nPenGrps,
nrow(tau2) == model$nPenGrps,
all(gamma %in% hyperparameters$gamma),
all(tau2 > 0),
all(is.finite(tau2)),
is.finite(sigma2),
sigma2 > 0,
all(is.integer(seed))
)
)
if (length(model$updateKsiGrps)) {
ksi <- matrix(start$beta, ncol = mcmc$nChains)
alpha <- matrix(1, nrow = model$nGroups, ncol = mcmc$nChains)
alpha[-model$updateKsiGrps, ] <- drop(t(t(ksi) %*%
model$G[, -model$updateKsiGrps]))
rescales <- apply(abs(ksi[model$updateKsi, , drop = F]), 2, function(x) {
tapply(x, model$groupIndicators[model$updateKsi, drop = T], mean)
})
alpha[model$updateKsiGrps, ] <- alpha[model$updateKsiGrps, ] * rescales
ksi[-model$updateKsi, ] <- 1
ksi[model$updateKsi, ] <- if (length(model$updateKsiGrps) > 1) {
ksi[model$updateKsi, , drop = F] / apply(
rescales, 2, rep,
model$d[model$updateKsiGrps]
)
} else {
ksi[model$updateKsi, , drop = F] / rescales
}
start$ksi <- ksi
start$alpha <- alpha
} else {
start$ksi <- matrix(1, nrow = nrow(start$beta), ncol = mcmc$nChains)
start$alpha <- start$beta
}
with(
start,
stopifnot(
nrow(alpha) == model$nGroups,
nrow(ksi) == model$q
)
)
blocksAlpha <- max(1, round(model$nGroups / mcmc$blocksizeAlpha))
alphaIndABegin <- alphaIndAEnd <- numeric(blocksAlpha)
startInd <- 0
for (i in 1:blocksAlpha) {
alphaIndABegin[i] <- startInd
alphaIndAEnd[i] <- ifelse(
i == blocksAlpha,
model$nGroups - 1,
min(model$nGroups - 1, (startInd + mcmc$blocksizeAlpha - 1))
)
startInd <- alphaIndAEnd[i] + 1
}
blocksizes <- model$d[model$updateKsiGrps]
tooLargeBlock <- blocksizes > 1.5 * mcmc$blocksizeKsi
if (any(tooLargeBlock)) {
blocksizes <- as.list(blocksizes)
for (b in seq(along = blocksizes)) {
if (tooLargeBlock[b]) {
blcks <- round(blocksizes[[b]] / mcmc$blocksizeKsi)
blcksSz <- blocksizes[[b]] %/% blcks
if (sum(rep(blcksSz, blcks)) == blocksizes[[b]]) {
blocksizes[[b]] <- rep(blcksSz, blcks)
} else {
blocksizes[[b]] <- c(rep(blcksSz, blcks - 1), blcksSz +
blocksizes[[b]] %% blcks)
}
}
}
blocksizes <- unlist(blocksizes)
}
ksiIndABegin <- ksiIndAEnd <- numeric()
ksiIndABegin[1] <- ksiIndAEnd[1] <- 1
block <- 0
i <- 1
while (block < length(blocksizes)) {
if (block == max(which(cumsum(blocksizes) - ksiIndABegin[i] <=
mcmc$blocksizeKsi))) {
block <- block + 1
}
else {
block <- max(which(cumsum(blocksizes) - ksiIndABegin[i] <=
mcmc$blocksizeKsi))
}
ksiIndAEnd[i] <- cumsum(blocksizes)[block]
if (block < length(blocksizes)) {
ksiIndABegin[i + 1] <- ksiIndAEnd[i] + 1
i <- i + 1
}
}
ksiIndAEnd <- ksiIndAEnd - 1
ksiIndABegin <- ksiIndABegin - 1
blocksKsi <- length(ksiIndAEnd)
if (mcmc$verbose) {
cat(
"\nModel has ", model$q, " coefficients in ",
model$nGroups, "model terms.\n"
)
cat(
"Blockwise sampling: alpha:", blocksAlpha, " block(s); xi:",
blocksKsi, "block(s).\n"
)
}
pcts <- round(quantile(mcmc$burnin:mcmc$totalLength, seq(.1, .9, by = .1)))
betaMat <- ksiMat <- matrix(0, nrow = mcmc$chainLength, ncol = model$q)
tau2Mat <- gammaMat <- probV1Mat <- matrix(0,
nrow = mcmc$chainLength,
ncol = model$nPenGrps
)
alphaMat <- matrix(0, nrow = mcmc$chainLength, ncol = model$nGroups)
wMat <- likMat <- logPostMat <- sigma2Mat <- matrix(0,
nrow = mcmc$chainLength, ncol = 1
)
parallel <- if (.Platform$OS.type != "windows") {
"parallel"
} else {
"snow"
}
if ((is.null(options()$mc.cores) || is.na(options()$mc.cores))) {
if (interactive()) {
options(mc.cores = as.integer(readline(
prompt =
paste0(
"Setting up parallel computation:\n",
"How many processes do you want to run? "
)
)))
stopifnot(
!is.null(options()$mc.cores), !is.na(options()$mc.cores),
options()$mc.cores > 0
)
} else {
message(
"Using 2 parallel processes.\n",
"Use 'options(mc.cores = <YourNumberHere>)' to override next time."
)
options(mc.cores = 2)
}
}
if (mcmc$verbose) {
cat("\nstarting chain(s):\n")
if (parallel == "parallel") {
cat(paste(paste(rep("b", mcmc$nChains), collapse = ""),
"0",
paste(rep("-", mcmc$nChains * 10 - 2), collapse = ""),
"100%\n",
sep = "", collapse = ""
))
}
if (parallel == "snow") {
cat("using <parallel> in SOCKET mode -- no progress info available.\n")
}
}
do1Chain <- function(i) {
set.seed(as.integer(start$seed + i))
res <- .C("sampler",
a1 = as.double(hyperparameters$tau2["a1"]),
a2 = as.double(hyperparameters$tau2["a2"]),
b1 = as.double(hyperparameters$sigma2["b1"]),
b2 = as.double(hyperparameters$sigma2["b2"]),
alphaW = as.double(hyperparameters$w["alpha"]),
betaW = as.double(hyperparameters$w["beta"]),
v0 = as.double(hyperparameters$gamma["v0"]),
varKsi = as.double(hyperparameters$varKsi),
q = as.integer(model$q), qKsiUpdate = as.integer(model$qKsiUpdate),
p = as.integer(model$nGroups), pPen = as.integer(model$nPenGrps),
n = as.integer(model$n),
d = as.integer(model$d),
beta = as.double(start$beta[, i]), alpha = as.double(start$alpha[, i]),
ksi = as.double(start$ksi[, i]), tau2 = as.double(start$tau2[, i]),
gamma = as.double(start$gamma[, i]), sigma2 = as.double(start$sigma2[i]),
w = as.double(start$w[i]),
y = as.double(y),
X = as.double(X),
G = as.double(model$G),
scale = as.double(model$scale),
offset = as.double(model$offset),
blocksAlpha = as.integer(blocksAlpha),
indA1Alpha = as.integer(alphaIndABegin),
indA2Alpha = as.integer(alphaIndAEnd),
blocksKsi = as.integer(blocksKsi),
indA1Ksi = as.integer(ksiIndABegin),
indA2Ksi = as.integer(ksiIndAEnd),
pcts = as.integer(pcts),
burnin = as.integer(mcmc$burnin),
thin = as.integer(mcmc$thin),
totalLength = as.integer(mcmc$totalLength),
verbose = as.integer(mcmc$verbose),
ksiDF = as.double(hyperparameters$ksiDF),
scaleMode = as.integer(mcmc$scalemode),
modeSwitching = as.double(mcmc$modeSwitching),
family = as.integer(family),
acceptKsi = as.double(rep(0, blocksKsi)),
acceptAlpha = as.double(rep(0, blocksAlpha)),
betaMat = as.double(betaMat),
alphaMat = as.double(alphaMat),
ksiMat = as.double(ksiMat),
gammaMat = as.double(gammaMat),
probV1Mat = as.double(probV1Mat),
tau2Mat = as.double(tau2Mat),
sigma2Mat = as.double(sigma2Mat),
wMat = as.double(wMat),
likMat = as.double(likMat),
logPostMat = as.double(logPostMat),
PACKAGE = "spikeSlabGAM"
)
beta <- matrix(res$betaMat, mcmc$chainLength, model$q)[, model$reverseOrder]
colnames(beta) <- paste(model$groupIndicators,
unlist(sapply(model$d, function(x) {
return(1:x)
})),
sep = "."
)[model$reverseOrder]
alpha <- matrix(res$alphaMat, mcmc$chainLength, model$nGroups)
colnames(alpha) <- paste("alpha", levels(model$groupIndicators), sep = ".")
ksi <- matrix(res$ksiMat, mcmc$chainLength, model$q)
colnames(ksi) <- paste("ksi", model$groupIndicators,
unlist(sapply(model$d, function(x) {
return(1:x)
})),
sep = "."
)
tau <- matrix(res$tau2Mat, mcmc$chainLength, model$nPenGrps)
gamma <- matrix(res$gammaMat, mcmc$chainLength, model$nPenGrps)
pV1 <- matrix(res$probV1Mat, mcmc$chainLength, model$nPenGrps)
colnames(tau) <- colnames(gamma) <-
colnames(pV1) <-
unique(model$groupIndicatorsOrig[properOrder[!(properOrder %in% unpen)]])
reorderedPenGroupNames <- if (length(unpen)) {
unique(model$groupIndicatorsOrig[-grep(
"u(.[0-9]+)?$",
model$groupIndicatorsOrig
)])
} else {
unique(model$groupIndicatorsOrig)
}
tau <- tau[, reorderedPenGroupNames, drop = F]
gamma <- gamma[, reorderedPenGroupNames, drop = F]
pV1 <- pV1[, reorderedPenGroupNames, drop = F ]
colnames(tau) <- paste("tau.", colnames(tau), sep = "")
colnames(gamma) <- paste("gamma.", colnames(gamma), sep = "")
colnames(pV1) <- paste("p1.", colnames(pV1), sep = "")
w <- matrix(res$wMat, mcmc$chainLength, 1)
colnames(w) <- "w"
sigma2 <- matrix(res$sigma2Mat, mcmc$chainLength, 1)
colnames(sigma2) <- "sigma2"
logLik <- matrix(res$likMat, mcmc$chainLength, 1)
colnames(logLik) <- "logLik"
logPost <- matrix(res$logPostMat, mcmc$chainLength, 1)
colnames(logPost) <- "uLogPost"
samples <- if (mcmc$reduceRet) {
list(
beta = beta, gamma = gamma,
pV1 = pV1, w = w, sigma2 = sigma2, logLik = logLik, logPost = logPost
)
} else {
list(
beta = beta, alpha = alpha,
ksi = ksi, tau = tau, gamma = gamma,
pV1 = pV1, w = w, sigma2 = sigma2, logLik = logLik, logPost = logPost
)
}
samples <- lapply(samples, mcmc,
start = mcmc$burnin + 1,
end = mcmc$totalLength, thin = mcmc$thin
)
accept <- if (family != 0) {
list(
alpha = res$acceptAlpha / mcmc$totalLength,
ksi = res$acceptKsi / mcmc$totalLength
)
} else {
NULL
}
posteriorPred <- if (mcmc$sampleY) {
mu <- X %*% t(samples$beta) + model$offset
yPred <- switch(familystr,
gaussian = mu + t(as.vector(sqrt(samples$sigma2)) *
matrix(rnorm(n * mcmc$chainLength),
nrow = mcmc$chainLength
)),
binomial = t(matrix(rbinom(
n * mcmc$chainLength,
model$scale, plogis(mu)
),
nrow = mcmc$chainLength
)),
poisson = t(matrix(rpois(n * mcmc$chainLength, exp(mu)),
nrow = mcmc$chainLength
))
)
list(mu = mu, y = yPred)
} else {
NULL
}
restart <- list(
beta = beta[mcmc$chainLength, , drop = F],
tau = tau[mcmc$chainLength, , drop = F],
gamma = gamma[mcmc$chainLength, , drop = F],
w = w[mcmc$chainLength, , drop = F],
sigma2 = sigma2[mcmc$chainLength, , drop = F]
)
return(list(
samples = samples, posteriorPred = posteriorPred,
accept = accept, restart = restart
))
}
if (parallel == "parallel") {
res <- mclapply(1:mcmc$nChains, do1Chain)
}
if (parallel == "snow") {
clusterExportLocal <- function(cl, list) {
for (name in list) {
clusterCall(cl, assign, name, get(name, pos = -1))
}
}
cl <- makeCluster(spec = options()$mc.cores, type = "PSOCK")
clusterExportLocal(
cl,
c(
"hyperparameters", "model", "start", "mcmc", "y", "X",
"blocksAlpha", "alphaIndABegin", "alphaIndAEnd",
"blocksKsi", "ksiIndABegin", "ksiIndAEnd", "pcts", "family",
"betaMat", "alphaMat", "ksiMat", "gammaMat", "probV1Mat",
"tau2Mat", "sigma2Mat", "wMat", "likMat", "logPostMat", "unpen",
"familystr"
)
)
res <- parLapply(cl, as.list(1:mcmc$nChains), do1Chain)
stopCluster(cl)
}
if (parallel == "none") {
res <- lapply(1:mcmc$nChains, function(x) {
ret <- do1Chain(x)
if (mcmc$verbose) {
cat("\n")
}
return(ret)
})
}
ret <- mget(names(formals()),
envir = as.environment(-1)
)
if (family != 0) {
acceptance <- list(
alpha = sapply(lapply(res, "[[", "accept"),
"[[", "alpha",
simplify = TRUE
),
ksi = sapply(lapply(res, "[[", "accept"),
"[[", "ksi",
simplify = TRUE
)
)
acceptanceWarning <- .15
if (any(unlist(acceptance) < acceptanceWarning)) {
cat("\nLow acceptance rates detected:\n")
print(acceptance, digits = 2)
}
ret$mcmc$accept <- c(
alpha = mean(acceptance$alpha),
ksi = mean(acceptance$ksi)
)
if (mcmc$verbose) {
cat("\nMean acceptance rates:\n")
print(ret$mcmc$accept, digits = 2)
}
}
if (mcmc$sampleY) {
ret$posteriorPred <- lapply(res, "[[", "posteriorPred")
}
ret$samples <- {
tmp <- lapply(res, "[[", "samples")
smpls <- vector(length(tmp[[1]]), mode = "list")
names(smpls) <- names(tmp[[1]])
for (n in names(smpls)) {
smpls[[n]] <- do.call(mcmc.list, lapply(tmp, "[[", n))
}
rm(tmp)
smpls
}
rm(smpls)
ret$postMeans <- if (mcmc$nChains > 1) {
lapply(ret$samples, function(x) {
tmp <- sapply(x, colMeans)
if (NCOL(tmp) > 1) {
return(rowMeans(tmp))
} else {
return(mean(tmp))
}
})
} else {
lapply(ret$samples, function(x) {
if (NCOL(x[[1]]) > 1) {
return(sapply(x, colMeans))
} else {
return(mean(x[[1]]))
}
})
}
ret$X <- ret$X[, model$reverseOrder]
ret$fitted <- cbind(eta = ret$X %*% ret$postMeans$beta)
ret$fitted <- cbind(eta = ret$fitted, mu = switch(familystr,
gaussian = ret$fitted,
binomial = plogis(ret$fitted),
poisson = exp(ret$fitted)
))
ret$DIC <- {
Dbar <- -2 * mean(unlist(ret$samples$logLik), na.rm = T)
Dhat <- -2 * switch(familystr,
gaussian = sum(dnorm(y - ret$fitted[, 1],
mean = 0,
sd = sqrt(ret$postMeans$sigma2), log = T
)),
binomial = sum(dbinom(y * model$scale, model$scale,
ret$fitted[, 2],
log = T
)),
poisson = sum(dpois(y, ret$fitted[, 2], log = T))
)
pD <- Dbar - Dhat
DIC <- pD + Dbar
c(DIC = DIC, pD = pD, Dbar = Dbar, Dhat = Dhat)
}
if (mcmc$reduceRet) {
ret$data <- NULL
}
runTime <- difftime(Sys.time(), startTime, units = "secs")
ret$runTime <- runTime
return(ret)
}
|
test_that("json_ptype_common works", {
expect_equal(
json_ptype_common(c("true", "false", "null")),
logical()
)
expect_equal(
json_ptype_common(c("integer", "true", "false", "null")),
integer()
)
expect_equal(
json_ptype_common(c("real", "integer", "true", "false", "null")),
numeric()
)
expect_equal(
json_ptype_common(c("text", "null")),
character()
)
expect_equal(
json_ptype_common(c("array", "null")),
new_json2()
)
expect_equal(
json_ptype_common(c("object", "null")),
new_json2()
)
expect_equal(
json_ptype_common(c("object", "array", "null")),
new_json2()
)
})
test_that("json_ptype_common incompatible types", {
expect_snapshot_error(json_ptype_common(c("true", "text")))
expect_snapshot_error(json_ptype_common(c("false", "text")))
expect_snapshot_error(json_ptype_common(c("integer", "text")))
expect_snapshot_error(json_ptype_common(c("real", "text")))
expect_snapshot_error(json_ptype_common(c("object", "text")))
expect_snapshot_error(json_ptype_common(c("array", "text")))
expect_equal(
json_ptype_common(c("object", "text"), ptype = character()),
character()
)
expect_equal(
json_ptype_common(c("array", "text"), ptype = character()),
character()
)
expect_snapshot_error(json_ptype_common(c("object", "true")))
expect_snapshot_error(json_ptype_common(c("array", "false")))
})
test_that("json_ptype_common incompatible ptype", {
expect_snapshot_error(
json_ptype_common("object", ptype = new_json_array())
)
expect_snapshot_error(
json_ptype_common("array", ptype = new_json_object())
)
})
test_that("json_vec_c works with `ptype = NULL`", {
expect_equal(
json_vec_c(
list(TRUE, FALSE, NA),
c("true", "false", "null")
),
c(TRUE, FALSE, NA)
)
expect_equal(
json_vec_c(
list(1L, TRUE, FALSE, NA),
c("integer", "true", "false", "null")
),
c(1, 1, 0, NA)
)
expect_equal(
json_vec_c(
list(1.2, 1L, TRUE, FALSE, NA),
c("real", "integer", "true", "false", "null")
),
c(1.2, 1, 1, 0, NA)
)
expect_equal(
json_vec_c(
list("a", NA),
c("text", "null")
),
c("a", NA)
)
expect_equal(
json_vec_c(
list(new_json2("[1]"), NA),
c("array", "null")
),
new_json2(c("[1]", NA))
)
expect_equal(
json_vec_c(
list(new_json2('{"a": 1}'), NA),
c("object", "null")
),
new_json2(c('{"a": 1}', NA))
)
expect_equal(
json_vec_c(
list(new_json2('{"a": 1}'), new_json2("[1]"), NA),
c("object", "array", "null")
),
new_json2(c('{"a": 1}', "[1]", NA))
)
})
test_that("json_vec_c handles mix of array/object and text", {
expect_snapshot_error(
json_vec_c(
list(new_json2('{"a": 1}'), "a"),
c("object", "text")
)
)
expect_snapshot_error(
json_vec_c(
list(new_json2("[1]"), "a"),
c("array", "text")
)
)
expect_equal(
json_vec_c(
list(new_json2('{"a": 1}'), "a"),
c("object", "text"),
ptype = character()
),
c('{"a": 1}', "a")
)
expect_equal(
json_vec_c(
list(new_json2("[1]"), "a"),
c("array", "text"),
ptype = character()
),
c("[1]", "a")
)
})
test_that("json_vec_c handles json (array/object) ptype", {
expect_snapshot_error(
json_vec_c(
list(new_json2('{"a": 1}'), new_json2("[1]")),
c("object", "array"),
ptype = new_json_array()
)
)
expect_snapshot_error(
json_vec_c(
list(new_json2('{"a": 1}'), new_json2("[1]")),
c("object", "array"),
ptype = new_json_object()
)
)
expect_equal(
json_vec_c(
list(new_json2('{"a": 1}'), new_json2("[1]")),
c("object", "array"),
ptype = new_json2()
),
new_json2(c('{"a": 1}', "[1]"))
)
})
test_that("json_convert_values errors for incompatible types", {
expect_snapshot_error(
json_vec_c(
x = list(1, "a"),
types = c("integer", "text"),
ptype = NULL
)
)
expect_snapshot_error(
json_vec_c(
x = list(1, 2),
types = c("integer", "integer"),
ptype = character()
)
)
})
test_that("json_convert_value works", {
expect_equal(
json_convert_value(
x = c("1", "0", "1", "1.5", "a", "[1, 2]", '{"a": 1}'),
json_types = c("true", "false", "integer", "real", "text", "array", "object"),
ptype = list()
),
list(TRUE, FALSE, 1, 1.5, "a", new_json2("[1, 2]"), new_json2('{"a": 1}'))
)
})
test_that("json_convert_value can wrap scalars", {
expect_equal(
json_convert_value(
x = c("[1, 2]", "a"),
json_types = c("array", "text"),
ptype = NULL,
wrap_scalars = TRUE
),
new_json2(c("[1, 2]", '["a"]'))
)
expect_equal(
json_convert_value(
x = c("[1, 2]", "a"),
json_types = c("array", "text"),
ptype = new_json_array(),
wrap_scalars = TRUE
),
new_json2(c("[1, 2]", '["a"]'))
)
})
test_that("json_convert_value can handle objects", {
expect_snapshot_error(
json_convert_value(
x = c('{"a": 1}', "[1, 2]"),
json_types = c("object", "array"),
ptype = new_json_object()
)
)
expect_equal(
json_convert_value(
x = c("[1, 2]", '{"a": 1}'),
json_types = c("array", "object"),
ptype = json2()
),
new_json2(c("[1, 2]", '{"a": 1}'))
)
expect_snapshot_error(
json_convert_value(
x = c("[1, 2]", '{"a": 1}', "1"),
json_types = c("array", "object", "integer"),
ptype = json2()
)
)
})
test_that("json_convert_value handles big integers", {
expect_equal(
json_convert_value(
x = c("9999999999", "1"),
json_types = c("integer", "true"),
ptype = NULL,
bigint_as_char = FALSE
),
bit64::as.integer64(c("9999999999", 1))
)
expect_equal(
json_convert_value(
x = c("9999999999", "1"),
json_types = c("integer", "true"),
ptype = bit64::integer64(),
bigint_as_char = FALSE
),
bit64::as.integer64(c("9999999999", 1))
)
expect_snapshot(
expect_equal(
json_convert_value(
x = c("9999999999", "1"),
json_types = c("integer", "true"),
ptype = NULL,
bigint_as_char = TRUE
),
c("9999999999", "1")
)
)
expect_equal(
json_convert_value(
x = c("9999999999", "1"),
json_types = c("integer", "true"),
ptype = bit64::integer64(),
bigint_as_char = TRUE
),
c("9999999999", "1")
)
expect_snapshot_error(
json_convert_value(
x = c("9999999999"),
json_types = c("integer"),
ptype = character(),
bigint_as_char = TRUE
)
)
})
|
acontext("VariantModels data viz")
data(VariantModels, package = "animint2")
auc.min.error <- subset(VariantModels$auc, metric.name=="min.error")
add.filterVar <- function(df, levs){
df$filterVar.fac <- factor(df$filterVar, levs)
df
}
add.filterVar.fac <- function(df){
add.filterVar(df, rev(paste(VariantModels$ranks$filterVar)))
}
add.filterVar.rev <- function(df){
add.filterVar(df, paste(VariantModels$ranks$filterVar))
}
thresh.colors <- c("min error"="black", selected="white")
method.colors <-
c(knn="
"
svmRadial="
ada="
gbm="
glmnet="
glmnetBinDev="
glmnetAcc="
MQ="
QUAL="
NegFQ="
DP="
rf="
"
"
fp.fn.colors <- c(FP="skyblue",
fp="skyblue",
fn="
FN="
tn="white",
tp="grey",
errors="black")
first.list <- with(auc.min.error, {
structure(as.list(threshold), names=paste0(filterVar, "_fold", test.fold))
})
first.list$test.fold <- 2
minima.df <- VariantModels$minima
minima.df$thresh.type <- "min error"
data_auc = add.filterVar.rev(VariantModels$roc)
data_auc$showVar <- with(data_auc,
paste0(filterVar, "_fold", test.fold))
data_roc <- VariantModels$roc
data_roc$showVar <- with(data_roc,
paste0(filterVar, "_fold", test.fold))
data_error <- add.filterVar.fac(VariantModels$thresholds)
data_error$clickVar <- with(data_error,
paste0(filterVar.fac, "_fold", test.fold))
viz <- list(
auc=ggplot()+
ggtitle("Performance on 3 test folds")+
theme_bw()+
theme_animint(height=500)+
theme(panel.margin=grid::unit(0, "cm"))+
facet_grid(.~metric.name, scales="free", space="fixed")+
scale_y_discrete("method . weights")+
scale_x_continuous("")+
scale_color_manual(values=method.colors, guide="none")+
scale_fill_manual("threshold", values=thresh.colors, guide="none")+
geom_point(aes(metric.value, filterVar.fac, color=method,
fill=thresh.type),
clickSelects="test.fold",
showSelected=c("method", "thresh.type"),
size=5,
pch=21,
data=add.filterVar.rev(VariantModels$auc))+
geom_point(aes(
error.or.Inf,
filterVar.fac,
key=filterVar,
fill=thresh.type, color=method),
showSelected=c("test.fold", "method", "thresh.type",
showVar="threshold"),
size=4,
pch=21,
data=data_auc),
roc=ggplot()+
ggtitle("ROC curves by weights and test fold")+
scale_y_continuous("True positive rate")+
scale_x_continuous("False positive rate",
breaks=c(0, 0.25, 0.5, 0.75, 1),
labels=c("0", "0.25", "0.5", "0.75", "1"))+
scale_color_manual(values=method.colors)+
coord_equal()+
theme_bw()+
theme_animint(width=500, height=500)+
theme(panel.margin=grid::unit(0, "cm"))+
facet_grid(test.fold ~ type, labeller=function(label_df){
if(names(label_df)=="test.fold"){
label_names <- mapply(paste, "test fold", label_df, SIMPLIFY = FALSE)
label_context(labels = label_names)
}else{
lapply(label_df, paste)
}
})+
geom_path(aes(FPR, TPR,
group=method, tooltip=method, color=method),
clickSelects="test.fold",
size=5,
data=VariantModels$roc)+
scale_fill_manual("threshold", values=thresh.colors)+
geom_point(aes(FPR, TPR, color=method,
fill=thresh.type),
clickSelects="test.fold",
pch=21,
size=4,
data=subset(VariantModels$auc, metric.name=="auc"))+
geom_point(aes(
FPR, TPR,
key=method,
fill=thresh.type,
color=method),
clickSelects="test.fold",
showSelected=c("test.fold", showVar="threshold"),
size=3,
pch=21,
data=data_roc),
error=ggplot()+
geom_hline(aes(yintercept=min.errors),
showSelected=c("test.fold", "thresh.type"),
data=minima.df,
color="grey50")+
geom_vline(aes(xintercept=threshold),
showSelected=c("test.fold", "thresh.type", "method"),
data=add.filterVar.fac(auc.min.error),
color="grey50")+
theme_bw()+
theme_animint(width=1800, height=500)+
theme(panel.margin=grid::unit(0, "cm"))+
theme(axis.text.x=element_text(angle=90))+
facet_grid(. ~ filterVar.fac, labeller=function(label_df){
label_df <- mapply(sub, "balanced", "b", label_df, SIMPLIFY = FALSE)
label_df <- mapply(sub, "one", "1", label_df, SIMPLIFY = FALSE)
label_value(label_df)
}, scales="free", space="fixed")+
scale_color_manual(values=fp.fn.colors)+
geom_line(aes(threshold, error.value,
group=error.type, color=error.type),
showSelected=c("test.fold", "thresh.type", "method"),
data=add.filterVar.fac(VariantModels$error))+
scale_fill_manual(values=method.colors, guide="none")+
geom_tallrect(aes(
xmin=xmin, xmax=xmax,
fill=method),
showSelected=c("test.fold", "thresh.type", "method"),
clickSelects = c(clickVar="threshold"),
alpha=0.5,
color=NA,
data=data_error),
selector.types=list(method="multiple", thresh.type="multiple"),
title="3-fold CV estimates variant calling test error",
first=first.list,
duration=with(auc.min.error, {
structure(as.list(rep(2000, length(threshold))),
names=paste0(filterVar, "_fold", test.fold))
})
)
info <- animint2HTML(viz)
viz$error+
facet_grid(test.fold ~ filterVar.fac, labeller=function(label_df){
if(names(label_df)=="test.fold"){
label_names <- mapply(paste, "test fold", label_df, SIMPLIFY = FALSE)
label_context(labels = label_names)
}else{
lapply(label_df, paste)
}
}, scales="free", space="fixed")
test_that("no duplicated rows in common data", {
common.tsv <- file.path("animint-htmltest", "geom8_line_error_chunk_common.tsv")
common.df <- read.table(common.tsv, comment.char="", header=TRUE)
common.unique <- unique(common.df)
expect_identical(common.unique, common.df)
})
test_that("error lines rendered in all panels", {
panel.list <- getNodeSet(info$html, '//g[@class="geom8_line_error"]//g')
computed.counts <- sapply(panel.list, function(x)length(xmlChildren(x)))
expected.counts <- rep(3, 20)
expect_equal(computed.counts, expected.counts)
})
xpath.vec <-
c('//g[@class="geom1_point_auc"]//circle',
'//g[@class="geom2_point_auc"]//circle',
'//g[@class="geom3_path_roc"]//path',
'//g[@class="geom4_point_roc"]//circle',
'//g[@class="geom5_point_roc"]//circle',
'//g[@class="geom6_hline_error"]//line',
'//g[@class="geom7_vline_error"]//line',
'//g[@class="geom8_line_error"]//path',
'//g[@class="geom9_tallrect_error"]//rect')
countGeoms <- function(html=getHTML()){
count.vec <- c()
for(xpath in xpath.vec){
node.list <- getNodeSet(html, xpath)
count.vec[[xpath]] <- length(node.list)
}
count.vec
}
thresh.fold2 <- subset(VariantModels$thresholds, test.fold==2)
test_that("initial geom counts", {
expected.counts <- c(120, 20, 60, 60, 20, 20, 20, 60, nrow(thresh.fold2))
computed.counts <- countGeoms()
expect_equal(expected.counts, as.numeric(computed.counts))
})
clickID("plot_roc_method_variable_MQ")
thresh.fold2.not.MQ <- subset(thresh.fold2, method != "MQ")
test_that("geom counts after hiding MQ", {
expected.counts <- c(
114, 19,
57, 57,
19,
20,
19,
57,
nrow(thresh.fold2.not.MQ))
computed.counts <- countGeoms()
expect_equal(expected.counts, as.numeric(computed.counts))
})
clickID("plot_roc_thresh_type_variable_min_error")
test_that("geom counts after hiding min error", {
expected.counts <- c(
0, 19,
57, 0,
19,
0,
0,
57,
nrow(thresh.fold2.not.MQ))
computed.counts <- countGeoms()
expect_equal(expected.counts, as.numeric(computed.counts))
})
clickID("plot_roc_thresh_type_variable_selected")
test_that("geom counts after hiding selected", {
expected.counts <- c(
0, 0,
57, 0,
0,
0,
0,
0,
0)
computed.counts <- countGeoms()
expect_equal(expected.counts, as.numeric(computed.counts))
})
clickID("plot_roc_thresh_type_variable_min_error")
test_that("geom counts after showing min error", {
expected.counts <- c(
114, 0,
57, 57,
0,
20,
19,
0,
0)
computed.counts <- countGeoms()
expect_equal(expected.counts, as.numeric(computed.counts))
})
clickID("plot_roc_method_variable_knn")
test_that("geom counts after hiding knn", {
expected.counts <- c(
102, 0,
51, 51,
0,
20,
17,
0,
0)
computed.counts <- countGeoms()
expect_equal(expected.counts, as.numeric(computed.counts))
})
clickID("plot_roc_thresh_type_variable_selected")
thresh.fold2.not.knn <- subset(thresh.fold2.not.MQ, method != "knn")
test_that("geom counts after showing selected", {
expected.counts <- c(
102, 17,
51, 51,
17,
20,
17,
51,
nrow(thresh.fold2.not.knn))
computed.counts <- countGeoms()
expect_equal(expected.counts, as.numeric(computed.counts))
})
clickID("plot_error_error_type_variable_errors")
test_that("geom counts after hiding errors", {
expected.counts <- c(
102, 17,
51, 51,
17,
20,
17,
34,
nrow(thresh.fold2.not.knn))
computed.counts <- countGeoms()
expect_equal(expected.counts, as.numeric(computed.counts))
})
|
plot(star.model2, which = c(1:2, 4:5))
|
repBE.print <- function(x, ...) {
design <- as.character(x$Design)
method <- as.character(x$Method)
n <- as.numeric(x$n)
nTT <- as.numeric(x$nTT)
nRR <- as.numeric(x$nRR)
Nsub.seq <- as.character(x[["Sub/seq"]])
Miss.seq <- as.character(x[["Miss/seq"]])
Miss.per <- as.character(x[["Miss/per"]])
alpha <- x$alpha
DF <- as.numeric(as.character(x$DF))
CVwT <- x[["CVwT(%)"]]
CVwR <- x[["CVwR(%)"]]
sw.ratio <- as.numeric(x$sw.ratio)
EL <- c(x[["EL.lo(%)"]], x[["EL.hi(%)"]])
CI <- c(x[["CI.lo(%)"]], x[["CI.hi(%)"]])
PE <- x[["PE(%)"]]
CI.ass <- x$CI
GMR.ass <- x$GMR
BE.ass <- x$BE
if (method == "ABE") {
BE.lim <- c(x[["BE.lo(%)"]], x[["BE.hi(%)"]])
} else {
outlier <- x$outlier
ifelse (is.null(x[["CVwR.new(%)"]]),
CVwR.new <- NA, CVwR.new<- x[["CVwR.new(%)"]])
ifelse (is.null(x$sw.ratio.new),
sw.ratio.new <- NA, sw.ratio.new<- x$sw.ratio.new)
ifelse (is.null(x[["EL.new.lo(%)"]]),
EL.new <- NA, EL.new <- c(x[["EL.new.lo(%)"]], x[["EL.new.hi(%)"]]))
ifelse (is.null(x$CI.new),
CI.new <- NA, CI.new <- x$CI.new)
ifelse (is.null(x$GMR.new),
GMR.new <- NA, GMR.new <- x$GMR.new)
ifelse (is.null(x$BE.new),
BE.new <- NA, BE.new <- x$BE.new)
}
cat("\ndesign =", design, " method =", method, " n =", n, " nTT =", nTT, " nRR =", nRR,
"\nSub/seq =", Nsub.seq, " Miss/seq =", Miss.seq, " Miss/per =", Miss.per,
"\nalpha =", alpha, " DF =", DF, " CVwT(%) =", signif(CVwT, 7), " CVwR(%) =", signif(CVwR, 7),
" sw.ratio =", signif(sw.ratio, 7))
if (method == "ABE") {
cat("\nBE.lim =", sprintf("%6.2f%%", BE.lim))
} else {
cat("\nEL =", sprintf("%6.2f%%", EL))
}
cat("\nCI =", sprintf("%6.2f%%", CI))
if (method == "ABE") {
cat(": BE =", BE.ass, "\n",
repBE.draw.line(called.from="ABE", L=BE.lim[1]/100, U=BE.lim[2]/100,
lo=CI[1]/100, hi=CI[2]/100, PE=PE/100))
} else {
cat(": CI =", CI.ass, " GMR =", GMR.ass, " BE =", BE.ass, "\n",
repBE.draw.line(called.from="ABEL", L=EL[1]/100, U=EL[2]/100,
lo=CI[1]/100, hi=CI[2]/100, PE=PE/100))
}
cat("\n\n")
}
|
test_that("nn_embedding", {
embedding <- nn_embedding(10, 3)
input <- torch_tensor(rbind(c(1,2,4,5),c(4,3,2,9)), dtype = torch_long())
output <- embedding(input)
expect_equal_to_tensor(output[1,1,], embedding$weight[1,])
embedding <- nn_embedding(10, 3, padding_idx=1)
input <- torch_tensor(matrix(c(1,3,1,6), nrow = 1), dtype = torch_long())
output <- embedding(input)
expect_equal_to_tensor(output[1,1,], embedding$weight[1,])
})
|
library(hamcrest)
expected <- c(-0x1.53f5c451fe60ap-1 + 0x1.95783880b4578p-1i, -0x1.49b84d1fa249p-1 + 0x1.9d8e13049d7a4p-1i,
-0x1.3eebb9383f4c2p-1 + 0x1.a51a1a600bad4p-1i, -0x1.33972a79dae7ep-1 + 0x1.ac145fe314b96p-1i,
-0x1.27c22e06839dcp-1 + 0x1.b27555a7a47fp-1i, -0x1.1b74b719b648p-1 + 0x1.b835d41afadep-1i,
-0x1.0eb71995dba98p-1 + 0x1.bd4f1f40fa50ep-1i, -0x1.0192044d8ddecp-1 + 0x1.c1baebadaecccp-1i,
-0x1.e81cf61905a1cp-2 + 0x1.c5736331a5734p-1i, -0x1.cc6ba0c847928p-2 + 0x1.c8732935e0fc8p-1i,
-0x1.b0233e800529p-2 + 0x1.cab55ec46c0b4p-1i, -0x1.9357888d0472p-2 + 0x1.cc35a63ac1ff8p-1i,
-0x1.761cae145828cp-2 + 0x1.ccf026a37ffd6p-1i, -0x1.5887462093fdp-2 + 0x1.cce18eb50ab84p-1i,
-0x1.3aac4162f5e8p-2 + 0x1.cc07177311f2p-1i, -0x1.1ca0dbb223168p-2 + 0x1.ca5e86711857ap-1i,
-0x1.fcf51aa0887a8p-3 + 0x1.c7e62fb465698p-1i, -0x1.c09df804e807p-3 + 0x1.c49cf7340726ep-1i,
-0x1.8467d80725478p-3 + 0x1.c08251f5ca1bap-1i, -0x1.487e61b9574fp-3 + 0x1.bb9646c750366p-1i,
-0x1.0d0d3c5a5bcbcp-3 + 0x1.b5d96e92b0fe2p-1i, -0x1.a47fe1b5092ap-4 + 0x1.af4cf44e50824p-1i,
-0x1.308396d24f5b8p-4 + 0x1.a7f29487dd33cp-1i, -0x1.7cf6f47ed1b4p-5 + 0x1.9fcc9c8aa7f7cp-1i,
-0x1.3af1eef70ap-6 + 0x1.96dde921cc888p-1i, 0x1.e65a31b2f204p-8 + 0x1.8d29e4f6e2fd4p-1i,
0x1.113113c17ef6p-5 + 0x1.82b4868e357ap-1i, 0x1.df1706f3f3a2p-5 + 0x1.77824de1b6a8ap-1i,
0x1.52efb73f10cc8p-4 + 0x1.6b98419c367a4p-1i, 0x1.b27860ec5157p-4 + 0x1.5efbebf6929ccp-1i,
0x1.06ed83a12c66dp-3 + 0x1.51b35738def4p-1i, 0x1.3267d8971261dp-3 + 0x1.43c509e1bfe38p-1i,
0x1.5b888caa408aep-3 + 0x1.353802766c8ecp-1i, 0x1.822e6feeafe82p-3 + 0x1.2613b2fe09b86p-1i,
0x1.a639dd2e62104p-3 + 0x1.165ffc2b46f4p-1i, 0x1.c78cd0dc0f2aap-3 + 0x1.062528375ee04p-1i,
0x1.e60afef420afep-3 + 0x1.ead7cae3a0a8p-2i, 0x1.00ccf3de5e76bp-2 + 0x1.c87a8110b29ecp-2i,
0x1.0d1075ab309f3p-2 + 0x1.a5453d15da9a8p-2i, 0x1.17c4ae07a6302p-2 + 0x1.814b6d5f1dd4p-2i,
0x1.20df47b6638a2p-2 + 0x1.5ca117b441628p-2i, 0x1.2856f6ef174ccp-2 + 0x1.375acbd8d4664p-2i,
0x1.2e23808740fcep-2 + 0x1.118d95c569f3cp-2i, 0x1.323dc0650c235p-2 + 0x1.d69ddf06233e8p-3i,
0x1.349faf3788f62p-2 + 0x1.89696564be3p-3i, 0x1.3544677004e77p-2 + 0x1.3baa138f19fcp-3i,
0x1.34282978c19d1p-2 + 0x1.db198415f2e2p-4i, 0x1.31485f25c7913p-2 + 0x1.3e7d5d06114fp-4i,
0x1.2ca39e5d12b6p-2 + 0x1.43b573d12336p-5i, 0x1.2639aaf3da82p-2 + 0x1.633c4ae25bp-10i,
0x1.1e0b77bf3b5a6p-2 + -0x1.2c212dc305e8p-5i, 0x1.141b26d70d706p-2 + -0x1.30a2a6d89dbbp-4i,
0x1.086c090a3bf4cp-2 + -0x1.c9ce7516c66fp-4i, 0x1.f6053908ee8bp-3 + -0x1.309cf23cda888p-3i,
0x1.d7c9154b48dc4p-3 + -0x1.7b45e16bf492p-3i, 0x1.b6314a17e8c0cp-3 + -0x1.c4b6038485fc8p-3i,
0x1.914dc3a429298p-3 + -0x1.0661039538358p-2i, 0x1.6930ae06e35f8p-3 + -0x1.299fb647d314cp-2i,
0x1.3dee6a9214b44p-3 + -0x1.4c0251aa193dcp-2i, 0x1.0f9d83a3a9ba8p-3 + -0x1.6d7493ee00fb8p-2i,
0x1.bcad3de8f281p-4 + -0x1.8de2d0033aad8p-2i, 0x1.5468dcdaf4c98p-4 + -0x1.ad39fb9a12e04p-2i,
0x1.cd4e7e30f5c7p-5 + -0x1.cb67bcc3d5124p-2i, 0x1.ce964b052fa8p-6 + -0x1.e85a77275206ep-2i,
-0x1.16d368952d8p-10 + -0x1.0200ac6036bd2p-1i, -0x1.022e08fb78bbp-5 + -0x1.0f263310ef161p-1i,
-0x1.0245dd125f8dp-4 + -0x1.1b9643184bfddp-1i, -0x1.879cf9c599408p-4 + -0x1.2749c6a855279p-1i,
-0x1.0867425e6e868p-3 + -0x1.323a23fdda7f8p-1i, -0x1.4ec4f154f4e94p-3 + -0x1.3c61425cb9935p-1i,
-0x1.96bdf3d388ba8p-3 + -0x1.45b98eb99eb8ap-1i, -0x1.e02787011e4bcp-3 + -0x1.4e3e000de639p-1i,
-0x1.156aebb4fe21p-2 + -0x1.55ea1b52778ddp-1i, -0x1.3b4e0f0fa68f8p-2 + -0x1.5cb9f71eac9c2p-1i,
-0x1.61a65f4c1547p-2 + -0x1.62aa3ee890bd2p-1i, -0x1.885cb2a083778p-2 + -0x1.67b835e3ff27p-1i,
-0x1.af599352ed642p-2 + -0x1.6be1b97e65b56p-1i, -0x1.d6854f9184b4cp-2 + -0x1.6f254375301fcp-1i,
-0x1.fdc80984451dcp-2 + -0x1.7181eb8520129p-1i, -0x1.1284e3c6a2d63p-1 + -0x1.72f768b1184ddp-1i,
-0x1.261942569d8a5p-1 + -0x1.7386121f23b2cp-1i, -0x1.39952080c01dap-1 + -0x1.732edf8ac4ddbp-1i,
-0x1.4cec892870da4p-1 + -0x1.71f3694bdf553p-1i, -0x1.60139a4e2bacep-1 + -0x1.6fd5e7f1d06d6p-1i,
-0x1.72fe8d5466306p-1 + -0x1.6cd93372936a8p-1i, -0x1.85a1bf3b89446p-1 + -0x1.6900c1ee1232dp-1i,
-0x1.97f1b8cf9012dp-1 + -0x1.6450a6060999ep-1i, -0x1.a9e336c1e173cp-1 + -0x1.5ecd8ccb2e15p-1i,
-0x1.bb6b31aa01213p-1 + -0x1.587cbb4083017p-1i, -0x1.cc7ee5e7c22fap-1 + -0x1.51640b761bbd5p-1i,
-0x1.dd13db61b39eep-1 + -0x1.4989e93cc21cp-1i, -0x1.ed1fed1a92b3p-1 + -0x1.40f54e74416b8p-1i,
-0x1.fc995098a4e74p-1 + -0x1.37adbef657d98p-1i, -0x1.05bb4e8cfa67ap+0 + -0x1.2dbb4420919f2p-1i,
-0x1.0cd7694844fa3p+0 + -0x1.232667ff918e8p-1i, -0x1.139cb030e9d8ep+0 + -0x1.17f8301e8975ap-1i,
-0x1.1a0715f2510a2p+0 + -0x1.0c3a17fde2027p-1i, -0x1.2012cb4c96f28p+0 + -0x1.ffec16689a99bp-2i,
-0x1.25bc420b6d01cp+0 + -0x1.e66cbe7b71759p-2i, -0x1.2b002fd5c210ep+0 + -0x1.cc0b99f794f34p-2i,
-0x1.2fdb90d434c8ep+0 + -0x1.b0ded3d7983f6p-2i, -0x1.344baa2c6b101p+0 + -0x1.94fd422c2e17bp-2i,
-0x1.384e0c4f83633p+0 + -0x1.787e57768f512p-2i, -0x1.3be09519f01b8p+0 + -0x1.5b7a13875567ep-2i,
-0x1.3f0171c328dedp+0 + -0x1.3e08f3eb05f88p-2i, -0x1.41af209bbbcep+0 + -0x1.2043e3eddcf3cp-2i,
-0x1.43e87298664e2p+0 + -0x1.02442c40ae8ep-2i, -0x1.45ac8ca8fc914p+0 + -0x1.c846c491fe06ap-3i,
-0x1.46fae8da0714bp+0 + -0x1.8bf6ae4d5a86cp-3i, -0x1.47d357401e32p+0 + -0x1.4fcc0cf38c59ap-3i,
-0x1.4835feac2d6e4p+0 + -0x1.13fb09e69001ep-3i, -0x1.48235d27ea676p+0 + -0x1.b16fbaef24c28p-4i,
-0x1.479c4839edf82p+0 + -0x1.3c6d56ec68d94p-4i, -0x1.46a1ecf1015a6p+0 + -0x1.92ad7e60c0458p-5i,
-0x1.4535cfb65498dp+0 + -0x1.624c4e7fb5e2p-6i, -0x1.4359cbe67778cp+0 + 0x1.5778aadfc8fp-8i,
-0x1.411013311204cp+0 + 0x1.00c880fd88dbp-5i, -0x1.3e5b2cbf7e049p+0 + 0x1.cf9f7e380582p-5i,
-0x1.3b3df42286d2p+0 + 0x1.4b588a6748e6p-4i, -0x1.37bb9807b90dep+0 + 0x1.aa9f3e2c8531p-4i,
-0x1.33d798b6cfa0dp+0 + 0x1.02a369430221p-3i, -0x1.2f95c657ef24ep+0 + 0x1.2d7a6f92bd4ccp-3i,
-0x1.2afa3f038421cp+0 + 0x1.55a8eeab04d98p-3i, -0x1.26096c9cbb7a4p+0 + 0x1.7b04b445ebcecp-3i,
-0x1.20c80277aecc8p+0 + 0x1.9d653eab47bbp-3i, -0x1.1b3afacc805dp+0 + 0x1.bca3db467dcccp-3i,
-0x1.156793f8c345ep+0 + 0x1.d89bc4446fdf4p-3i, -0x1.0f534d90ad11p+0 + 0x1.f12a3d25a42b8p-3i,
-0x1.0903e541ad64ep+0 + 0x1.03175718ab67cp-2i, -0x1.027f538827252p+0 + 0x1.0bc55f5b62918p-2i,
-0x1.f797907447ecfp-1 + 0x1.1291370557f14p-2i, -0x1.e9df4dd1ef892p-1 + 0x1.176e1597e4e0ep-2i,
-0x1.dbe30637ca9a5p-1 + 0x1.1a50758cc5edap-2i, -0x1.cdb038cbddf69p-1 + 0x1.1b2e1ebcdc132p-2i,
-0x1.bf54b4b230abep-1 + 0x1.19fe3004d58f6p-2i, -0x1.b0de90b2e7d94p-1 + 0x1.16b92820c050ep-2i,
-0x1.a25c22a4dfda2p-1 + 0x1.1158edb7fe0f4p-2i, -0x1.93dbf6a1d0b6cp-1 + 0x1.09d8d6938c998p-2i,
-0x1.856cc6093263dp-1 + 0x1.0035adf9135f9p-2i, -0x1.771d6e5738ep-1 + 0x1.e8db744b5343ap-3i,
-0x1.68fce7d56084p-1 + 0x1.cd0181c79cef6p-3i, -0x1.5b1a3c2a1fe49p-1 + 0x1.ace0167129aep-3i,
-0x1.4d847ccd6e44cp-1 + 0x1.887cd04923572p-3i, -0x1.404ab967e3dcap-1 + 0x1.5fe05ceb50aep-3i,
-0x1.337bf6224be62p-1 + 0x1.33167b4ec50cep-3i, -0x1.272721eb8fa69p-1 + 0x1.022dfba0255p-3i,
-0x1.1b5b0cbaed317p-1 + 0x1.9a717a665081p-4i, -0x1.10265dd474b2p-1 + 0x1.2897551445bfp-4i,
-0x1.05978a15cb544p-1 + 0x1.5dfacdce71abp-5i, -0x1.f77994a267276p-2 + 0x1.6ecc53f126b2p-7i,
-0x1.e5482379af744p-2 + -0x1.6a61f7a5f304p-6i, -0x1.d4b608f8994ap-2 + -0x1.d42e3f3a2cfap-5i,
-0x1.c5dddc9471232p-2 + -0x1.805b125af723p-4i, -0x1.b8d9728ff76aap-2 + -0x1.0e8bbb74a364p-3i,
-0x1.adc1c9f24d73ep-2 + -0x1.5ffcfca7fe954p-3i, -0x1.a4aefae0ec23cp-2 + -0x1.b4557b52cff5p-3i,
-0x1.9db82567e0854p-2 + -0x1.05b3699714c68p-2i, -0x1.98f360bb5223ep-2 + -0x1.328011bea4e5cp-2i,
-0x1.9675aafd17834p-2 + -0x1.6077138a32a56p-2i, -0x1.9652d990d70e4p-2 + -0x1.8f7da6feb394ep-2i,
-0x1.989d8a08e5ff3p-2 + -0x1.bf77ec569593ap-2i, -0x1.9d6713b5c3cfep-2 + -0x1.f048fa5d5a80cp-2i,
-0x1.a4bf79e1b742ep-2 + -0x1.10e976c23c68ap-1i, -0x1.aeb55ec1b2d43p-2 + -0x1.29fb7bd4a7f06p-1i,
-0x1.bb55f724412d3p-2 + -0x1.434ab841c61efp-1i, -0x1.caacfee6cf706p-2 + -0x1.5cc6f3597542ap-1i,
-0x1.dcc4ae393b1d7p-2 + -0x1.765f98b16f658p-1i, -0x1.f1a5afb714225p-2 + -0x1.9003c13d21ccap-1i,
-0x1.04ab8baec4d66p-1 + -0x1.a9a23ca66b17ap-1i, -0x1.11ef2d323ce3ep-1 + -0x1.c3299ae1f722p-1i,
-0x1.209fa4004c85fp-1 + -0x1.dc8835f9c736ap-1i, -0x1.30be018a1079ep-1 + -0x1.f5ac3c084fa89p-1i,
-0x1.424a7e697482bp-1 + -0x1.0741dcaf38e43p+0i, -0x1.5544782f20b55p-1 + -0x1.137e51673d316p+0i,
-0x1.69aa6fae2a6b7p-1 + -0x1.1f82700b18dp+0i, -0x1.7f7a07c72235ap-1 + -0x1.2b452b30f89fep+0i,
-0x1.96b004b3cd5p-1 + -0x1.36bd797150ffp+0i, -0x1.af484bd48d614p-1 + -0x1.41e25ab838205p+0i,
-0x1.c93de4002cb52p-1 + -0x1.4caadd99fda8ep+0i, -0x1.e48af65677f8cp-1 + -0x1.570e24a7dc927p+0i,
-0x1.009467cae06f8p+0 + -0x1.61036bc1a199ap+0i, -0x1.0f87f0f98b999p+0 + -0x1.6a820d611fa84p+0i,
-0x1.1f1be3ba5bf78p+0 + -0x1.738187dc4cafep+0i, -0x1.2f4ba266f207cp+0 + -0x1.7bf9829ae45aap+0i,
-0x1.4012265d81afep+0 + -0x1.83e1d33c72c95p+0i, -0x1.516a01ee552e2p+0 + -0x1.8b3282abb040bp+0i,
-0x1.634d6287e6f5dp+0 + -0x1.91e3d21c1f432p+0i, -0x1.75b613209210ep+0 + -0x1.97ee3feee8ec5p+0i,
-0x1.889d7edcb354ap+0 + -0x1.9d4a8c7bffaebp+0i, -0x1.9bfcb3eff117p+0 + -0x1.a1f1bebc9e91ap+0i,
-0x1.afcc66b83b0b5p+0 + -0x1.a5dd28d44ae6ep+0i, -0x1.c404f510f0c24p+0 + -0x1.a9066c758fedep+0i,
-0x1.d89e69dc7ae3ep+0 + -0x1.ab677f1fbf29cp+0i, -0x1.ed9080c281d79p+0 + -0x1.acfaae3315062p+0i,
-0x1.016955106613ap+1 + -0x1.adbaa2d8b7f6ep+0i, -0x1.0c2e079657cc4p+1 + -0x1.ada265bc204acp+0i,
-0x1.1711cb2170edap+1 + -0x1.acad629390803p+0i, -0x1.220ff3b1ac645p+1 + -0x1.aad76b7560f1cp+0i,
-0x1.2d23b86b674bdp+1 + -0x1.a81cbbf7fe1f1p+0i, -0x1.384835fdb2202p+1 + -0x1.a479fc1a968e4p+0i,
-0x1.4378711ae1c08p+1 + -0x1.9fec42f494486p+0i, -0x1.4eaf5902055efp+1 + -0x1.9a71192a1e1bcp+0i,
-0x1.59e7ca17dba1cp+1 + -0x1.94067b23fe24bp+0i, -0x1.651c908dd73p+1 + -0x1.8caadb096d652p+0i,
-0x1.70486b15b9af6p+1 + -0x1.845d227a6789fp+0i, -0x1.7b660da043e02p+1 + -0x1.7b1cb4094e1dfp+0i,
-0x1.867024257209p+1 + -0x1.70e96c72c7699p+0i, -0x1.91615574b551p+1 + -0x1.65c3a392eadbep+0i,
-0x1.9c34460b94f6ap+1 + -0x1.59ac2d16f3317p+0i, -0x1.a6e39af11d97cp+1 + -0x1.4ca458ead5526p+0i,
-0x1.b169fc9480eaep+1 + -0x1.3eadf362422f4p+0i, -0x1.bbc219ad45704p+1 + -0x1.2fcb451cc1793p+0i,
-0x1.c5e6aa1b63b44p+1 + -0x1.1fff12a4baf48p+0i, -0x1.cfd271c5adcfbp+1 + -0x1.0f4c9bc96c30cp+0i,
-0x1.d9804374ddd19p+1 + -0x1.fb6f3567e11afp-1i, -0x1.e2eb03a9a8bc3p+1 + -0x1.d688856f53114p-1i,
-0x1.ec0dab6c35afcp+1 + -0x1.afee7dbcfaaabp-1i, -0x1.f4e34b135bc64p+1 + -0x1.87ab606312f2fp-1i,
-0x1.fd670d020d018p+1 + -0x1.5dca577e1d66ep-1i, -0x1.02ca1c2cacbbep+2 + -0x1.325770bd04ed6p-1i,
-0x1.06b319cebdd8p+2 + -0x1.055f9867b1e1ap-1i, -0x1.0a6c43a632e3p+2 + -0x1.ade127cd02378p-2i,
-0x1.0df370322744cp+2 + -0x1.4e31f79ab54ccp-2i, -0x1.1146896c631e4p+2 + -0x1.d7a0d5b5b824ap-3i,
-0x1.14638dfa71fd4p+2 + -0x1.0db9afc386cb8p-3i, -0x1.17489254937e9p+2 + -0x1.f791208116ffp-6i,
-0x1.19f3c1e1d9023p+2 + 0x1.28de978050afcp-4i, -0x1.1c636008c97d3p+2 + 0x1.6c2163d5ecaa6p-3i,
-0x1.1e95c933eac86p+2 + 0x1.23ec283f9f07cp-2i, -0x1.208973c99678ap+2 + 0x1.93a2e50767227p-2i,
-0x1.223cf116875dcp+2 + 0x1.02864e8b90e3p-1i, -0x1.23aeee2a94242p+2 + 0x1.3bfff8a3ec5fep-1i,
-0x1.24de34a71355bp+2 + 0x1.7629413a521e4p-1i, -0x1.25c9ab7e6cf72p+2 + 0x1.b0ec830962738p-1i,
-0x1.267057a466591p+2 + 0x1.ec33adac65514p-1i, -0x1.26d15caebd47fp+2 + 0x1.13f4283a4ee82p+0i,
-0x1.26ebfd65b0a0ep+2 + 0x1.31f9d2bd37eccp+0i, -0x1.26bf9c441d695p+2 + 0x1.501f4e7222b6cp+0i,
-0x1.264bbbe6e0d0dp+2 + 0x1.6e58f42e80034p+0i, -0x1.258fff6b39002p+2 + 0x1.8c9b0359d29d5p+0i,
-0x1.248c2abbe8438p+2 + 0x1.aad9a7ceee017p+0i, -0x1.234022cce7e88p+2 + 0x1.c908ffcb5d0aep+0i,
-0x1.21abedc582171p+2 + 0x1.e71d21e9a741p+0i, -0x1.1fcfb318b3f31p+2 + 0x1.0285119192164p+1i,
-0x1.1dabbb8bc36fcp+2 + 0x1.11620e6b0369bp+1i, -0x1.1b40712afe66cp+2 + 0x1.201f99662413dp+1i,
-0x1.188e5f2ca2b73p+2 + 0x1.2eb7cca00aea2p+1i, -0x1.159631c1f9622p+2 + 0x1.3d24cd6d35b22p+1i,
-0x1.1258b5d6b8cbap+2 + 0x1.4b60cf543f256p+1i, -0x1.0ed6d8becc6a7p+2 + 0x1.5966170254e44p+1i,
-0x1.0b11a7d2aa48p+2 + 0x1.672efd37c70e2p+1i, -0x1.070a4ffa68af1p+2 + 0x1.74b5f1ab0f5fep+1i,
-0x1.02c21d27d04cdp+2 + 0x1.81f57de0b2d89p+1i, -0x1.fc74f37f618f7p+1 + 0x1.8ee847f666f8p+1i,
-0x1.f2e9dbe58ed85p+1 + 0x1.9b89155feaa9cp+1i, -0x1.e8e63e0d21f02p+1 + 0x1.a7d2cd940ad53p+1i,
-0x1.de6d9d1cd1984p+1 + 0x1.b3c07ca8535c6p+1i, -0x1.d383b32ac18f8p+1 + 0x1.bf4d55d9f6fdfp+1i,
-0x1.c82c6f728bb8cp+1 + 0x1.ca74b602831adp+1i, -0x1.bc6bf46e9bc4p+1 + 0x1.d53225f6ffb76p+1i,
-0x1.b04695d5e6e81p+1 + 0x1.df815cd0283c8p+1i, -0x1.a3c0d67f190d4p+1 + 0x1.e95e421a766bcp+1i,
-0x1.96df662a60088p+1 + 0x1.f2c4efecc6abp+1i, -0x1.89a71f330c069p+1 + 0x1.fbb1b4e46b2b5p+1i,
-0x1.7c1d042a4a278p+1 + 0x1.02108b02c9442p+2i, -0x1.6e463d5c4b5cdp+1 + 0x1.0607e83f7b18bp+2i,
-0x1.6028164135f6dp+1 + 0x1.09bd6da7eaa4ap+2i, -0x1.51c7fadb4bd48p+1 + 0x1.0d2fb467a8c1bp+2i,
-0x1.432b7503b9e2p+1 + 0x1.105d740a2a82bp+2i, -0x1.345829a78f6f3p+1 + 0x1.1345831e9d194p+2i,
-0x1.2553d5f664eb2p+1 + 0x1.15e6d7cb4059cp+2i, -0x1.16244c8441a63p+1 + 0x1.1840884ff6e63p+2i,
-0x1.06cf72605778ep+1 + 0x1.1a51cb77c4a11p+2i, -0x1.eeb6784462d8ap+0 + 0x1.1c19f8f8fdc31p+2i,
-0x1.cf9b55ddefb8dp+0 + 0x1.1d9889c3f2cfdp+2i, -0x1.b05992f0e1d54p+0 + 0x1.1ecd183fefa2bp+2i,
-0x1.90fd51eecf0f2p+0 + 0x1.1fb760766de39p+2i, -0x1.7192bc464b938p+0 + 0x1.2057402c6557ap+2i,
-0x1.5225fc4f618dep+0 + 0x1.20acb6e9aeb8cp+2i, -0x1.32c33738e940ap+0 + 0x1.20b7e5ee77f28p+2i,
-0x1.137686fa1df98p+0 + 0x1.20791016d2dd5p+2i, -0x1.e897e89792c8cp-1 + 0x1.1ff099ac71c2ap+2i,
-0x1.aa9ee158b3d9p-1 + 0x1.1f1f0826af18ep+2i, -0x1.6d19a0e464113p-1 + 0x1.1e0501d907f8fp+2i,
-0x1.301f89deeb39fp-1 + 0x1.1ca34d903ac76p+2i, -0x1.e78f5aaa4002ep-2 + 0x1.1afad21e456b6p+2i,
-0x1.70517eba82d2ep-2 + 0x1.190c95d58823p+2i, -0x1.f5642fb7745b3p-3 + 0x1.16d9bdf35b9p+2i,
-0x1.0db9afc386c8ap-3 + 0x1.14638dfa71fd4p+2i, -0x1.4fc7531b183dp-6 + 0x1.11ab66fd65009p+2i,
0x1.6b15a80f1f638p-4 + 0x1.0eb2c6d9d9904p+2i, 0x1.908087d93f29ap-3 + 0x1.0b7b4764ad518p+2i,
0x1.334cce9980dbfp-2 + 0x1.08069d87a850ep+2i, 0x1.9bc50ad0fe9e9p-2 + 0x1.0456985136782p+2i,
0x1.00c22b13e1f4ap-1 + 0x1.006d1ff6b3e72p+2i, 0x1.3233be2a01212p-1 + 0x1.f8986993bdadp+1i,
0x1.622663d9696d8p-1 + 0x1.efebdc4411a7fp+1i, 0x1.908a087b5c22ap-1 + 0x1.e6d8f2734fecp+1i,
0x1.bd4f66fb762e3p-1 + 0x1.dd643001de24cp+1i, 0x1.e8680fcbd453ep-1 + 0x1.d3923fcc341cep+1i,
0x1.08e337b107a8cp+0 + 0x1.c967f12842082p+1i, 0x1.1caeea1cd820ap+0 + 0x1.beea355114636p+1i,
0x1.2f913a2c82851p+0 + 0x1.b41e1cc22ef0fp+1i, 0x1.4184b92ac2eafp+0 + 0x1.a908d48421138p+1i,
0x1.528470eaa3ad8p+0 + 0x1.9dafa36bdda2cp+1i, 0x1.628be5c5a0ed6p+0 + 0x1.9217e74e67414p+1i,
0x1.71971856410f8p+0 + 0x1.8647122a6841p+1i, 0x1.7fa286ee5408p+0 + 0x1.7a42a7495231ap+1i,
0x1.8cab2ec832dadp+0 + 0x1.6e103859a557ap+1i, 0x1.98ae8cf280abep+0 + 0x1.61b5628403706p+1i,
0x1.a3aa9ef616ddep+0 + 0x1.5537cb7cb3642p+1i, 0x1.ad9de335ee0e8p+0 + 0x1.489d1e933cb74p+1i,
0x1.b6875908fe17bp+0 + 0x1.3beb09c1c1db9p+1i, 0x1.be66808e378cfp+0 + 0x1.2f273abdbfc72p+1i,
0x1.c53b5a3ae155ap+0 + 0x1.22575c0bd791p+1i, 0x1.cb066623ccefep+0 + 0x1.15811218442d5p+1i,
0x1.cfc8a301fb871p+0 + 0x1.08a9f8559ad1ap+1i, 0x1.d3838cf375374p+0 + 0x1.f7af3cc6e005bp+0i,
0x1.d6391bf93a884p+0 + 0x1.de1f0a7cebad9p+0i, 0x1.d7ebc2335e388p+0 + 0x1.c4ae38f74328ep+0i,
0x1.d89e69dc7ae46p+0 + 0x1.ab677f1fbf29bp+0i, 0x1.d8547305dca7ap+0 + 0x1.9255664ba83bcp+0i,
0x1.d711b115daad9p+0 + 0x1.798245063dce8p+0i, 0x1.d4da6809ff6e6p+0 + 0x1.60f839fd1a352p+0i,
0x1.d1b3497ec0325p+0 + 0x1.48c1271135dfcp+0i, 0x1.cda1717ea52b6p+0 + 0x1.30e6ac8f35166p+0i,
0x1.c8aa631ae309p+0 + 0x1.1972249193023p+0i, 0x1.c2d404cf85358p+0 + 0x1.026c9e8f22d82p+0i,
0x1.bc249cb564f78p+0 + 0x1.d7bdb63089363p-1i, 0x1.b4a2cc84454e2p+0 + 0x1.aba28f8a1c67ep-1i,
0x1.ac558d678599cp+0 + 0x1.8097f6ad17436p-1i, 0x1.a3442ba7f5cf4p+0 + 0x1.56ad641a33a8p-1i,
0x1.9976422d6e21p+0 + 0x1.2df1946b7ee4ap-1i, 0x1.8ef3b5dae191dp+0 + 0x1.067281e08aec4p-1i,
0x1.83c4b0c7b6d39p+0 + 0x1.c07abcbebc9dep-2i, 0x1.77f19d5944fa8p+0 + 0x1.76bd1bda3759ep-2i,
0x1.6b83213f62158p+0 + 0x1.2fc3434222874p-2i, 0x1.5e82185700633p+0 + 0x1.d7454c525f0c3p-3i,
0x1.50f78f75e3ca2p+0 + 0x1.54de0147733ecp-3i, 0x1.42ecbf228443cp+0 + 0x1.b0e9421b4e404p-4i,
0x1.346b063b3b2a5p+0 + 0x1.88a67a5eaa0e8p-5i, 0x1.257be48fe0a93p+0 + -0x1.bcc4c14a6458p-8i,
0x1.1628f57104114p+0 + -0x1.de859f10c8ep-5i, 0x1.067bea37ed554p+0 + -0x1.b5e505071e96cp-4i,
0x1.ecfd09952f59fp-1 + -0x1.37c777285e834p-3i, 0x1.cc75243daa2e6p-1 + -0x1.8e11ed6082874p-3i,
0x1.ab73c97f90b1ap-1 + -0x1.ddc7336fa4caap-3i, 0x1.8a0c9eb1be238p-1 + -0x1.13701df2e6657p-2i,
0x1.68533e92df364p-1 + -0x1.34accca434d78p-2i, 0x1.465b2e882d4c4p-1 + -0x1.5299bbd95a144p-2i,
0x1.2437d3f9cdfb2p-1 + -0x1.6d38ca39bee0bp-2i, 0x1.01fc69d2e4c97p-1 + -0x1.848d99d7d6845p-2i,
0x1.bf77ec569595p-2 + -0x1.989d8a08e6002p-2i, 0x1.7b12804183cbap-2 + -0x1.a96fb04816cc7p-2i,
0x1.36ed8bcab0a52p-2 + -0x1.b70cd02a245f9p-2i, 0x1.e65acc223104p-3 + -0x1.c17f52677cc4p-2i,
0x1.5feb5c025f5f4p-3 + -0x1.c8d33b0331ea6p-2i, 0x1.b5a4dfc915b1p-4 + -0x1.cd161e959a6ebp-2i,
0x1.5d4fdec68366p-5 + -0x1.ce5716c1fd562p-2i, -0x1.526fbe89e88ap-6 + -0x1.cca6b5df1c18ap-2i,
-0x1.53a68c21ba79p-4 + -0x1.c816f9dae154p-2i, -0x1.26fdf6585a23cp-3 + -0x1.c0bb3e61e8154p-2i,
-0x1.a192460ac15ecp-3 + -0x1.b6a82e53f7dd8p-2i, -0x1.0cab64ad0278p-2 + -0x1.a9f3b48ef3c61p-2i,
-0x1.470a4336165cfp-2 + -0x1.9ab4ec1a17a26p-2i, -0x1.7fcb87705e2bp-2 + -0x1.89040fbbb41d1p-2i,
-0x1.b6d64bd4a3fd6p-2 + -0x1.74fa6903eab27p-2i, -0x1.ec130794a02a1p-2 + -0x1.5eb23ed7338aep-2i,
-0x1.0fb5cc6484593p-1 + -0x1.4646c383b9e55p-2i, -0x1.2865a6dc727d4p-1 + -0x1.2bd4026cd7537p-2i,
-0x1.400f769ae808ep-1 + -0x1.0f76cd582accep-2i, -0x1.56aa5f04b2b9fp-1 + -0x1.e29952cfec478p-3i,
-0x1.6c2e46b853d81p-1 + -0x1.a2e7779d25c24p-3i, -0x1.8093da5162b68p-1 + -0x1.60156c8ddd2c8p-3i,
-0x1.93d48eb09bb63p-1 + -0x1.1a6186bc2d3ap-3i, -0x1.a5eaa2c7e4a1cp-1 + -0x1.a415ca67ae38p-4i,
-0x1.b6d120e9dae76p-1 + -0x1.0ea292247788p-4i, -0x1.c683df9ccbfefp-1 + -0x1.d3a76c896b62p-6i,
-0x1.d4ff81f143e69p-1 + 0x1.4499feb2bdap-7i, -0x1.e241775ca8e09p-1 + 0x1.92a69eace949p-5i,
-0x1.ee47fb18a6741p-1 + 0x1.6cd4de8f6f7ep-4i, -0x1.f912130873c1dp-1 + 0x1.094b61027f5b4p-3i,
-0x1.014fc712a543ep+0 + 0x1.5d0c32bcf9dd4p-3i, -0x1.05788139d62e8p+0 + 0x1.b16d0c74fca6p-3i,
-0x1.0903e541ad646p+0 + 0x1.03175718ab67cp-2i, -0x1.0bf3013e1633p+0 + 0x1.2d894aa3db0ecp-2i,
-0x1.0e47425d16c28p+0 + 0x1.57ed90730537cp-2i, -0x1.100272fdde88fp+0 + 0x1.8225dae50bfcep-2i,
-0x1.1126b8924b9bep+0 + 0x1.ac1470893f646p-2i, -0x1.11b6914c7edfcp+0 + 0x1.d59c3d0a90576p-2i,
-0x1.11b4d19a35575p+0 + 0x1.fea0e193be85ap-2i, -0x1.1124a16fb9e6ap+0 + 0x1.1383625194ef5p-1i,
-0x1.100979645ec4p+0 + 0x1.275990a2a94e6p-1i, -0x1.0e671fa28867fp+0 + 0x1.3ac60ad6bd3d4p-1i,
-0x1.0c41a4ad6d1bp+0 + 0x1.4dbc58922317cp-1i, -0x1.099d5ffec41a7p+0 + 0x1.603080a257c46p-1i,
-0x1.067eec7eb5c4ep+0 + 0x1.72170f40070f6p-1i, -0x1.02eb24d8732aep+0 + 0x1.83651bf13b28p-1i,
-0x1.fdce3f5bdd96cp-1 + 0x1.94104f0895e4p-1i, -0x1.f4f0575a841a6p-1 + 0x1.a40ee6beb2e88p-1i,
-0x1.eb479714b677ap-1 + 0x1.b357bbe313fb4p-1i, -0x1.e0df63bf3c9d5p-1 + 0x1.c1e246223c3fp-1i,
-0x1.d5c379f05f343p-1 + 0x1.cfa69fdee3ecep-1i, -0x1.c9ffe50d5542p-1 + 0x1.dc9d899c73ff2p-1i,
-0x1.bda0f696213fp-1 + 0x1.e8c06cf94009dp-1i, -0x1.b0b33d5583f71p-1 + 0x1.f4095f373c0dp-1i,
-0x1.a3437c7ab7438p-1 + 0x1.fe73235234256p-1i, -0x1.955ea2a2aaad8p-1 + 0x1.03fc95d16a45bp+0i,
-0x1.8711c0d680967p-1 + 0x1.084bcd870c7f7p+0i, -0x1.786a01850b56fp-1 + 0x1.0c25a2e081c62p+0i,
-0x1.69749f7d07265p-1 + 0x1.0f88d8bc619c8p+0i, -0x1.5a3edcedc74cap-1 + 0x1.12748aabddb8p+0i,
-0x1.4ad5fa74035ccp-1 + 0x1.14e82ca41274p+0i, -0x1.3b472e3863dc5p-1 + 0x1.16e38a76a3f1fp+0i,
-0x1.2b9f9b255cf82p-1 + 0x1.1866c7124b044p+0i, -0x1.1bec4839d1a5p-1 + 0x1.19725b8c17ab8p+0i,
-0x1.0c3a17fde2008p-1 + 0x1.1a0715f25109cp+0i, -0x1.f92b803e599d6p-2 + 0x1.1a2617e9fc145p+0i,
-0x1.da1782735bc4ap-2 + 0x1.19d0d5183300dp+0i, -0x1.bb50bda483ca7p-2 + 0x1.190911589742bp+0i,
-0x1.9cef2f0f67533p-2 + 0x1.17d0dec246e1p+0i, -0x1.7f0a3afe1fa0ep-2 + 0x1.162a9b7cdbe99p+0i,
-0x1.61b89e1fa2dc7p-2 + 0x1.1418ef6719b98p+0i, -0x1.45105f689aad1p-2 + 0x1.119ec991079e7p+0i,
-0x1.2926c2852464fp-2 + 0x1.0ebf5d8b5302dp+0i, -0x1.0e103ae382b23p-2 + 0x1.0b7e208decb82p+0i,
-0x1.e7c0bebebfbdcp-3 + 0x1.07dec677ed10fp+0i, -0x1.b553bd29a4268p-3 + 0x1.03e53eaae13a2p+0i,
-0x1.84fce7c3c2b0cp-3 + 0x1.ff2b618773346p-1i, -0x1.56ddba39b2a6cp-3 + 0x1.f5e8f26749ba1p-1i,
-0x1.2b15a20a6ecdcp-3 + 0x1.ec0c4b766b6ap-1i, -0x1.01c1ece912318p-3 + 0x1.e19ee3948450bp-1i,
-0x1.b5fb71503baep-4 + 0x1.d6aa858df50d8p-1i, -0x1.6dc3c96dd542p-4 + 0x1.cb39487d87732p-1i,
-0x1.2b0a0a71c205p-4 + 0x1.bf558806d9435p-1i, -0x1.dbed5ef408cep-5 + 0x1.b309dc6ec0f62p-1i,
-0x1.6d5ae66cf52p-5 + 0x1.a661129701b5bp-1i, -0x1.0a9a7fefda12p-5 + 0x1.996623e2b176cp-1i,
-0x1.67c08c68879cp-6 + 0x1.8c242e08be66cp-1i, -0x1.a55a1e6b2d84p-7 + 0x1.7ea66ada07b47p-1i,
-0x1.58edd41ca658p-8 + 0x1.70f828008118ap-1i, 0x1.ace1e5e9bbcp-11 + 0x1.6324bebcd84e6p-1i,
0x1.6084025213ep-8 + 0x1.55378ba81019p-1i, 0x1.13d90e927d84p-7 + 0x1.473be67e7d44ep-1i,
0x1.45aea3e93114p-7 + 0x1.393d19f9879bap-1i, 0x1.4604d43e33acp-7 + 0x1.2b465bbd82bb4p-1i,
0x1.1543f70eaacp-7 + 0x1.1d62c460e1738p-1i, 0x1.67f43a8ce2ep-8 + 0x1.0f9d4791f1a61p-1i,
0x1.16d368952fep-10 + 0x1.0200ac6036bbp-1i, -0x1.3a8735ea97ap-8 + 0x1.e92f0b5cbb2f6p-2i,
-0x1.8b64f8b9f31p-7 + 0x1.ced855a34da02p-2i, -0x1.5336097e085cp-6 + 0x1.b51160c704f6ap-2i,
-0x1.f68cde3349d4p-6 + 0x1.9bedc293e9a9cp-2i, -0x1.57839325faa4p-5 + 0x1.83806ff6676cep-2i,
-0x1.bdf2b3949e04p-5 + 0x1.6bdbb0018632cp-2i, -0x1.1716483ed84fp-4 + 0x1.55110f7c54842p-2i,
-0x1.53e15e6baaecp-4 + 0x1.3f3154fe5859ap-2i, -0x1.951ffc434b3ep-4 + 0x1.2a4c75a2789cp-2i,
-0x1.da9447652a8cp-4 + 0x1.16718a5769f44p-2i, -0x1.11feae2f53528p-3 + 0x1.03aec5d43dabp-2i,
-0x1.388bc0ea65e8p-3 + 0x1.e422d66e82d48p-3i, -0x1.60ce2eb976958p-3 + 0x1.c34b8aa9d61e8p-3i,
-0x1.8aa1953c8b298p-3 + 0x1.a4ee3d78292dp-3i, -0x1.b5e078e230488p-3 + 0x1.891f74e8a3a9cp-3i,
-0x1.e26461952ae08p-3 + 0x1.6ff19af5594p-3i, -0x1.0802fbfff1498p-2 + 0x1.5974f201286d4p-3i,
-0x1.1f4e91a8b06fp-2 + 0x1.45b78ae095efp-3i, -0x1.370093b7bbf3p-2 + 0x1.34c53c73330ep-3i,
-0x1.4f0461c0b4014p-2 + 0x1.26a79cd212872p-3i, -0x1.6745285f16948p-2 + 0x1.1b65fc16c294p-3i,
-0x1.7fadf0b4be2d8p-2 + 0x1.130560bd33a84p-3i, -0x1.9829aff533528p-2 + 0x1.0d8885a1e37f2p-3i,
-0x1.b0a356f348c2p-2 + 0x1.0aefd99c93b7cp-3i, -0x1.c905e1a67e8dcp-2 + 0x1.0b3980b6c2ef4p-3i,
-0x1.e13c669db32ap-2 + 0x1.0e6156fc103d6p-3i, -0x1.f9322654bb5bcp-2 + 0x1.1460f4e1a35c4p-3i,
-0x1.08694d3149212p-1 + 0x1.1d2fb540a86f9p-3i, -0x1.1404c23af8f1cp-1 + 0x1.28c2bcdee62b1p-3i,
-0x1.1f617e8b2529p-1 + 0x1.370d037f7048cp-3i, -0x1.2a75c10f9ccd4p-1 + 0x1.47ff5e7477feep-3i,
-0x1.353802766c8f4p-1 + 0x1.5b888caa40858p-3i, -0x1.3f9efc17b6df8p-1 + 0x1.7195442247d02p-3i,
-0x1.49a1aeaea37c8p-1 + 0x1.8a1040d4c3d06p-3i, -0x1.533768dceecd8p-1 + 0x1.a4e254edab7a2p-3i,
-0x1.5c57cd74c6af4p-1 + 0x1.c1f27a59a106p-3i, -0x1.64fad984ca25p-1 + 0x1.e125e59638fcep-3i,
-0x1.6d18ea222c1b4p-1 + 0x1.01300cdc2415dp-2i, -0x1.74aac1ed2686cp-1 + 0x1.12c17ecd0d024p-2i,
-0x1.7ba98e4c1ac16p-1 + 0x1.2537791158ee7p-2i, -0x1.820eec59ee004p-1 + 0x1.388174cb421c8p-2i,
-0x1.87d4ed8464cc6p-1 + 0x1.4c8e3ff0b5368p-2i, -0x1.8cf61bd77696p-1 + 0x1.614c09e479692p-2i,
-0x1.916d7df2ca91p-1 + 0x1.76a8707acd5edp-2i, -0x1.95369aa6c8e4p-1 + 0x1.8c908d607b03ep-2i,
-0x1.984d7c36e6aa6p-1 + 0x1.a2f103db252fp-2i, -0x1.9aaeb33f1049cp-1 + 0x1.b9b60ed959914p-2i,
-0x1.9c57593a53dc4p-1 + 0x1.d0cb8f48bed6cp-2i, -0x1.9d4512a92cedcp-1 + 0x1.e81d1aa88ac38p-2i,
-0x1.9d7610d613358p-1 + 0x1.ff9609ce4656p-2i, -0x1.9ce913372f50ap-1 + 0x1.0b90c3e96375p-1i,
-0x1.9b9d686c5a716p-1 + 0x1.1755508e9557bp-1i, -0x1.9992eed8d0826p-1 + 0x1.230e2940ca8ccp-1i,
-0x1.96ca14d83f056p-1 + 0x1.2eb0cc34ae44dp-1i, -0x1.9343d88f1e0bp-1 + 0x1.3a32befd2b296p-1i,
-0x1.8f01c7568398ep-1 + 0x1.4589961978282p-1i, -0x1.8a05fcc3e4ba6p-1 + 0x1.50aafc7868468p-1i,
-0x1.8453214d79fccp-1 + 0x1.5b8cbaebe191p-1i, -0x1.7dec688c3f278p-1 + 0x1.6624bf876a83p-1i,
-0x1.76d58f1cc7578p-1 + 0x1.706924e4cbbfcp-1i, -0x1.6f12d8205f414p-1 + 0x1.7a503949d5d18p-1i,
-0x1.66a90a6036de4p-1 + 0x1.83d085aa6fa1p-1i, -0x1.5d9d6d148a42p-1 + 0x1.8ce0d4822a8ccp-1i
)
assertThat(stats:::fft(z=c(-0.809016994374947+0.587785252292473i, 0.768433929458297-0.653094724769415i,
-0.582818297627362+0.922551781210857i, 0.768433929458297-0.653094724769414i,
-0.809016994374948+0.587785252292474i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i,
0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i, 0+0i))
, identicalTo( expected, tol = 1e-6 ) )
|
selection_standard <- function(X, U, J, G){
assertthat::assert_that(is.matrix(X), is.numeric(X),
is.matrix(U), is.numeric(U),
is.numeric(J), is.numeric(G),
assertthat::are_equal(dim(X), dim(U)),
length(J) == nrow(X),
length(G) == nrow(U))
sel.vec <- (G <= J)
X[sel.vec, ] <- U[sel.vec, ]
J[sel.vec] <- G[sel.vec]
return(list(Xsel = X,
Jsel = J))
}
|
context("panSharpen")
data(lsat)
library(raster)
agg <- aggregate(lsat,10)
pan <- sum(lsat[[1:3]])
meth <- c("brovey", "ihs", "pca")
panList <- lapply(meth, function(m) panSharpen(img = agg, pan = pan, r = 3, g = 2, b = 1, method = m))
nlayers <- c(3,3,7)
names(nlayers) <- names(panList) <- meth
test_that("panSharpen methods", {
for(m in meth) expect_is(panList[[m]], "RasterBrick", info = m)
for(m in meth) expect_equal(names(panList[[m]]), paste0(names(agg)[1:nlayers[m]], "_pan"), info = m)
for(m in meth) expect_equal(res(panList[[m]]), res(pan), info = m)
})
|
mat_df = function(m){
stopifnot(is.matrix(m))
res = as.data.frame.table(m)
setnames(res,old = names(res),new = c("row","col","value"))
res
}
df_mat = function(df,row,col,value){
stopifnot(is.data.frame(df))
df = df
eval(substitute(with(df, tapply(value, list(row, col), identity))))
}
|
read.euring2000 <- function(filename){
options(encoding="latin1")
warnorig <- options("warn")
options(warn= -1)
rodat<-read.table(filename, colClasses = "character", sep=",")
dat<-data.frame(scheme=substr(rodat$V1, 1,3), id.method=substr(rodat$V1, 4, 5), ring=substr(rodat$V1, 6, 15))
dat$ring.verif<-substr(rodat$V1, 16, 16)
dat$metal.ring.info<-substr(rodat$V1, 17, 17)
dat$marks.info<-substr(rodat$V1, 18, 19)
dat$spec.byringer<-substr(rodat$V1, 20, 24)
dat$spec.byscheme<-substr(rodat$V1, 25, 29)
dat$manipulated<-substr(rodat$V1, 30, 30)
dat$moved<-substr(rodat$V1, 31, 31)
dat$catching.method<-substr(rodat$V1, 32, 32)
dat$catching.lures<-substr(rodat$V1, 33, 33)
dat$sex.byringer<-substr(rodat$V1, 34, 34)
dat$sex.byscheme<-substr(rodat$V1, 35, 35)
dat$age.byringer<-substr(rodat$V1, 36, 36)
dat$age.byscheme<-substr(rodat$V1, 37, 37)
dat$status<-substr(rodat$V1, 38, 38)
dat$broodsize<-substr(rodat$V1, 39, 40)
dat$pullus.age<-substr(rodat$V1, 41, 42)
dat$pullus.age.acc<-substr(rodat$V1, 43, 43)
dat$day<-as.numeric(substr(rodat$V1, 44, 45))
dat$month<-as.numeric(substr(rodat$V1, 46, 47))
dat$year<-as.numeric(substr(rodat$V1, 48, 51))
dat$date.acc<-substr(rodat$V1, 52, 52)
dat$time<-substr(rodat$V1, 53, 56)
dat$place.code<-substr(rodat$V1, 57, 60)
dat$country<-substr(rodat$V1, 57, 58)
dat$region<-substr(rodat$V1, 59, 60)
latitude<-substr(rodat$V1, 61, 67)
latitude.grad<-as.numeric(substr(latitude, 2,3))
latitude.min<-as.numeric(substr(latitude, 4,5))
latitude.sec<-as.numeric(substr(latitude, 6,7))
latitude.sign <- substr(latitude, 1, 1)
longitude<-substr(rodat$V1, 68, 75)
longitude.grad<-as.numeric(substr(longitude, 2,4))
longitude.min<-as.numeric(substr(longitude, 5,6))
longitude.sec<-as.numeric(substr(longitude, 7,8))
longitude.sign <- substr(longitude, 1, 1)
dat$lat <- as.numeric(paste0(latitude.sign, 1)) * decimal.coord(latitude.grad+latitude.min/100)
dat$lon <- as.numeric(paste0(longitude.sign, 1)) * decimal.coord(longitude.grad+longitude.min/100)
dat$coord.acc<-substr(rodat$V1, 76, 76)
suppressWarnings(dat$condition<-as.numeric(substr(rodat$V1, 77, 77)))
suppressWarnings(dat$circumstances<-as.numeric(substr(rodat$V1, 78, 79)))
suppressWarnings(dat$circumstances.presumed<-as.numeric(substr(rodat$V1, 80, 80)))
dat$euring.codeid<-substr(rodat$V1, 81, 81)
suppressWarnings(dat$distance<-as.numeric(substr(rodat$V1, 82, 86)))
suppressWarnings(dat$direction<-as.numeric(substr(rodat$V1, 87, 89)))
suppressWarnings(dat$time.elapsed<-as.numeric(substr(rodat$V1, 90, 94)))
return(dat)
options(warn= as.numeric(warnorig))
}
|
icomb <- function(n, k)
{
stopifnot(length(n) == 1L)
stopifnot(n > 0L)
stopifnot((n %% 1) == 0)
stopifnot(length(k) == 1L)
stopifnot(k > 0L)
stopifnot((k %% 1) == 0)
stopifnot(k <= n)
n <- as.integer(n)
k <- as.integer(k)
obj <- recursiveiter(nextFunc = function(i,n,k) NextComb(i, n),
prevFunc = function(i,n,k) PrevComb(i, n),
firstFunc = function(n,k) 1:k,
lastFunc = function(n,k) (n-k+1):n,
n = n, k = k)
class(obj) <- c("icomb", class(obj))
obj
}
icombv <- function(values, k)
{
n <- length(values)
obj <- icomb(n,k)
nextElem <- function() values[obj$nextElem()]
prevElem <- function() values[obj$prevElem()]
hasNext <- function() obj$hasNext()
hasPrev <- function() obj$hasPrev()
getFirst <- function() values[obj$getFirst()]
getLast <- function() values[obj$getLast()]
out <- list(nextElem=nextElem, prevElem=prevElem,
hasNext=hasNext, hasPrev=hasPrev,
getFirst=getFirst, getLast=getLast)
class(out) <- c("icombv", "recursiveiter", "abstractiter", "iter")
out
}
|
library(testthat)
library(polite)
test_check("polite")
|
modarrhenius <- function(Ea, Hd, dS, Tleaf) {
param = exp(Ea * ((Tleaf + 273.15) - 298.15) /
(298.15 * (Tleaf + 273.15) * 0.008314)) *
((1 + exp((298.15 * dS - Hd) / (298.15 * 0.008314))) /
(1 + exp(((Tleaf + 273.15) * dS - Hd) /
((Tleaf + 273.15) * 0.008314))))
}
|
mpoint <- function(...,cpch,add=FALSE,type="p")
{
arglist <- list(...)
nptsets <- length(arglist)
if(missing(cpch)){
alphanum <- c(as.character(1:9),LETTERS)
cpch <- alphanum[1:nptsets]
}
cpch <- rep(cpch,length=nptsets)
ipch <- 1
xmax <- NA;ymax <- NA;xmin <- NA;ymin <- NA
if(add==FALSE){
for(ia in 1:nptsets){
if(is.points(arglist[[ia]]))
{
ptsc <- arglist[[ia]]
ymax <- max(ymax,ptsc[,2],na.rm=TRUE)
ymin <- min(ymin,ptsc[,2],na.rm=TRUE)
xmax <- max(xmax,ptsc[,1],na.rm=TRUE)
xmin <- min(xmin,ptsc[,1],na.rm=TRUE)
}
}
pointmap(cbind(c(xmin,xmax,xmin,xmax),c(ymin,ymax,ymax,ymin)),type="n")
}
for(ia in 1:nptsets){
ptsc <- arglist[[ia]]
pointmap(ptsc,add=TRUE,pch=cpch[ipch],type=type)
ipch <- ipch+1
}
invisible(0)
}
|
lav_samplestats_step1 <- function(Y,
wt = NULL,
ov.names = NULL,
ov.types = NULL,
ov.levels = NULL,
ov.names.x = character(0L),
eXo = NULL,
scores.flag = TRUE,
group = 1L) {
Y <- as.matrix(Y)
nvar <- NCOL(Y); N <- NROW(Y)
nTH <- ov.levels - 1L; nTH[nTH == -1L] <- 1L
nth <- sum(nTH)
th.end.idx <- cumsum(nTH); th.start.idx <- th.end.idx - (nTH - 1L)
nexo <- length(ov.names.x)
if(nexo > 0L) stopifnot(NCOL(eXo) == nexo)
TH <- vector("list", length=nvar)
TH.NOX <- vector("list", length=nvar)
TH.NAMES <- vector("list", length=nvar)
TH.IDX <- vector("list", length=nvar)
SLOPES <- matrix(as.numeric(NA), nrow=nvar, ncol=nexo)
VAR <- numeric(length=nvar)
SC.VAR <- matrix(0, N, nvar)
SC.SL <- matrix(0, N, nvar*nexo)
SC.TH <- matrix(0, N, nth)
FIT <- vector("list", length=nvar)
for(i in 1:nvar) {
th.idx <- th.start.idx[i]:th.end.idx[i]
sl.idx <- seq(i, by=nvar, length.out=nexo)
if(ov.types[i] == "numeric") {
fit <- lav_uvreg_fit(y = Y[,i], X = eXo, wt = wt)
if( any(is.na(fit$theta)) ) {
stop("lavaan ERROR: linear regression failed for ", ov.names[i],
"; X may not be of full rank in group ", group)
}
FIT[[i]] <- fit
TH[[i]] <- TH.NOX[[i]] <- fit$theta[1L]
VAR[i] <- fit$theta[fit$var.idx]
TH.NAMES[[i]] <- ov.names[i]; TH.IDX[[i]] <- 0L
if(scores.flag) {
scores <- lav_uvreg_scores(y = Y[,i], X = eXo, wt = wt)
SC.TH[,th.idx] <- scores[,1L]
SC.VAR[,i] <- scores[,fit$var.idx]
}
if(nexo > 0L) {
SLOPES[i,] <- fit$theta[-c(1L, fit$var.idx)]
if(scores.flag) {
SC.SL[,sl.idx] <- scores[,-c(1L, fit$var.idx),drop = FALSE]
}
TH.NOX[[i]] <- mean(Y[,i], na.rm = TRUE)
}
} else if(ov.types[i] == "ordered") {
y.freq <- tabulate(Y[,i], nbins = ov.levels[i])
if(length(y.freq) != ov.levels[i]) {
stop("lavaan ERROR: variable ", ov.names[i], " has fewer categories (", length(y.freq), ") than expected (", ov.levels[i], ") in group ", group)
}
if(any(y.freq == 0L)) {
stop("lavaan ERROR: some categories of variable `", ov.names[i], "' are empty in group ", group, "; frequencies are [", paste(y.freq, collapse=" "), "]")
}
fit <- lav_uvord_fit(y = Y[,i], X = eXo, wt = wt)
if( any(is.na(fit$theta)) ) {
stop("lavaan ERROR: probit regression failed for ", ov.names[i],
"; X may not be of full rank in group ", group)
}
FIT[[i]] <- fit
TH[[i]] <- fit$theta[fit$th.idx]
TH.NOX[[i]] <- lav_uvord_th(y = Y[,i], wt = wt)
if(scores.flag) {
scores <- lav_uvord_scores(y = Y[,i], X = eXo, wt = wt)
SC.TH[,th.idx] <- scores[, fit$th.idx, drop = FALSE]
}
SLOPES[i,] <- fit$theta[fit$slope.idx]
if(scores.flag) {
SC.SL[,sl.idx] <- scores[, fit$slope.idx, drop = FALSE]
}
VAR[i] <- 1.0
TH.NAMES[[i]] <- paste(ov.names[i], "|t", 1:length(TH[[i]]),
sep = "")
TH.IDX[[i]] <- rep(i, length(TH[[i]]))
} else {
stop("lavaan ERROR: unknown ov.types:", ov.types[i])
}
}
list(FIT = FIT, VAR = VAR, SLOPES = SLOPES,
TH = TH, TH.NOX = TH.NOX, TH.IDX = TH.IDX, TH.NAMES = TH.NAMES,
SC.TH = SC.TH, SC.VAR = SC.VAR, SC.SL = SC.SL,
th.start.idx = th.start.idx, th.end.idx = th.end.idx)
}
|
tableUnlist <- function(dataFrame, useNA = c("no","ifany", "always")) {
useNA<- match.arg(useNA)
if( !"data.frame" %in% class(dataFrame) ) {
warning("Argument of 'tableUnlist' has to be of class 'data.frame'. Object will be converted to data.frame.")
dataFrame <- data.frame(dataFrame, stringsAsFactors=FALSE)
}
vek <- do.call("c", lapply(dataFrame, FUN = function ( col ) { return(col)}))
freqT<- table(vek, useNA = useNA)
isna <- which(is.na(names(freqT)))
if ( length(isna)>0) { names(freqT)[isna] <- "NA"}
return(freqT)}
|
context("File directory existence check")
tenant <- Sys.getenv("AZ_TEST_TENANT_ID")
app <- Sys.getenv("AZ_TEST_APP_ID")
password <- Sys.getenv("AZ_TEST_PASSWORD")
subscription <- Sys.getenv("AZ_TEST_SUBSCRIPTION")
if(tenant == "" || app == "" || password == "" || subscription == "")
skip("Authentication tests skipped: ARM credentials not set")
rgname <- Sys.getenv("AZ_TEST_STORAGE_RG")
storname <- Sys.getenv("AZ_TEST_STORAGE_NOHNS")
if(rgname == "" || storname == "")
skip("File client tests skipped: resource names not set")
sub <- AzureRMR::az_rm$new(tenant=tenant, app=app, password=password)$get_subscription(subscription)
stor <- sub$get_resource_group(rgname)$get_storage_account(storname)
fl <- stor$get_file_endpoint()
opts <- options(azure_storage_progress_bar=FALSE)
basedir <- tempfile()
dirs <- file.path(basedir, c("dir1", "dir1/dir2", "dir1/dir2/dir3"))
files <- sapply(dirs, function(d)
{
dir.create(d, recursive=TRUE)
file.path(d, write_file(d))
})
test_that("Azure file direxist check works",
{
cont <- create_file_share(fl, make_name())
upload_azure_file(cont, files[1], "/dir1/file1", create_dir=TRUE)
upload_azure_file(cont, files[2], "/dir1/dir2/file2", create_dir=TRUE)
upload_azure_file(cont, files[3], "/dir1/dir2/dir3/file3", create_dir=TRUE)
expect_true(azure_dir_exists(cont, "/"))
expect_true(azure_dir_exists(cont, "dir1"))
expect_true(azure_dir_exists(cont, "dir1/dir2"))
expect_false(azure_dir_exists(cont, "dir1/file1"))
expect_false(azure_dir_exists(cont, "dir1/dir2/file2"))
expect_false(azure_dir_exists(cont, "badfile"))
expect_false(azure_dir_exists(cont, "dir1/badfile"))
})
teardown(
{
unlink(basedir, recursive=TRUE)
options(opts)
conts <- list_file_shares(fl)
lapply(conts, delete_file_share, confirm=FALSE)
})
|
mcga <- function(tbl) {
x <- colnames(tbl)
x <- tolower(x)
x <- gsub("[[:punct:][:space:]]+", "_", x)
x <- gsub("_+", "_", x)
x <- gsub("(^_|_$)", "", x)
x <- make.unique(x, sep = "_")
colnames(tbl) <- x
tbl
}
|
cellplot <- function(x, y, name=NULL, vp=NULL, clip = TRUE, e) {
pushViewport(viewport(layout.pos.row=x, layout.pos.col=y, name=name, clip=clip))
n <- 1
if (!is.null(vp)){
pushViewport(vp)
n <- n + 1
}
v <- current.viewport()
x <- e
upViewport(n=n)
gTree(children=gList(x), vp=v, name=name)
}
|
cut_number <- function(x, n = NULL, ...) {
brk <- breaks(x, "n", n)
if (anyDuplicated(brk)) {
stop("Insufficient data values to produce ", n, " bins.",
call. = FALSE
)
}
cut(x, brk, include.lowest = TRUE, ...)
}
breaks <- function(x, equal, nbins = NULL, binwidth = NULL) {
equal <- match.arg(equal, c("numbers", "width"))
if ((!is.null(nbins) && !is.null(binwidth)) || (is.null(nbins) &&
is.null(binwidth))) {
stop("Specify exactly one of n and width")
}
rng <- range(x, na.rm = TRUE, finite = TRUE)
if (equal == "width") {
if (!is.null(binwidth)) {
fullseq(rng, binwidth)
}
else {
seq(rng[1], rng[2], length.out = nbins + 1)
}
}
else {
if (!is.null(binwidth)) {
probs <- seq(0, 1, by = binwidth)
}
else {
probs <- seq(0, 1, length.out = nbins + 1)
}
stats::quantile(x, probs, na.rm = TRUE)
}
}
fullseq <- function(range, size, ..., pad = FALSE) {
if (zero_range(range)) {
return(range + size * c(-1, 1) / 2)
}
x <- seq(
round_any(range[1], size, floor),
round_any(range[2], size, ceiling),
by = size
)
if (pad) {
c(min(x) - size, x, max(x) + size)
}
else {
x
}
}
zero_range <- function(x, tol = 1000 * .Machine$double.eps) {
if (length(x) == 1) {
return(TRUE)
}
if (length(x) != 2) {
stop("x must be length 1 or 2")
}
if (any(is.na(x))) {
return(NA)
}
if (x[1] == x[2]) {
return(TRUE)
}
if (all(is.infinite(x))) {
return(FALSE)
}
m <- min(abs(x))
if (m == 0) {
return(FALSE)
}
abs((x[1] - x[2]) / m) < tol
}
|
squash_hal_fit <- function(object) {
assertthat::assert_that(is(object, "hal9001"))
nz_coefs <- which(as.vector(object$coefs)[-1] != 0)
new_coefs <- object$coefs[c(1, nz_coefs + 1)]
nz_basis_groups <- object$copy_map[nz_coefs]
all_nz_basis_index <- sort(unlist(nz_basis_groups))
new_basis <- object$basis_list[all_nz_basis_index]
new_copy_map <- lapply(nz_basis_groups, match, all_nz_basis_index)
new_keys <- sapply(new_copy_map, `[[`, 1)
names(new_copy_map) <- new_keys
fit <- list(
basis_list = new_basis,
copy_map = new_copy_map,
coefs = as.matrix(new_coefs),
times = object$times,
lambda_star = object$lambda_star,
prediction_bounds = object$prediction_bounds,
family = object$family,
unpenalized_covariates = object$unpenalized_covariates,
p_reserve = object$p_reserve
)
class(fit) <- "hal9001"
return(fit)
}
|
kuiper.2samp<-function(x,y)
{
x<-x[!is.na(x)]
nx<-length(x)
if(nx<1)
stop("Not enough 'x' data")
pval<-NULL
y<-y[!is.na(y)]
ny<-length(y)
if(ny<1)
stop("Not Enough'y' data")
r<-rank(c(x,y),ties.method="min")
c<-c(x,y)
csort<-sort(c)
c.min<-min(c(x,y))
c.max<-max(c(x,y))
x1<-rbind(sort(x),seq(1/nx,1,by=1/nx))
y1<-rbind(sort(y),seq(1/ny,1,by=1/ny))
temp<-matrix(0,2,nx+ny)
for (i in (1:(nx+ny))){
temp[1,i]<-ifelse(sum(csort[i]==sort(x))>0,x1[2,which.max(csort[i]==sort(x))],max(temp[1,1:i]))
temp[2,i]<-ifelse(sum(csort[i]==sort(y))>0,y1[2,which.max(csort[i]==sort(y))],max(temp[2,1:i]))
}
kp<-abs(max(temp[1,]-temp[2,]))+abs(max(temp[2,]-temp[1,]))
n<-nx*ny/(nx+ny)
if (kp<0|kp>2){
stop("The test statistic much be in the range of (0,2) by definition of the Kuiper Test")
} else if (kp<2/n){
PVAL<-1-factorial(n)*(kp-1/n)^(n-1)
} else if (kp<3/n){
k<--(n*kp-1)/2
r<-sqrt(k^2-(n*kp-2)/2)
a<--k+r
b<--k-r
PVAL<-1-factorial(n-1)*(b^(n-1)*(1-a)-a^(n-1)*(1-b))/(n^(n-2)*(b-a))
} else if ((kp>0.5&&n%%2==0)|(kp>(n-1)/(2*n)&&n%%2==1)){
temp<-as.integer(floor(n*(1-kp)))+1
c<-matrix(0,ncol=1,nrow=temp)
for (t in 0:temp){
y<-kp+t/n
tt<-y^(t-3)*(y^3*n-y^2*t*(3-2/n)/n-t*(t-1)*(t-2)/n^2)
p_temp<-choose(n,t)*(1-kp-t/n)^(n-t-1)*tt
c[t]<-p_temp
}
PVAL<-sum(c)
} else {
z<-kp*sqrt(n)
s1<-0
term<-1e-12
abs<-1e-100
for (m in 1:1e+08){
t1<-2*(4*m^2*z^2-1)*exp(-2*m^2*z^2)
s<-s1
s1<-s1+t1
if ((abs(s1-s)/(abs(s1)+abs(s))<term)|(abs(s1-s)<abs)) break
}
s2<-0
for (m in 1:1e+08){
t2<-m^2*(4*m^2*z^2-3)*exp(-2*m^2*z^2)
s<-s2
s2<-s2+t2
if ((abs(s2-s)/(abs(s2)+abs(s)))<term|(abs(s1-s)<abs)) break
PVAL<-s1-8*kp/(3*sqrt(n))*s2
}
}
output<-list(Kuiper.statistic=kp, p.value=PVAL)
return(output)
}
|
miRNA_removeOutliers <- function(inputDataset, qualityThresholdFrame) {
if (!(("Subject" %in% colnames(inputDataset)) & ("miRNA" %in% colnames(inputDataset)) & ("Mean" %in% colnames(inputDataset)) & ("StdDev" %in% colnames(inputDataset)) & ("SampleSize" %in% colnames(inputDataset)))) {
stop("ERROR: unsuitable dataset format. Dataset must contain columns 'Subject', 'miRNA', 'Mean', 'StdDev', 'SampleSize'.\n")
}
if (!(("miRNA" %in% colnames(qualityThresholdFrame)) & ("QualityThreshold" %in% colnames(qualityThresholdFrame)))) {
stop("ERROR: unsuitable qualityThresholdFrame format. Data frame must contain columns 'miRNA', 'QualityThreshold'.\n")
}
if (length(inputDataset[1,]) > 7) {
warning("WARNING: more than 7 dataset columns. Columns other than 'Subject', 'miRNA', 'Mean', 'StdDev', 'SampleSize', 'Class' will not be present in output.\n")
}
if ("Class" %in% colnames(inputDataset)) {
selectedDataset <- subset(inputDataset, select=c("Subject", "miRNA", "Mean", "StdDev", "SampleSize", "Class"))
} else {
selectedDataset <- subset(inputDataset, select=c("Subject", "miRNA", "Mean", "StdDev", "SampleSize"))
}
setOfFeatures <- unique(qualityThresholdFrame$miRNA)
setOfFeatures <- setOfFeatures[order(setOfFeatures)]
selectedDataset <- selectedDataset[selectedDataset$miRNA %in% setOfFeatures, ]
for(i in seq (1,nrow(qualityThresholdFrame))) {
feature <- qualityThresholdFrame$miRNA[i]
sigmaLimit <- as.numeric(as.vector(qualityThresholdFrame$QualityThreshold[i]))
selectedDataset <- selectedDataset[!(selectedDataset$miRNA == feature & selectedDataset$StdDev > sigmaLimit),]
}
return(selectedDataset)
}
|
expected <- eval(parse(text="TRUE"));
test(id=0, code={
argv <- eval(parse(text="list(structure(c(3+2i, 3+2i, NA, 3+2i, 3+2i, 3+2i, 3+2i, 3+2i, 4-5i, 3-5i, NA, NA, 2-5i, 3-5i, 4-5i, 5-5i), .Dim = c(8L, 2L), .Dimnames = list(NULL, c(\"x1\", \"x2\"))))"));
do.call(`is.array`, argv);
}, o=expected);
|
fab_button <- function(...,
position = c("bottom-right", "top-right", "bottom-left", "top-left", "none"),
animation = c("slidein", "slidein-spring", "fountain", "zoomin"),
toggle = c("hover", "click"),
inputId = NULL,
label = NULL) {
args <- list(...)
if (!is.null(args$status)) {
warning("fab_button: status argument is deprecated.", call. = FALSE)
args$status <- NULL
}
if (!is.null(args$icon)) {
warning("fab_button: icon argument is deprecated.", call. = FALSE)
args$icon <- NULL
}
toggle <- match.arg(toggle)
animation <- match.arg(animation)
position <- match.arg(position)
if (position == "none") return(NULL)
position <- switch(
position,
"bottom-right" = "br",
"top-right" = "tr",
"bottom-left" = "bl",
"top-left" = "tl"
)
tagList(
tags$ul(
class = paste("mfb-component", position, sep = "--"),
class = paste("mfb", animation, sep = "-"),
`data-mfb-toggle` = toggle,
tags$li(
class = "mfb-component__wrap",
tags$a(
id = inputId,
`data-mfb-label` = label,
class = "mfb-component__button--main action-button",
icon("plus", class = "mfb-component__main-icon--resting"),
icon("close", class = "mfb-component__main-icon--active")
),
tags$ul(
class = "mfb-component__list",
lapply(
X = args,
FUN = function(x) {
if (inherits(x, "list")) {
id <- x$inputId
label <- x$label
tagIcon <- x$icon
} else if (inherits(x, "shiny.tag")) {
id <- x$attribs$id
label <- x$children[[1]][[2]]
tagIcon <- x$children[[1]][[1]]
} else {
stop("Arguments in `...` must be lists or actionButtons")
}
if (!is.null(tagIcon) && inherits(tagIcon, "shiny.tag")) {
tagIcon <- htmltools::tagAppendAttributes(
tagIcon,
class = "mfb-component__child-icon"
)
}
tags$li(
tags$a(
`data-mfb-label` = label,
id = id,
class = "mfb-component__button--child action-button",
tagIcon
)
)
}
)
)
)
),
html_dependency_fab()
)
}
html_dependency_fab <- function() {
htmlDependency(
name = "fab-button",
version = "0.3.7",
src = c(
href = "shinymanager/fab-button",
file = "assets/fab-button"
),
package = "shinymanager",
stylesheet = "fab-button.min.css",
all_files = FALSE
)
}
|
"store.atom" <-
function(pdb=NULL) {
atom.names <- c("N", "CA", "C", "O", "CB", "*G", "*G1", "*G2",
"*D", "*D1", "*D2", "*E", "*E1", "*E2", "*E3", "*Z",
"*Z1", "*Z2", "*Z3", "*H", "*H1", "*H2")
atom.greek <- c("N", "CA", "C", "O", "CB", "G", "G1", "G2",
"D", "D1", "D2", "E", "E1", "E2", "E3", "Z",
"Z1", "Z2", "Z3", "H", "H1", "H2")
if(is.null(pdb)) return(atom.names)
colpaste <- function(x, col.names = colnames(x)) {
apply(x, 1, function(row) paste(row[col.names], collapse = "."))
}
getinds <- function(atoms, ref = atom.names) {
sort(atom2xyz(charmatch(atoms, ref)))
}
repadd <- function(num, nrep = nres, toadd = nxyz) {
c(num, rep(num, (nrep - 1)) + rep(cumsum(rep(toadd, (nrep - 1))), each = length(num)))
}
atom.data <- colpaste(pdb$atom, c("elety", "resno", "insert", "chain"))
atom.list <- matrix(unlist(strsplit(atom.data, "\\.")), ncol = 4, byrow = TRUE)
res.data <- colpaste(pdb$atom, c("resno", "insert", "chain"))
res.list <- unique(res.data)
coords <- NULL
blank <- matrix(NA, nrow = ncol(pdb$atom), ncol = length(atom.names))
for (i in 1:length(res.list)) {
res.blank <- blank
res.ind <- which(res.list[i] == res.data)
blank.ind <- charmatch(atom.list[res.ind, 1], atom.names,
nomatch = 0) + charmatch(substr(atom.list[res.ind,1], 2, 4),
atom.greek, nomatch = 0)
res.blank[, blank.ind[blank.ind != 0]] <-
t( pdb$atom[(res.ind[blank.ind != 0]),] )
coords <- cbind(coords, res.blank)
}
natm <- length(atom.names)
nxyz <- ncol(pdb$atom) * natm
nres <- length(coords)/(nxyz)
dim(coords) <- c(ncol(pdb$atom), natm, nres)
dimnames(coords) = list(atom = colnames(pdb$atom), type = atom.names,
res = res.list)
return(coords)
}
|
linearDL = function(X, nrun, burn, thin = 1, prop = 1, epsilon = 1e-3,
k = NULL, output = c("covMean", "covSamples",
"factSamples", "sigSamples"),
verbose = TRUE, dump = FALSE, filename = "samps.Rds",
buffer = 10000, augment = NULL){
if(nrun <= burn) stop("nrun must be larger than burn")
if(!is.matrix(X)) stop("X must be a matrix")
if(any(is.na(X))) stop("X cannot contain missing data")
if(!is.null(augment)) if(!is.expression(augment)) stop("augment must be an expression (see expression())")
cm = any(output %in% "covMean")
cs = any(output %in% "covSamples")
fs = any(output %in% "factSamples")
ss = any(output %in% "sigSamples")
nf = any(output %in% "numFactors")
p = ncol(X)
n = nrow(X)
a = 1/2
as = 1
bs = 0.3
if(is.null(k)) k = floor(log(p)*3)
sp = floor((nrun - burn)/thin)
VY= apply(X, 2, var)
scaleMat = sqrt((VY) %*% t(VY))
X = scale(X)
ps = rgamma(p,as,bs)
lambda = matrix(0,p,k)
eta = matrix(rnorm(n*k),n,k)
tau = rgamma(p,p*a,1/2)
psi = matrix(rexp(p*k,1/2),p,k)
phi = matrix(0,p,k)
for(j in 1:p){
gam = rgamma(k, a)
phi[j,] = gam /sum(gam)
}
Plam = phi*(phi^2)*matrix(rep(tau^2,k),p,k,byrow=F)
if(cm) COVMEAN = matrix(0, nrow = p, ncol = p)
if(cs) OMEGA = array(dim = c(p, p, sp))
if(fs) {LAMBDA = list()
ETA = list()}
if(ss) SIGMA = array(dim = c(p, sp))
if(nf) K = rep(NA, sp)
ind = 1
at = ceiling(nrun/100)
if(verbose) {
pb = txtProgressBar(style = 3)
}
for(i in 1:nrun){
eta = eta_lin(lambda, ps, k, n, X)
Plam = plm_dl(psi, phi, tau)
lambda = lam_lin(eta, Plam, ps, k, p, X)
psi = psi_dl(lambda, phi, tau)
tau = tau_dl(lambda, phi, k, p)
phi = phi_dl(lambda, a, k, p)
ps = sig_lin(lambda, eta, k, p, n, X, as, bs)
if(!is.null(augment)) eval(augment)
if((i %% thin == 0) & (i > burn)) {
if(cm | cs) Omega = (tcrossprod(lambda) + diag(1/c(ps))) * scaleMat
if(cm) COVMEAN = COVMEAN + Omega / sp
if(cs) OMEGA[,,ind] = Omega
if(fs) {LAMBDA[[ind]] = lambda
ETA[[ind]] = eta}
if(ss) SIGMA[,ind] = 1/ps
if(nf) K[ind] = k
ind = ind + 1
}
if(verbose & (i %% at == 0)) setTxtProgressBar(pb, i / nrun)
if(dump & (i %% buffer == 0)){
out = list()
if(cm) out = c(out, list(covMean = COVMEAN))
if(cs) out = c(out, list(omegaSamps = OMEGA))
if(fs) out = c(out, list(lambdaSamps = LAMBDA, etaSamps = ETA))
if(ss) out = c(out, list(sigmaSamps = SIGMA))
if(nf) out = c(out, list(numFacts = K))
saveRDS(out, filename, compress = FALSE)
}
}
if(verbose) close(pb)
out = list()
if(cm) out = c(out, list(covMean = COVMEAN))
if(cs) out = c(out, list(omegaSamps = OMEGA))
if(fs) out = c(out, list(lambdaSamps = LAMBDA, etaSamps = ETA))
if(ss) out = c(out, list(sigmaSamps = SIGMA))
if(nf) out = c(out, list(numFacts = K))
return(out)
}
|
Selectivity <-
function (Ra, Rb, Rf = 0, ...)
{
Period = Frequency(Ra)
CAPM.jensenAlpha(Ra,Rb,Rf,Period)
}
|
SeriesAggreg.list <- function(x,
Format,
ConvertFun,
NewTimeFormat = NULL,
simplify = FALSE,
except = NULL,
recursive = TRUE,
...) {
classIni <- class(x)
class(x) <- "list"
if (missing(Format)) {
Format <- .GetSeriesAggregFormat(NewTimeFormat)
} else if (!is.null(NewTimeFormat)) {
warning("deprecated 'NewTimeFormat' argument: 'Format' argument is used instead",
call. = FALSE)
}
if (any(classIni %in% c("InputsModel", "OutputsModel"))) {
if (!all(is.na(ConvertFun))) {
warning("Argument 'ConvertFun' is ignored on 'InputsModel' and 'OutputsModel' objects")
}
} else if (length(ConvertFun) != 1) {
stop("Argument 'ConvertFun' must be of length 1 with 'list' object")
} else if (!is.character(ConvertFun)) {
stop("Argument 'ConvertFun' must be a character")
}
if (!is.null(x$DatesR)) {
if (!inherits(x$DatesR, "POSIXt")) {
stop("'x$DatesR' should be of class 'POSIXt'")
}
DatesR <- x$DatesR
} else {
itemPOSIXt <- which(sapply(x, function(x) {
inherits(x, "POSIXt")
}, simplify = TRUE))[1]
if (is.na(itemPOSIXt)) {
stop("At least one item of argument 'x' should be of class 'POSIXt'")
}
warning("Item 'DatesR' not found in 'x' argument: the item ",
names(x)[itemPOSIXt],
" has been automatically chosen")
DatesR <- x[[names(x)[itemPOSIXt]]]
}
numericCols <- names(which(sapply(x, inherits, "numeric")))
arrayCols <- names(which(sapply(x, inherits, "array")))
numericCols <- setdiff(numericCols, arrayCols)
if (!is.null(except)) {
if (!inherits(except, "character")) {
stop("Argument 'except' should be a 'character'")
}
numericCols <- setdiff(numericCols, except)
}
cols <- x[numericCols]
lengthCols <- sapply(cols, length, simplify = TRUE)
if (any(lengthCols != length(DatesR))) {
sErr <- paste0(names(lengthCols)[lengthCols != length(DatesR)],
" (", lengthCols[lengthCols != length(DatesR)], ")",
collapse = ", ")
warning("The length of the following `numeric` items in 'x' ",
"is different than the length of 'DatesR (",
length(DatesR),
")': they will be ignored in the aggregation: ",
sErr)
cols <- cols[lengthCols == length(DatesR)]
}
dfOut <- NULL
if (length(cols)) {
if (is.na(ConvertFun)) {
ConvertFun2 <- .GetAggregConvertFun(names(cols), Format)
} else {
ConvertFun2 <- rep(ConvertFun, length(cols))
}
dfOut <- SeriesAggreg(cbind(DatesR, as.data.frame(cols)),
Format,
...,
ConvertFun = ConvertFun2)
}
if (simplify) {
return(dfOut)
} else {
res <- list()
if (!is.null(dfOut)) {
res <- as.list(dfOut)
res$DatesR <- as.POSIXlt(res$DatesR)
}
if (is.null(recursive) || recursive) {
listCols <- x[sapply(x, inherits, "list")]
dfCols <- x[sapply(x, inherits, "data.frame")]
dfCols <- c(dfCols, x[sapply(x, inherits, "matrix")])
listCols <- listCols[setdiff(names(listCols), names(dfCols))]
if (length(listCols) > 0) {
if (is.na(ConvertFun)) {
listConvertFun <- .GetAggregConvertFun(names(listCols), Format)
}
listRes <- lapply(names(listCols), function(y) {
listCols[[y]]$DatesR <- DatesR
if (is.na(ConvertFun)) {
SeriesAggreg.list(listCols[[y]],
Format = Format,
recursive = NULL,
...,
ConvertFun = listConvertFun[y])
} else {
SeriesAggreg.list(listCols[[y]],
Format = Format,
recursive = NULL,
...)
}
})
names(listRes) <- names(listCols)
if (is.null(res$DatesR)) {
res$DatesR <- listRes[[1]]$DatesR
}
lapply(names(listRes), function(x) {
listRes[[x]]$DatesR <<- NULL
})
res <- c(res, listRes)
}
if (length(dfCols) > 0) {
for (i in length(dfCols)) {
key <- names(dfCols)[i]
m <- dfCols[[i]]
if (nrow(m) != length(DatesR)) {
warning(
"The number of rows of the 'matrix' item ",
key, " (", nrow(m),
") is different than the length of 'DatesR ('", length(DatesR),
"), it will be ignored in the aggregation"
)
} else {
if (is.na(ConvertFun)) {
ConvertFun2 <- rep(.GetAggregConvertFun(key, Format), ncol(m))
} else {
ConvertFun2 <- rep(ConvertFun, ncol(m))
}
res[[key]] <- SeriesAggreg.data.frame(data.frame(DatesR, m),
Format = Format,
ConvertFun = ConvertFun2)
}
}
}
}
res <- c(res, x[setdiff(names(x), names(res))])
class(res) <- gsub("hourly|daily|monthly|yearly",
.GetSeriesAggregClass(Format),
classIni)
return(res)
}
}
|
context("RJournal")
stopwords.en <- c("a", "about", "above", "across", "after", "again",
"against", "all", "almost", "alone", "along", "already", "also",
"although", "always", "am", "among", "an", "and", "another",
"any", "anybody", "anyone", "anything", "anywhere", "are", "area",
"areas", "aren't", "around", "as", "ask", "asked", "asking",
"asks", "at", "away", "b", "back", "backed", "backing", "backs",
"be", "became", "because", "become", "becomes", "been", "before",
"began", "behind", "being", "beings", "below", "best", "better",
"between", "big", "both", "but", "by", "c", "came", "can", "can't",
"cannot", "case", "cases", "certain", "certainly", "clear", "clearly",
"come", "could", "couldn't", "d", "did", "didn't", "differ",
"different", "differently", "do", "does", "doesn't", "doing",
"don't", "done", "down", "downed", "downing", "downs", "during",
"e", "each", "early", "either", "end", "ended", "ending", "ends",
"enough", "even", "evenly", "ever", "every", "everybody", "everyone",
"everything", "everywhere", "f", "face", "faces", "fact", "facts",
"far", "felt", "few", "find", "finds", "first", "for", "four",
"from", "full", "fully", "further", "furthered", "furthering",
"furthers", "g", "gave", "general", "generally", "get", "gets",
"give", "given", "gives", "go", "going", "good", "goods", "got",
"great", "greater", "greatest", "group", "grouped", "grouping",
"groups", "h", "had", "hadn't", "has", "hasn't", "have", "haven't",
"having", "he", "he'd", "he'll", "he's", "her", "here", "here's",
"hers", "herself", "high", "higher", "highest", "him", "himself",
"his", "how", "how's", "however", "i", "i'd", "i'll", "i'm",
"i've", "if", "important", "in", "interest", "interested", "interesting",
"interests", "into", "is", "isn't", "it", "it's", "its", "itself",
"j", "just", "k", "keep", "keeps", "kind", "knew", "know", "known",
"knows", "l", "large", "largely", "last", "later", "latest",
"least", "less", "let", "let's", "lets", "like", "likely", "long",
"longer", "longest", "m", "made", "make", "making", "man", "many",
"may", "me", "member", "members", "men", "might", "more", "most",
"mostly", "mr", "mrs", "much", "must", "mustn't", "my", "myself",
"n", "necessary", "need", "needed", "needing", "needs", "never",
"new", "newer", "newest", "next", "no", "nobody", "non", "noone",
"nor", "not", "nothing", "now", "nowhere", "number", "numbers",
"o", "of", "off", "often", "old", "older", "oldest", "on", "once",
"one", "only", "open", "opened", "opening", "opens", "or", "order",
"ordered", "ordering", "orders", "other", "others", "ought",
"our", "ours", "ourselves", "out", "over", "own", "p", "part",
"parted", "parting", "parts", "per", "perhaps", "place", "places",
"point", "pointed", "pointing", "points", "possible", "present",
"presented", "presenting", "presents", "problem", "problems",
"put", "puts", "q", "quite", "r", "rather", "really", "right",
"room", "rooms", "s", "said", "same", "saw", "say", "says", "second",
"seconds", "see", "seem", "seemed", "seeming", "seems", "sees",
"several", "shall", "shan't", "she", "she'd", "she'll", "she's",
"should", "shouldn't", "show", "showed", "showing", "shows",
"side", "sides", "since", "small", "smaller", "smallest", "so",
"some", "somebody", "someone", "something", "somewhere", "state",
"states", "still", "such", "sure", "t", "take", "taken", "than",
"that", "that's", "the", "their", "theirs", "them", "themselves",
"then", "there", "there's", "therefore", "these", "they", "they'd",
"they'll", "they're", "they've", "thing", "things", "think",
"thinks", "this", "those", "though", "thought", "thoughts", "three",
"through", "thus", "to", "today", "together", "too", "took",
"toward", "turn", "turned", "turning", "turns", "two", "u", "under",
"until", "up", "upon", "us", "use", "used", "uses", "v", "very",
"w", "want", "wanted", "wanting", "wants", "was", "wasn't", "way",
"ways", "we", "we'd", "we'll", "we're", "we've", "well", "wells",
"went", "were", "weren't", "what", "what's", "when", "when's",
"where", "where's", "whether", "which", "while", "who", "who's",
"whole", "whom", "whose", "why", "why's", "will", "with", "within",
"without", "won't", "work", "worked", "working", "works", "would",
"wouldn't", "x", "y", "year", "years", "yes", "yet", "you", "you'd",
"you'll", "you're", "you've", "young", "younger", "youngest",
"your", "yours", "yourself", "yourselves", "z")
library(R.temis)
corpus <- import_corpus(system.file("texts", "reut21578-factiva.xml", package="tm.plugin.factiva"),
"factiva", language="en")
test_that("importation works", {
expect_equal(length(corpus), 19)
})
dtm <- build_dtm(corpus)
dict <- dictionary(dtm)
dict <- dict[!rownames(dict) %in% stopwords.en,]
dtm2 <- combine_terms(dtm, dict)
test_that("dtm works", {
expect_equal(nrow(dtm), 19)
expect_equal(nrow(dtm2), 19)
expect_equal(ncol(dtm), 1032)
expect_equal(ncol(dtm2), 705)
})
specTerms <- specific_terms(dtm2, meta(corpus)[["Date"]], p=0.1, min_occ=5, n=10)
test_that("specific terms match Table 1", {
expect_equal(round(c(specTerms[[1]]), 4),
c(2.0101, 1.2563, 1.5075, 1.7588, 1.005, 1.2563, 2.5126, 1.7588,
NA, 0, 0, 66.6667, 71.4286, 60, 50, 66.6667, 55.5556, 38.4615,
43.75, NA, 0, 0, 0.5794, 0.338, 0.4829, 0.676, 0.2897, 0.4346,
1.2554, 0.7726, NA, 0.9174, 1.0623, 8, 5, 6, 7, 4, 5, 10, 7,
NA, 0, 0, 12, 7, 10, 14, 6, 9, 26, 16, NA, 19, 22, 3.3408,
2.6673, 2.5714, 2.3631, 2.1825, 2.1365, 2.1162, 2.0293, NA,
-2.1201, -2.3698, 0.0004, 0.0038, 0.0051, 0.0091, 0.0145, 0.0163,
0.0172, 0.0212, NA, 0.017, 0.0089),
check.attributes=FALSE)
})
ca <- corpus_ca(corpus, dtm2, sparsity=0.94)
test_that("CA matches text and Figure 4", {
expect_equal(nrow(ca$row$coord), length(corpus))
expect_equal(nrow(ca$col$coord), 239)
expect_equal(head(rownames(ca$col$coord)[order(ca$col$contrib[,1], decreasing=TRUE)], 12),
c("post", "grade", "crude", "west", "bbl", "texa", "bring", "sweet",
"dlrs", "texaco", "compani", "effect"))
})
|
backLog<-function(x){1/(1+(exp(-x)))}
|
visr <- function(x, ...){
UseMethod("visr", x)
}
visr.default <- function(x, ...){
base::plot(x)
}
visr.survfit <- function(
x = NULL
,x_label = NULL
,y_label = NULL
,x_units = NULL
,x_ticks = NULL
,y_ticks = NULL
,fun = "surv"
,legend_position = "right"
,...
){
if (!("survfit" %in% class(x))) {
stop("Can only be used with `survfit` objects.")
}
if (!(is.null(x_label) | is.character(x_label) | is.expression(x_label))) {
stop("Invalid `x_label` argument, must be either `character` or `expression`.")
}
if (!(is.null(y_label) | is.character(y_label) | is.expression(y_label))) {
stop("Invalid `y_label` argument, must be either `character` or `expression`.")
}
if (!(is.null(x_units) | is.character(x_units))) {
stop("Invalid `x_units` argument, must be `character`.")
}
if (!(is.null(x_ticks) | is.numeric(x_ticks))) {
stop("Invalid `x_ticks` argument, must be `numeric`.")
}
if (!(is.null(y_ticks) | is.numeric(y_ticks))) {
stop("Invalid `y_ticks` argument, must be `numeric`.")
}
if (is.character(legend_position) &&
!legend_position %in% c("top", "bottom", "right", "left", "none")) {
stop(
"Invalid legend position given. Must either be [\"top\", \"bottom\", \"right\", \"left\", \"none\"] or a vector with two numbers indicating the position relative to the axis. For example c(0.5, 0.5) to place the legend in the center of the plot."
)
} else if (is.numeric(legend_position) &&
length(legend_position) != 2) {
stop(
"Invalid legend position given. Must either be [\"top\", \"bottom\", \"right\", \"left\", \"none\"] or a vector with two numbers indicating the position relative to the axis. For example c(0.5, 0.5) to place the legend in the center of the plot."
)
}
valid_funs <- c("surv", "log", "event", "cloglog", "pct", "logpct", "cumhaz")
if (is.character(fun)) {
if (!(fun %in% valid_funs)) {
stop(
"Unrecognized `fun` argument, must be one of [\"surv\", \"log\", \"event\", \"cloglog\", \"pct\", \"logpct\", \"cumhaz\"] or a user-defined function."
)
}
}
if (is.null(y_label) & is.character(fun)) {
y_label <- base::switch(
fun,
surv = "survival probability",
log = "log(survival probability)",
event = "failure probability",
cloglog = "log(-log(survival probability))",
pct = "percentage survival",
logpct = "log(percentage survival)",
cumhaz = "cumulative hazard",
stop("Unrecognized fun argument")
)
} else if (is.null(y_label) & is.function(fun)) {
stop("No Y label defined. No default label is available when `fun` is a function.")
}
if (is.character(fun)) {
.transfun <- base::switch(
fun,
surv = function(y) y,
log = function(y) log(y),
event = function(y) 1 - y,
cloglog = function(y) log(-log(y)),
pct = function(y) y * 100,
logpct = function(y) log(y * 100),
cumhaz = function(y) -log(y)
)
} else if (is.function(fun)) {
.transfun <- function(y) fun(y)
} else {
stop("fun should be a character or a user-defined function.")
}
correctme <- NULL
tidy_object <- tidyme(x)
if ("estimate" %in% colnames(tidy_object)) {
tidy_object[["est"]] <- .transfun(tidy_object[["estimate"]])
correctme <- c(correctme, "est")
}
if (all(c("conf.high", "conf.low") %in% colnames(tidy_object))) {
tidy_object[["est.upper"]] <- .transfun(tidy_object[["conf.high"]])
tidy_object[["est.lower"]] <- .transfun(tidy_object[["conf.low"]])
correctme <- c(correctme, "est.lower", "est.upper")
}
if (nrow(tidy_object[tidy_object[["est"]] == "-Inf",]) > 0) {
warning("NAs introduced by y-axis transformation.")
}
tidy_object[ , correctme] <- sapply(tidy_object[, correctme],
FUN = function(x) {
x[which(x == -Inf)] <- min(x[which(x != -Inf)], na.rm = TRUE)
return(x)
}
)
ymin = min(sapply(tidy_object[, correctme], function(x) min(x[which(x != -Inf)], na.rm = TRUE)), na.rm = TRUE)
ymax = max(sapply(tidy_object[, correctme], function(x) max(x[which(x != -Inf)], na.rm = TRUE)), na.rm = TRUE)
if (is.null(x_label)) {
if ("PARAM" %in% names(x)) {
if (length(unique(x[["PARAM"]])) == 1) {
x_label <- as.character(x[["PARAM"]][[1]])
} else {
warning("More than one unique entry in 'PARAM'.")
}
} else if ("PARAMCD" %in% names(x)) {
if (length(unique(x[["PARAMCD"]])) == 1) {
x_label <- as.character(x[["PARAMCD"]][[1]])
} else {
warning("More than one unique entry in 'PARAMCD'.")
}
} else {
warning("The x-axis label was not specified and could also not be automatically determined due to absence of 'PARAM' and 'PARAMCD'.")
x_label <- "Time"
}
if (!is.null(x_units)) { x_label = paste0(x_label, " (", x_units, ")") }
} else {
if (!is.null(x_units)) { x_label = paste0(x_label, " (", x_units, ")") }
}
if (is.null(x_ticks)) x_ticks = pretty(x$time, 10)
if (is.null(y_ticks) & is.character(fun)) {
y_ticks <- switch(
fun,
surv = pretty(c(0, 1), 5),
log = pretty(c(ymin, ymax), 5),
event = pretty(c(0, 1), 5),
cloglog = pretty(c(ymin, ymax), 5),
pct = pretty(c(0, 100), 5),
logpct = pretty(c(0, 5), 5),
cumhaz = pretty(c(ymin, ymax), 5),
stop("Unrecognized fun argument")
)
} else if (is.null(y_ticks) & is.function(fun)) {
y_ticks = pretty(c(ymin, ymax), 5)
}
yscaleFUN <- function(x) sprintf("%.2f", x)
gg <- ggplot2::ggplot(tidy_object, ggplot2::aes(x = time,
group = strata,
fill = strata)) +
ggplot2::geom_step(ggplot2::aes(y = est, col = strata)) +
ggplot2::scale_x_continuous(breaks = x_ticks,
limits = c(min(x_ticks), max(x_ticks))) +
ggplot2::xlab(x_label) +
ggplot2::scale_y_continuous(breaks = y_ticks,
labels = yscaleFUN,
limits = c(min(y_ticks), max(y_ticks))) +
ggplot2::ylab(y_label) +
ggplot2::theme(legend.position = legend_position) +
ggplot2::theme(legend.key = ggplot2::element_blank()) +
NULL
if (is.character(fun)) {
attr(gg, "fun") <- .transfun
} else {
fun_call <- utils::capture.output(fun)
if (grepl("rimitive", fun_call[1])) {
fun_call_fun <- regmatches(fun_call, regexpr("\".*\"", fun_call))
fun_call_fun <- gsub("\"", "", fun_call_fun)
fun_call_fun <- paste0("function(x) ", fun_call_fun, "(x)")
attr(gg, "fun") <- eval(parse(text = fun_call_fun))
} else if (is.function(fun)) {
attr(gg, "fun") <- fun
}
}
class(gg) <- append(class(gg), "ggsurvfit")
return(gg)
}
visr.attrition <- function(x,
description_column_name = "Criteria",
value_column_name = "Remaining N",
complement_column_name="",
box_width = 50,
font_size = 12,
fill="white",
border="black",
...){
if (!description_column_name %in% names(x)) {
stop(paste0("Column \"", description_column_name, "\" cannot be found in the input data. ",
"Please provide the column name as string in the input ",
"data containing the inclusion descriptions."))
}
if (!value_column_name %in% names(x)) {
stop(paste0("Column \"", value_column_name, "\" cannot be found in the input data. ",
"Please provide the column name as string in the input data containing",
"the sample size after applying inclusion criteria."))
}
if (complement_column_name != "" & !complement_column_name %in% names(x)) {
stop(paste0("Column \"", complement_column_name, "\" cannot be found in the input data. ",
"Please provide a valid column name as string in the input data containing",
"complement description or omit this argument for default labels."))
}
if (!is.numeric(box_width)) {
warning("An invalid input was given for `box_width`, must be `numeric` value. Setting it to 50.")
box_width <- 50
}
if (!is.numeric(font_size)) {
warning("An invalid input was given for `font_size`, must be `numeric` value. Setting it to 12.")
font_size <- 12
}
if (!is.character(fill)) {
warning("An invalid input was given for `fill`, must be `character` string. Setting it to \"white\".")
fill <- "white"
}
if (!is.character(border)) {
warning("An invalid input was given for `border`, must be `character` string. Setting it to \"black\".")
border <- "black"
}
label <- complement_label <- NULL
y <- down_ystart <- down_yend <- side_xstart <- side_xend <- side_y <- NULL
cx <- cy <- NULL
field_height <- 100/nrow(x)
box_height <- 0.75 * field_height
plotting_data <- x %>%
.get_labels(description_column_name, value_column_name, complement_column_name, wrap_width = box_width) %>%
.get_labelsizes(label, complement_label) %>%
.get_coordinates(box_width, box_height, field_height)
gg <- plotting_data %>%
ggplot2::ggplot() +
ggplot2::geom_tile(data=plotting_data, ggplot2::aes(x = x,
y = y,
width=box_width,
height=box_height),
color=border, fill=fill) +
ggplot2::geom_text(data=plotting_data, ggplot2::aes(x = x,
y = y,
label = label),
size = font_size / ggplot2::.pt) +
ggplot2::geom_segment(data=plotting_data, ggplot2::aes(x=x,
xend=x,
y=down_ystart,
yend=down_yend),
arrow = ggplot2::arrow(length = 0.5 * ggplot2::unit(font_size, "pt")),
size = .2,
na.rm=TRUE) +
ggplot2::geom_segment(data=plotting_data, ggplot2::aes(x=side_xstart,
xend=side_xend,
y=side_y,
yend=side_y),
arrow = ggplot2::arrow(length = 0.5 * ggplot2::unit(font_size, "pt")),
size = .2,
na.rm=TRUE) +
ggplot2::geom_tile(data=plotting_data, ggplot2::aes(x = cx,
y = cy,
width=box_width,
height=box_height),
color=border, fill=fill,
na.rm=TRUE) +
ggplot2::geom_text(data=plotting_data, ggplot2::aes(x = cx,
y = cy,
label = complement_label),
size = font_size / ggplot2::.pt,
na.rm=TRUE) +
ggplot2::theme_void() +
ggplot2::theme(legend.position = "none")
return(gg)
}
visr.tidycuminc <- function(x = NULL
,x_label = "Time"
,y_label = "Cumulative Incidence"
,x_units = NULL
,x_ticks = pretty(x$tidy$time, 10)
,y_ticks = pretty(c(0, 1), 5)
,legend_position = "right"
,...){
if (!is.null(x_units)) {
x_label <- paste0(x_label, " (", x_units, ")")
}
yscaleFUN <- function(x) sprintf("%.2f", x)
gg <-
visr_tidy_tidycuminc(x) %>%
ggplot2::ggplot(ggplot2::aes(x = time,
group = strata,
fill = strata)) +
ggplot2::geom_step(ggplot2::aes(y = est, col = strata)) +
ggplot2::scale_x_continuous(breaks = x_ticks,
limits = c(min(x_ticks), max(x_ticks))) +
ggplot2::xlab(x_label) +
ggplot2::scale_y_continuous(breaks = y_ticks,
labels = yscaleFUN,
limits = c(min(y_ticks), max(y_ticks))) +
ggplot2::ylab(y_label) +
ggplot2::theme(legend.position = legend_position) +
ggplot2::theme(legend.key = ggplot2::element_blank()) +
NULL
class(gg) <- append(class(gg), "ggtidycuminc")
attr(gg, "tidycuminc") <- x
gg
}
|
test_that("as.Distribution errors when expected", {
mat <- matrix(rep(0.1, 200), 20, 10)
expect_error(as.Distribution(mat), "'obj' must have")
colnames(mat) <- 1:10
expect_error(as.Distribution(mat, "surv"), "'fun' should be one of")
})
test_that("as.Distribution works with pdf expected", {
mat <- matrix(rep(0.1, 200), 20, 10)
colnames(mat) <- 1:10
wd <- as.Distribution(mat, fun = "pdf")
expect_R6_class(wd, "VectorDistribution")
expect_equal(unique(wd$modelTable$Distribution), "WeightedDiscrete")
expect_equal(
vapply(wd$getParameterValue("x"), identity, numeric(10)),
matrix(1:10, 10, 20, FALSE, list(NULL, paste0("WeightDisc", 1:20)))
)
expect_equal(
vapply(wd$getParameterValue("pdf"), identity, numeric(10)),
matrix(t(mat), 10, 20, FALSE, list(1:10, paste0("WeightDisc", 1:20)))
)
})
test_that("as.Distribution works with cdf expected", {
mat <- matrix(rep(0.1, 200), 20, 10)
colnames(mat) <- 1:10
mat <- t(apply(mat, 1, function(x) cumsum(x)))
wd <- as.Distribution(mat, fun = "cdf")
expect_R6_class(wd, "VectorDistribution")
expect_equal(unique(wd$modelTable$Distribution), "WeightedDiscrete")
expect_equal(
vapply(wd$getParameterValue("x"), identity, numeric(10)),
matrix(1:10, 10, 20, FALSE, list(NULL, paste0("WeightDisc", 1:20)))
)
expect_equal(
vapply(wd$getParameterValue("cdf"), identity, numeric(10)),
matrix(t(mat), 10, 20, FALSE, list(1:10, paste0("WeightDisc", 1:20)))
)
})
|
is.tridiagonal<-function(A){
n<-nrow(A)
R<-A[-n,-1]
L<-A[-1,-n]
all(R[upper.tri(R)]==0) & all(L[lower.tri(L)]==0)
}
|
"%w/o%" <- function(x, y) x[!x %in% y]
"%innc%" <- function(x, y) (tolower(x) %in% tolower(y))
"%==nc%" <- function(x, y) (tolower(x) == tolower(y))
|
"_PACKAGE"
`:=` = function(...) NULL
|
NULL
injector_X <- function(.switchboard, ...) {
switchboard_engine(.switchboard,
constructor = injector_X_construct(.switchboard, ...),
updater = injector_X_update(.switchboard, ...), ...)
}
injector_X_construct <- function(.switchboard,
label = " ",
inject = "",
minimum = " ",
maximum = " ",
switch = FALSE,
size = 1,
...) {
aCanvas <- tcltk::tkcanvas(.switchboard, width = 80 * size, height = 80 * size, background = switchboard.env$mainColors[2], borderwidth = 0, highlightthickness = 0)
tcltk::tkcreate(aCanvas, "line", 2, 5, 2, 80 * size - 2, 80 * size - 5, 80 * size - 2, width = 4, fill = switchboard.env$mainColors[4])
if(inject != "") {
if(as.integer(tcltk::tcl("info", "exists", inject)) == 1) tcltk::tcl("unset", inject)
tcltk::.Tcl(paste("set", inject, mget(inject, envir = parent.frame(n = 3), ifnotfound = NA)))
injectorScaleX <- tcltk::ttkscale(aCanvas, from = maximum, to = minimum, variable = inject, value = as.numeric(tcltk::tclvalue(inject)),
command = function(...){assign(inject, as.numeric(tcltk::tclvalue(inject)), envir = parent.frame(n = 5));})
tcltk::tkcreate(aCanvas, "window", 5, 80 * size + 8, width = 80 * size - 10, anchor = "sw", window = injectorScaleX)
}
tcltk::tkcreate(aCanvas, "text", 80 * size - 5, 80 * size - 4, text = label, anchor = "se", font = paste(switchboard.env$font, floor(9 * size / 1.2)), fill = switchboard.env$mainColors[3])
tcltk::tkcreate(aCanvas, "rectangle", -5, -5, -5, -5, width = 5, tags = "theMean", outline = switchboard.env$mainColors[3])
tcltk::tkcreate(aCanvas, "line", -5, -5, -5, -5, width = 2, tags = "theSD", fill = switchboard.env$mainColors[3])
tcltk::.Tcl(paste("set", paste0(aCanvas[1], "Switch"), 1))
if(switch == TRUE) {
tcltk::.Tcl(paste("set", paste0(aCanvas[1], "Switch"), 0))
stateSwitch <- tcltk::ttkcheckbutton(aCanvas, text = "", style = "MicroSwitch", variable = paste0(aCanvas[1], "Switch"))
tcltk::tkcreate(aCanvas, "window", 80 * size - 5, 5, anchor = "ne", window = stateSwitch)
}
return (aCanvas)
}
injector_X_update <- function(.switchboard,
eavesdrop = NULL,
minimum = " ",
maximum = " ",
size = 1,
updates = 1,
plotMean = FALSE,
...) {
if(switchboard.env$totalIterations %% updates == 0) {
aCanvas <- paste0(.switchboard$theSwitchboard, ".", .switchboard$theWidget)
if(as.numeric(tcltk::tclvalue(paste0(aCanvas, "Switch")))) {
theX <- value_to_coordinate(eavesdrop, minimum, maximum, size, c(-1, 5))
tcltk::.Tcl(paste("tcltk_injector_X_update", aCanvas, "movingPoint", size, theX, switchboard.env$rangeColors[floor(theX/size)]))
tcltk::.Tcl(paste("tcltk_plotMean_X", aCanvas, "theMean", "theSD", "movingPoint", size, plotMean))
}
}
}
|
get_setting_value <- function(df, method, value_column) {
return(
df[which(df[['method']] == method), ][[value_column]]
)
}
filler_df <- function(x, column_names) {
if (length(x) == 0) {
filler_df <- data.frame(row.names = 1)
for (col_name in column_names) {
filler_df[col_name] <- NA
}
return(filler_df)
} else return(x)
}
split_coords <- function(input) {
if (grepl(',', input, fixed = TRUE)) {
split <- as.list(unlist(strsplit(input, "," , fixed = TRUE)))
}
else split <- (list('', ''))
return(as.numeric(split))
}
get_na_value <- function(lat, long, rows = 1) {
NA_df <- tibble::tibble(a = rep(as.numeric(NA), rows), b = rep(as.numeric(NA), rows))
colnames(NA_df) <- c(lat, long)
return(NA_df)
}
rm_quote <- function(string) gsub("\"","", string)
get_seconds_elapsed <- function(t0) {
return(as.numeric(difftime(Sys.time(), t0, units = 'secs')))
}
print_time <- function(text, num_seconds) {
message(paste0(text, ': ', round(num_seconds, 1), ' seconds'))
}
pause_until <- function(start_time, min_time, debug = FALSE) {
seconds_elapsed <- get_seconds_elapsed(start_time)
if (debug == TRUE) print_time("Query completed in", seconds_elapsed)
if (seconds_elapsed < min_time) {
Sys.sleep(min_time - seconds_elapsed)
total_time_elapsed <- get_seconds_elapsed(start_time)
if (debug == TRUE) print_time("Total query time (including sleep)", total_time_elapsed)
}
}
format_address <- function(df, fields) {
frmt_df <- tibble::as_tibble(df)
col_order <- intersect(fields, names(frmt_df))
frmt_df <- dplyr::relocate(frmt_df[col_order], col_order)
frmt_char <- as.character(apply(frmt_df, 1, function(x) {
y <- unique(as.character(x))
y <- y[!y %in% c('', 'NA')]
paste0(y, collapse = ', ')
}))
frmt_char[frmt_char == 'NA'] <- NA
frmt_out <- tibble::tibble(formatted_address = frmt_char)
return(frmt_out)
}
check_api_options <- function(api_options, func_name) {
for (param in names(api_options)) {
if (!param %in% c('cascade_flag', "init", names(pkg.globals$default_api_options))) {
stop(paste0("Invalid parameter ", '"', param, '"', " used in the api_options argument. See ?", func_name), call. = FALSE)
}
}
}
check_address_argument_datatype <- function(arg, arg_name) {
if (!(is.null(arg) || is.character(arg) || is.numeric(arg) || is.na(arg) || is.factor(arg))) {
stop(paste0('Improper datatype for ', arg_name, '. See ?geo'), call. = FALSE)
}
}
check_verbose_quiet <- function(verbose, quiet, reverse) {
input_terms <- get_coord_address_terms(reverse)
if (quiet == TRUE && verbose == TRUE) {
stop(paste0("quiet and verbose cannot both be TRUE. See ?", input_terms$base_func_name))
}
}
check_method <- function(method, reverse, mode, batch_funcs, cascade_order = list()) {
input_terms <- get_coord_address_terms(reverse)
method_services <- unique(tidygeocoder::api_parameter_reference[['method']])
batch_methods <- names(batch_funcs)
single_input_methods <- if (reverse == FALSE) {
c('cascade', method_services)
} else {
method_services[!method_services %in% pkg.globals$no_reverse_methods]
}
if (reverse == FALSE) {
if (!(cascade_order[1] %in% method_services) || !(cascade_order[2] %in% method_services) || (length(cascade_order) != 2) || !(is.character(cascade_order))) {
stop('Invalid cascade_order argument. See ?geo', call. = FALSE)
}
if (method == 'cascade' && mode == 'batch' && (length(intersect(cascade_order, names(batch_funcs)) != 2))) {
stop("To use method = 'cascade' and mode = 'batch', both methods specified in cascade_order
must have batch geocoding capabilities. See ?geo", call. = FALSE)
}
}
if (mode == 'batch' && (!method %in% batch_methods)) {
stop(paste0('The "', method, '" method does not have a batch',
if (reverse == TRUE) " reverse" else "",
' geocoding function. See ?', input_terms$base_func_name) , call. = FALSE)
}
if (!(method %in% single_input_methods)) {
stop(paste0('Invalid method argument. See ?', input_terms$base_func_name), call. = FALSE)
}
}
check_common_args <- function(fun_name, mode, limit, batch_limit, min_time) {
if (!(mode %in% c('', 'single', 'batch'))) {
stop(paste0('Invalid mode argument. See ?', fun_name), call. = FALSE)
}
if (!(is.null(limit) || (is.numeric(limit) && limit >= 1))) {
stop(paste0('limit must be NULL or >= 1. See ?', fun_name), call. = FALSE)
}
if (!(is.null(batch_limit) || (is.numeric(batch_limit) && batch_limit >= 1))) {
stop(paste0('batch_limit must be NULL or >= 1. See ?', fun_name), call. = FALSE)
}
if (!(is.null(min_time) || (is.numeric(min_time) && min_time >= 0))) {
stop(paste0('min_time must be NULL or >= 0. See ?', fun_name), call. = FALSE)
}
}
check_limit_return_input <- function(limit, return_input) {
if ((is.null(limit) || limit != 1) && return_input == TRUE) {
stop('To use limit > 1 or limit = NULL, set return_input to FALSE.', call. = FALSE)
}
}
check_limit_for_batch <- function(limit, return_input, reverse) {
input_terms <- get_coord_address_terms(reverse)
if ((is.null(limit) || limit != 1) && return_input == TRUE) {
stop(paste0('For batch geocoding (more than one ', input_terms$input_singular,
' per query) the limit argument must
be 1 (the default) OR the ', input_terms$return_arg, ' argument must be FALSE. Possible solutions:
1) Set the mode argument to "single" to force single (not batch) geocoding
2) Set limit argument to 1 (ie. 1 result is returned per ', input_terms$input_singular, ')
3) Set ', input_terms$return_arg, ' to FALSE
See ?', input_terms$base_func_name, ' for details.'),
call. = FALSE)
}
}
check_here_return_input <- function(here_request_id, return_input, reverse) {
input_terms <- get_coord_address_terms(reverse)
if (is.character(here_request_id) && return_input == TRUE) {
stop('HERE: When requesting a previous job via here_request_id, set ', input_terms$return_arg,
' to FALSE. See ?', input_terms$base_func_name, ' for details.', call. = FALSE)
}
}
extract_osm_reverse_full <- function(response) {
a <- response[!(names(response) %in% c('display_name', 'boundingbox', 'address'))]
a[sapply(a, function(x) length(x) == 0)] <- NULL
b <- tibble::as_tibble(response[['address']])
c <- tibble::tibble(boundingbox = list(response$boundingbox))
return(
tibble::as_tibble(dplyr::bind_cols(as.data.frame(a), b, c))
)
}
extract_bing_latlng <- function(response) {
if (length(response$resourceSets$resources[[1]]) == 0) return(data.frame())
latlng <- as.data.frame(matrix(unlist(response$resourceSets$resources[[1]]$point$coordinates),
ncol = 2, byrow = TRUE), col.names = c('lat', 'long'))
return(latlng)
}
show_progress_bar <- function() {
getOption("tidygeocoder.progress_bar", TRUE) &&
interactive() &&
!isTRUE(getOption("rstudio.notebook.executing")) &&
!isTRUE(getOption("knitr.in.progress"))
}
create_progress_bar <- function(
total_count,
format_text = "[:bar] :current/:total (:percent) Elapsed: :elapsed Remaining: :eta"
) {
pb <- progress::progress_bar$new(
format = format_text,
clear = FALSE,
total = total_count,
show_after = 0
)
pb$tick(0)
return(pb)
}
query_start_message <- function(method, num_inputs, reverse, batch, display_time = FALSE) {
input_terms <- get_coord_address_terms(reverse)
message(paste0('Passing ',
format(num_inputs, big.mark = ','), ' ',
if (num_inputs == 1) input_terms$input_singular else input_terms$input_plural,
' to the ',
get_setting_value(tidygeocoder::api_info_reference, method, 'method_display_name'), ' ',
if (batch == TRUE) 'batch' else paste0('single ', input_terms$input_singular),
' geocoder',
if (display_time == TRUE) paste0(" - ", format(Sys.time(), "%I:%M %p")) else "")
)
}
query_complete_message <- function(start_time) {
print_time("Query completed in", get_seconds_elapsed(start_time))
}
api_url_modification <- function(method, api_url, generic_query, custom_query, reverse) {
if (method %in% c('mapbox', 'tomtom')) {
api_url <- if (reverse == TRUE) {
paste0(api_url, custom_query[["to_url"]], ".json")
} else {
gsub(" ", "%20", paste0(api_url, generic_query[['address']], ".json"))
}
api_url <- gsub(";", ",", api_url)
}
return(api_url)
}
apply_api_options_defaults <- function(api_options) {
for (name in names(pkg.globals$default_api_options)) {
if (is.null(api_options[[name]])) api_options[[name]] <- pkg.globals$default_api_options[[name]]
}
return(api_options)
}
initialize_init <- function(api_options) {
if (is.null(api_options[["init"]])) {
api_options[["init"]] <- TRUE
}
return(api_options)
}
|
filterDate <- function(...) UseMethod("filterDate")
filterDate.default <- function(text, meta,
s.date = min(meta$date, na.rm = TRUE),
e.date = max(meta$date, na.rm = TRUE), ...){
stopifnot(is.textmeta(textmeta(meta = meta, text = text)),
length(s.date) == 1, length(e.date) == 1)
meta <- meta[match(names(text), meta$id),]
ind <- meta$date >= s.date & meta$date <= e.date
ind[is.na(ind)] <- FALSE
meta <- meta[ind, ]
text <- text[match(meta$id, names(text))]
invisible(text)
}
filterDate.textmeta <- function(object,
s.date = min(object$meta$date, na.rm = TRUE),
e.date = max(object$meta$date, na.rm = TRUE),
filtermeta = TRUE, ...){
stopifnot(is.textmeta(object), is.logical(filtermeta), length(filtermeta) == 1)
text <- NextMethod("filterDate", object = object$text, text = object$text,
meta = object$meta, s.date = s.date, e.date = e.date)
object$text <- text
if(filtermeta){
object$meta <- object$meta[object$meta$id %in% names(object$text),]
}
return(object)
}
|
layout.cna <- function(x, pdb, renumber=TRUE, k=2, full=FALSE){
if( !inherits(pdb, "pdb") ) {
stop("Input 'pdb' is not of class 'pdb' as obtained from 'read.pdb()'")
}
if(!k %in% c(1,2,3)) {
stop("Input 'k' should have a value of 3, 2 or 1")
}
if(inherits(x, "cna") || is.list(x)) {
if(!full) {
membership <- x$communities$membership
} else {
membership <- c(1:length(x$communities$membership))
}
} else {
if(full) {
membership <- c(1:sum(pdb$calpha))
}
stop("Input object 'x' should be of class cna")
}
if(renumber) {
pdb <- convert.pdb(pdb, renumber=TRUE, rm.h=FALSE, verbose=FALSE)
}
notprotein.inds <- atom.select(pdb, "notprotein", verbose=FALSE)
if(length(notprotein.inds$atom)>0){
num.res <- length(pdb$atom[pdb$calpha,"resno"]) + length(unique(pdb$atom[notprotein.inds$atom,7]))
}
if(length(notprotein.inds$atom)==0){
num.res <- length(pdb$atom[pdb$calpha,"resno"])
}
n <- unique(membership[!is.na(membership)])
cent <- matrix(NA, nrow=length(n), ncol=3)
a <- 1
for(i in n){
inds <- atom.select(pdb, resno=which(membership==i),
elety="CA", verbose=FALSE)
cent[a,] <- apply( matrix(pdb$xyz[inds$xyz], nrow=3), 1, mean)
a <- a + 1
}
if(k != 3) {
if(nrow(cent) - 1 < k) {
cent <- cmdscale(dist(cent), k = nrow(cent) - 1)
cent <- cbind(cent, matrix(0, nrow=nrow(cent), ncol=k-nrow(cent)+1))
} else {
cent <- cmdscale(dist(cent),k=k)
}
}
return(cent)
}
|
lama_translate_all <- function(
.data,
dictionary,
prefix = "",
suffix = "",
fn_colname = function(x) x,
keep_order = FALSE,
to_factor = TRUE
) {
UseMethod("lama_translate_all")
}
lama_translate_all.data.frame <- function(
.data,
dictionary,
prefix = "",
suffix = "",
fn_colname = function(x) x,
keep_order = FALSE,
to_factor = TRUE
) {
err_handler <- composerr("Error while calling 'lama_translate_all'")
check_and_translate_all(
.data = .data,
dictionary = dictionary,
prefix = prefix,
suffix = suffix,
fn_colname = fn_colname,
keep_order = keep_order,
to_factor = to_factor,
is_translated = FALSE,
err_handler = err_handler
)
}
lama_to_factor_all <- function(
.data,
dictionary,
prefix = "",
suffix = "",
fn_colname = function(x) x,
keep_order = FALSE
) {
UseMethod("lama_to_factor_all")
}
lama_to_factor_all.data.frame <- function(
.data,
dictionary,
prefix = "",
suffix = "",
fn_colname = function(x) x,
keep_order = FALSE
) {
err_handler <- composerr("Error while calling 'lama_to_factor_all'")
check_and_translate_all(
.data = .data,
dictionary = dictionary,
prefix = prefix,
suffix = suffix,
fn_colname = fn_colname,
keep_order = keep_order,
to_factor = TRUE,
is_translated = TRUE,
err_handler = err_handler
)
}
check_and_translate_all <- function(
.data,
dictionary,
prefix,
suffix,
fn_colname,
keep_order,
to_factor,
is_translated,
err_handler
) {
if (!is.lama_dictionary(dictionary))
err_handler("The argument 'dictionary' must be a lama_dictionary class object.")
if (!is.character(prefix) || length(prefix) != 1 || is.na(prefix))
err_handler("The argument 'prefix' must be a character string.")
if (!is.syntactic(paste0(prefix, "a")))
err_handler("The argument 'prefix' must be a valid object name prefix.")
if (!is.character(suffix) || length(suffix) != 1 || is.na(suffix))
err_handler("The argument 'suffix' must be a character string.")
if (!is.syntactic(paste0("a", suffix)))
err_handler("The argument 'suffix' must be a valid object name suffix.")
if (!is.function(fn_colname))
err_handler(paste(
"The argument 'fn_colname' must be a function taking a character string",
"and returning a character string."
))
if (!is.logical(keep_order) || length(keep_order) != 1 || is.na(keep_order))
err_handler(paste(
"The argument 'keep_order' must be a logical."
))
if (!is.logical(to_factor) || length(to_factor) != 1 || is.na(to_factor))
err_handler(paste(
"The argument 'to_factor' must be a logical."
))
translation <- intersect(names(dictionary), colnames(.data))
if (length(translation) == 0)
return(.data)
col_new <- sapply(translation, fn_colname)
if (!is.character(col_new) || length(col_new) != length(translation) ||
any(is.na(col_new))
)
err_handler(paste(
"The function given in argument 'fn_colname' does not produce valid",
"column names:",
"It must take character strings and return character strings."
))
col_new <- paste0(prefix, col_new, suffix)
invalid <- !is.syntactic(col_new)
if (any(invalid))
err_handler(paste0(
"The function given in argument 'fn_colname' does not produce valid ",
"column names: The following produced column names are invalid: ",
stringify(col_new[invalid]),
"."
))
translate_df(
.data = .data,
dictionary = dictionary,
translation = translation,
col = translation,
col_new = col_new,
keep_order = keep_order,
to_factor = to_factor,
is_translated = is_translated,
err_handler = err_handler
)
}
|
rglaft<-function(m,n,STime,Event,alpha,data){
a<-alpha
nr<-nrow(data)
if(STime!="os"){
names(data)[names(data) == STime] <- "os"
}
if(Event!="death"){
names(data)[names(data) == Event] <- "death"
}
d11 <- subset(data, select = c(m:n))
le<-length(d11)
for(i in 1:nr) {
for(j in 1:le) {
d11[i,j] = ifelse(is.na(d11[i,j])=="TRUE", mean(d11[,j], na.rm=TRUE), d11[i,j])
}
}
pnt<-NULL
for(j in 1:le)
{
if(sum(d11[,j])==0) {
pnt<-c(pnt,j)
}
}
if(is.null(pnt)==F){
d11 <- d11[,-pnt]
}
len<-length(d11)
os<-data$os
death<-data$death
x<-as.matrix(d11)
cv.ReglVar<-cv.glmnet(x,Surv(os,death),alpha = a,family = "cox")
var_minlmd = coef(cv.ReglVar, cv.ReglVar$lambda.min)
p <- as.matrix(var_minlmd)
sg<-subset(p,p[,1]!=0)
if(nrow(sg)==0){
stop("Increase number of variables, chosen are not sufficient")
} else{
sgnf_var <- rownames(sg)
}
ln<-length(sgnf_var)
pnt1<-NULL
for(i in 1:ln){
for(j in 1:len)
{
if(colnames(d11[j])==sgnf_var[i]) {
pnt1<-c(pnt1,j)
}
}
}
fdt<-subset(d11,select = pnt1)
d12<-data.frame(data[,c('death','os')],fdt)
ht<-colnames(d12)[3:length(d12)]
mtx<-matrix(nrow=ln,ncol = 4)
for(i in 1:ln)
{
rglaft<-aft(Surv(os,death==1)~get(ht[i]),data=d12)
q1<-coef(summary(rglaft))[1,]
mtx[i,]<-q1
}
colnames(mtx)<-colnames(coef(summary(rglaft)))
rownames(mtx)<-colnames(fdt)
mtx<-data.frame(mtx)
mtx<-mtx[order(mtx[,4]),]
return(mtx)
}
|
setwd("~/git/molgenis-r-armadillo/vignettes")
knitr::knit("MolgenisArmadillo.Rmd.orig", output = "MolgenisArmadillo.Rmd")
knitr::knit("creating_data_subsets.Rmd.orig",
output = "creating_data_subsets.Rmd")
knitr::purl("MolgenisArmadillo.Rmd.orig", output = "MolgenisArmadillo.R")
knitr::purl("creating_data_subsets.Rmd.orig",
output = "creating_data_subsets.R")
|
library(hamcrest)
expected <- c(-0x1.0e4d28f85ff8ep+11 + 0x0p+0i, 0x1.cef844f323d96p+5 + -0x1.a64caa3c0779ap+8i,
-0x1.89a2ce7135597p+3 + 0x1.cd8648d4cb19p+6i, -0x1.2654525c01dc9p+7 + 0x1.02fb32a025057p+7i,
-0x1.f53cb1e6e5debp+8 + 0x1.393d0b63f1bf1p+7i, -0x1.ab8119a576f98p+3 + -0x1.7257a58220a8dp+7i,
0x1.35047fab664e4p+6 + 0x1.984f493d589aep+8i, -0x1.0ebb272ba8eb7p+6 + 0x1.68be64b99b7e3p+7i,
-0x1.f15743d0ab3dep+8 + -0x1.5bb4954738197p+6i, 0x1.3dbdef979f445p+7 + 0x1.77e2a54e81bcep+7i,
0x1.fb56d1916455ap+5 + 0x1.5fb569977f611p+6i, 0x1.898a7e3be3552p+8 + 0x1.1174706632b7p+8i,
-0x1.7463f753a71a4p+7 + 0x1.c8e0fd46f593p+7i, 0x1.4a952353424efp+7 + -0x1.e038d79531344p+5i,
0x1.2159284a6f6dep+7 + 0x1.fb6cb333477c2p+8i, 0x1.161aad24d1p+8 + -0x1.ac2d95b465c3cp+5i,
0x1.a3d478dcc43adp+6 + 0x1.73892a5aaf076p+7i, 0x1.0f37020950b24p+6 + 0x1.82736062576b8p+5i,
-0x1.42648846cfed1p+5 + 0x1.d85f56d1116bdp+6i, -0x1.2c698457e5f4ap+6 + -0x1.6b0c3c97a7298p+6i,
0x1.710ddebed9808p+7 + -0x1.cab86548644f6p+6i, 0x1.19b8f56444c8ap+6 + -0x1.6c3f025667e54p+7i,
-0x1.3e073dd2c538ep+7 + -0x1.134968213e6fbp+7i, 0x1.74f99f04333bdp+6 + -0x1.5bbc9f8eec948p+6i,
0x1.e0b5d578663bep+5 + -0x1.3f5b78a154db6p+6i, -0x1.582a7b195cc76p+6 + -0x1.98159d26fc33ep+7i,
-0x1.9c4324ca6cda3p+4 + 0x1.2fe3f90e2795ep+5i, -0x1.e285a8ea9e73fp+5 + -0x1.9163fb43afc4ap+6i,
-0x1.cb2da04146bd6p+4 + -0x1.eea2a7a9c4d75p+5i, 0x1.e071769bf0e46p+5 + -0x1.a8321403efa58p+6i,
0x1.d589d37d25d7ep+5 + -0x1.aeec6de81535p+5i, -0x1.34c45ce11dbfap+6 + -0x1.ac3423495cacp+4i,
-0x1.8474133f87bcep+5 + -0x1.8df74a48702a4p+4i, 0x1.414c4b2f47adp+7 + 0x1.b2b13b8e2595ep+4i,
-0x1.015c7d27626c6p+6 + 0x1.5ce38bd7f9a8p+5i, -0x1.829836606cb88p+6 + 0x1.23ad65906866p+3i,
0x1.0000105e77d8p+2 + 0x1.7773ec5fda0eep+6i, 0x1.a12b3f5e289ebp+6 + 0x1.ed9030f31cec6p+4i,
-0x1.e14c15df42518p+4 + -0x1.af0296756fe4p+2i, -0x1.6feccc3a53588p+3 + -0x1.a5cdf908cda8p+6i,
0x1.b488fc8b5f85bp+5 + -0x1.b4ecb6567cb98p+3i, 0x1.4c13d94136a16p+6 + 0x1.392fa95c7d782p+6i,
0x1.87a2eed400e63p+4 + -0x1.6249dbd1ddc33p+4i, -0x1.79cccb077adcap+3 + -0x1.318bfab6006f2p+7i,
0x1.62411222bf016p+6 + 0x1.e97c2ed335aaep+3i, 0x1.eb46295c41533p+5 + 0x1.9ff2e8e9d408ap+5i,
0x1.4f6b497882848p+6 + -0x1.c3c0ef49f2f0cp+4i, -0x1.34acb3709a8a6p+5 + -0x1.7eaa48571cc0ep+7i,
0x1.2c8c333b71b99p+6 + 0x1.d4e4b288c1b8dp+4i, 0x1.09df32d09ff7cp+4 + -0x1.016eb38f13a2p+4i,
0x1.0ff79d3340ff8p+4 + 0x1.245d774d639b4p+4i, 0x1.3bed91618ab5cp+2 + -0x1.2014c92629dc1p+6i,
0x1.8788610dcef3p+5 + -0x1.17b237a573038p+5i, -0x1.17d2eab115d1p+4 + 0x1.82e2d9f805f37p+4i,
0x1.710c9c07f56d4p+5 + 0x1.ebcfa3ba4d1dcp+6i, 0x1.28d098492974p+0 + -0x1.34a115d076ab3p+6i,
-0x1.4f41b92b9387ep+5 + 0x1.29e3efa5ed01ep+5i, -0x1.1ac85a7c8588p-2 + 0x1.2e6f175ae7152p+5i,
0x1.eaf72b2a6812p+5 + 0x1.7c2c16b579cfp+4i, -0x1.716b29c77fdc4p+4 + -0x1.26fc966828ed8p+6i,
-0x1.c6d9676062fc2p+4 + 0x1.11fd65b88b038p+4i, 0x1.0daf73fa06564p+2 + 0x1.76a4e83015d2p+5i,
0x1.50989f6308a52p+2 + -0x1.e8dbf927f2534p+4i, 0x1.2797cdca3136ap+3 + 0x1.33355f1778cc4p+5i,
-0x1.6785ef67c4583p+3 + 0x1.6fde8591241dp+3i, -0x1.1437ca560e4fp+4 + -0x1.4d79df009831ep+2i,
-0x1.54f062d3f694ap+4 + 0x1.b1aaf3cb595ddp+4i, 0x1.1a0f297db9539p+5 + 0x1.c43cac5088d18p+2i,
-0x1.00eba496dcd9dp+4 + -0x1.c128110bb8192p+4i, -0x1.9120e785a4ee9p+4 + 0x1.8e639d9b8ca7dp+4i,
0x1.456876ab7899cp+5 + 0x1.a1b8442c3749ap+5i, 0x1.dd24119b54d1bp+4 + -0x1.9dbcbf2410462p+4i,
-0x1.2f72193de7cp-3 + 0x1.95542b6e9624ap+3i, 0x1.cc45cab497e8cp+3 + 0x1.5d81466a5c70dp+4i,
-0x1.f080ca7775e3ep+5 + 0x1.dd3b732020da8p+2i, -0x1.f5fe9201b8c44p+2 + -0x1.236fc7326bc9ap+5i,
0x1.c7287287c1568p+4 + 0x1.506807594148dp+2i, -0x1.1c5a82e93f4dp+5 + -0x1.bddb3ea5e4f02p+3i,
-0x1.e85bcd3231b35p+5 + 0x1.eb2af615dd14p+5i, 0x1.5a1da187679b4p+4 + 0x1.7ed072ae0892p-1i,
-0x1.0fa4fa96b707p+1 + -0x1.836f1414efbbbp+2i, -0x1.9e6588ff46b34p+3 + -0x1.08fa4cc8c4338p+4i,
0x1.2967d4eb7bee6p+5 + 0x1.82f9d4f954b45p+4i, 0x1.4706aa689e611p+5 + -0x1.c3d2495a0f37p+0i,
0x1.0ada226837e6cp+3 + -0x1.f675d431cd617p+3i, 0x1.2201eddb45c16p+6 + 0x1.2d7654b4ec10cp+0i,
0x1.ef467a090f46p+1 + 0x1.78c817d70574cp+5i, -0x1.35556b4d44afep+5 + -0x1.ad1f8f2f3b88p-1i,
-0x1.6927c2c7d0832p+4 + 0x1.69cb3503614a8p+2i, 0x1.2ea847e13a751p+6 + -0x1.be55b8ea01152p+4i,
0x1.1bbb58b7e3328p+2 + 0x1.ca5d3714d7398p+4i, -0x1.cebf46243ac4ap+4 + 0x1.883e75bdcb015p+5i,
0x1.640a806703744p+3 + 0x1.bbf36cbd7e4c6p+4i, -0x1.209c1af91255ep+4 + 0x1.7930fe1fa7bd5p+4i,
-0x1.61cc2016397f8p+4 + 0x1.32126dc5675ccp+5i, -0x1.fa830c647b8a4p+1 + 0x1.29a8eeba1126cp+5i,
-0x1.2f4f1f1eba49dp+6 + -0x1.e008a51bfde9ep+3i, 0x1.10cf7188bd0c7p+4 + 0x1.5622c335f1e1p+1i,
0x1.e700806108588p+4 + 0x1.6eac249bdbb94p+2i, -0x1.c63b330e19884p+4 + 0x1.128625fa69348p+5i,
-0x1.84ee912c9530bp+5 + 0x1.a965598ec252dp+5i, 0x1.34bac0e67432ap+5 + -0x1.3cb9dffbc2e8ap+5i,
-0x1.6720d5db8ca48p+3 + -0x1.bd6cdeb2f0478p+2i, -0x1.b34b5536830dep+4 + 0x1.a5a640a5ccf6p+1i,
-0x1.88a48b50b2ffep+4 + 0x1.9d6b88177c2f3p+5i, 0x1.f6afcbaf926aep+4 + -0x1.2857fbb1daee2p+6i,
0x1.237c51515245bp+5 + 0x1.2774d7de6c28ap+4i, 0x1.aaf599e32c1f6p+3 + -0x1.14a89e3e0d219p+4i,
-0x1.975c1f71beb3ep+4 + 0x1.2f9fd7314bc39p+4i, -0x1.931e6e996bcdap+3 + 0x1.456751312435p+2i,
0x1.54f2baf11697cp+4 + -0x1.37f697dd7ce8ep+4i, 0x1.93aa8d577c2p+5 + -0x1.358bc27e088cp+6i,
-0x1.0f295996b6487p+5 + 0x1.25855ca779b9ap+6i, -0x1.7f6abae0e2478p+3 + -0x1.eb8bb31f81ec6p+5i,
0x1.20ed4ebeb9c7p+4 + 0x1.5cef9862bbbcp+5i, 0x1.fe6bec3326e94p+3 + -0x1.2f600fcb32783p+5i,
-0x1.4ff0cc421da4cp+3 + 0x1.2f50166cb3adbp+4i, -0x1.7cbbff3ae748p+6 + 0x1.06cda00ab19c4p+5i,
-0x1.05a341b6126bp+4 + 0x1.3065774614f5dp+5i, -0x1.5d47c5a07c11fp+6 + -0x1.6af8ef1231286p+5i,
0x1.b0c8cc234e8f4p+5 + 0x1.23cfaea911608p+4i, -0x1.8f8db18b177e5p+6 + -0x1.deb5f147429d8p+3i,
-0x1.8eafc8270ee01p+6 + 0x1.db23bd1db2dafp+6i, -0x1.244cdf733136p+4 + -0x1.6788c5d3aafe6p+6i,
0x1.afb5cc1da5c19p+5 + 0x1.a5537045b455p+1i, -0x1.c04919ecf5ec6p+6 + -0x1.df4c546a7b3ap+0i,
-0x1.0a8c2720a1daap+4 + 0x1.9c60f1dd9bbdap+4i, -0x1.cd6bd6699ba48p+6 + -0x1.a292c49bc6df3p+5i,
0x1.ed4a72a038e71p+6 + 0x1.de1184a1ecc7p+5i, -0x1.4f00a3076d6aep+6 + 0x1.8b7465c273188p+4i,
-0x1.cba7a4f604b85p+5 + 0x1.51abeca311e8cp+6i, -0x1.1344feb4531eap+6 + 0x1.caff63cb7fc44p+6i,
0x1.9eadfc8fc3affp+6 + -0x1.7545bdf2d3ff8p+2i, -0x1.4d8660d5b5f88p+3 + -0x1.275ef54c3aec9p+6i,
-0x1.37c7109f2e36p+5 + 0x1.0d70ef0363dd1p+6i, -0x1.58c89dbac822cp+7 + 0x1.e989a8bcee0d8p+4i,
0x1.4778cb2df35e2p+4 + 0x1.e39753197627ep+6i, -0x1.520b6fc4e760bp+6 + 0x1.0e273222a9f1bp+7i,
-0x1.47ea723c2952bp+5 + 0x1.3a74c1af2b907p+6i, -0x1.68e5b107f3141p+7 + 0x1.05e8299fb27c6p+5i,
0x1.667dab2fed5fcp+7 + 0x1.0b2d9d33a9d94p+6i, -0x1.c03868ca8eb88p+4 + 0x1.9fb6372ad783ep+5i,
-0x1.25d4ae0a08276p+5 + -0x1.21df6d0a06d0ep+7i, -0x1.8dc873c50d46p+5 + 0x1.f6da4cba3166bp+5i,
0x1.7c8ef769b1b9cp+5 + 0x1.13f8f9799bee4p+5i, -0x1.82f095a6dc8cp+4 + 0x1.ee0418fd2e15p+3i,
0x1.5881b81f20226p+5 + -0x1.24cc804edd7e8p+5i, 0x1.e67abe20ab94fp+4 + 0x1.f298756d53706p+5i,
0x1.cd93ec9c9f148p+6 + 0x1.8c54be542340ap+6i, 0x1.04a79556158d1p+7 + 0x1.c6a123e6f63e8p+4i,
0x1.40f3ee04c4fd8p+6 + 0x1.7322c68bd7cep+5i, -0x1.d627edfa44c9ep+5 + -0x1.0427a074ef33ap+7i,
0x1.bcf24f9a6d178p+7 + -0x1.813717127ad6ap+7i, 0x1.4bfd8016fafe8p+5 + 0x1.5ae1cf3967fcap+7i,
0x1.51f0fa07097acp+7 + -0x1.3649f6ee84552p+7i, 0x1.427956096aebap+5 + -0x1.0ab1a41a893c8p+7i,
-0x1.2420ff058b72p+5 + -0x1.977f476b5186cp+6i, -0x1.073301a040ad5p+4 + -0x1.bf7e8fdbb70cp+0i,
-0x1.d328249efa788p+6 + -0x1.f80293b72bf6p+7i, 0x1.8763a9f43a52cp+3 + -0x1.bc57437a0fb37p+6i,
0x1.74f4dbf9f2628p+5 + -0x1.fc2215a340cadp+7i, -0x1.f788fd3f7b3e4p+6 + -0x1.e58996104d92dp+7i,
0x1.b4aa33ccffae7p+7 + -0x1.413869c69f409p+6i, -0x1.0dac8f4333c9bp+7 + -0x1.5d7616e9c1ae4p+7i,
-0x1.f7b6af037fe96p+5 + -0x1.235bc87032c22p+8i, -0x1.0d7b8b0708b0ap+7 + 0x1.0a37724576ba9p+6i,
-0x1.c0710fe8dce61p+6 + -0x1.a6e7d427cb604p+8i, 0x1.14ec8bb9e6653p+7 + 0x1.73931631db12ep+7i,
-0x1.bd197edc67c73p+7 + -0x1.739eec4511ac9p+6i, -0x1.5ba66e58a4c14p+8 + 0x1.a60d669dc5274p+5i,
-0x1.8c1a12a2280c2p+7 + -0x1.79388bf041812p+7i, 0x1.dd42573877235p+6 + 0x1.820816392435ap+7i,
-0x1.bdac18e6d6894p+7 + 0x1.19476d386c1b2p+8i, -0x1.744d94905ec31p+7 + -0x1.6c270b65cf45p+6i,
0x1.a3874c0b54048p+1 + -0x1.eabdbd4eafdcap+7i, -0x1.cf57b033be044p+5 + 0x1.4964e3acf051ep+9i,
-0x1.04d1b4358076p+8 + -0x1.a2202ede708p+6i, -0x1.4cdf5d77c7d61p+8 + 0x1.11a6a92a07e78p+5i,
-0x1.339a48ca6f124p+7 + -0x1.143716c98f0dp+8i, 0x1.1c79c04d8236cp+8 + 0x1.525b044ea6553p+8i,
-0x1.5d03576e1568ap+6 + 0x1.80e47a79dd448p+4i, 0x1.ae1a724d50905p+7 + 0x1.adb10c2c2283p+2i,
-0x1.56b0b99813f41p+5 + -0x1.77bd610807ddcp+6i, 0x1.b33d3a6cbc6bcp+7 + 0x1.d25891877b122p+7i,
0x1.5c45972d4192p+4 + 0x1.2a01ba05a2d7dp+5i, 0x1.edd2c129a21a4p+7 + -0x1.857059fafb0d2p+5i,
-0x1.a7d666c4caa46p+1 + -0x1.ee9258407c37ep+6i, 0x1.b7acefd4d9c3p+7 + 0x1.7334cdb8adf6cp+5i,
0x1.167604c2d92a7p+5 + -0x1.760d0adb0f836p+5i, 0x1.095f80d486117p+8 + -0x1.1ad1e84078a7cp+6i,
-0x1.6a1c6562710a4p+6 + 0x1.c80b46470d2a8p+2i, 0x1.d2672f9bcd037p+6 + 0x1.6a698805a71eap+6i,
0x1.74527a901821ap+5 + 0x1.5dcbf6618a11ep+5i, 0x1.12d5c711e3945p+5 + -0x1.66d7b6aba2b5p+2i,
-0x1.ce0c7dfeef458p+7 + -0x1.03ebffe42e444p+7i, 0x1.93e125cc8fcp-2 + -0x1.90f8deb6672bap+6i,
-0x1.198014b24ca74p+7 + -0x1.2e9cee16f2406p+3i, -0x1.a32844e4819ccp+1 + -0x1.1e119f1e2ebcap+6i,
-0x1.97db65664df5ep+6 + -0x1.0e6c0f155e242p+4i, -0x1.b8878f031f5d1p+4 + 0x1.9095178fcb9p+4i,
-0x1.75938f99966c6p+7 + 0x1.1d68a1c568853p+7i, -0x1.2ae9c3401c724p+5 + -0x1.8ce6cad369f73p+7i,
-0x1.54234195b7287p+5 + -0x1.5724aafa39294p+1i, -0x1.98c4d054b2abdp+3 + -0x1.d89cb27e0b63ep+4i,
-0x1.03581a66e6bbep+6 + 0x1.029a9f187b6bp+6i, -0x1.105cc51911f85p+6 + 0x1.21f532960229bp+4i,
0x1.8ae0ab22b91e9p+5 + -0x1.b959ac3c0d47cp+6i, 0x1.379819e370eefp+4 + 0x1.508d6920a30b4p+7i,
0x1.43e4427a9e1d8p+6 + 0x1.50d372314741p+3i, 0x1.42c6a02ec210ep+6 + 0x1.6d5de8b363f14p+6i,
0x1.54898b74b0434p+6 + -0x1.5591c429c4212p+4i, 0x1.dd70974b116ddp+5 + 0x1.b07d27676bf3bp+6i,
0x1.65691efbbce63p+5 + 0x1.fc230b3a20ccp+1i, 0x1.d22d720e2d0d8p+1 + 0x1.7b7351eb46646p+6i,
0x1.46e9a304d4617p+7 + -0x1.677f2dd8ea284p+5i, -0x1.00f35196fd998p+5 + 0x1.cedaab12eb9fep+5i,
0x1.12b170d6b9d4ep+7 + 0x1.f76bd6b67c94ep+3i, -0x1.7bc1de644d48cp+4 + 0x1.13afe2b6d35cbp+6i,
0x1.cb6ffb5ea353cp+4 + -0x1.831efb8dc2f7ap+5i, 0x1.58556a1f62408p+2 + -0x1.62f5b5b628a52p+5i,
0x1.689cf41ff6c4p-2 + -0x1.1bb850c57aa69p+5i, 0x1.0d1c86aa9ace8p+2 + 0x1.7b31a78ee6478p+5i,
-0x1.eb4160e990101p+4 + -0x1.05a2e3325e49ap+6i, 0x1.e372e24fbef98p+3 + -0x1.c138a5c36bb51p+4i,
-0x1.d0ce5eff2ac8p+5 + -0x1.cac66c2bc0243p+5i, 0x1.a38bc6bc197a4p+3 + 0x1.23ab92f6116a6p+6i,
-0x1.9a6df6a8e234fp+4 + -0x1.8849eea09ebcp+6i, 0x1.9d309a59e93d4p+5 + 0x1.6a854c7d96c22p+3i,
-0x1.ff3592923a78p+5 + -0x1.4a76c6509d18ap+4i, 0x1.1cf80a3804e3cp+4 + 0x1.2227dff762dccp+6i,
-0x1.703d41638437cp+5 + -0x1.2444c7e93a7a6p+6i, 0x1.8d4ac83af0f8ap+4 + 0x1.767527af64cb1p+4i,
0x1.8336c9be7fbp+3 + -0x1.3dc27c7ae6872p+3i, -0x1.1f7459c881a96p+5 + 0x1.c4536a0b80f5ap+3i,
0x1.0428d1e7f6b3ep+3 + 0x1p-48i, -0x1.1f7459c881a86p+5 + -0x1.c4536a0b80f49p+3i,
0x1.8336c9be7faf4p+3 + 0x1.3dc27c7ae6834p+3i, 0x1.8d4ac83af0f7fp+4 + -0x1.767527af64cc1p+4i,
-0x1.703d416384372p+5 + 0x1.2444c7e93a799p+6i, 0x1.1cf80a3804e35p+4 + -0x1.2227dff762dd3p+6i,
-0x1.ff3592923a77p+5 + 0x1.4a76c6509d19p+4i, 0x1.9d309a59e93cep+5 + -0x1.6a854c7d96c75p+3i,
-0x1.9a6df6a8e233cp+4 + 0x1.8849eea09ebb4p+6i, 0x1.a38bc6bc19754p+3 + -0x1.23ab92f6116a1p+6i,
-0x1.d0ce5eff2ac8p+5 + 0x1.cac66c2bc022cp+5i, 0x1.e372e24fbefc4p+3 + 0x1.c138a5c36bb7dp+4i,
-0x1.eb4160e990121p+4 + 0x1.05a2e3325e493p+6i, 0x1.0d1c86aa9ac6dp+2 + -0x1.7b31a78ee647cp+5i,
0x1.689cf41ff5fep-2 + 0x1.1bb850c57aa64p+5i, 0x1.58556a1f623efp+2 + 0x1.62f5b5b628a5ep+5i,
0x1.cb6ffb5ea3514p+4 + 0x1.831efb8dc2f83p+5i, -0x1.7bc1de644d4a2p+4 + -0x1.13afe2b6d35c9p+6i,
0x1.12b170d6b9d4cp+7 + -0x1.f76bd6b67c984p+3i, -0x1.00f35196fd99cp+5 + -0x1.cedaab12eb9dep+5i,
0x1.46e9a304d4614p+7 + 0x1.677f2dd8ea279p+5i, 0x1.d22d720e2d07ap+1 + -0x1.7b7351eb4664p+6i,
0x1.65691efbbce64p+5 + -0x1.fc230b3a20d5p+1i, 0x1.dd70974b116fp+5 + -0x1.b07d27676bf3p+6i,
0x1.54898b74b043p+6 + 0x1.5591c429c421p+4i, 0x1.42c6a02ec210ep+6 + -0x1.6d5de8b363f1bp+6i,
0x1.43e4427a9e1d5p+6 + -0x1.50d3723147438p+3i, 0x1.379819e370effp+4 + -0x1.508d6920a30b2p+7i,
0x1.8ae0ab22b91eep+5 + 0x1.b959ac3c0d47cp+6i, -0x1.105cc51911f7fp+6 + -0x1.21f53296022a2p+4i,
-0x1.03581a66e6bbdp+6 + -0x1.029a9f187b6b1p+6i, -0x1.98c4d054b2a75p+3 + 0x1.d89cb27e0b64p+4i,
-0x1.54234195b7292p+5 + 0x1.5724aafa39328p+1i, -0x1.2ae9c3401c718p+5 + 0x1.8ce6cad369f74p+7i,
-0x1.75938f99966cbp+7 + -0x1.1d68a1c56884ep+7i, -0x1.b8878f031f5c6p+4 + -0x1.9095178fcb90cp+4i,
-0x1.97db65664df5ep+6 + 0x1.0e6c0f155e24dp+4i, -0x1.a32844e48195p+1 + 0x1.1e119f1e2ebc8p+6i,
-0x1.198014b24ca73p+7 + 0x1.2e9cee16f2411p+3i, 0x1.93e125cc8fcp-2 + 0x1.90f8deb6672bdp+6i,
-0x1.ce0c7dfeef454p+7 + 0x1.03ebffe42e448p+7i, 0x1.12d5c711e3937p+5 + 0x1.66d7b6aba2b4p+2i,
0x1.74527a9018216p+5 + -0x1.5dcbf6618a11dp+5i, 0x1.d2672f9bcd03bp+6 + -0x1.6a698805a71f1p+6i,
-0x1.6a1c6562710a3p+6 + -0x1.c80b46470d1e8p+2i, 0x1.095f80d486116p+8 + 0x1.1ad1e84078a78p+6i,
0x1.167604c2d92a2p+5 + 0x1.760d0adb0f83ap+5i, 0x1.b7acefd4d9c32p+7 + -0x1.7334cdb8adf77p+5i,
-0x1.a7d666c4caa38p+1 + 0x1.ee9258407c382p+6i, 0x1.edd2c129a21a5p+7 + 0x1.857059fafb0c2p+5i,
0x1.5c45972d41924p+4 + -0x1.2a01ba05a2d8p+5i, 0x1.b33d3a6cbc6cp+7 + -0x1.d25891877b126p+7i,
-0x1.56b0b99813f3bp+5 + 0x1.77bd610807decp+6i, 0x1.ae1a724d50906p+7 + -0x1.adb10c2c2284p+2i,
-0x1.5d03576e1568cp+6 + -0x1.80e47a79dd44dp+4i, 0x1.1c79c04d8236ep+8 + -0x1.525b044ea6558p+8i,
-0x1.339a48ca6f11ep+7 + 0x1.143716c98f0d2p+8i, -0x1.4cdf5d77c7d62p+8 + -0x1.11a6a92a07e8p+5i,
-0x1.04d1b4358076p+8 + 0x1.a2202ede7080ep+6i, -0x1.cf57b033be066p+5 + -0x1.4964e3acf051fp+9i,
0x1.a3874c0b5411p+1 + 0x1.eabdbd4eafdcdp+7i, -0x1.744d94905ec32p+7 + 0x1.6c270b65cf456p+6i,
-0x1.bdac18e6d689ap+7 + -0x1.19476d386c1b5p+8i, 0x1.dd42573877236p+6 + -0x1.820816392435cp+7i,
-0x1.8c1a12a2280c1p+7 + 0x1.79388bf04181cp+7i, -0x1.5ba66e58a4c19p+8 + -0x1.a60d669dc5266p+5i,
-0x1.bd197edc67c77p+7 + 0x1.739eec4511ad2p+6i, 0x1.14ec8bb9e6651p+7 + -0x1.73931631db13p+7i,
-0x1.c0710fe8dce65p+6 + 0x1.a6e7d427cb609p+8i, -0x1.0d7b8b0708b0ap+7 + -0x1.0a37724576bbp+6i,
-0x1.f7b6af037fe84p+5 + 0x1.235bc87032c25p+8i, -0x1.0dac8f4333c9fp+7 + 0x1.5d7616e9c1aefp+7i,
0x1.b4aa33ccffaeep+7 + 0x1.413869c69f40ep+6i, -0x1.f788fd3f7b3ecp+6 + 0x1.e58996104d933p+7i,
0x1.74f4dbf9f264p+5 + 0x1.fc2215a340cb5p+7i, 0x1.8763a9f43a55p+3 + 0x1.bc57437a0fb3ep+6i,
-0x1.d328249efa79p+6 + 0x1.f80293b72bf68p+7i, -0x1.073301a040aep+4 + 0x1.bf7e8fdbb6f8p+0i,
-0x1.2420ff058b72p+5 + 0x1.977f476b5186cp+6i, 0x1.427956096aeb4p+5 + 0x1.0ab1a41a893c2p+7i,
0x1.51f0fa07097a8p+7 + 0x1.3649f6ee84548p+7i, 0x1.4bfd8016fafe3p+5 + -0x1.5ae1cf3967fc7p+7i,
0x1.bcf24f9a6d172p+7 + 0x1.813717127ad61p+7i, -0x1.d627edfa44c97p+5 + 0x1.0427a074ef335p+7i,
0x1.40f3ee04c4fd6p+6 + -0x1.7322c68bd7ce6p+5i, 0x1.04a79556158cdp+7 + -0x1.c6a123e6f6404p+4i,
0x1.cd93ec9c9f13bp+6 + -0x1.8c54be5423409p+6i, 0x1.e67abe20ab938p+4 + -0x1.f298756d5370ep+5i,
0x1.5881b81f2021ep+5 + 0x1.24cc804edd7ep+5i, -0x1.82f095a6dc8b8p+4 + -0x1.ee0418fd2e138p+3i,
0x1.7c8ef769b1b94p+5 + -0x1.13f8f9799bee2p+5i, -0x1.8dc873c50d46cp+5 + -0x1.f6da4cba31668p+5i,
-0x1.25d4ae0a0825ep+5 + 0x1.21df6d0a06d08p+7i, -0x1.c03868ca8eb8cp+4 + -0x1.9fb6372ad7836p+5i,
0x1.667dab2fed5f6p+7 + -0x1.0b2d9d33a9d9ap+6i, -0x1.68e5b107f313fp+7 + -0x1.05e8299fb27c4p+5i,
-0x1.47ea723c29522p+5 + -0x1.3a74c1af2b905p+6i, -0x1.520b6fc4e760ap+6 + -0x1.0e273222a9f16p+7i,
0x1.4778cb2df35dp+4 + -0x1.e39753197627ep+6i, -0x1.58c89dbac822ap+7 + -0x1.e989a8bcee0c4p+4i,
-0x1.37c7109f2e356p+5 + -0x1.0d70ef0363dd6p+6i, -0x1.4d8660d5b5f3p+3 + 0x1.275ef54c3aec4p+6i,
0x1.9eadfc8fc3afcp+6 + 0x1.7545bdf2d4016p+2i, -0x1.1344feb4531eap+6 + -0x1.caff63cb7fc3bp+6i,
-0x1.cba7a4f604b87p+5 + -0x1.51abeca311e8cp+6i, -0x1.4f00a3076d6a7p+6 + -0x1.8b7465c27318p+4i,
0x1.ed4a72a038e7p+6 + -0x1.de1184a1ecc71p+5i, -0x1.cd6bd6699ba45p+6 + 0x1.a292c49bc6deep+5i,
-0x1.0a8c2720a1db4p+4 + -0x1.9c60f1dd9bbe2p+4i, -0x1.c04919ecf5ebfp+6 + 0x1.df4c546a7b49p+0i,
0x1.afb5cc1da5c19p+5 + -0x1.a5537045b45c8p+1i, -0x1.244cdf733136p+4 + 0x1.6788c5d3aafe8p+6i,
-0x1.8eafc8270ee08p+6 + -0x1.db23bd1db2db2p+6i, -0x1.8f8db18b177e1p+6 + 0x1.deb5f147429dcp+3i,
0x1.b0c8cc234e8eep+5 + -0x1.23cfaea91160ep+4i, -0x1.5d47c5a07c11ep+6 + 0x1.6af8ef123127fp+5i,
-0x1.05a341b6126bcp+4 + -0x1.3065774614f56p+5i, -0x1.7cbbff3ae7486p+6 + -0x1.06cda00ab19c4p+5i,
-0x1.4ff0cc421daap+3 + -0x1.2f50166cb3aebp+4i, 0x1.fe6bec3326eb7p+3 + 0x1.2f600fcb3278p+5i,
0x1.20ed4ebeb9c6ap+4 + -0x1.5cef9862bbbbdp+5i, -0x1.7f6abae0e243ep+3 + 0x1.eb8bb31f81ec2p+5i,
-0x1.0f295996b6494p+5 + -0x1.25855ca779b98p+6i, 0x1.93aa8d577c204p+5 + 0x1.358bc27e088bep+6i,
0x1.54f2baf11697p+4 + 0x1.37f697dd7ce84p+4i, -0x1.931e6e996bcbfp+3 + -0x1.45675131243aap+2i,
-0x1.975c1f71beb49p+4 + -0x1.2f9fd7314bc3p+4i, 0x1.aaf599e32c2p+3 + 0x1.14a89e3e0d201p+4i,
0x1.237c51515245dp+5 + -0x1.2774d7de6c2ap+4i, 0x1.f6afcbaf926d1p+4 + 0x1.2857fbb1daedep+6i,
-0x1.88a48b50b2ffap+4 + -0x1.9d6b88177c2eep+5i, -0x1.b34b5536830c2p+4 + -0x1.a5a640a5ccfdp+1i,
-0x1.6720d5db8ca5cp+3 + 0x1.bd6cdeb2f0466p+2i, 0x1.34bac0e67432bp+5 + 0x1.3cb9dffbc2e8ap+5i,
-0x1.84ee912c9530bp+5 + -0x1.a965598ec252ep+5i, -0x1.c63b330e198a1p+4 + -0x1.128625fa6935p+5i,
0x1.e70080610857p+4 + -0x1.6eac249bdbbe4p+2i, 0x1.10cf7188bd0c7p+4 + -0x1.5622c335f1e98p+1i,
-0x1.2f4f1f1eba49ap+6 + 0x1.e008a51bfdebap+3i, -0x1.fa830c647b8f8p+1 + -0x1.29a8eeba1126cp+5i,
-0x1.61cc20163980ap+4 + -0x1.32126dc5675bep+5i, -0x1.209c1af912587p+4 + -0x1.7930fe1fa7bd8p+4i,
0x1.640a806703713p+3 + -0x1.bbf36cbd7e48ep+4i, -0x1.cebf46243ac7p+4 + -0x1.883e75bdcb012p+5i,
0x1.1bbb58b7e3384p+2 + -0x1.ca5d3714d7382p+4i, 0x1.2ea847e13a746p+6 + 0x1.be55b8ea0117fp+4i,
-0x1.6927c2c7d083p+4 + -0x1.69cb350361478p+2i, -0x1.35556b4d44b0bp+5 + 0x1.ad1f8f2f3bd4p-1i,
0x1.ef467a090f5b8p+1 + -0x1.78c817d70576p+5i, 0x1.2201eddb45c2p+6 + -0x1.2d7654b4ebf54p+0i,
0x1.0ada226837e6p+3 + 0x1.f675d431cd675p+3i, 0x1.4706aa689e621p+5 + 0x1.c3d2495a0f24p+0i,
0x1.2967d4eb7bf0ep+5 + -0x1.82f9d4f954b46p+4i, -0x1.9e6588ff46b19p+3 + 0x1.08fa4cc8c433bp+4i,
-0x1.0fa4fa96b7018p+1 + 0x1.836f1414efc3ep+2i, 0x1.5a1da187679afp+4 + -0x1.7ed072ae08e4p-1i,
-0x1.e85bcd3231b32p+5 + -0x1.eb2af615dd14p+5i, -0x1.1c5a82e93f4cep+5 + 0x1.bddb3ea5e4f07p+3i,
0x1.c7287287c157cp+4 + -0x1.5068075941426p+2i, -0x1.f5fe9201b8bf4p+2 + 0x1.236fc7326bc9p+5i,
-0x1.f080ca7775e2ep+5 + -0x1.dd3b732020d1p+2i, 0x1.cc45cab497e66p+3 + -0x1.5d81466a5c70cp+4i,
-0x1.2f72193de7p-3 + -0x1.95542b6e9623p+3i, 0x1.dd24119b54d4p+4 + 0x1.9dbcbf241045cp+4i,
0x1.456876ab7899cp+5 + -0x1.a1b8442c3749bp+5i, -0x1.9120e785a4ed6p+4 + -0x1.8e639d9b8ca8bp+4i,
-0x1.00eba496dcd8dp+4 + 0x1.c128110bb8189p+4i, 0x1.1a0f297db953cp+5 + -0x1.c43cac5088cfcp+2i,
-0x1.54f062d3f6943p+4 + -0x1.b1aaf3cb595ep+4i, -0x1.1437ca560e504p+4 + 0x1.4d79df00983p+2i,
-0x1.6785ef67c458dp+3 + -0x1.6fde85912419cp+3i, 0x1.2797cdca31354p+3 + -0x1.33355f1778cc2p+5i,
0x1.50989f6308a78p+2 + 0x1.e8dbf927f252ap+4i, 0x1.0daf73fa064fep+2 + -0x1.76a4e83015d21p+5i,
-0x1.c6d9676062facp+4 + -0x1.11fd65b88b04p+4i, -0x1.716b29c77fde3p+4 + 0x1.26fc966828edbp+6i,
0x1.eaf72b2a68114p+5 + -0x1.7c2c16b579cf6p+4i, -0x1.1ac85a7c85cdp-2 + -0x1.2e6f175ae715fp+5i,
-0x1.4f41b92b93876p+5 + -0x1.29e3efa5ed026p+5i, 0x1.28d098492969p+0 + 0x1.34a115d076ab6p+6i,
0x1.710c9c07f56dp+5 + -0x1.ebcfa3ba4d1dap+6i, -0x1.17d2eab115cf8p+4 + -0x1.82e2d9f805f34p+4i,
0x1.8788610dcef2ep+5 + 0x1.17b237a573033p+5i, 0x1.3bed91618ab55p+2 + 0x1.2014c92629dc6p+6i,
0x1.0ff79d3340ff8p+4 + -0x1.245d774d639bep+4i, 0x1.09df32d09ff7fp+4 + 0x1.016eb38f13a2ap+4i,
0x1.2c8c333b71b97p+6 + -0x1.d4e4b288c1b95p+4i, -0x1.34acb3709a898p+5 + 0x1.7eaa48571cc0fp+7i,
0x1.4f6b497882845p+6 + 0x1.c3c0ef49f2f0cp+4i, 0x1.eb46295c4152ep+5 + -0x1.9ff2e8e9d408p+5i,
0x1.62411222bf00ap+6 + -0x1.e97c2ed335adcp+3i, -0x1.79cccb077adacp+3 + 0x1.318bfab6006fp+7i,
0x1.87a2eed400e5ep+4 + 0x1.6249dbd1ddc2fp+4i, 0x1.4c13d94136a16p+6 + -0x1.392fa95c7d78p+6i,
0x1.b488fc8b5f85cp+5 + 0x1.b4ecb6567cb77p+3i, -0x1.6feccc3a535b8p+3 + 0x1.a5cdf908cda7fp+6i,
-0x1.e14c15df4251cp+4 + 0x1.af0296756fdfp+2i, 0x1.a12b3f5e289f2p+6 + -0x1.ed9030f31ced6p+4i,
0x1.0000105e77d6cp+2 + -0x1.7773ec5fda0f2p+6i, -0x1.829836606cb85p+6 + -0x1.23ad659068658p+3i,
-0x1.015c7d27626cdp+6 + -0x1.5ce38bd7f9a7ap+5i, 0x1.414c4b2f47ad4p+7 + -0x1.b2b13b8e2595ep+4i,
-0x1.8474133f87bd6p+5 + 0x1.8df74a48702b4p+4i, -0x1.34c45ce11dbf8p+6 + 0x1.ac3423495cab6p+4i,
0x1.d589d37d25d7cp+5 + 0x1.aeec6de81534fp+5i, 0x1.e071769bf0e64p+5 + 0x1.a8321403efa57p+6i,
-0x1.cb2da04146bdcp+4 + 0x1.eea2a7a9c4d76p+5i, -0x1.e285a8ea9e73ap+5 + 0x1.9163fb43afc48p+6i,
-0x1.9c4324ca6cdbap+4 + -0x1.2fe3f90e2795fp+5i, -0x1.582a7b195cc73p+6 + 0x1.98159d26fc33dp+7i,
0x1.e0b5d578663b8p+5 + 0x1.3f5b78a154db5p+6i, 0x1.74f99f04333c8p+6 + 0x1.5bbc9f8eec941p+6i,
-0x1.3e073dd2c539p+7 + 0x1.134968213e702p+7i, 0x1.19b8f56444c84p+6 + 0x1.6c3f025667e55p+7i,
0x1.710ddebed9802p+7 + 0x1.cab86548644fap+6i, -0x1.2c698457e5f47p+6 + 0x1.6b0c3c97a7288p+6i,
-0x1.42648846cfed7p+5 + -0x1.d85f56d1116bep+6i, 0x1.0f37020950b2dp+6 + -0x1.82736062576b8p+5i,
0x1.a3d478dcc43adp+6 + -0x1.73892a5aaf07ep+7i, 0x1.161aad24d1002p+8 + 0x1.ac2d95b465c3cp+5i,
0x1.2159284a6f6dbp+7 + -0x1.fb6cb333477c6p+8i, 0x1.4a952353424f2p+7 + 0x1.e038d7953133cp+5i,
-0x1.7463f753a71a9p+7 + -0x1.c8e0fd46f5933p+7i, 0x1.898a7e3be3558p+8 + -0x1.1174706632b78p+8i,
0x1.fb56d1916457ap+5 + -0x1.5fb569977f614p+6i, 0x1.3dbdef979f448p+7 + -0x1.77e2a54e81bd2p+7i,
-0x1.f15743d0ab3e6p+8 + 0x1.5bb49547381a3p+6i, -0x1.0ebb272ba8ebep+6 + -0x1.68be64b99b7ebp+7i,
0x1.35047fab664e5p+6 + -0x1.984f493d589b4p+8i, -0x1.ab8119a576f7cp+3 + 0x1.7257a58220a95p+7i,
-0x1.f53cb1e6e5df4p+8 + -0x1.393d0b63f1bebp+7i, -0x1.2654525c01dcdp+7 + -0x1.02fb32a02505bp+7i,
-0x1.89a2ce71355c4p+3 + -0x1.cd8648d4cb191p+6i, 0x1.cef844f323daap+5 + 0x1.a64caa3c0779ep+8i
)
assertThat(stats:::fft(z=c(-7.15819670452361, 0.110255314982191, -3.48914353236225, -5.87497659701262,
-0.199362647840113, -16.4525265946458, -6.03222347742571, -3.92614999642132,
-29.8889981257789, -7.09076953338402, -0.222630216361647, -36.9739754380066,
-11.4770101680298, -0.308884804040162, -48.039088958724, 0.253785279122959,
-26.0509453467696, -27.2922715965335, -0.300724712814251, -23.6391349989218,
-4.54658732908124, -4.94867893197349, -0.341259462777404, -0.625167487518708,
-0.114385753785174, -0.0767324692224788, 0.614300312477045, 0.0131282889107916,
1.07408025950145, -1.32710351817283, -0.108290218119744, -0.289110554262111,
-0.396748345989383, 1.9410214912765, 0.372492214249686, -0.824264384163732,
-4.61783087501709, -2.88728067599778, -2.17623608536996, -4.96050632352764,
0.0373300106654156, -1.92988623796856, -8.64401146357585, -0.0282593716171552,
-2.18593858103637, -8.68605511023393, 2.38038740026519, -0.711708232340793,
-7.31861977980452, 1.66158838103957, -0.896089679328537, -0.233771738581161,
-3.71661440304846, -1.82227154585777, 0.256795401715731, -10.1241299791316,
-2.30958932957345, -1.16490906254227, -4.11235704125641, -5.33718212378153,
0.485222179569908, -1.07824867748324, -5.14912601521273, 1.53226358732353,
-0.684558953341767, 0.477956551316482, -4.11900441553011, 0.418754304890273,
-0.383083866170827, -7.97181970755405, 1.0269399842436, -1.92091437753192,
-4.64420774827086, 1.68380329506172, -3.89559841155951, -0.978698177417727,
-0.75459101514509, -6.96976603105698, 0.377355050937388, -1.92285642379862,
-4.55934545650533, 0.643516719844505, -1.99522205145459, -2.31223904437235,
-1.52479476089734, 1.16770433924122, -3.15384436065269, -1.98974677597651,
1.33810909435721, -0.00505273688004622, 0.609130542293436, 0.984918956632043,
0.000967866009781687, 1.15176881104263, 0.457084361268859, 1.00479872252607,
-1.73643562227572, -1.36764351165645, 0.615247420757093, 1.41003786046067,
-1.80681905857143, -0.554075116861985, -5.00887947661957, -0.858399231618332,
-5.2413214929228, -18.4623550054035, -4.42492627100836, -5.43042296442198,
-31.7711610636777, -9.17349821272494, -4.83931965531691, -13.8691761646829,
5.99360349714817, -8.05821791289218, 4.27274603500634, -8.80791491153245,
-8.96201150485753, -0.538156308551415, -13.7372701219991, -3.83277861929957,
-0.577985322182915, -6.13463994465355, 0.579745921102388, -5.15991440871385,
-0.0996802890502659, -1.12855998192496, -5.506045862697, 0.0760896631962742,
-4.84381896467133, -4.24546473312554, 1.15685389078641, -3.72217338383406,
-5.61023207478232, -0.518712149200282, -4.81966298476001, -0.915191938725926,
1.02317367334019, 1.40283187845736, 0.840011531157073, 2.54849196975158,
-1.28326157748604, 0.296497506714737, -2.8565083686299, -0.00452044049872998,
-0.121981917151517, -6.16027434926615, -0.00506597639971598,
-2.66758921841215, -10.5579565604083, -1.62863059318314, -13.9013996696183,
-12.6273631864582, 1.28039582686027, 3.09836921856781, 1.51273587008052,
1.03291877132337, -1.24641006909649, -0.235203840904289, -1.28936792849172,
-0.0835383756348976, 0.803424954248551, -1.75104913325774, 0.109629740873643,
-3.36436562962488, -0.046942203599961, -6.32766563380515, -8.96478334614007,
-0.0758160015765137, -4.60068588254512, -16.9605263185831, -2.4513209393517,
-5.07017402385314, -15.6092894774963, 2.75046116510564, -12.1943508557121,
-8.92573565546724, -0.461240700458072, -16.3639719153864, -4.47458975534417,
0.223806932863578, -9.73989554590262, -5.97913919382373, 1.5105081805112,
-8.28656884869639, 0.154429266740954, -7.84197070793348, -5.6961960547203,
-0.0521569627526388, -5.82791208218465, -3.02427648874163, 0.133104377667652,
-0.189281160079311, 0.613203017176358, 0.00297304925698635, -0.100271146242006,
1.04927277195552, -0.0199823019711895, -1.45149024684856, 1.25434062175162,
0.778436302570509, -0.608519494892313, 0.440907811609158, -0.474302974674083,
0.0338302758764299, -2.10507185732011, -0.898890624635911, 0.26418179549768,
-4.84257476903016, 3.13622768834639, -10.3284779263283, 3.60193072162944,
-5.07486166952205, 1.47075640671491, -2.59232958335453, 3.96397554584659,
-1.22401252505758, 1.28312505630325, -4.3395183130406, -6.38612891192683,
-1.13720402016854, -7.17313760304412, -0.0154549740373913, -3.50996802171922,
-1.92956427890303, -0.0174563249602141, -4.56515778296751, -2.14371607949166,
-3.61657494315927, -7.31849812170335, -11.0563317270459, 2.83896706502344,
-16.0094287337996, 1.98420616588948, -10.7564015063533, -13.9558227657496,
-1.84063825671323, -42.4044983014428, -1.0206124731377, -4.18480479977434,
-43.2549955444102, -0.594176745518253, -5.37436416741231, -24.411492910598,
5.89047841556017, -26.5194928052969, 5.02938874924396, -13.3832261976622,
-15.0617775751774, -0.773989314112271, -8.16434400350765, -0.236860690761725,
0.0722131767937754, -0.76428481821163, -0.0725656396395854, -0.0970454979446763,
0.0270376103527894, -0.490432969552532, -1.16029995984957, -0.0736796072251184,
-1.17315727258434, -4.05940736505419, 0.138629060920818, -6.71310986794777,
-3.82874076491464, -0.424045277865107, -8.47762849169003, 2.07189149486188,
-15.5626878117142, -3.32468462701773, -6.29844278402556, -20.8589660456123,
-0.721594286754113, -15.4729942238103, -23.3812039274025, -1.42421504647167,
-11.9579915786702, -27.2396057372332, -3.59011638853979, -15.1381245353494,
-17.526750847862, 2.97255035818552, -16.129297217086, 0.876679286718808,
-1.30542775993246, -9.436565023882, 0.0590987446774052, -0.763946612939243,
-4.81382153844393, -0.0848688802808428, -3.43008551615109, -1.70501351066984,
0.496746570757065, -4.419159645439, -0.70382542690878, -3.75190031477674,
-0.0462784501551708, 0.623820532117866, -3.22732837900555, 0.0382740191211295,
-1.85803143742927, 0.597343669499164, -1.63800332956934, -2.6333594883176,
-0.582891107446426, -2.41961836924216, -1.19225287806285, -2.72739009066484,
-4.13365031731353, -0.983373301454717, -1.39459235722949, -6.63538261146678,
-3.96137643031749, -0.787062834086072, -13.9169913441169, -1.20420505683255,
-4.97142608837069, -18.8895390552947, 0.140227906234822, -8.73566804190373,
-16.441363711976, 1.7279722702286, -4.27862567765539, -13.7830376912835,
-5.69461232430024, -2.23460457974009, -4.40899690633133, 1.09769935856464,
-2.678207576471, -1.68733773268793, -1.11289954129617, -10.0197768431525,
0.179314786925604, -7.70253207464919, -16.2903830602222, -0.34635191050428,
-25.4493886671878, -6.69369235815694, -9.22691152795012, -21.6813262552328,
0.441049317496584, -13.3083099159783, -14.3044346847961, -0.540406991848385,
-22.1981146405202, -13.6094053694029, -7.84329594401468, -37.393712225402,
-11.3923876846212, -10.002997057252, -31.8681583747117, -0.429157196291696,
-13.8653361326185, -11.3097241075593, 0.565929063136098, -21.772611967141,
-0.947586203135595, -21.2965120426077, -19.1741706993877, 0.685197778079437,
-14.5720767953138, -19.2524207625041, -2.65202463181875, -14.6221046002996,
-0.331543605318902, -4.73153171834871, -21.7761590225422, 0.0392987874669245,
-8.93087022050141, -10.1744279727116, 0.983564568303662, -2.40723371003616,
0.632171874628587, -0.937872539111691, 0.990147393152718, -0.163950772662844,
0.596982411163802, -0.267196859784088, -0.460561089786097, -0.591535269936192,
0.0976022529288891, -0.5946562475941, -0.857815187921029, -0.0615396925484975,
-2.35427234048284, -2.12780837147864, 0.292058339898327, -7.55726674154101,
1.45174429934292, -7.97678097269065, -1.75007902404576, -3.97192466313402,
-11.4308612187384, 0.513217011573376, -12.6265942036126, -7.88334131728564,
0.547398597122868, -8.59060678670501, -8.9680320874082, -0.4266818235921,
-9.56315837918168, -7.74300697465212, 1.43659419374979, -7.83086784695056,
-5.59462406190873, -5.18044488876905, -6.09860688356103, 3.05312845517547,
-5.0778038579875, -3.13089504565841, -3.40271273866243, -7.25972410094478,
1.19722591186143, -10.3328728235165, -3.1108565012105, -4.0398134593185,
-14.0858568594959, 1.80232474015431, -11.8667072572156, -10.1615059709618,
-1.64135375395728, -8.56933500959885, -2.65819750093737, -0.415251967311957,
-0.410527840933909, -0.690675755056803, -0.640287651561469, -0.022302161916274,
-0.0218293452728281, 0.0921834722294081, -0.0507932392168763,
-0.0282460272024155, -0.0998101412228079, 0.156057867448074,
-1.28240232636664, -0.195846563371405, 1.12470127279208, -2.01802756137791,
0.139953280554965, -5.48778652946471, -3.22208788704005, 0.71289312580309,
-10.3924015007937, -9.83103153860035, 0.673354144262813, -23.5858346021631,
-7.96333612277547, -3.04028819515916, -15.1537981749156, 1.67402037216778,
-15.220757103962, 1.01093199693031, -2.55053156499774, -4.91781241843231,
0.270583898449446, -6.95825839957177, -1.13431292594513, 0.0704955835920941,
3.06721052689997, -1.19044549748404, 0.208047711897964, 0.595911309886204,
-4.15243413321848, -8.53319957955728, -0.836951674685598, -10.7049196213065,
-12.922621375839, 4.13957886438286, -2.47611037619287))
, identicalTo( expected, tol = 1e-6 ) )
|
moduleServer <- function(id, module){
shiny::callModule(module, id)
}
highlightText <- function(text, value){
value <- sub('^"', '', sub('"$', '', value))
value <- gsub("[[:punct:]]", ".?", value)
return(unlist(lapply(
text,
function(x){
if(is.na(x)){
return(x)
}
p <- gregexpr(value, x, ignore.case=TRUE)[[1]]
if(p[1]>0){
toRet <- c(substr(x, 0, p[1]-1))
for(i in 1:length(p)){
toRet <- c(
toRet,
'<mark style="background-color:yellow;font-weight:bold;">',
substr(x, p[i], p[i]+attr(p, "match.length")[i]-1),
'</mark>',
substr(
x,
p[i]+attr(p, "match.length")[i],
min(
p[i+1]-1,
nchar(x)+1,
na.rm=TRUE
)
)
)
}
toRet <- paste(toRet, collapse="")
}else{
toRet <- x
}
return(toRet)
}
)))
}
beidsServer <- function(
id,
toGene=TRUE,
multiple=FALSE,
beOfInt=NULL, selectBe=TRUE,
orgOfInt=NULL, selectOrg=TRUE,
tableHeight=150
){
if(toGene){
selectBe <- FALSE
beOfInt <- c(listBe(), "Probe")
}
moduleServer(id, function(input, output, session) {
allOrg <- sort(listOrganisms())
allBe <- c(listBe(), "Probe")
ni <- 1
if(selectOrg){
ni <- ni+1
}
if(selectBe){
ni <- ni+1
}
cw <- 12 %/% ni
output$mainUI <- shiny::renderUI({
shiny::fluidRow(shiny::column(12,
shiny::fluidRow(
shiny::column(
cw,
shiny::textInput(
inputId=shiny::NS(id, "beSearchTerm"),
label="Search a gene",
placeholder='e.g. snca, ENSG00000186868, "M-CSF receptor"',
width="100%"
)
),
if(selectBe){
shiny::column(
cw,
shiny::selectizeInput(
inputId=shiny::NS(id, "beFocus"),
label="Focus on BE",
choices=allBe,
selected=beOfInt,
multiple=TRUE,
width="100%"
)
)
},
if(selectOrg){
shiny::column(
cw,
shiny::selectizeInput(
inputId=shiny::NS(id, "beOrganisms"),
label="Focus on organisms",
choices=allOrg,
selected=orgOfInt,
multiple=TRUE,
width="100%"
)
)
}
),
shiny::fluidRow(
shiny::column(
12,
DT::DTOutput(
shiny::NS(id, "searchRes")
)
)
)
))
})
appState <- shiny::reactiveValues(
orgOfInt=orgOfInt,
beOfInt=beOfInt,
matches=NULL,
genes=NULL,
fmatches=NULL,
fgense=NULL,
geneEntity=NULL,
sel=NULL
)
if(selectOrg){
shiny::observe({
selOrg <- input$beOrganisms
if(length(selOrg)==0){
appState$orgOfInt <- allOrg
}else{
appState$orgOfInt <- selOrg
}
appState$sel <- NULL
})
}
if(selectBe){
shiny::observe({
selBe <- input$beFocus
if(length(selBe)==0){
appState$beOfInt <- allBe
}else{
appState$beOfInt <- selBe
}
appState$sel <- NULL
})
}
shiny::observe({
v <- input$beSearchTerm
if(is.null(v)){
m <- g <- NULL
}else{
shiny::withProgress(
message="Searching genes",
value=0,
style="notification",
expr={
m <- searchBeid(v)
}
)
if(is.null(m) || nrow(m)==0){
m <- g <- NULL
}else{
.data <- NULL
g <- dplyr::mutate(m, order=1:nrow(m))
g <- dplyr::mutate(
g, url=getBeIdURL(.data$GeneID, .data$Gene_source)
)
g <- dplyr::group_by(g, .data$Gene_entity, .data$organism)
g <- dplyr::summarise(
g,
order=min(.data$order),
value=ifelse(
length(unique(.data$value)) <= 2,
paste(unique(.data$value), collapse=", "),
paste(
c(head(unique(.data$value), 2), "..."),
collapse=", "
)
),
from=paste(unique(ifelse(
.data$from %in% c("BESymbol", "BEName"),
stringr::str_replace(
.data$from, "^BE", paste(.data$be, " ")
),
sprintf(
'%s%s',
.data$from,
ifelse(
!is.na(.data$symbol),
ifelse(
!is.na(.data$name),
sprintf(': %s (%s)', .data$symbol, .data$name),
sprintf(': %s', .data$symbol)
),
ifelse(
!is.na(.data$name),
sprintf(' (%s)', .data$name),
''
)
)
)
)), collapse=", "),
symbol=paste(setdiff(.data$symbol, NA), collapse=", "),
name=paste(setdiff(.data$name, NA), collapse=", "),
GeneIDs=paste(unique(sprintf(
'<a href="%s" target="_blank">%s</a>',
url,
highlightText(
sprintf(
'%s%s%s',
ifelse(.data$preferred_gene, "<u><strong>", ""),
.data$GeneID,
ifelse(.data$preferred_gene, "</strong></u>", "")
),
!!v
)
)[order(.data$preferred_gene, decreasing=T)]), collapse=","),
Gene_symbol=paste(
setdiff(.data$Gene_symbol, NA), collapse=", "
),
Gene_name=paste(
setdiff(.data$Gene_name, NA), collapse=", "
)
)
g <- dplyr::arrange(g, .data$order)
g <- dplyr::select(
g,
"value", "from",
"Gene_symbol", "Gene_name", "organism", "GeneIDs",
"Gene_entity"
)
g <- dplyr::ungroup(g)
}
}
if(!is.null(m)){
m <- dplyr::rename(m, "match"="value")
}
if(!is.null(g)){
g <- dplyr::rename(g, "match"="value")
}
appState$matches <- m
appState$genes <- g
appState$sel <- NULL
})
shiny::observe({
fmatches <- appState$matches[
which(
appState$matches$organism %in% appState$orgOfInt &
appState$matches$be %in% appState$beOfInt
),
]
if(!is.null(fmatches) && nrow(fmatches)==0){
fmatches <- NULL
}else{
if(!toGene && !is.null(fmatches)){
fmatches <- dplyr::distinct(dplyr::select(
fmatches,
"match", "from", "be", "beid", "source", "preferred",
"symbol", "name", "entity", "organism"
))
}
}
fgenes <- appState$genes[
which(
appState$genes$organism %in% appState$orgOfInt
),
]
if(!is.null(fgenes) && nrow(fgenes)==0){
fgenes <- NULL
}
appState$fmatches <- fmatches
appState$fgenes <- fgenes
appState$sel <- NULL
})
output$searchRes <- DT::renderDataTable({
v <- input$beSearchTerm
if(toGene){
toShow <- appState$fgenes
shiny::req(toShow)
toShow <- dplyr::select(
dplyr::mutate(
toShow,
Match=highlightText(.data$match, !!v),
From=highlightText(.data$from, !!v),
Symbol=highlightText(.data$Gene_symbol, !!v),
Name=highlightText(.data$Gene_name, !!v),
Organism=as.factor(.data$organism)
),
"Match",
"Symbol", "Name", "Organism", "GeneIDs",
)
}else{
toShow <- appState$fmatches
shiny::req(toShow)
toShow <- dplyr::select(
dplyr::mutate(
toShow,
Match=highlightText(.data$match, !!v),
From=highlightText(.data$from, !!v),
Symbol=highlightText(.data$symbol, !!v),
Name=highlightText(.data$name, !!v),
Organism=as.factor(.data$organism),
ID=sprintf(
'<a href="%s" target="_blank">%s</a>',
getBeIdURL(.data$beid, .data$source),
highlightText(.data$beid, !!v)
)
),
"Match",
"BE"="be", "Symbol", "Name", "Organism", "ID",
"Source"="source", "Preferred"="preferred"
)
}
toShow <- DT::datatable(
toShow,
rownames=FALSE,
escape=FALSE,
selection=list(
mode=ifelse(multiple, "multiple", "single"),
target="row"
),
options=list(
dom="t",
paging=FALSE,
scrollResize=TRUE,
scrollY=tableHeight,
scrollCollapse=TRUE
)
)
if(!toGene){
DT::formatStyle(
toShow, "Preferred",
backgroundColor=DT::styleEqual(
c(TRUE, FALSE), c('darkgreen', 'transparent')
),
color=DT::styleEqual(
c(TRUE, FALSE), c('white', 'black')
)
)
}else{
toShow
}
})
shiny::observe({
appState$sel <- input$searchRes_rows_selected
})
return(shiny::reactive({
sel <- appState$sel
g <- appState$fgenes
m <- appState$fmatches
if(
length(sel)==0 ||
is.null(g) || nrow(g)==0 ||
is.null(m) || nrow(m)==0
){
return(NULL)
}else{
if(toGene){
ge <- unique(g$Gene_entity[sel])
toRet <- unique(m[
which(m$Gene_entity %in% ge),
c(
"GeneID", "preferred_gene", "Gene_source", "organism",
"Gene_entity"
)
])
colnames(toRet) <- c(
"beid", "preferred", "source", "organism", "entity"
)
if(nrow(toRet)>0){
toRet$be <- "Gene"
toRet <- dplyr::left_join(
toRet,
g[,c("Gene_entity", "match")],
by=c("entity"="Gene_entity")
)
toRet <- toRet[
,
c(
"beid", "preferred", "be", "source", "organism",
"entity", "match"
)
]
}
}else{
toRet <- m[
sel,
c(
"beid", "preferred", "be", "source", "organism",
"entity", "match"
)
]
}
return(toRet)
}
}))
})
}
beidsUI <- function(id) {
shiny::uiOutput(outputId=NS(id, "mainUI"))
}
|
returnReferences <- function(names,targets,file,level=2) {
if(length(names)!=length(targets)) stop("names and targets must have the same lengths!")
x <- NULL
zz <- textConnection("x",open = "w", local=TRUE)
.header(zz,"References",level=level)
close(zz)
for(i in 1:length(names)) {
x <- c(x,paste0("[",names[i],"]: ",targets[i]))
}
writeLines(x,file)
}
|
plot.pedigree <- function(x, id = x$id, sex = x$sex, status = x$status,
affected = x$affected,
cex = 1, col = rep(1, length(x$id)),
symbolsize = 1, branch = 0.6,
packed = T, align = packed, width = 8,
density=c(-1, 50,70,90), mar=c(4.1, 1, 4.1, 1),
angle=c(90,70,50,0), keep.par=F,
extraInfo = NULL,
...)
{
col[is.na(affected)] <- "red"
maxlev <- max(x$depth) + 1
n <- length(x$depth)
sex <- as.numeric(sex)
sex[is.na(sex)] <- 3
if(any(sex < 1 | sex > 4))
stop("Invalid sex code")
if(length(sex) != n)
stop("Wrong length for sex")
if(is.null(status))
status <- rep(0, n)
else {
if(!all(status == 0 | status == 1 | status == 2))
stop("Invalid status code")
if(length(status) != n)
stop("Wrong length for status")
}
if(!is.null(id)) {
if(length(id) != n)
stop("Wrong length for id")
}
symbol <- c(0, 1, 5, 2)[sex]
points.sym <- function(x, y, symbol, status, affected, size, col, aspect,
angle, density, adj)
{
circle <- function(cx, cy, r, code=0, col=1, angle, density, ...)
{
z <- (0:360 * pi)/180
pin <- par()$pin
usr <- par()$usr
adj <- (pin[2]/pin[1])/((usr[4] - usr[3])/(usr[2] - usr[1]))
x <- sin(z) * r + cx
y <- cos(z) * r * 1/adj + cy
if(sum(code,na.rm=T)==0) polygon(x, y, border=T,
density=0,col=col, ...)
else {
if(length(code)==1) polygon(x,y,border=T,col=col,
density=density[1], angle=angle[1],...)
if(length(code)==2) {
polygon(x,y,border=T,density=0, ...)
z <- (0:180 * pi)/180
x <- sin(z) * r + cx
y <- cos(z) * r * 1/adj + cy
polygon(x,y,border=T,col=col,density=density[2]*code[2],
angle=angle[2], ...)
z <- (180:360 * pi)/180
x <- sin(z) * r + cx
y <- cos(z) * r * 1/adj + cy
polygon(x,y,border=T,col=col,density=code[1]*density[1],
angle=angle[1], ...)
}
if(length(code)==3) {
polygon(x,y,border=T,density=0, ...)
z <- (0:90 * pi)/180
x <- c(cx,sin(z) * r + cx)
y <- c(cy,cos(z) * r * 1/adj + cy)
polygon(x,y,border=T,col=col,density=code[3]*density[3],
angle=angle[3],...)
z <- (180:270 * pi)/180
x <- c(cx,sin(z) * r + cx)
y <- c(cy,cos(z) * r * 1/adj + cy)
polygon(x,y,border=T,col=col,density=code[1]*density[1],
angle=angle[1], ...)
z <- (270:360 * pi)/180
x <- c(cx, sin(z) * r + cx)
y <- c(cy, cos(z) * r * 1/adj + cy)
polygon(x,y,border=T,col=col,density=code[2]*density[2],
angle=angle[2], ...)
}
if(length(code)==4) {
polygon(x,y,border=T,density=0, ...)
z <- (0:90 * pi)/180
x <- c(cx,sin(z) * r + cx)
y <- c(cy,cos(z) * r * 1/adj + cy)
polygon(x,y,border=T,col=col,density=code[3]*density[3],
angle=angle[3], ...)
z <- (90:180 * pi)/180
x <- c(cx,sin(z) * r + cx)
y <- c(cy,cos(z) * r * 1/adj + cy)
polygon(x,y,border=T,col=col,density=code[4]*density[4],
angle=angle[4],...)
z <- (180:270 * pi)/180
x <- c(cx,sin(z) * r + cx)
y <- c(cy,cos(z) * r * 1/adj + cy)
polygon(x,y,border=T,col=col,density=code[1]*density[1],
angle=angle[1], ...)
z <- (270:360 * pi)/180
x <- c(cx, sin(z) * r + cx)
y <- c(cy, cos(z) * r * 1/adj + cy)
polygon(x,y,border=T,col=col,density=code[2]*density[2],
angle=angle[2], ...)
}
if(length(code)>4) stop('Can only plot up to 4 levels of codes')
}
invisible()
}
square <- function(cx, cy, r, code=0, col=1, angle, density, ...) {
pin <- par()$pin
usr <- par()$usr
adj <- (pin[2]/pin[1])/((usr[4] - usr[3])/(usr[2] - usr[1]))
x <- cx + c(-r,-r,r,r)
y <- cy + (1/adj)*c(-r,r,r,-r)
if(sum(code,na.rm=T)==0) polygon(x,y,border=T,density=0, col=col,...)
else {
if(length(code)==1) polygon(x,y,border=T,col=col,
density=density[1], angle=angle[1], ...)
if(length(code)==2) {
polygon(x,y,border=T,density=0, ...)
x <- cx + c(-r,-r,0,0)
polygon(x,y,border=T,col=col,density=code[1]*density[1],
angle=angle[1], ...)
x <- cx + c(0,0,r,r)
polygon(x,y,border=T,col=col,density=density[2]*code[2],
angle=angle[2], ...)
}
if(length(code)==3) {
polygon(x,y,border=T,density=0, ...)
x <- cx + c(-r,-r,0,0)
y <- cy + (1/adj)*c(-r,0,0,-r)
polygon(x,y,border=T,col=col,density=code[1]*density[1],
angle=angle[1], ...)
x <- cx + c(-r,-r,0,0)
y <- cy + (1/adj)*c(0,r,r,0)
polygon(x,y,border=T,col=col,density=code[2]*density[2],
angle=angle[2], ...)
x <- cx + c(0,0,r,r)
y <- cy + (1/adj)*c(0,r,r,0)
polygon(x,y,border=T,col=col,density=density[3]*code[3],
angle[3], ...)
}
if(length(code)==4) {
polygon(x,y,border=T,density=0, ...)
x <- cx + c(-r,-r,0,0)
y <- cy + (1/adj)*c(-r,0,0,-r)
polygon(x,y,border=T,col=col,density=code[1]*density[1],
angle=angle[1], ...)
x <- cx + c(-r,-r,0,0)
y <- cy + (1/adj)*c(0,r,r,0)
polygon(x,y,border=T,col=col,density=code[2]*density[2],
angle=angle[2], ...)
x <- cx + c(0,0,r,r)
y <- cy + (1/adj)*c(0,r,r,0)
polygon(x,y,border=T,col=col,density=code[3]*density[3],
angle=angle[3], ...)
x <- cx + c(0,0,r,r)
y <- cy + (1/adj)*c(-r,0,0,-r)
polygon(x,y,border=T,col=col,density=code[4]*density[4],
angle[4], ...)
}
if(length(code)>4) stop('Can only plot up to 4 levels of codes')
}
invisible()
}
diamond <- function(cx, cy, r, code=0, col=1, angle, density, ...) {
pin <- par()$pin
usr <- par()$usr
adj <- (pin[2]/pin[1])/((usr[4] - usr[3])/(usr[2] - usr[1]))
x <- cx + c(-r,0,r,0)
y <- cy + (1/adj)*c(0,r,0,-r)
if(sum(code,na.rm=T)==0) polygon(x,y,border=T,density=0,col=col, ...)
else {
if(length(code)==1) polygon(x,y,border=T,col=col,
density=density[1], angle=angle[1], ...)
if(length(code)==2) {
polygon(x,y,border=T,density=0, ...)
x <- cx + c(-r,0,0)
y <- cy + (1/adj)*c(0,r,-r)
polygon(x,y,border=T,col=col,density=code[1]*density[1],
angle=angle[1], ...)
x <- cx + c(0,0,r)
y <- cy + (1/adj)*c(r,-r,0)
polygon(x,y,border=T,col=col,density=density[2]*code[2],
angle=angle[2], ...)
}
if(length(code)==3) {
polygon(x,y,border=T,density=0, ...)
x <- cx + c(-r,0,0)
y <- cy + (1/adj)*c(0,0,-r)
polygon(x,y,border=T,col=col,density=code[1]*density[1],
angle=angle[1], ...)
x <- cx + c(-r,0,0)
y <- cy + (1/adj)*c(0,r,0)
polygon(x,y,border=T,col=col,density=code[2]*density[2],
angle=angle[2], ...)
x <- cx + c(0,0,r)
y <- cy + (1/adj)*c(0,r,0)
polygon(x,y,border=T,col=col,density=density[3]*code[3],
angle=angle[3], ...)
}
if(length(code)==4) {
polygon(x,y,border=T,density=0, ...)
x <- cx + c(-r,0,0)
y <- cy + (1/adj)*c(0,0,-r)
polygon(x,y,border=T,col=col,density=code[1]*density[1],
angle=angle[1], ...)
x <- cx + c(-r,0,0)
y <- cy + (1/adj)*c(0,r,0)
polygon(x,y,border=T,col=col,density=code[2]*density[2],
angle=angle[2], ...)
x <- cx + c(0,0,r)
y <- cy + (1/adj)*c(0,r,0)
polygon(x,y,border=T,col=col,density=code[3]*density[3],
angle=angle[3], ...)
x <- cx + c(0,0,r)
y <- cy + (1/adj)*c(-r,0,0)
polygon(x,y,border=T,col=col,density=code[4]*density[4],
angle=angle[4], ...)
}
if(length(code)>4) stop('Can only plot up to 4 levels of codes')
}
invisible()
}
triangle <- function(cx, cy, r, code=0, col=1, angle, density, ...) {
pin <- par()$pin
usr <- par()$usr
adj <- (pin[2]/pin[1])/((usr[4] - usr[3])/(usr[2] - usr[1]))
r <- r*1.25
a <- 3*r/sqrt(3)
b <- r/2
x <- cx + c((-1/2)*a, (1/2)*a, 0)
y <- cy + (1/adj)*c(-b, -b, r)
if(sum(code,na.rm=T)==0) polygon(x,y,border=T,density=0,col=col, ...)
else {
if(length(code)==1) polygon(x,y,border=T,col=col,
density=density[1],angle=angle[1], ...)
if(length(code)==2) {
polygon(x,y,border=T,density=0, ...)
x <- cx + c((-1/2)*a, 0, 0)
y <- cy + (1/adj)*c(-b, -b, r)
polygon(x,y,border=T,col=col,density=code[1]*density[1],
angle=angle[1], ...)
x <- cx + c(0, (1/2)*a, 0)
y <- cy + (1/adj)*c(-b, -b, r)
polygon(x,y,border=T,col=col,density=density[2]*code[2],
angle=angle[2], ...)
}
if(length(code)==3) {
polygon(x,y,border=T,density=0, ...)
midx <- (r*(.5)*a)/(b+r)
x <- cx + c((-1/2)*a,-midx, 0, 0)
y <- cy + (1/adj)*c(-b, 0, 0, -b)
polygon(x,y,border=T,col=col,density=code[1]*density[1],
angle=angle[1], ...)
x <- cx + c(-midx, 0,0)
y <- cy + (1/adj)*c(0,r,0)
polygon(x,y,border=T,col=col,density=code[2]*density[2],
angle=angle[2], ...)
x <- cx + c(0,0,midx)
y <- cy + (1/adj)*c(0,r,0)
polygon(x,y,border=T,col=col,density=density[3]*code[3],
angle=angle[3],...)
}
if(length(code)==4) {
polygon(x,y,border=T,density=0, ...)
midx <- (r*(.5)*a)/(b+r)
x <- cx + c((-1/2)*a, -midx , 0, 0)
y <- cy + (1/adj)*c(-b, 0, 0, -b)
polygon(x,y,border=T,col=col,density=code[1]*density[1],
angle=angle[1], ...)
x <- cx + c(-midx, 0,0)
y <- cy + (1/adj)*c(0,r,0)
polygon(x,y,border=T,col=col,density=code[2]*density[2],
angle=angle[2], ...)
x <- cx + c(0,0,midx)
y <- cy + (1/adj)*c(0,r,0)
polygon(x,y,border=T,col=col,density=code[3]*density[3],
angle=angle[3], ...)
x <- cx + c(0,midx,(1/2)*a,0)
y <- cy + (1/adj)*c(0,0,-b,-b)
polygon(x,y,border=T,col=col,density=code[4]*density[4],
angle=angle[4], ...)
}
if(length(code)>4) stop('Can only plot up to 4 levels of codes')
}
invisible()
}
for(i in (1:length(x))[!is.na(match(symbol,c(0,15)))]){
square(x[i],y[i],size, code=(affected[i,,drop=F]),
col=col[i], angle=angle, density=density)
}
for(i in (1:length(x))[!is.na(match(symbol,c(1,16)))]){
circle(x[i],y[i],size, code=(affected[i,,drop=F]),
col=col[i],angle=angle, density=density)
}
for(i in (1:length(x))[!is.na(match(symbol,c(5,18)))]){
diamond(x[i],y[i],size, code=(affected[i,,drop=F]),
col=col[i],angle=angle, density=density)
}
for(i in (1:length(x))[!is.na(match(symbol,c(2,17)))]){
triangle(x[i],y[i],size, code=(affected[i,,drop=F]),
col=col[i],angle=angle, density=density)
}
who <- (status == 1)
if(any(who)) {
deltax <- size*cos(pi/4) + aspect
deltay <- (1/adj)*(size*sin(pi/4) + aspect)
segments(x[who] - deltax, y[who] - deltay,
x[who] + deltax, y[who] + deltay)
}
}
plist <- kinship2::align.pedigree(x, packed = packed, width = width, align =
align)
who <- (plist$nid > 0)
xp <- plist$pos[who]
yp <- - (row(plist$nid))[who]
np <- plist$nid[who]
oldpar <- par(mar = mar, err=-1)
par(usr = c(range(xp) + c(-0.5, 0.5), - (maxlev + 0.5), -0.5))
pin <- par()$pin
usr <- par()$usr
adj <- (pin[2]/pin[1])/((usr[4] - usr[3])/(usr[2] - usr[1]))
symbolsize <- symbolsize * adj
radius <- 0.08 * symbolsize
delta <- .1
aspect <- 0.05 * symbolsize
textheight <- cex*par()$cin[2]
textoff <- - (1/adj)*(radius) - .5*cex*(par()$"cin"[2]/7)
totalTextHeight <- textheight
if(!is.null(extraInfo))
totalTextHeight <- textheight * (1 + ncol(extraInfo))
xmin <- min(xp)
xmax <- max(xp)
ymin <- min(yp)
ymax <- max(yp)
xlen <- xmax - xmin
ylen <- ymax - ymin
fudge <- max(0.1 * c(xlen, ylen)) + totalTextHeight
xmin <- xmin - fudge
xmax <- xmax + fudge
ymin <- ymin - fudge
ymax <- ymax + fudge
plot(c(xmin,xmax), c(ymin,ymax), axes=F,type='n',xlab='',ylab='',...)
points.sym(xp, yp, symbol[np], status[np], affected[np, ,drop=F],
radius, col[np], aspect, angle=angle, density=density, adj=adj)
for(p in 1:length(np)){
textOut <- c()
if(!is.null(id))
textOut <- c(textOut, paste("ID:", id[np[p]]))
if(!is.null(extraInfo))
for(i in 1:ncol(extraInfo))
textOut <- c(textOut, paste(colnames(extraInfo)[i], ": ", extraInfo[np[p],i], sep=""))
if(length(textOut) > 0)
text(xp[p], yp[p] + textoff, paste(textOut, collapse="\n"), cex=cex, pos=1)
}
if(!is.null(id)) {
if(!is.null(extraInfo)){
}
}
for(i in 1:maxlev) {
if(any(plist$spouse[i, ]>0)) {
temp <- (1:ncol(plist$spouse))[plist$spouse[i, ]>0]
segments(plist$pos[i, temp] + radius, rep( - i, length(temp)),
plist$pos[i, temp + 1] - radius, rep(-i, length(temp)))
}
}
for(i in 2:maxlev) {
zed <- unique(plist$fam[i, ])
zed <- zed[zed > 0]
for(fam in zed) {
xx <- plist$pos[i - 1, fam + 0:1]
parentx <- mean(xx)
if(!is.null(plist$twins)){
tw.left <- (plist$twins[i, ] > 0 & plist$twins[i, ] < 4) & plist$fam[i,]==fam
mz.left <- (plist$twins[i, ] == 1) & plist$fam[i,]==fam
un.left <- (plist$twins[i, ] == 3) & plist$fam[i,]==fam
tw.right <- rep(F,length(tw.left))
famlst <- plist$fam[i,]
twloc <- (1:length(tw.right))[tw.left]
famloc <- (1:length(tw.right))[famlst==fam]
flag <- NULL
for(j in twloc) flag <- c(flag,min(famloc[j<famloc]))
tw.right[flag] <- T
mz.right <- rep(F,length(mz.left))
mzloc <- (1:length(mz.right))[mz.left]
flag <- NULL
for(j in mzloc) flag <- c(flag,min(famloc[j<famloc]))
mz.right[flag] <- T
un.right <- rep(F,length(un.left))
unloc <- (1:length(un.right))[un.left]
flag <- NULL
for(j in unloc) flag <- c(flag,min(famloc[j<famloc]))
un.right[flag] <- T
}
if(is.null(plist$twins)){
twn <- length(plist$fam[i,]==fam)
tw.left <- rep(F,twn)
tw.right <- rep(F,twn)
mz.left <- rep(F,twn)
mz.right <- rep(F,twn)
un.left <- rep(F,twn)
un.right <- rep(F,twn)
}
tw <- tw.left|tw.right
who <- (plist$fam[i, ] == fam) & !tw
xx <- plist$pos[i, who]
yy <- rep( - i, length = sum(who))
ww <- plist$nid[i, who]
xx.l <- plist$pos[i, tw.left]
yy.l <- rep( - i, length = sum(tw.left))
ww.l <- plist$nid[i, tw.left]
xx.r <- plist$pos[i, tw.right]
yy.r <- rep( - i, length = sum(tw.right))
ww.r <- plist$nid[i, tw.right]
segments(xx, yy + (1/adj) * radius, xx, yy + 3 * delta, col
= col[ww])
segments(xx.l, yy.l + (1/adj) * radius, .5*(xx.l+xx.r), yy.l + 3 * delta,
col = col[ww.l])
segments(xx.r, yy.r + (1/adj) * radius, .5*(xx.l+xx.r), yy.r + 3 * delta,
col = col[ww.r])
xx.lm <- plist$pos[i, mz.left]
yy.lm <- rep( - i, length = sum(mz.left))
xx.rm <- plist$pos[i, mz.right]
yy.rm <- rep( - i, length = sum(mz.right))
segments(.5*(xx.lm+.5*(xx.rm+xx.lm)),
.5*(yy.lm+(1/adj)*radius + yy.lm+3*delta),
.5*(xx.rm+.5*(xx.rm+xx.lm)),
.5*(yy.rm+(1/adj)*radius + yy.lm+3*delta))
who <- (plist$fam[i, ] == fam)
xx <- plist$pos[i, who]
yy <- rep( - i, length = sum(who))
ww <- plist$nid[i, who]
xx2 <- plist$pos[i,]
xx2 <- xx2[who]
if(sum(tw)>=2){
tw.who <- tw[who]
n <- length(tw.who)
n2 <- sum(tw.who)
flagL <- sum(tw.who[1:2]) == 2
flagR <- sum(tw.who[c(n,n-1)]) == 2
xx2.save <- xx2
if(flagL) xx2[tw.who][1:2] <- rep(mean(xx2.save[tw.who][1:2]),2)
if(flagR) xx2[tw.who][c(n2,n2-1)] <- rep(mean(xx2.save[tw.who][c(n2,n2-1)]),2)
}
segments(min(xx2), 3 * delta - i, max(xx2), 3 * delta - i)
x1 <- mean(range(xx))
y1 <- 3 * delta - i
if(branch == 0)
segments(x1, y1, parentx, - (i - 1))
else {
y2 <- 1 - i
x2 <- parentx
ydelta <- ((y2 - y1) * branch)/2
segments(c(x1, x1, x2), c(y1, y1 + ydelta, y2 - ydelta),
c(x1, x2, x2), c(y1 + ydelta, y2 - ydelta, y2))
}
}
}
arcconnect <- function(x, y)
{
xx <- seq(x[1], x[2], length = 15)
yy <- seq(y[1], y[2], length = 15) + 0.5 - (seq(-7, 7))^2/98
lines(xx, yy, lty = 2)
}
xx <- table(np)
xx <- xx[xx > 1]
if(length(xx) > 0) {
multi <- as.numeric(names(xx))
for(i in 1:length(xx)) {
x2 <- xp[np == multi[i]]
y2 <- yp[np == multi[i]]
nn <- xx[i]
for(j in 1:(nn - 1))
arcconnect(x2[j + 0:1], y2[j + 0:1])
}
}
ckall <- x$id[is.na(match(x$id,x$id[plist$nid]))]
if(length(ckall>0)) cat('Did not plot the following people:',ckall,'\n')
if(!keep.par) par(oldpar)
tmp <- plist$nid[plist$nid!=0]
xp2 <- xp[order(tmp)]
yp2 <- yp[order(tmp)]
invisible(list(plist=plist,object=x,x=xp2,y=yp2,textoff=textoff,
symbolsize=symbolsize))
}
mergePhePed <-
function (ped, phe)
{
if (is.null(phe) || is.null(ped)) {
return(NULL)
}
data <- merge(ped, phe, all.x = TRUE)
data <- data[order(data$pid, data$id), ]
return(data)
}
alignPhePed <-
function (ped, phe)
{
ped <- sort(ped)
phe <- sort(phe)
ndata <- mergePhePed(ped, phe)
nped <- ndata[, 1:ncol(ped)]
class(nped) <- c("ped", "data.frame")
nphe <- ndata[, c(1, 2, (ncol(ped) + 1):ncol(ndata))]
class(nphe) <- c("phe", "data.frame")
return(list(ped = nped, phe = nphe))
}
plotPed <- function( ped, sink=NULL, geno="percent", phe=NULL, pheCols=NULL ) {
alev <- unique(ped$AffectionStatus)
if(any(is.na(alev)) || max(alev,na.rm=TRUE)==1){
}else{
ped$AffectionStatus[ped$AffectionStatus == 0] <- NA
ped$AffectionStatus <- ped$AffectionStatus - 1
}
extraInfo <- NULL
if(geno == "percent") {
extraInfo <- data.frame(G=paste(round(100 * rowSums(ped[,7:ncol(ped)]!=0) / (ncol(ped)-6), digits=2), "%", sep=""))
}
if(geno == "each") {
extraInfo <- data.frame(matrix("NA",nrow=nrow(ped),ncol=(ncol(ped)-6)/2),stringsAsFactors=FALSE)
colnames(extraInfo) <- ped.markerNames(ped)
for(i in 1:ncol(extraInfo)){
a0 <- ped[[6+i*2-1]]
a1 <- ped[[6+i*2]]
extraInfo[[i]] <- paste(apply(ped[,6+i*2-c(0,1)],1,min), "/", apply(ped[,6+i*2-c(0,1)],1,max), sep="")
miss <- a0==0 | a1==0
if(any(miss))
extraInfo[[i]][miss] <- "?"
}
}
pheInfo <- NULL
if(!is.null(phe)){
res <- alignPhePed(ped, phe)
ped <- res$ped
phe <- res$phe
}
if(!is.null(pheCols)) {
pheInfo <- phe[, match(pheCols, colnames(phe))]
if(is.null(extraInfo))
extraInfo <- pheInfo
else
extraInfo <- cbind(extraInfo, pheInfo)
}
if( any( ped$sex==0 ) )
ped$sex[ped$sex==0] <- 3;
if( !is.null(sink) ) {
pdf( sink );
}else{
}
for( pid in unique(ped$pid) ) {
subPed <- ped[ ped$pid==pid, ]
subExtraInfo <- NULL
if(!is.null(extraInfo))
subExtraInfo <- subset(extraInfo, ped$pid==pid)
pedigr <- kinship2::pedigree(id = subPed$id, dadid=subPed$idfath, momid=subPed$idmoth, sex=subPed$sex)
pedigr$affected <- matrix(subPed$AffectionStatus)
SUCCESS <- FALSE;
try( {
plot.pedigree(pedigr, extraInfo=subExtraInfo);
title(paste("Pedigree", pid));
SUCCESS <- TRUE;
} );
if( !SUCCESS )
print( paste( "Plotting pedigree", pid, "failed." ) );
}
if( !is.null(sink) )
dev.off()
}
|
compare <- function(x, ...) UseMethod("compare")
compare.trtsel <-
function(x, ..., x2, bootstraps = 500,
bias.correct = TRUE,
alpha = .05, plot = TRUE,
ci = "horizontal", fixed.values = NULL, offset = .01,
conf.bands = TRUE, conf.bandsN =100, model.names = c("Model 1", "Model 2"),
xlab = NULL, ylab = NULL,
xlim = NULL, ylim = NULL,
main = NULL, annotate.plot = TRUE){
quantile <- NULL
if(!is.trtsel(x)) stop("x must be an object of class 'trtsel' created by using the function 'trtsel' see ?trtsel for more help")
if(!is.trtsel(x2)) stop("x2 must be an object of class 'trtsel' created by using the function 'trtsel' see ?trtsel for more help")
if(x$model.fit$outcome != x2$model.fit$outcome) stop("This function can not compare trtsel objects with different outcome types: binary outcome to one with a time-to-event outcome.")
if(alpha<0 | alpha > 1) stop("Error: alpha should be between 0 and 1")
if(bootstraps ==0 ) cat("bootstrap confidence intervals will not be calculated\n")
if(bootstraps == 1) {warning("Number of bootstraps must be greater than 1, bootstrap confidence intervals will not be computed"); bootstraps <- 0;}
stopifnot(is.logical(bias.correct))
if(x$model.fit$family$family == "risks_provided"){
bias.correct = FALSE
}
if(missing(bias.correct)){
if(x$model.fit$family$family == "risks_provided"){
bias.correct = FALSE
}else if (bootstraps > 1){
bias.correct =TRUE
message("Bootstrap bias-correction will be implemented to correct for over-optimism bias in estimation.")
}else{
bias.correct = FALSE
}
}
study.design <-x$model.fit$study.design
rho <-x$model.fit$cohort.attributes
link <- x$model.fit$family
data1 <- x$derived.data
data2 <- x2$derived.data
if(x$default.trt != x2$default.trt) stop("default.trt is different between markers. Summary measure comparison would not be valid.")
if(nrow(data1) != nrow(data2)) stop("trtsel objects must have the same number of observations for comparison")
if( x$model.fit$outcome == "time-to-event"){
event.name1 = x$formula[[2]]
event.name2 = x$formula[[2]]
mysurv <- with(x$derived.data, eval(event.name1))
event1 <- mysurv[,2]
mysurv <- with(x2$derived.data, eval(event.name2))
event2 <- mysurv[,2]
}else{
event.name1 = as.character(x$formula[[2]])
event.name2 = as.character(x2$formula[[2]])
event1 <- x$derived.data[[event.name1]]
event2 <- x2$derived.data[[event.name2]]
}
if(!all.equal(data1[[x$treatment.name]],
data2[[x2$treatment.name]], check.attributes = FALSE, use.names = FALSE)) stop("trt labels must be identical to compare markers!")
if(!all.equal(event1, event2, check.attributes = FALSE, use.names = FALSE)) stop("event labels must be identical to compare markers!")
boot.sample <- x$functions$boot.sample
get.summary.measures <- x$functions$get.summary.measures
if(bootstraps > 1){
boot.data <- replicate(bootstraps, one.boot.compare(data1 = data1, data2 = data2,
formulas = list(x$formula, x2$formula),
event.names = c(event.name1, event.name2),
treatment.names = c(x$treatment.name, x2$treatment.name),
rho = rho, study.design = study.design, obe.boot.sample = boot.sample,
obe.get.summary.measures = get.summary.measures, link = link,
d = x$model.fit$thresh,
disc.rec.no.trt1 = x$model.fit$disc.rec.no.trt,
disc.rec.no.trt2 = x2$model.fit$disc.rec.no.trt,
prediction.times = c(x$prediction.time, x2$prediction.time),
bbc = bias.correct))
boot.data1 <- boot.data[c( 9:24),]
boot.data2 <- boot.data[c( 25:40),]
boot.data.diff = (boot.data1) - (boot.data2 )
if(link$family == "time-to-event") data1$prediction.time = x$prediction.time
if(link$family == "time-to-event") data2$prediction.time = x2$prediction.time
sm.m1 <- get.summary.measures(data1, event.name1, x$treatment.name, rho)
sm.m2 <- get.summary.measures(data2, event.name2, x2$treatment.name, rho)
sm.diff <- as.data.frame(t(unlist(sm.m1) - unlist(sm.m2) ))
ci.m1 <- apply(boot.data1, 1, quantile, probs = c(alpha/2, 1-alpha/2), na.rm = TRUE)
ci.m2 <- apply(boot.data2, 1, quantile, probs = c(alpha/2, 1-alpha/2), na.rm = TRUE)
ci.diff <- apply(boot.data.diff, 1, quantile, probs = c(alpha/2, 1-alpha/2), na.rm = TRUE)
if(bias.correct){
biasvec <- apply(boot.data[9:72, ], 1, mean, na.rm = TRUE)
bias1 <- biasvec[1:16] - biasvec[33:48]
bias2 <- biasvec[17:32] - biasvec[49:64]
}else{
bias1 <- bias2 <- rep(0, dim(ci.m2)[[2]])
}
ci.m1 <- ci.m1 - rbind(bias1, bias1)
ci.m2 <- ci.m2 - rbind(bias2, bias2)
ci.diff <- ci.diff - (rbind(bias1, bias1) - rbind(bias2, bias2) )
potential.pvals <- (1:bootstraps)/bootstraps
p.vals <- rep(0, 16)
for( tmp.ind in 1:16 ){
i = tmp.ind
tmp.boot.data <- boot.data.diff[tmp.ind,]
tmp.boot.data <- tmp.boot.data[is.finite(tmp.boot.data)]
if(!cover(min(tmp.boot.data), max(tmp.boot.data), 0) ){
p.vals[i] <- 0
}else{
reject.all <- unname( mapply( cover,
quantile(tmp.boot.data, potential.pvals/2, type = 1, na.rm = TRUE),
quantile(tmp.boot.data, 1 - potential.pvals/2, type = 1, na.rm = TRUE),
rep(0, bootstraps)) )
reject.all <- c(reject.all, FALSE)
tmp.reject <- which(reject.all==FALSE)[1]
p.vals[i] <- potential.pvals[ifelse(tmp.reject==1, 1, tmp.reject - 1)]
}
}
p.vals <- data.frame(t(p.vals))
names(p.vals) <- names(sm.diff)
row.names(p.vals) <- c("p.values")
row.names(ci.m1) <- c("lower", "upper")
row.names(ci.m2) <- c("lower", "upper")
row.names(ci.diff) <- c("lower", "upper")
result <- list(estimates.model1 = data.frame(sm.m1) - bias1,
estimates.model2 = data.frame(sm.m2) - bias2,
estimates.diff = data.frame(sm.diff),
ci.model1 = data.frame(ci.m1),
ci.model2 = data.frame(ci.m2),
ci.diff = data.frame(ci.diff),
bias.model1 = bias1,
bias.model2 = bias2,
x = x,
x2 = x2,
p.values = p.vals,
bootstraps = bootstraps,
bias.correct = bias.correct)
}else{
sm.m1 <- get.summary.measures(data1, rho)
sm.m2 <- get.summary.measures(data2, rho)
sm.diff <- as.data.frame(t(unlist(sm.m1) - unlist(sm.m2) ))
result <- list(estimates.model1 = data.frame(sm.m1) ,
estimates.model2 = data.frame(sm.m2) ,
estimates.diff = data.frame(sm.diff),
x = x,
x2 = x2,
bootstraps = bootstraps,
bias.correct = bias.correct)
}
same.marker.type = (is.null(x$model.fit$disc.rec.no.trt) == is.null(x2$model.fit$disc.rec.no.trt))
if(plot & !same.marker.type) {
warning("Can not generate plots to compare a discrete marker to a continuous marker (bootstrap methods are not comparable). No plots will be produced!")
plot = FALSE
}
if(plot & is.null(x$model.fit$disc.rec.no.trt)){
if(!is.element(ci, c("vertical", "horizontal"))) stop("If plotting, ci must be one of `vertical` or `horizontal`")
if(length(fixed.values>0)) conf.bands = FALSE
if(conf.bands){
if(substr(ci, 1,1 )=="v"){
fixed.values1 = seq(from = 0, to = 100, length.out = conf.bandsN)
fixed.values2 = seq(from = 0, to = 100, length.out = conf.bandsN)
offset = 0
}else{
fixed.values1 = seq(from = min(c(data1$trt.effect)), to = max(c(data1$trt.effect)), length.out = conf.bandsN)
fixed.values2 = seq(from = min(c(data2$trt.effect)), to = max(c(data2$trt.effect)), length.out = conf.bandsN)
offset = 0
}
}else{
fixed.values1 <- fixed.values
fixed.values2 <- fixed.values
}
curves <- myplotcompare.trtsel( x = result, bootstraps =bootstraps, alpha = alpha, ci = ci, marker.names = model.names,
fixeddeltas.y1 = fixed.values1, fixeddeltas.y2 = fixed.values2,
xlab = xlab,
ylab = ylab,
xlim = xlim,
ylim = ylim,
main = main, offset = offset, conf.bands=conf.bands)
result$plot <- curves$plot
result$plot.ci.marker1 <- curves$x$conf.intervals
result$plot.ci.marker2 <- curves$x2$conf.intervals
}else if(plot & !is.null(x$model.fit$disc.rec.no.trt)){
curves <- myplotcompare.trtsel_disc( x = result, bootstraps =bootstraps, alpha = alpha, ci = ci, marker.names = model.names,
xlab = xlab,
ylab = ylab,
xlim = xlim,
ylim = ylim,
main = main, offset = offset, conf.bands=conf.bands, annotate.plot)
result$plot <- curves$plot
result$plot.ci <- curves$ci.bounds
}
result$x <- NULL
result$x2 <- NULL
class(result) <- "compare.trtsel"
result$alpha <- alpha
result$model.names <- model.names
result$formulas <- list(x$formula, x2$formula)
return(result)
}
|
NULL
mortalityTable.MakehamGompertz = setClass(
"mortalityTable.MakehamGompertz",
slots = list(
A = "numeric",
B = "numeric",
c = "numeric",
omega = "numeric"
),
prototype = list(
A = 0,
B = 1,
c = 1,
omega = 120
),
contains = "mortalityTable.period"
)
setMethod("initialize", "mortalityTable.MakehamGompertz", function(.Object, A = 0, B = 1, c = 1, omega = 120, name = NULL, ...) {
if (missing(name) || is.null(name)) {
if (A == 0) {
name = paste("Gompertz mortality, B=", B, ", c=", c, collapse = "")
} else if (B == 0 || c == 1) {
name = paste("Exponential mortality, mu=", A + B * c, collapse = "")
} else {
name = paste("Makeham-Gompertz mortality, A=", A, ", B=", B, ", c=", c, collapse = "")
}
}
ages = 0:omega
if (c == 1 || B == 0) {
deathProbs = 1 - exp(-A)
} else {
deathProbs = 1 - exp(-A) * exp(B/log(c) * (c^ages - c^(ages + 1)))
}
callNextMethod(.Object, A = A, B = B, c = c, omega = omega, name = name, ages = ages, deathProbs = deathProbs, ...)
})
|
library(OpenMx)
library(testthat)
if (mxOption(NULL,"Default optimizer") == 'NPSOL') stop("SKIP")
mxOption(NULL, "Standard Errors", "No")
data(demoOneFactor)
mkModel <- function() {
manifests <- sample(names(demoOneFactor), ncol(demoOneFactor))
mxModel("One Factor", type="RAM",
manifestVars = manifests,
latentVars = c("G"),
mxPath(from="G", to=manifests,
labels=paste0("loading_",manifests)),
mxPath(from=manifests, arrows=2),
mxPath(from="G", arrows=2, free=FALSE, values=1.0),
mxPath(from="one", to=manifests,
labels=paste0("mean_",manifests)),
mxData(cov(demoOneFactor), type="cov", numObs=500,
means=colMeans(demoOneFactor)))
}
interest <- c(paste0("loading_x",1:5),paste0("mean_x",1:5))
c1 <- c()
for (rep in 1:5) {
fit <- mxRun(mkModel())
if (is.null(c1)) {
c1 <- coef(fit)[interest]
} else {
expect_equivalent(c1 - coef(fit)[interest],
rep(0,10), tolerance=1e-6)
}
}
numManifestsPerLatent <- 5
mkModel <- function(shuffle, fellner) {
varStruct <- expand.grid(l=1:3, i=1:numManifestsPerLatent)
manifestVars <- paste0('i', apply(varStruct, 1, paste0, collapse=''))
if (shuffle) {
manifestVars <- sample(manifestVars, length(manifestVars))
}
latentVars <- paste0('l', unique(varStruct$l))
allVars <- c(manifestVars, latentVars)
if (shuffle) {
allVars <- sample(allVars, length(allVars))
}
Fval <- diag(length(manifestVars))[,match(allVars, manifestVars)]
Fval[is.na(Fval)] <- 0
ta1 <- mxModel(
model="tangle",
mxMatrix("Full", length(manifestVars), length(allVars),
values=Fval,
dimnames=list(manifestVars, allVars), name="F"),
mxMatrix("Symm", length(allVars), length(allVars),
values=diag(length(allVars)),
free=diag(length(allVars)) == 1,
dimnames=list(allVars, allVars), name="S"),
mxMatrix("Full", length(allVars), length(allVars),
values=0,
dimnames=list(allVars, allVars), name="A"),
mxMatrix("Full", 1, length(allVars),
free=!is.na(match(allVars, manifestVars)),
dimnames=list(NULL, allVars), name="M"),
mxExpectationRAM(M="M"),
mxFitFunctionML(fellner=fellner))
for (lx in 1:length(latentVars)) {
lvar <- paste0('l', lx)
ivar <- paste0(paste0('i', lx), 1:numManifestsPerLatent)
ta1$A$values[ivar, lvar] <- 1
ta1$A$free[ivar, lvar[-1]] <- TRUE
}
ta1$S$free[latentVars, latentVars] <- TRUE
ta1$expectation$.maxDebugGroups <- 10L
ta1
}
set.seed(1)
ta1 <- mxGenerateData(mkModel(FALSE, FALSE), nrow=25, returnModel=TRUE)
for (useFellner in c(TRUE,FALSE)) {
fit1 <- mxRun(mxModel(mkModel(TRUE, useFellner), ta1$data))
fit2 <- mxRun(mxModel(mkModel(FALSE, useFellner), ta1$data))
omxCheckCloseEnough(fit1$output$fit - fit2$output$fit, 0, 1e-8)
if (useFellner) {
omxCheckEquals(names(fit1$expectation$debug$g1$fullMean[1:ncol(fit1$F)]),
paste0('tangle.', colnames(fit1$F)))
omxCheckTrue(length(rle(fit1$expectation$debug$g1$latentFilter)$lengths) !=
length(rle(fit2$expectation$debug$g1$latentFilter)$lengths))
}
}
if (0) {
all(rownames(fit1$F$values) == fit1$expectation$.runDims)
filter <- !apply(fit1$F$values, 2, function(x) all(x==0))
map1 <- apply(fit1$F$values != 0, 2, function(x) ifelse(any(x), which(x), NA))
man1 <- colnames(fit1$F)[filter]
all(man1[ match(rownames(fit1$F), man1) ] == rownames(fit1$F))
all(rownames(fit1$F)[ match(man1, rownames(fit1$F)) ] == man1)
all(match(man1, rownames(fit1$F)) == map1[!is.na(map1)])
}
data("jointdata", package ="OpenMx", verbose= TRUE)
jointData <- jointdata
jointData[,c(2,4,5)] <- mxFactor(jointData[,c(2,4,5)],
levels=list(c(0,1), c(0, 1, 2, 3), c(0, 1, 2)))
mkModel <- function(shuffle, wls) {
set.seed(shuffle)
myData <- jointData
if (shuffle) {
dperm <- sample.int(ncol(myData), ncol(myData))
myData <- myData[, dperm]
}
thresh <- mxMatrix("Full", 3, 3, FALSE, 0, name="Th")
thresh$free[,1] <- c(TRUE, FALSE, FALSE)
thresh$values[,1] <- c(0, NA, NA)
thresh$labels[,1] <- c("z2t1", NA, NA)
thresh$free[,2] <- TRUE
thresh$values[,2] <- c(-1, 0, 1)
thresh$labels[,2] <- c("z4t1", "z4t2", "z4t3")
thresh$free[,3] <- c(TRUE, TRUE, FALSE)
thresh$values[,3] <- c(-1, 1, NA)
thresh$labels[,3] <- c("z5t1", "z5t2", NA)
colnames(thresh) <- paste0('z',c(2,4,5))
manifestVars <- colnames(jointData)
if (shuffle) manifestVars <- sample(manifestVars, length(manifestVars))
latentVars <- 'l1'
allVars <- c(manifestVars, latentVars)
if (shuffle) allVars <- sample(allVars, length(allVars))
Fval <- diag(length(manifestVars))[,match(allVars, manifestVars)]
Fval[is.na(Fval)] <- 0
freeMean <- !sapply(myData, is.factor)[match(allVars,colnames(myData))]
freeMean <- !is.na(freeMean) & freeMean
ta1 <- mxModel(
model="tangle", thresh,
mxData(myData, 'raw'),
mxMatrix("Full", length(manifestVars), length(allVars),
values=Fval,
dimnames=list(manifestVars, allVars), name="F"),
mxMatrix("Symm", length(allVars), length(allVars),
values=diag(length(allVars)),
free=diag(length(allVars)) == 1, lbound=0, ubound=5,
dimnames=list(allVars, allVars), name="S"),
mxMatrix("Full", length(allVars), length(allVars),
values=0,
dimnames=list(allVars, allVars), name="A"),
mxMatrix("Full", 1, length(allVars),
free=freeMean,
dimnames=list(NULL, allVars), name="M"),
mxExpectationRAM(M="M", thresholds="Th"),
mxComputeGradientDescent())
lvar <- 'l1'
ivar <- manifestVars
ta1$A$values[ivar, lvar] <- 1
ta1$A$lbound[ivar, lvar] <- 0
ta1$A$free[ivar, lvar] <- TRUE
ta1$S$free[lvar,lvar] <- FALSE
ta1$M$values[1,'z1'] <- c(.1)
if (wls) {
ta1 <- mxModel(ta1, mxFitFunctionWLS('WLS'))
} else {
ta1 <- mxModel(ta1, mxFitFunctionML(jointConditionOn = "continuous"))
}
ta1
}
for (wls in c(FALSE)) {
fit1 <- mxRun(mkModel(0, wls))
fit2 <- mxRun(mkModel(1, wls))
omxCheckCloseEnough(fit1$output$fit - fit2$output$fit, 0, 1e-6)
fit3 <- mxRun(mkModel(2, wls))
omxCheckCloseEnough(fit1$output$fit - fit3$output$fit, 0, 1e-6)
}
for (sx in 1:4) {
for (wls in c(TRUE)) {
fit1 <- mxRun(mkModel(0, wls))
fit2 <- mxRun(mxModel(mkModel(sx, wls), fit1$data))
fit3 <- mxRun(mkModel(sx, wls))
fit4 <- mxRun(mxModel(mkModel(0, wls), fit3$data))
omxCheckCloseEnough(fit1$output$fit - fit2$output$fit, 0, 1e-5)
omxCheckCloseEnough(fit1$output$fit - fit3$output$fit, 0, 1e-5)
omxCheckCloseEnough(fit1$output$fit - fit4$output$fit, 0, 1e-5)
}
}
|
KM41 <- data.frame(
Batch = rep(c("B1","B2","B3","B4","B5"), each=5),
y = c(379, 357, 390, 376, 376,
363, 367, 382, 381, 359,
401, 402, 407, 402, 396,
402, 387, 392, 395, 394,
415, 405, 396, 390, 395)
)
fit <- aov1r(y~Batch, KM41)
I <- fit[["Design"]][["I"]]
J <- fit[["Design"]][["Jh"]]
ssb <- fit[["Sums of squares"]][["ssb"]]
ssw <- fit[["Sums of squares"]][["ssw"]]
n <- 1000000
Z <- rnorm(n)
U2b <- rchisq(n, I-1)
U2w <- rchisq(n, I*(J-1))
X <- Z*sqrt(pmax(0, 1/J*(1+1/I)*ssb/U2b - 1/J*ssw/U2w))
quantile(X, .975)
|
expected <- eval(parse(text="logical(0)"));
test(id=0, code={
argv <- eval(parse(text="list(FALSE, 0L)"));
.Internal(`rep.int`(argv[[1]], argv[[2]]));
}, o=expected);
|
plot_shiny.fosr = function(obj, xlab = "", ylab="", title = "", ...) {
fosr.obj <- obj
value = subj = covariate = UB = LB = residual = depth.rank = coef = grid = x = y = NULL
p = dim(fosr.obj$beta.hat)[1]
D = dim(fosr.obj$beta.hat)[2]
grid = 1:D
covar.list = names(attributes(terms(fosr.obj$terms))$dataClasses)
covar.list[1] = "None"
covarInputValues = 1:length(covar.list)
names(covarInputValues) = covar.list
spaghetti.help = "Observed response data, colored according to the covariate selected below."
spaghetti.call = eval(call("selectInput", inputId = "CovarChoice", label = ("Select Covariate"), choices = covarInputValues, selected = 1))
lasagna.help = "Observed response data, each row is a subject. When a covariate is selected, the rows are ordered and widths
are assigned by value of that covariate. Right plot displays distribution of covariate selected in
correspondence with ordering of the rows at right."
lasagna.call = eval(call("selectInput", inputId = "CovarChoice2", label = ("Select Covariate"), choices = covarInputValues, selected = 1))
pred.list = names(attributes(terms(fosr.obj$terms))$dataClasses)[-1]
fitted.help = "Fitted response curve for a subject with covariate values specified below."
fitted.call <- vector("list", length(pred.list))
for(i in 1:length(pred.list)){
fitted.call[[i]] = eval(createInputCall(pred.list[i], get(pred.list[i], fosr.obj$data) ))
}
coef.list = colnames(model.matrix(fosr.obj$terms, fosr.obj$data[1,]))
coefInputValues = 1:p
names(coefInputValues) = coef.list
coef.help = "Coefficient function for the predictor selected below."
coef.call = eval(call("selectInput", inputId = "CoefChoice", label = ("Select Predictor"), choices = coefInputValues, selected = 1))
residuals.help = "If 'Show Outliers' is selected, the median and outlying curves are shown in blue and red respectively. If 'Rainbowize'
is selected, curves are ordered by band depth with most outlying curves shown in red and
curves closest to the median shown in violet."
residuals.call = eval(call("radioButtons","residOptions", label="Plot Options",
choices = list("None"=1, "Show Median and Outliers"=2,"Rainbowize by Depth"=3), selected=1))
shinyApp(
ui = navbarPage(title = strong(style = "color:
windowTitle = "refund.shiny", collapsible = FALSE, id = "nav", inverse = TRUE, header = NULL,
tabPanel("Observed Data", icon = icon("stats", lib = "glyphicon"),
tabsetPanel(
tabPanelModuleUI("spaghetti", tabTitle = "Spaghetti Plot", calls = spaghetti.call,
helperText = spaghetti.help),
tabPanelModuleUI("lasagna", tabTitle = "Lasagna Plot", calls = lasagna.call,
helperText = lasagna.help)
) ),
tabPanelModuleUI("fitted", tabTitle = "Fitted Values", icon("chart-line"), calls = fitted.call,helperText = fitted.help ),
tabPanelModuleUI("coef", tabTitle = "Coefficient Functions", icon("chart-area"), calls = coef.call, helperText = coef.help),
tabPanelModuleUI("residuals", tabTitle = "Residuals", icon("medkit"), calls = residuals.call,helperText = residuals.help )
),
server = function(input, output){
plotInputSpagheti <- reactive({
y.obs = fosr.obj$data[,names(attributes(terms(fosr.obj$terms))$dataClasses)[1]]
colnames(y.obs) = grid
y.obs.m = melt(y.obs)
colnames(y.obs.m) = c("subj", "grid", "value")
CovarChoice = as.numeric(input$CovarChoice)
selected = covar.list[CovarChoice]
if(selected == "None") {
y.obs.m$covariate = NULL
} else {
y.obs.m$covariate = rep(fosr.obj$data[,selected], length(grid))
}
if(is.null(y.obs.m$covariate)){
p1 <- ggplot(y.obs.m, aes(x=grid, y=value, group = subj)) + geom_line(alpha = .3, color="black") +
theme_bw() + xlab("") + ylab("")
} else {
p1 <- ggplot(y.obs.m, aes(x=grid, y=value, group = subj, color = covariate)) + geom_line(alpha = .3) +
theme_bw() + xlab("") + ylab("") + theme(legend.position="bottom", legend.title=element_blank())
}
})
plotInputLasagna = reactive({
y.obs.char = as.character(fosr.obj$terms[[2]])
CovarChoice2 = as.numeric(input$CovarChoice2)
selected = covar.list[CovarChoice2]
if(selected == "None") {
covariate = NULL
}
else if(length(table(fosr.obj$data[, selected])) < 3){
fosr.obj$data[, selected] = factor(fosr.obj$data[, selected])
covariate = selected
}
else {
covariate = selected
}
df = makeLasagna(data = fosr.obj$data, outcome = y.obs.char, covariate = covariate)
plots = bakeLasagna(data = fosr.obj$data, data.long = df$data.long, covariate = covariate)
grid.arrange(plots$lasagnaPlot, plots$densityPlot, ncol=2, nrow=1, widths=c(4, 1))
})
callModule(tabPanelModule, "spaghetti", plotObject = plotInputSpagheti, plotName = "spaghetti")
callModule(tabPanelModule, "lasagna", plotObject = plotInputLasagna, plotName = "lasagna", is.grid = TRUE)
plotInputFittedVal <- reactive({
variables = sapply(pred.list, function(u) {input[[u]]})
input.data = fosr.obj$data[1,]
reassign = function(var, newdata){
if(is.numeric(fosr.obj$data[,var])){
var.value = as.numeric(newdata[var])
} else if(is.factor(fosr.obj$data[,var])){
var.value = factor(newdata[var], levels = levels(fosr.obj$data[,var]))
}
var.value
}
input.data[,pred.list] = lapply(pred.list, reassign, variables)
X.design = t(matrix(model.matrix(fosr.obj$terms, input.data)))
fit.vals = as.vector(X.design %*% fosr.obj$beta.hat)
df <- data.frame(grid = grid,
fit.vals = fit.vals)
p2 <- ggplot(df, aes(x = grid, y = fit.vals)) + geom_line(lwd=1) + theme_bw() +
xlab(xlab) + ylab(ylab) + ylim(c(.9, 1.1) * range(fosr.obj$Yhat))
})
callModule(tabPanelModule, "fitted", plotObject = plotInputFittedVal, plotName = "fitted")
plotInputCoefFunc <- reactive({
CoefChoice = as.numeric(input$CoefChoice)
df <- data.frame(grid = grid,
coef = fosr.obj$beta.hat[CoefChoice,],
UB = fosr.obj$beta.UB[CoefChoice,],
LB = fosr.obj$beta.LB[CoefChoice,])
p3 <- ggplot(df, aes(x=grid, y=coef))+geom_line(linetype=1, lwd=1.5, color="black")+
geom_line(data = df, aes(y=UB), color = "blue") +
geom_line(data = df, aes(y=LB), color = "blue")+
theme_bw() + xlab("") + ylab("")
})
callModule(tabPanelModule, "coef", plotObject = plotInputCoefFunc, plotName = "coef")
response = fosr.obj$data[,names(attributes(terms(fosr.obj$terms))$dataClasses)[1]]
resid = response - fosr.obj$Yhat
colnames(resid) = grid
outs = outliers(resid, 1.5)
resid.m = melt(resid)
colnames(resid.m) = c("subj", "grid", "residual")
resid.m = resid.m[order(resid.m$subj),]
resid.m$depths = rep(outs$depth, each = dim(resid)[2])
resid.m = resid.m[order(resid.m$depths, decreasing = FALSE),]
resid.m$depth.rank = rep(1:dim(resid)[1], each=dim(resid)[2])
resid.outs.m = melt(outs$outcurves)
colnames(resid.outs.m) = c("subj", "grid", "residual")
resid.med.m = melt(outs$medcurve)
colnames(resid.med.m) = c("subj", "grid", "residual")
plotInputResid <- reactive({
residPlot = ggplot(resid.m, aes(x=grid, y=residual, group = subj))+ theme_bw() + geom_line(alpha = .3, color="black")
if(input$residOptions==2 & dim(outs$outcurves)[1]!= 0){residPlot=residPlot+
geom_line(data=resid.outs.m, aes(x=grid, y=residual, group=subj, color="outliers"))+
geom_line(data=resid.med.m, aes(x=grid, y=residual, group=subj, color = "median"))+
scale_colour_manual("", values = c("outliers"="indianred", "median"="blue"), guide = FALSE)
}
else if(input$residOptions==2 & dim(outs$outcurves)[1]== 0){residPlot=residPlot+
geom_line(data=resid.med.m, aes(x=grid, y=residual, group=subj, color = "median"))+
scale_colour_manual("", values = c("median"="blue"), guide=FALSE)
}
else if (input$residOptions == 3){residPlot = ggplot(resid.m, aes(x=grid, y=residual, group = subj)) +
geom_line(aes(color=factor(depth.rank))) + theme_bw()+ theme(legend.position="none")}
residPlot + xlab("") + ylab("")
})
callModule(tabPanelModule, "residuals", plotObject = plotInputResid, plotName = "residuals")
}
)
}
|
setClass(
"mbsts",
slots=c(
Xtrain="array",
Ind="array",
beta.hat="array",
B.hat="array",
ob.sig2="array",
States="array",
st.sig2="array",
ki="array",
ntrain="numeric",
mtrain="numeric"
),
prototype=prototype(
Xtrain=array(data=numeric(0),dim=c(0,0)),
Ind=array(data=numeric(0),dim=c(0,0)),
beta.hat=array(data=numeric(0),dim=c(0,0)),
B.hat=array(data=numeric(0),dim=c(0,0,0)),
ob.sig2=array(data=numeric(0),dim=c(0,0,0)),
States=array(data=numeric(0),dim=c(0,0,0)),
st.sig2=array(data=numeric(0),dim=c(0,0)),
ki=array(data=numeric(0),dim=c(0,0)),
ntrain=as.double(NA),
mtrain=as.double(NA)
)
)
|
BIFIE_data_select_pv_vars <- function(pvpre, cn_data)
{
nc1 <- nchar( pvpre[1] )
pv_vars <- which( substring( cn_data, 1, nc1 )==pvpre[1] )
pv_elim <- NULL
LP <- length(pvpre)
for (pp in 2:LP){
pvpre_pp <- pvpre[pp]
pv1 <- which( substring( cn_data, 1, nchar(pvpre_pp) )==pvpre_pp )
pv_elim <- c( pv_elim, pv1 )
}
pv_vars <- setdiff(pv_vars, pv_elim)
pv_vars <- gsub( pvpre[1], "", cn_data[ pv_vars ] )
return(pv_vars)
}
|
PseKRAAC_T16 <- function(seqs,type="gap",Grp=2,GapOrLambdaValue=2,k=4,label=c())
{
numGrp=Grp
if(length(seqs)==1&&file.exists(seqs)){
seqs<-fa.read(seqs,alphabet="aa")
seqs_Lab<-alphabetCheck(seqs,alphabet = "aa",label)
seqs<-seqs_Lab[[1]]
label<-seqs_Lab[[2]]
}
else if(is.vector(seqs)){
seqs<-sapply(seqs,toupper)
seqs_Lab<-alphabetCheck(seqs,alphabet = "aa",label)
seqs<-seqs_Lab[[1]]
label<-seqs_Lab[[2]]
}
else {
stop("ERROR: Input sequence is not in the correct format. It should be a FASTA file or a string vector.")
}
if(type!="lambda"&&type!="gap"){
stop("ERROR: type should be lambda or gap ")
}
lenSeqs<-sapply(seqs,nchar)
numSeqs<-length(seqs)
Grp<-paste0("Grp",Grp)
AAGroup = list(
Grp2=c('IMVLFWY', 'GPCASTNHQEDRK'),
Grp3=c('IMVLFWY', 'GPCAST', 'NHQEDRK'),
Grp4=c('IMVLFWY', 'G', 'PCAST', 'NHQEDRK'),
Grp5=c('IMVL', 'FWY', 'G', 'PCAST', 'NHQEDRK'),
Grp6=c('IMVL', 'FWY', 'G', 'P', 'CAST', 'NHQEDRK'),
Grp7=c('IMVL', 'FWY', 'G', 'P', 'CAST', 'NHQED', 'RK'),
Grp8=c('IMV', 'L', 'FWY', 'G', 'P', 'CAST', 'NHQED', 'RK'),
Grp9=c('IMV', 'L', 'FWY', 'G', 'P', 'C', 'AST', 'NHQED', 'RK'),
Grp10=c('IMV', 'L', 'FWY', 'G', 'P', 'C', 'A', 'STNH', 'RKQE', 'D'),
Grp11=c('IMV', 'L', 'FWY', 'G', 'P', 'C', 'A', 'STNH', 'RKQ', 'E', 'D'),
Grp12=c('IMV', 'L', 'FWY', 'G', 'P', 'C', 'A', 'ST', 'N', 'HRKQ', 'E', 'D'),
Grp13=c('IMV', 'L', 'F', 'WY', 'G', 'P', 'C', 'A', 'ST', 'N', 'HRKQ', 'E', 'D'),
Grp14=c('IMV', 'L', 'F', 'WY', 'G', 'P', 'C', 'A', 'S', 'T', 'N', 'HRKQ', 'E', 'D'),
Grp15=c('IMV', 'L', 'F', 'WY', 'G', 'P', 'C', 'A', 'S', 'T', 'N', 'H', 'RKQ', 'E', 'D'),
Grp16=c('IMV', 'L', 'F', 'W', 'Y', 'G', 'P', 'C', 'A', 'S', 'T', 'N', 'H', 'RKQ', 'E', 'D'),
Grp20=c('I', 'M', 'V', 'L', 'F', 'W', 'Y', 'G', 'P', 'C', 'A', 'S', 'T', 'N', 'H', 'R', 'K', 'Q', 'E', 'D')
)
if(is.null(AAGroup[[Grp]])){
stop(paste0("Error: There is no ",Grp))
}
lenGrp<-length(AAGroup[[Grp]])
aa<-vector()
chars<-vector()
VectGrp<-c("Grp10"='a',"Grp11"='b',"Grp12"='c',"Grp13"='d',"Grp14"='e',"Grp15"='f',"Grp16"='g',"Grp17"='h',"Grp18"='i',"Grp19"='j',"Grp20"='k')
for(i in 1:lenGrp){
str<-AAGroup[[Grp]][i]
lenStr<-nchar(str)
if(i<10){
aa<-c(aa,rep(i,lenStr))
} else {
aa<-c(aa,rep(VectGrp[(i-9)],lenStr))
}
chars<-c(chars,unlist(strsplit(str,split = "")))
}
names(aa)<-chars
grpChars<-lapply(seqs,function(s){
Chars<-unlist(strsplit(s,split = ""))
return(aa[Chars])
})
if(type=="lambda"){
lambda_model(grpchars = grpChars,GapOrLambdaValue = GapOrLambdaValue,k = k,numGrp = numGrp)
}
else if(type=="gap"){
grpStr<-lapply(grpChars, function(s) paste0(s,collapse = ""))
gap_model(grpstr = grpStr,GapOrLambdaValue = GapOrLambdaValue,k = k,numGrp = numGrp)
}
else{
stop("type should be lambda or gap")
}
}
lambda_model<-function(grpchars,GapOrLambdaValue,k,numGrp){
featureMatrix<-matrix(0,ncol = (numGrp^k),nrow = length(grpchars))
colnames(featureMatrix)<-nameKmer(k=k,type = "num",num=numGrp)
lens<-lapply(grpchars, length)
strIndx=1
for(n in 1:length(grpchars)){
len<-lens[n]
endIdx<-strIndx+((k-1)*(GapOrLambdaValue+1))
if(endIdx>len){
stop(paste0("ERROR: Sequence ",n," doesn't have a suffitient length"))
}
tempVect<-seq(1,endIdx,(GapOrLambdaValue+1))
while(endIdx<=len){
name<-paste(grpchars[[n]][tempVect],collapse = '')
featureMatrix[n,name]<-featureMatrix[n,name]+1
tempVect<-tempVect+1
endIdx<-endIdx+1
}
}
return(featureMatrix)
}
gap_model<-function(grpstr,GapOrLambdaValue,k,numGrp){
featureMatrix<-matrix(0,ncol = (numGrp^k),nrow = length(grpstr))
colnames(featureMatrix)<-nameKmer(k=k,type = "num",num=numGrp)
substrVector<-lapply(grpstr, function(x){
numChars<-nchar(x)
if(numChars<k){
stop(paste0("ERROR: Length of all the sequences should be greater than k"))
}
strts<-(numChars-k+1)
g<-(GapOrLambdaValue+k)
substrVector<-substring(x, seq(1, strts, g), seq(k, numChars, g))
return(substrVector)
})
tabSubVect<-lapply(substrVector,table)
for(j in 1:length(grpstr)){
featureMatrix[j,names(tabSubVect[[j]])]<-tabSubVect[[j]]
}
return(featureMatrix)
}
|
binned_residuals <- function(model, term = NULL, n_bins = NULL, ...) {
fv <- stats::fitted(model)
mf <- insight::get_data(model)
if (is.null(term)) {
pred <- fv
} else {
pred <- mf[[term]]
}
y <- .recode_to_zero(insight::get_response(model, verbose = FALSE)) - fv
if (is.null(n_bins)) n_bins <- round(sqrt(length(pred)))
breaks.index <- floor(length(pred) * (1:(n_bins - 1)) / n_bins)
breaks <- unique(c(-Inf, sort(pred)[breaks.index], Inf))
model.binned <- as.numeric(cut(pred, breaks))
d <- suppressWarnings(lapply(1:n_bins, function(.x) {
items <- (1:length(pred))[model.binned == .x]
model.range <- range(pred[items], na.rm = TRUE)
xbar <- mean(pred[items], na.rm = TRUE)
ybar <- mean(y[items], na.rm = TRUE)
n <- length(items)
sdev <- stats::sd(y[items], na.rm = TRUE)
data.frame(
xbar = xbar,
ybar = ybar,
n = n,
x.lo = model.range[1],
x.hi = model.range[2],
se = 2 * sdev / sqrt(n)
)
}))
d <- do.call(rbind, d)
d <- d[stats::complete.cases(d), ]
gr <- abs(d$ybar) > abs(d$se)
d$group <- "yes"
d$group[gr] <- "no"
resid_ok <- sum(d$group == "yes") / length(d$group)
if (resid_ok < .8) {
insight::print_color(sprintf("Warning: Probably bad model fit. Only about %g%% of the residuals are inside the error bounds.\n", round(100 * resid_ok)), "red")
} else if (resid_ok < .95) {
insight::print_color(sprintf("Warning: About %g%% of the residuals are inside the error bounds (~95%% or higher would be good).\n", round(100 * resid_ok)), "yellow")
} else {
insight::print_color(sprintf("Ok: About %g%% of the residuals are inside the error bounds.\n", round(100 * resid_ok)), "green")
}
add.args <- lapply(match.call(expand.dots = FALSE)$`...`, function(x) x)
size <- if ("size" %in% names(add.args)) add.args[["size"]] else 2
color <- if ("color" %in% names(add.args)) add.args[["color"]] else c("
class(d) <- c("binned_residuals", "see_binned_residuals", class(d))
attr(d, "resp_var") <- insight::find_response(model)
attr(d, "term") <- term
attr(d, "geom_size") <- size
attr(d, "geom_color") <- color
d
}
|
test_that("classif_featureless", {
checkLearnerModel = function(mod, probs) {
lmod = getLearnerModel(mod)
expect_named(lmod, c("method", "probs"))
expect_equal(lmod$method, m)
expect_equal(as.numeric(lmod$probs), probs)
}
df = data.frame(
y = as.factor(c(1, 2, 3, 3, 3)),
x = rep(1, 5)
)
lvls = levels(df$y)
method = c("majority", "sample-prior")
task = makeClassifTask(data = df, target = "y")
n = 10
test = data.frame(rep(1, n))
probs = c(0.2, 0.2, 0.6)
majority.class = 3
for (m in method) {
lrn = makeLearner("classif.featureless", method = m)
mod = train(lrn, task)
checkLearnerModel(mod, probs)
p = predict(mod, newdata = test)
if (m == "sample-prior") {
set.seed(getOption("mlr.debug.seed"))
pred = factor(sample(lvls, size = n, prob = probs, replace = TRUE))
} else {
pred = factor(rep(majority.class, n), levels = lvls)
}
expect_equal(getPredictionResponse(p), pred)
expect_output(print(lrn), "featureless")
expect_output(print(lrn), m)
lrn = setPredictType(lrn, predict.type = "prob")
mod = train(lrn, task)
p = predict(mod, newdata = test)
expect_equal(as.numeric(unique(getPredictionProbabilities(p))), probs)
}
df = data.frame(
y = as.factor(c(1, 2, 1, 2)),
x = rep(1, 4)
)
lvls = levels(df$y)
method = c("majority", "sample-prior")
task = makeClassifTask(data = df, target = "y")
probs = c(0.5, 0.5)
for (m in method) {
lrn = makeLearner("classif.featureless", method = m)
mod = train(lrn, task)
checkLearnerModel(mod, probs)
p = predict(mod, newdata = test)
set.seed(getOption("mlr.debug.seed"))
if (m == "sample-prior") {
pred = factor(sample(lvls, size = n, prob = probs, replace = TRUE))
} else {
pred = factor(rep(getMaxIndex(probs, ties.method = "random"), n), levels = lvls)
}
expect_equal(getPredictionResponse(p), pred)
expect_output(print(lrn), "featureless")
expect_output(print(lrn), m)
lrn = setPredictType(lrn, predict.type = "prob")
mod = train(lrn, task)
p = predict(mod, newdata = test)
expect_equal(getPredictionProbabilities(p), rep(0.5, n))
}
})
|
expected <- eval(parse(text="c(3.14159265358979, 3.14159265358981, 3.14159265358981, 3.14159265358981, 3.14159265358978, 3.1415926535898, 3.1415926535898, 3.14159265358978, 3.14159265358981, 3.14159265358979, 3.14159265358979, 3.14159265358978, 3.14159265358979, 3.14159265358981, 3.1415926535898, 3.14159265358978, 3.14159265358978, 3.14159265358978, 3.14159265358978, 3.14159265358981, 3.14159265358981, 3.14159265358978, 3.14159265358979, 3.14159265358978, 3.14159265358978, 3.14159265358978, 3.1415926535898, 3.14159265358977, 3.14159265358979, 3.14159265358979, 3.1415926535898, 3.14159265358979, 3.1415926535898, 3.14159265358979, 3.14159265358979, 3.14159265358981, 3.14159265358978, 3.1415926535898, 3.14159265358979, 3.14159265358981, 3.1415926535898, 3.14159265358981, 3.14159265358978, 3.1415926535898, 3.14159265358981, 3.1415926535898, 3.14159265358978, 3.14159265358979, 3.14159265358978, 3.14159265358979, 3.1415926535898, 3.14159265358981, 3.14159265358978, 3.1415926535898, 3.14159265358979, 3.1415926535898, 3.14159265358978, 3.1415926535898, 3.14159265358978, 3.14159265358979, 3.1415926535898, 3.14159265358978, 3.1415926535898, 3.14159265358981, 3.14159265358977, 3.14159265358981, 3.14159265358978, 3.14159265358978, 3.14159265358981, 3.14159265358979, 3.14159265358977, 3.14159265358978, 3.14159265358981, 3.14159265358979, 3.14159265358981, 3.1415926535898, 3.14159265358979, 3.14159265358979, 3.1415926535898, 3.14159265358979, 3.14159265358981, 3.14159265358979, 3.14159265358979, 3.14159265358981, 3.14159265358977, 3.1415926535898, 3.14159265358979, 3.1415926535898, 3.14159265358979, 3.1415926535898, 3.1415926535898, 3.1415926535898, 3.14159265358978, 3.1415926535898, 3.1415926535898, 3.1415926535898, 3.14159265358981, 3.14159265358979, 3.14159265358978, 3.14159265358981, 3.14159265358981)"));
test(id=0, code={
argv <- eval(parse(text="list(c(3.14159265358979, 3.14159265358981, 3.14159265358981, 3.14159265358981, 3.14159265358978, 3.1415926535898, 3.1415926535898, 3.14159265358978, 3.14159265358981, 3.14159265358979, 3.14159265358979, 3.14159265358978, 3.14159265358979, 3.14159265358981, 3.1415926535898, 3.14159265358978, 3.14159265358978, 3.14159265358978, 3.14159265358978, 3.14159265358981, 3.14159265358981, 3.14159265358978, 3.14159265358979, 3.14159265358978, 3.14159265358978, 3.14159265358978, 3.1415926535898, 3.14159265358977, 3.14159265358979, 3.14159265358979, 3.1415926535898, 3.14159265358979, 3.1415926535898, 3.14159265358979, 3.14159265358979, 3.14159265358981, 3.14159265358978, 3.1415926535898, 3.14159265358979, 3.14159265358981, 3.1415926535898, 3.14159265358981, 3.14159265358978, 3.1415926535898, 3.14159265358981, 3.1415926535898, 3.14159265358978, 3.14159265358979, 3.14159265358978, 3.14159265358979, 3.1415926535898, 3.14159265358981, 3.14159265358978, 3.1415926535898, 3.14159265358979, 3.1415926535898, 3.14159265358978, 3.1415926535898, 3.14159265358978, 3.14159265358979, 3.1415926535898, 3.14159265358978, 3.1415926535898, 3.14159265358981, 3.14159265358977, 3.14159265358981, 3.14159265358978, 3.14159265358978, 3.14159265358981, 3.14159265358979, 3.14159265358977, 3.14159265358978, 3.14159265358981, 3.14159265358979, 3.14159265358981, 3.1415926535898, 3.14159265358979, 3.14159265358979, 3.1415926535898, 3.14159265358979, 3.14159265358981, 3.14159265358979, 3.14159265358979, 3.14159265358981, 3.14159265358977, 3.1415926535898, 3.14159265358979, 3.1415926535898, 3.14159265358979, 3.1415926535898, 3.1415926535898, 3.1415926535898, 3.14159265358978, 3.1415926535898, 3.1415926535898, 3.1415926535898, 3.14159265358981, 3.14159265358979, 3.14159265358978, 3.14159265358981, 3.14159265358981))"));
do.call(`as.double`, argv);
}, o=expected);
|
test_that("get_library_versions", {
a <- get_library_versions()
expect_true(is.character(a))
expect_equal(1, length(a))
expect_true(nchar(a) > 10)
})
|
expected <- eval(parse(text="FALSE"));
test(id=0, code={
argv <- eval(parse(text="list(c(-0.5, -0.47979797979798, -0.45959595959596, -0.439393939393939, -0.419191919191919, -0.398989898989899, -0.378787878787879, -0.358585858585859, -0.338383838383838, -0.318181818181818, -0.297979797979798, -0.277777777777778, -0.257575757575758, -0.237373737373737, -0.217171717171717, -0.196969696969697, -0.176767676767677, -0.156565656565657, -0.136363636363636, -0.116161616161616, -0.0959595959595959, -0.0757575757575757, -0.0555555555555555, -0.0353535353535353, -0.0151515151515151, 0.00505050505050508, 0.0252525252525253, 0.0454545454545455, 0.0656565656565657, 0.0858585858585859, 0.106060606060606, 0.126262626262626, 0.146464646464647, 0.166666666666667, 0.186868686868687, 0.207070707070707, 0.227272727272727, 0.247474747474748, 0.267676767676768, 0.287878787878788, 0.308080808080808, 0.328282828282828, 0.348484848484849, 0.368686868686869, 0.388888888888889, 0.409090909090909, 0.429292929292929, 0.44949494949495, 0.46969696969697, 0.48989898989899, 0.51010101010101, 0.53030303030303, 0.550505050505051, 0.570707070707071, 0.590909090909091, 0.611111111111111, 0.631313131313131, 0.651515151515152, 0.671717171717172, 0.691919191919192, 0.712121212121212, 0.732323232323232, 0.752525252525253, 0.772727272727273, 0.792929292929293, 0.813131313131313, 0.833333333333333, 0.853535353535354, 0.873737373737374, 0.893939393939394, 0.914141414141414, 0.934343434343434, 0.954545454545455, 0.974747474747475, 0.994949494949495, 1.01515151515152, 1.03535353535354, 1.05555555555556, 1.07575757575758, 1.0959595959596, 1.11616161616162, 1.13636363636364, 1.15656565656566, 1.17676767676768, 1.1969696969697, 1.21717171717172, 1.23737373737374, 1.25757575757576, 1.27777777777778, 1.2979797979798, 1.31818181818182, 1.33838383838384, 1.35858585858586, 1.37878787878788, 1.3989898989899, 1.41919191919192, 1.43939393939394, 1.45959595959596, 1.47979797979798, 1.5))"));
do.call(`is.expression`, argv);
}, o=expected);
|
predict.bigspline <-
function(object,newdata=NULL,se.fit=FALSE,
effect=c("all","0","lin","non"),
design=FALSE,smoothMatrix=FALSE,...) {
effect <- effect[1]
if(!any(effect==c("all","0","lin","non"))){stop("Must set 'effect' to one of four specified options.")}
if(effect=="0"){
yhat <- object$coef[1]
if(se.fit){
pse <- sqrt(sum(object$coef.csqrt[1,]^2))
predcss <- list(fit=as.numeric(yhat),se.fit=pse)
} else {
predcss <- as.numeric(yhat)
}
return(predcss)
}
if(is.null(newdata)){
newdata <- object$x
} else {
newdata <- as.matrix(newdata+0.0)
if(ncol(newdata)>1){stop("Too many predictors in 'newdata' input.")}
}
nunewr <- nrow(newdata)
nknots <- nrow(object$myknots)
if(object$type=="cub"){
newdata <- (newdata-object$xrng[1])/(object$xrng[2]-object$xrng[1])
if(effect=="all"){
Kmat <- cbind(1,newdata-0.5)
Jmat <- (.Fortran("cubker",newdata,object$myknots,nunewr,nknots,
matrix(0,nunewr,nknots),PACKAGE="bigsplines"))[[5]]
cidx <- 1:(nknots+2)
} else if(effect=="non"){
Kmat <- NULL
Jmat <- (.Fortran("cubker",newdata,object$myknots,nunewr,nknots,
matrix(0,nunewr,nknots),PACKAGE="bigsplines"))[[5]]
cidx <- 3:(nknots+2)
} else {
Kmat <- newdata-0.5
Jmat <- NULL
cidx <- 2
}
} else if(object$type=="per"){
newdata <- (newdata-object$xrng[1])/(object$xrng[2]-object$xrng[1])
if(effect=="all"){
Kmat <- matrix(1,nunewr)
Jmat <- (.Fortran("perker",newdata,object$myknots,nunewr,nknots,
matrix(0,nunewr,nknots),PACKAGE="bigsplines"))[[5]]
cidx <- 1:(nknots+1)
} else if(effect=="non"){
Kmat <- NULL
Jmat <- (.Fortran("perker",newdata,object$myknots,nunewr,nknots,
matrix(0,nunewr,nknots),PACKAGE="bigsplines"))[[5]]
cidx <- 2:(nknots+1)
} else {stop("There is no linear effect for periodic splines.")}
} else if(object$type=="lin"){
newdata <- (newdata-object$xrng[1])/(object$xrng[2]-object$xrng[1])
if(effect=="all"){
Kmat <- matrix(1,nunewr)
Jmat <- (.Fortran("linker",newdata,object$myknots,nunewr,nknots,
matrix(0,nunewr,nknots),PACKAGE="bigsplines"))[[5]]
cidx <- 1:(nknots+1)
} else if(effect=="non"){
Kmat <- NULL
Jmat <- (.Fortran("linker",newdata,object$myknots,nunewr,nknots,
matrix(0,nunewr,nknots),PACKAGE="bigsplines"))[[5]]
cidx <- 2:(nknots+1)
} else {stop("There is no linear effect for linear splines.")}
} else {
if(effect=="all"){
Kmat <- cbind(1,newdata)
Jmat <- (.Fortran("cubkerz",newdata,object$myknots,nunewr,nknots,
matrix(0,nunewr,nknots),PACKAGE="bigsplines"))[[5]]
cidx <- 1:(nknots+2)
} else if(effect=="non"){
Kmat <- NULL
Jmat <- (.Fortran("cubkerz",newdata,object$myknots,nunewr,nknots,
matrix(0,nunewr,nknots),PACKAGE="bigsplines"))[[5]]
cidx <- 3:(nknots+2)
} else {
Kmat <- newdata
Jmat <- NULL
cidx <- 2
}
}
yhat <- cbind(Kmat,Jmat)%*%object$coef[cidx]
if(se.fit){pse <- sqrt(postvar(Kmat,Jmat,object$coef.csqrt[cidx,]))}
if(se.fit | design | smoothMatrix){
predcss <- list(fit=as.numeric(yhat))
if(se.fit){predcss <- c(predcss,list(se.fit=pse))}
if(design){predcss <- c(predcss,list(X=cbind(Kmat,Jmat),ix=cidx))}
if(smoothMatrix){predcss <- c(predcss,list(S=tcrossprod(cbind(Kmat,Jmat)%*%object$coef.csqrt[cidx,])))}
} else {
predcss <- as.numeric(yhat)
}
return(predcss)
}
|
`ddst.exp.test` <-
function(x, base = ddst.base.legendre, c = 100, B=1000, compute.p = F, Dmax = 5, ...) {
base = ddst.base.legendre
method.name = "ddst.base.legendre"
n = length(x)
if(n<5)
stop("length(x) should be at least 5")
er = mean(x)
maxN = max(min(Dmax, n-2, 20),1)
coord = numeric(maxN)
u = numeric(maxN)
for (j in 1:maxN) {
u[j] = ddst.phi(pexp(x,1/er), j, base)
coord[j] = t(u[1:j]) %*% MMexp[[j]] %*% u[1:j] * n
}
l = ddst.IIC(coord, n, c)
attr(l, "names") = "n. coord"
t = coord[l]
attr(t, "names") = "WT*"
result = list(statistic = t, parameter = l, method = "Data Driven Smooth Test for Expotentiality")
result$data.name = paste(paste(as.character(substitute(x)), collapse=""), ", base: ", method.name, ", c: ", c, sep="")
class(result) = "htest"
if (compute.p) {
tmp = numeric(B)
for (i in 1:B) {
y = rexp(length(x))
tmpC = ddst.exp.Nk(y, base, Dmax = Dmax, n=length(y))
l = ddst.IIC(tmpC, n, c)
tmp[i] = tmpC[l]
}
p.val = mean(tmp > t)
result$p.value = p.val
}
result
}
`MMexp` <-
list(structure(4, .Dim = c(1L, 1L)), structure(c(7.75, 2.90473750965556,
2.90473750965556, 2.25), .Dim = c(2L, 2L)), structure(c(13.0000000000001,
5.16397779494326, 3.05505046330393, 5.16397779494326, 3.22222222222224,
1.31468439624438, 3.05505046330393, 1.31468439624438, 1.77777777777779
), .Dim = c(3L, 3L)), structure(c(19.7499999999998, 8.06871530459869,
4.7735163489123, 3.24759526419154, 8.06871530459869, 4.47222222222218,
2.05419436913180, 1.39754248593732, 4.7735163489123, 2.05419436913180,
2.21527777777777, 0.826797284707661, 3.24759526419154, 1.39754248593732,
0.826797284707661, 1.56249999999997), .Dim = c(4L, 4L)), structure(c(28.0000000000111,
11.6189500386270, 6.87386354243662, 4.67653718043779, 3.44673758792592,
11.6189500386270, 6.00000000000206, 2.95803989155104, 2.01246117975060,
1.48323969742047, 6.87386354243662, 2.95803989155104, 2.75000000000074,
1.19058808997954, 0.877496438740007, 4.67653718043779, 2.01246117975060,
1.19058808997954, 1.8100000000003, 0.596992462264497, 3.44673758792592,
1.48323969742047, 0.877496438740007, 0.596992462264497, 1.44000000000061
), .Dim = c(5L, 5L)), structure(c(37.7499999996889, 15.8146819968797,
9.356092043789, 6.3652867177616, 4.69139282796864, 3.64291549898935,
15.8146819968797, 7.80555555549795, 4.02622096346428, 2.73918327241400,
2.01885403258216, 1.56766122880296, 9.356092043789, 4.02622096346428,
3.3819444444243, 1.62052267801332, 1.19437015271885, 0.927440890247034,
6.3652867177616, 2.73918327241400, 1.62052267801332, 2.10249999999062,
0.812573073630574, 0.630971473192956, 4.69139282796864, 2.01885403258216,
1.19437015271885, 0.812573073630574, 1.59888888888440, 0.465043473333310,
3.64291549898935, 1.56766122880296, 0.927440890247034, 0.630971473192956,
0.465043473333310, 1.36111111109903), .Dim = c(6L, 6L)), structure(c(49.0000000062404,
20.6559111824583, 12.2202018548044, 8.3138438774113, 6.12753349044019,
4.75809371362456, 3.83325939138121, 20.6559111824583, 9.88888889004452,
5.25873758566114, 3.57770876446472, 2.63687057353367, 2.04755752361801,
1.64957219827918, 12.2202018548044, 5.25873758566114, 4.11111111151561,
2.11660104912681, 1.55999366907329, 1.21135136702101, 0.975900073300267,
8.3138438774113, 3.57770876446472, 2.11660104912681, 2.44000000018715,
1.06131993305220, 0.824126005917164, 0.663940002446266, 6.12753349044019,
2.63687057353367, 1.55999366907329, 1.06131993305220, 1.78222222232468,
0.607403720356187, 0.489342193649563, 4.75809371362456, 2.04755752361801,
1.21135136702101, 0.824126005917164, 0.607403720356187, 1.47165532884771,
0.379979321051083, 3.83325939138121, 1.64957219827918, 0.975900073300267,
0.663940002446266, 0.489342193649563, 0.379979321051083, 1.30612244916046
), .Dim = c(7L, 7L)), structure(c(61.7499999643167, 26.1426375715444,
15.4661929613915, 10.5222086498002, 7.75515956827492, 6.02196235198601,
4.85146891373646, 4.01705348301015, 26.1426375715444, 12.249999993392,
6.65558975207775, 4.52803765177731, 3.33728931723443, 2.59143998896998,
2.08773981194937, 1.72866458228031, 15.4661929613915, 6.65558975207775,
4.93749999768723, 2.67882320087937, 1.9743669860045, 1.53311657278613,
1.23512352938459, 1.02269175869889, 10.5222086498002, 4.52803765177731,
2.67882320087937, 2.82249999892943, 1.34323303930558, 1.04303447549065,
0.840299064993236, 0.695774072929495, 7.75515956827492, 3.33728931723443,
1.9743669860045, 1.34323303930558, 1.98999999941946, 0.768745333024312,
0.619323713393434, 0.512804786392375, 6.02196235198601, 2.59143998896998,
1.53311657278613, 1.04303447549065, 0.768745333024312, 1.59693877514465,
0.480911327860278, 0.398198269214986, 4.85146891373646, 2.08773981194937,
1.23512352938459, 0.840299064993236, 0.619323713393434, 0.480911327860278,
1.38743622444076, 0.320800166404736, 4.01705348301015, 1.72866458228031,
1.02269175869889, 0.695774072929495, 0.512804786392375, 0.398198269214986,
0.320800166404736, 1.26562499909206), .Dim = c(8L, 8L)), structure(c(75.9999998148397,
32.2748611387149, 19.0940653485099, 12.9903810246956, 9.57427105393107,
7.43452140821745, 5.98946778346764, 4.95932527833625, 4.19435243809508,
32.2748611387149, 14.8888888546000, 8.21677745624167, 5.59016992994832,
4.12011026043898, 3.19930862233875, 2.57745655311289, 2.13415380126909,
1.80496190454075, 19.0940653485099, 8.21677745624167, 5.86111109911003,
3.30718913066588, 2.43749010159244, 1.89273650605146, 1.52484386056889,
1.26258241577133, 1.06782986327185, 12.9903810246956, 5.59016992994832,
3.30718913066588, 3.2499999944451, 1.65831239108443, 1.28769688089909,
1.03740625112627, 0.858980335333887, 0.726483152763092, 9.57427105393107,
4.12011026043898, 2.43749010159244, 1.65831239108443, 2.22222221920599,
0.949068310590093, 0.764597175590399, 0.63309232768836, 0.535438229829078,
7.43452140821745, 3.19930862233875, 1.89273650605146, 1.28769688089909,
0.949068310590093, 1.73696144940933, 0.593717687599357, 0.491602800575069,
0.415773374288155, 5.98946778346764, 2.57745655311289, 1.52484386056889,
1.03740625112627, 0.764597175590399, 0.593717687599357, 1.47831632557016,
0.396049587408857, 0.334959184833341, 4.95932527833625, 2.13415380126909,
1.26258241577133, 0.858980335333887, 0.63309232768836, 0.491602800575069,
0.396049587408857, 1.32793209702753, 0.277348774984669, 4.19435243809508,
1.80496190454075, 1.06782986327185, 0.726483152763092, 0.535438229829078,
0.415773374288155, 0.334959184833341, 0.277348774984669, 1.23456789891182
), .Dim = c(9L, 9L)), structure(c(91.7500063635929, 39.0525848127125,
23.1038207488272, 15.7183621808938, 11.5848688162142, 8.99577155695548,
7.24725654408169, 6.00078402238999, 5.07516681850665, 4.36549072927617,
39.0525848127125, 17.8055567339987, 9.94230144377437, 6.76410610625093,
4.9853337770217, 3.87116371404166, 3.1187226556579, 2.58232628698933,
2.18400406303342, 1.87860809916772, 23.1038207488272, 9.94230144377437,
6.8819448568996, 4.0016991385932, 2.94936323702418, 2.29021133857108,
1.84506120522325, 1.52772483398243, 1.29207422835195, 1.11139953958534,
15.7183621808938, 6.76410610625093, 4.0016991385932, 3.72250019090767,
2.00655813887029, 1.55811333899295, 1.25526165498353, 1.03936628120268,
0.879044678654103, 0.756125174307707, 11.5848688162142, 4.9853337770217,
2.94936323702418, 2.00655813887029, 2.47888899259333, 1.14837273917558,
0.925162649622896, 0.76604177211068, 0.647880305123485, 0.557285221716005,
8.99577155695548, 3.87116371404166, 2.29021133857108, 1.55811333899295,
1.14837273917558, 1.89172341851641, 0.718398454144509, 0.594839431875843,
0.503085819408188, 0.432737791524058, 7.24725654408169, 3.1187226556579,
1.84506120522325, 1.25526165498353, 0.925162649622896, 0.718398454144509,
1.57876279595288, 0.479220035551796, 0.405300643069535, 0.348626215287706,
6.00078402238999, 2.58232628698933, 1.52772483398243, 1.03936628120268,
0.76604177211068, 0.594839431875843, 0.479220035551796, 1.39679786620728,
0.335592042092423, 0.288665181059883, 5.07516681850665, 2.18400406303342,
1.29207422835195, 0.879044678654103, 0.647880305123485, 0.503085819408188,
0.405300643069535, 0.335592042092423, 1.28382717828662, 0.24413875638701,
4.36549072927617, 1.87860809916772, 1.11139953958534, 0.756125174307707,
0.557285221716005, 0.432737791524058, 0.348626215287706, 0.288665181059883,
0.24413875638701, 1.21000008783516), .Dim = c(10L, 10L)), structure(c(108.999909639504,
46.4757612695227, 27.4954311650789, 18.7061330708465, 13.7869388165529,
10.7057018971028, 8.624826413336, 7.14142244340708, 6.03986247238459,
5.19529004113727, 4.53087098633189, 46.4757612695227, 20.9999832665748,
11.8321496665714, 8.04983798392535, 5.93295382574333, 4.60700057299338,
3.71153434030891, 3.07317891017194, 2.59914297432541, 2.23569686756021,
1.94977643043087, 27.4954311650789, 11.8321496665714, 7.99999414330124,
4.76234837539283, 3.50998281825438, 2.72553829506146, 2.19577332749816,
1.81811716203164, 1.53767372037920, 1.32265610393122, 1.15350329216362,
18.7061330708465, 8.04983798392535, 4.76234837539283, 4.23999728918498,
2.38796785111126, 1.85428196164682, 1.49386375543597, 1.23693065102935,
1.04613486728985, 0.899850631130616, 0.784769875086638, 13.7869388165529,
5.93295382574333, 3.50998281825438, 2.38796785111126, 2.75999852746031,
1.36665722717996, 1.10101901437664, 0.911652191368105, 0.771030407757874,
0.663214869072507, 0.57839716054173, 10.7057018971028, 4.60700057299338,
2.72553829506146, 1.85428196164682, 1.36665722717996, 2.06122360187336,
0.854952756938788, 0.707907442289478, 0.598713159526537, 0.514993268374537,
0.449131432385561, 8.624826413336, 3.71153434030891, 2.19577332749816,
1.49386375543597, 1.10101901437664, 0.854952756938788, 1.68877493424281,
0.570310930113578, 0.482340823789774, 0.414893632053117, 0.36183341160907,
7.14142244340708, 3.07317891017194, 1.81811716203164, 1.23693065102935,
0.911652191368105, 0.707907442289478, 0.570310930113578, 1.47222182579071,
0.399381902812281, 0.343535110572130, 0.299600840944936, 6.03986247238459,
2.59914297432541, 1.53767372037920, 1.04613486728985, 0.771030407757874,
0.598713159526537, 0.482340823789774, 0.399381902812281, 1.33777749265798,
0.290545033392701, 0.253387597535103, 5.19529004113727, 2.23569686756021,
1.32265610393122, 0.899850631130616, 0.663214869072507, 0.514993268374537,
0.414893632053117, 0.343535110572130, 0.290545033392701, 1.24991723327949,
0.217955635255067, 4.53087098633189, 1.94977643043087, 1.15350329216362,
0.784769875086638, 0.57839716054173, 0.449131432385561, 0.36183341160907,
0.299600840944936, 0.253387597535103, 0.217955635255067, 1.19008156546897
), .Dim = c(11L, 11L)), structure(c(127.750817320277, 54.5448671777347,
32.2691785982051, 21.9538855499597, 16.1806224577019, 12.5644222293746,
10.1222658498964, 8.38131378584157, 7.08850134627143, 6.09729453596856,
5.31751927022201, 4.69110156706042, 54.5448671777347, 24.4723735778291,
13.8864434785157, 9.44744812439306, 6.96303125666103, 5.40686644989844,
4.35592967361478, 3.60674319021145, 3.05040529596424, 2.62385779941419,
2.28829595296743, 2.01872869384361, 32.2691785982051, 13.8864434785157,
9.21533075224026, 5.58918568506044, 4.11938484466232, 3.19874532941639,
2.57700274786762, 2.13377804704423, 1.80464411017141, 1.55229520808426,
1.35377414250993, 1.19429600132113, 21.9538855499597, 9.44744812439306,
5.58918568506044, 4.80252451960815, 2.80256601948291, 2.17622176690241,
1.75322787397396, 1.45168613112547, 1.22776444812623, 1.05608239250094,
0.92102135462509, 0.812522625761445, 16.1806224577019, 6.96303125666103,
4.11938484466232, 2.80256601948291, 3.06556887485098, 1.60393579142739,
1.29217756221491, 1.06993293562407, 0.904896445638785, 0.778362009695168,
0.678818279377299, 0.598851707405877, 12.5644222293746, 5.40686644989844,
3.19874532941639, 2.17622176690241, 1.60393579142739, 2.24547288369041,
1.00338936462015, 0.83081409231548, 0.702661535215176, 0.604406224957035,
0.527109479342321, 0.465014601527138, 10.1222658498964, 4.35592967361478,
2.57700274786762, 1.75322787397396, 1.29217756221491, 1.00338936462015,
1.80835980471101, 0.669328120364857, 0.566084674018348, 0.486927323728754,
0.424654805807897, 0.374629356989992, 8.38131378584157, 3.60674319021145,
2.13377804704423, 1.45168613112547, 1.06993293562407, 0.83081409231548,
0.669328120364857, 1.55420881901880, 0.468722453318310, 0.403179559951243,
0.351617437332770, 0.31019598189602, 7.08850134627143, 3.05040529596424,
1.80464411017141, 1.22776444812623, 0.904896445638785, 0.702661535215176,
0.566084674018348, 0.468722453318310, 1.39642230636767, 0.340989363544816,
0.297380666276484, 0.26234844458304, 6.09729453596856, 2.62385779941419,
1.55229520808426, 1.05608239250094, 0.778362009695168, 0.604406224957035,
0.486927323728754, 0.403179559951243, 0.340989363544816, 1.29330777855588,
0.255797018723013, 0.225663459670135, 5.31751927022201, 2.28829595296743,
1.35377414250993, 0.92102135462509, 0.678818279377299, 0.527109479342321,
0.424654805807897, 0.351617437332770, 0.297380666276484, 0.255797018723013,
1.22308346239483, 0.196803645994492, 4.69110156706042, 2.01872869384361,
1.19429600132113, 0.812522625761445, 0.598851707405877, 0.465014601527138,
0.374629356989992, 0.31019598189602, 0.26234844458304, 0.225663459670135,
0.196803645994492, 1.17361966082530), .Dim = c(12L, 12L)), structure(c(147.996562053869,
63.2572485315976, 37.4234929172294, 25.4605514015246, 18.7651324343239,
14.5713212029584, 11.7390823316768, 9.72005023762722, 8.22073853285857,
7.07120753590464, 6.16687977169189, 5.44040517593633, 4.8455723556124,
63.2572485315976, 28.2215855655312, 16.1045072028156, 10.9564768403736,
8.07522726750147, 6.27049826125522, 5.05169670781577, 4.18284363273663,
3.53764260347632, 3.04296322490390, 2.65380251709179, 2.34117762700245,
2.08520233734776, 37.4234929172294, 16.1045072028156, 10.5275549479360,
6.4819391129334, 4.77736887812004, 3.70967679933735, 2.98862407634599,
2.47460366515002, 2.09289758862582, 1.80024132155696, 1.57001074197057,
1.38505936277544, 1.23362233916552, 25.4605514015246, 10.9564768403736,
6.4819391129334, 5.40989686161587, 3.2502162787007, 2.52382686569291,
2.03326870326979, 1.68356208636919, 1.42387368146500, 1.22476907230505,
1.06813490887389, 0.942305817848223, 0.83927775116717, 18.7651324343239,
8.07522726750147, 4.77736887812004, 3.2502162787007, 3.39549952976909,
1.86013038873919, 1.49857541927151, 1.24083194483497, 1.04943438895196,
0.902688770593242, 0.787245048492656, 0.694505519016251, 0.618570976781375,
14.5713212029584, 6.27049826125522, 3.70967679933735, 2.52382686569291,
1.86013038873919, 2.44441066262473, 1.16365945497522, 0.963518956786588,
0.814896756863755, 0.700947252498923, 0.611303997303143, 0.539290784663079,
0.48032682002406, 11.7390823316768, 5.05169670781577, 2.98862407634599,
2.03326870326979, 1.49857541927151, 1.16365945497522, 1.93747807475515,
0.776239038609117, 0.65650464960568, 0.564703597747668, 0.492484370776738,
0.434468421476367, 0.386965327840699, 9.72005023762722, 4.18284363273663,
2.47460366515002, 1.68356208636919, 1.24083194483497, 0.963518956786588,
0.776239038609117, 1.64273187958895, 0.543590886843331, 0.46757891157001,
0.407780837542892, 0.359743186400301, 0.320410260406975, 8.22073853285857,
3.53764260347632, 2.09289758862582, 1.42387368146500, 1.04943438895196,
0.814896756863755, 0.65650464960568, 0.543590886843331, 1.45974233057818,
0.39545515522294, 0.344880896929245, 0.304253023603323, 0.270987176985400,
7.07120753590464, 3.04296322490390, 1.80024132155696, 1.22476907230505,
0.902688770593242, 0.700947252498923, 0.564703597747668, 0.46757891157001,
0.39545515522294, 1.34015745210089, 0.296655146932111, 0.261708393318463,
0.233094211715109, 6.16687977169189, 2.65380251709179, 1.57001074197057,
1.06813490887389, 0.787245048492656, 0.611303997303143, 0.492484370776738,
0.407780837542892, 0.344880896929245, 0.296655146932111, 1.25871629640267,
0.228238838789949, 0.203284088583955, 5.44040517593633, 2.34117762700245,
1.38505936277544, 0.942305817848223, 0.694505519016251, 0.539290784663079,
0.434468421476367, 0.359743186400301, 0.304253023603323, 0.261708393318463,
0.228238838789949, 1.20135170554199, 0.179336690297472, 4.8455723556124,
2.08520233734776, 1.23362233916552, 0.83927775116717, 0.618570976781375,
0.48032682002406, 0.386965327840699, 0.320410260406975, 0.270987176985400,
0.233094211715109, 0.203284088583955, 0.179336690297472, 1.15972871151143
), .Dim = c(13L, 13L)), structure(c(169.708363605662, 72.6005202900706,
42.9510470330602, 29.2211457426805, 21.5367947495137, 16.7235459209089,
13.4729774814976, 11.1557287248254, 9.43496450617895, 8.1156445799142,
7.07774508667577, 6.24396817013748, 5.56127688584052, 4.99186288885493,
72.6005202900706, 32.2422895566041, 18.4831877623571, 12.5747789798335,
9.26796082172822, 7.19666831569057, 5.79784637885196, 4.80066128511737,
4.06016226716546, 3.49241736686069, 3.04577653882185, 2.68697608191018,
2.39319252916762, 2.148155759454, 42.9510470330602, 18.4831877623571,
11.9348013448115, 7.43933956995392, 5.48299956479859, 4.25760639281307,
3.43005217474436, 2.84010951743920, 2.40202439048816, 2.06614197782306,
1.80190570051631, 1.58963648758611, 1.41583179388737, 1.27086608594549,
29.2211457426805, 12.5747789798335, 7.43933956995392, 6.06125090816965,
3.73028227383396, 2.89660312177248, 2.33358815271847, 1.93222889468527,
1.63418378923106, 1.40567087485821, 1.22590140931432, 1.08148701115207,
0.9632414121234, 0.86461601479141, 21.5367947495137, 9.26796082172822,
5.48299956479859, 3.73028227383396, 3.74932148098385, 2.13487682699919,
1.71991918173104, 1.42410627839054, 1.20443877052521, 1.03601841569726,
0.903523334370124, 0.797085918141371, 0.70993563256601, 0.637245979732655,
16.7235459209089, 7.19666831569057, 4.25760639281307, 2.89660312177248,
2.13487682699919, 2.65775413969673, 1.33553519687885, 1.10583338978316,
0.935259277068427, 0.804479113597514, 0.701595299982726, 0.618945535302927,
0.551272428891733, 0.494828154742676, 13.4729774814976, 5.79784637885196,
3.43005217474436, 2.33358815271847, 1.71991918173104, 1.33553519687885,
2.07594619696050, 0.890891706178717, 0.753472214499101, 0.648111891646325,
0.56522568374531, 0.498640617178190, 0.444121184332248, 0.398648027014641,
11.1557287248254, 4.80066128511737, 2.84010951743920, 1.93222889468527,
1.42410627839054, 1.10583338978316, 0.890891706178717, 1.73766516799833,
0.623880774549554, 0.536641618860344, 0.468011202781713, 0.412878256796512,
0.367735748104881, 0.330083624957404, 9.43496450617895, 4.06016226716546,
2.40202439048816, 1.63418378923106, 1.20443877052521, 0.935259277068427,
0.753472214499101, 0.623880774549554, 1.52764755303375, 0.453864982860186,
0.395820765784057, 0.349192042432809, 0.311012737635123, 0.279168431069279,
8.1156445799142, 3.49241736686069, 2.06614197782306, 1.40567087485821,
1.03601841569726, 0.804479113597514, 0.648111891646325, 0.536641618860344,
0.453864982860186, 1.39039965500134, 0.340471938219705, 0.300363451782258,
0.267522875875129, 0.240131456033224, 7.07774508667577, 3.04577653882185,
1.80190570051631, 1.22590140931432, 0.903523334370124, 0.701595299982726,
0.56522568374531, 0.468011202781713, 0.395820765784057, 0.340471938219705,
1.29692941382001, 0.261950350848327, 0.233309714546246, 0.209421348650710,
6.24396817013748, 2.68697608191018, 1.58963648758611, 1.08148701115207,
0.797085918141371, 0.618945535302927, 0.498640617178190, 0.412878256796512,
0.349192042432809, 0.300363451782258, 0.261950350848327, 1.23109191314793,
0.205825218847325, 0.184750965047323, 5.56127688584052, 2.39319252916762,
1.41583179388737, 0.9632414121234, 0.70993563256601, 0.551272428891733,
0.444121184332248, 0.367735748104881, 0.311012737635123, 0.267522875875129,
0.233309714546246, 0.205825218847325, 1.18332108699290, 0.164551010440494,
4.99186288885493, 2.148155759454, 1.27086608594549, 0.86461601479141,
0.637245979732655, 0.494828154742676, 0.398648027014641, 0.330083624957404,
0.279168431069279, 0.240131456033224, 0.209421348650710, 0.184750965047323,
0.164551010440494, 1.14770278466675), .Dim = c(14L, 14L)), structure(c(194.223702948996,
83.1502426237768, 49.1923469346356, 33.4673270734251, 24.6663481419357,
19.1536767959448, 15.4307619556333, 12.7767892903259, 10.8059774875029,
9.2949446253555, 8.10622594486867, 7.1512912883777, 6.3693968102166,
5.71724016156512, 5.29884051697693, 83.1502426237768, 36.7821672127771,
21.1690156043001, 14.4020444886058, 10.6147061739413, 8.24243013881486,
6.64034267482875, 5.4982546821593, 4.65015231651012, 3.99990730421356,
3.48836423167454, 3.07742578486278, 2.74095197459506, 2.46030843688999,
2.28025789738453, 49.1923469346356, 21.1690156043001, 13.5237585244721,
8.52036442343422, 6.27974485991968, 4.87628743078538, 3.92847970514082,
3.25281133674556, 2.75106721080395, 2.36637707367304, 2.06374411070976,
1.82062964698163, 1.62156905633489, 1.45553810036743, 1.34901876469699,
33.4673270734251, 14.4020444886058, 8.52036442343422, 6.79671108846964,
4.27233682190139, 3.31751413623288, 2.67268637066572, 2.21300482084460,
1.87165020338001, 1.60993163446546, 1.40403951941453, 1.23863998511946,
1.10321188888621, 0.990255043890387, 0.917786099660839, 24.6663481419357,
10.6147061739413, 6.27974485991968, 4.27233682190139, 4.14883071472746,
2.44509991702001, 1.96984397195543, 1.63104592222066, 1.37945810297935,
1.18656425992184, 1.03481606149584, 0.912912017994389, 0.813097755488148,
0.729845428298447, 0.676433806751174, 19.1536767959448, 8.24243013881486,
4.87628743078538, 3.31751413623288, 2.44509991702001, 2.89864560716111,
1.52960440516647, 1.26652418322296, 1.07116361554524, 0.921379533013388,
0.803545473010114, 0.708885710814673, 0.631378894131914, 0.566732593093505,
0.525257911459359, 15.4307619556333, 6.64034267482875, 3.92847970514082,
2.67268637066572, 1.96984397195543, 1.52960440516647, 2.23229402447727,
1.02034890692653, 0.862960722534151, 0.742290286935001, 0.647359723495542,
0.571099051835679, 0.508657294521293, 0.456576344567752, 0.423163128593591,
12.7767892903259, 5.4982546821593, 3.25281133674556, 2.21300482084460,
1.63104592222066, 1.26652418322296, 1.02034890692653, 1.84485672346564,
0.714538099242797, 0.614622052734197, 0.536018817860557, 0.472874396623399,
0.421172142488611, 0.378048716340917, 0.350382317154572, 10.8059774875029,
4.65015231651012, 2.75106721080395, 1.87165020338001, 1.37945810297935,
1.07116361554524, 0.862960722534151, 0.714538099242797, 1.60432104176806,
0.519816983300907, 0.45333824852733, 0.399933814999827, 0.356206601414431,
0.319734936933840, 0.296336062617718, 9.2949446253555, 3.99990730421356,
2.36637707367304, 1.60993163446546, 1.18656425992184, 0.921379533013388,
0.742290286935001, 0.614622052734197, 0.519816983300907, 1.44712938562838,
0.389946575540285, 0.344009847191490, 0.306397143540442, 0.275025423385213,
0.254898485186838, 8.10622594486867, 3.48836423167454, 2.06374411070976,
1.40403951941453, 1.03481606149584, 0.803545473010114, 0.647359723495542,
0.536018817860557, 0.45333824852733, 0.389946575540285, 1.34007680251634,
0.300014864100097, 0.267212401419356, 0.239852770769835, 0.222299841173098,
7.1512912883777, 3.07742578486278, 1.82062964698163, 1.23863998511946,
0.912912017994389, 0.708885710814673, 0.571099051835679, 0.472874396623399,
0.399933814999827, 0.344009847191490, 0.300014864100097, 1.26467232700082,
0.235734080373908, 0.211597485903456, 0.196112337405947, 6.3693968102166,
2.74095197459506, 1.62156905633489, 1.10321188888621, 0.813097755488148,
0.631378894131914, 0.508657294521293, 0.421172142488611, 0.356206601414431,
0.306397143540442, 0.267212401419356, 0.235734080373908, 1.20995982949724,
0.188462236736698, 0.174670174370834, 5.71724016156512, 2.46030843688999,
1.45553810036743, 0.990255043890387, 0.729845428298447, 0.566732593093505,
0.456576344567752, 0.378048716340917, 0.319734936933840, 0.275025423385213,
0.239852770769835, 0.211597485903456, 0.188462236736698, 1.16916576261682,
0.156785856760988, 5.29884051697693, 2.28025789738453, 1.34901876469699,
0.917786099660839, 0.676433806751174, 0.525257911459359, 0.423163128593591,
0.350382317154572, 0.296336062617718, 0.254898485186838, 0.222299841173098,
0.196112337405947, 0.174670174370834, 0.156785856760988, 1.14531193842076
), .Dim = c(15L, 15L)), structure(c(204.036379451817, 87.372946254571,
51.6905320926518, 35.1669324995374, 25.9190044730623, 20.1263775121080,
16.2143980880111, 13.4256460203089, 11.3547484703757, 9.7669792842934,
8.51789268989926, 7.51446261218168, 6.69286038876759, 6.00758460346407,
5.56793694272373, 3.21107515764815, 87.372946254571, 38.5993295281143,
22.2440633279379, 15.1334382119898, 11.1537636304940, 8.66101388043088,
6.97756597373827, 5.77747816097024, 4.8863057473488, 4.20303867898013,
3.66551739252908, 3.23370983918644, 2.88014853602091, 2.58525279112760,
2.39605856132245, 1.38182673433241, 51.6905320926518, 22.2440633279379,
14.1597653348401, 8.95306278547407, 6.59865555198374, 5.12392491191625,
4.12798369924769, 3.41800217454157, 2.89077746459338, 2.48655121563002,
2.16854933405414, 1.91308854040213, 1.70391885262773, 1.52945617717919,
1.41752736137626, 0.817499720673055, 35.1669324995374, 15.1334382119898,
8.95306278547407, 7.09109138355426, 4.48930326289479, 3.48599084232821,
2.80841613025823, 2.32539010316094, 1.96670012578552, 1.69169043568685,
1.47534229123247, 1.30154310358751, 1.15923742413104, 1.04054417639681,
0.964394967813702, 0.556174531996873, 25.9190044730623, 11.1537636304940,
6.59865555198374, 4.48930326289479, 4.3087409984773, 2.5692719214719,
2.06988056872293, 1.71387699186547, 1.44951253163971, 1.24682276369089,
1.08736818163641, 0.959273360683702, 0.85439012861838, 0.76690991353319,
0.710785835099234, 0.409916053463574, 20.1263775121080, 8.66101388043088,
5.12392491191625, 3.48599084232821, 2.5692719214719, 2.99506646470721,
1.60728386672378, 1.33084337338073, 1.12556161061789, 0.9681708901595,
0.844352742830608, 0.744885777325835, 0.663442852871287, 0.595513552751955,
0.551932620033072, 0.318304094158236, 16.2143980880111, 6.97756597373827,
4.12798369924769, 2.80841613025823, 2.06988056872293, 1.60728386672378,
2.29487486954961, 1.07216632679204, 0.906785337607922, 0.779986772126583,
0.680235253001849, 0.600101757824657, 0.53448895702315, 0.479763127036497,
0.444653053615402, 0.256435083393446, 13.4256460203089, 5.77747816097024,
3.41800217454157, 2.32539010316094, 1.71387699186547, 1.33084337338073,
1.07216632679204, 1.88776194467854, 0.750825216764094, 0.645835031695544,
0.563240008526169, 0.496888859702792, 0.442560957231136, 0.397247550123433,
0.368176139952049, 0.212330216523696, 11.3547484703757, 4.8863057473488,
2.89077746459338, 1.96670012578552, 1.44951253163971, 1.12556161061789,
0.906785337607922, 0.750825216764094, 1.63501089397674, 0.546215379667168,
0.47636058746019, 0.420244062082548, 0.374296204783495, 0.335972362544143,
0.311385199313721, 0.179578412661851, 9.7669792842934, 4.20303867898013,
2.48655121563002, 1.69169043568685, 1.24682276369089, 0.9681708901595,
0.779986772126583, 0.645835031695544, 0.546215379667168, 1.46983641354014,
0.409749630448977, 0.361480050343357, 0.321957222376859, 0.288992320140332,
0.267843255098725, 0.154467414311342, 8.51789268989926, 3.66551739252908,
2.16854933405414, 1.47534229123247, 1.08736818163641, 0.844352742830608,
0.680235253001849, 0.563240008526169, 0.47636058746019, 0.409749630448977,
1.35734726984657, 0.31525082512621, 0.280782521506342, 0.252033458811462,
0.233589120877234, 0.134712772587334, 7.51446261218168, 3.23370983918644,
1.91308854040213, 1.30154310358751, 0.959273360683702, 0.744885777325835,
0.600101757824657, 0.496888859702792, 0.420244062082548, 0.361480050343357,
0.31525082512621, 1.27811345189632, 0.247705604757796, 0.222343256977561,
0.206071710380414, 0.118843254997948, 6.69286038876759, 2.88014853602091,
1.70391885262773, 1.15923742413104, 0.85439012861838, 0.663442852871287,
0.53448895702315, 0.442560957231136, 0.374296204783495, 0.321957222376859,
0.280782521506342, 0.247705604757796, 1.22062243379475, 0.198033106841508,
0.183540628096921, 0.105849394015022, 6.00758460346407, 2.58525279112760,
1.52945617717919, 1.04054417639681, 0.76690991353319, 0.595513552751955,
0.479763127036497, 0.397247550123433, 0.335972362544143, 0.288992320140332,
0.252033458811462, 0.222343256977561, 0.198033106841508, 1.17775668018323,
0.164748072933914, 0.0950115724568016, 5.56793694272373, 2.39605856132245,
1.41752736137626, 0.964394967813702, 0.710785835099234, 0.551932620033072,
0.444653053615402, 0.368176139952049, 0.311385199313721, 0.267843255098725,
0.233589120877234, 0.206071710380414, 0.183540628096921, 0.164748072933914,
1.15269146288882, 0.0880584260042643, 3.21107515764815, 1.38182673433241,
0.817499720673055, 0.556174531996873, 0.409916053463574, 0.318304094158236,
0.256435083393446, 0.212330216523696, 0.179578412661851, 0.154467414311342,
0.134712772587334, 0.118843254997948, 0.105849394015022, 0.0950115724568016,
0.0880584260042643, 1.05078402055781), .Dim = c(16L, 16L)), structure(c(-114.490281610438,
-49.6991041473369, -29.4023865284223, -20.0035035529712, -14.7431368395068,
-11.4481996425816, -9.22300430289411, -7.63671832542447, -6.45875927259913,
-5.55561122135773, -4.84511114776556, -4.2743443592478, -3.80700411012573,
-3.41720848020366, -3.16712998547596, -1.82650998422218, -13.4604222716588,
-49.6991041473369, -20.3870891871182, -12.6527725959259, -8.60813734738428,
-6.34443593891854, -4.92652072886401, -3.96894911856758, -3.28632032156067,
-2.77940745554879, -2.39075441536906, -2.08500386509110, -1.83938494659137,
-1.63827372416224, -1.47053239270528, -1.36291574322473, -0.786004750063787,
-5.79244347678379, -29.4023865284223, -12.6527725959259, -6.48548121549143,
-5.09264273310051, -3.75341891934068, -2.91456896850537, -2.34806196405088,
-1.94421332151746, -1.64431962567686, -1.41438938631211, -1.23350492139501,
-1.08819480958670, -0.969215805869958, -0.869978695887686, -0.806311827456003,
-0.465006681127265, -3.4268557747748, -20.0035035529712, -8.60813734738428,
-5.09264273310051, -2.464708448313, -2.55358620689657, -1.98288634361427,
-1.59747120510386, -1.32271841427272, -1.11868992139981, -0.962260090249116,
-0.839197867624813, -0.740338159926247, -0.659392454336117, -0.591877870776784,
-0.548563004901913, -0.316360809320458, -2.33141352658443, -14.7431368395068,
-6.34443593891854, -3.75341891934068, -2.55358620689657, -0.882063848468242,
-1.46144222304258, -1.1773805779398, -0.974880151875275, -0.824505494674938,
-0.709212371131439, -0.618512100395393, -0.545649754324166, -0.485990524583461,
-0.436230404240456, -0.404306146917881, -0.233166689531036, -1.71831642196528,
-11.4481996425816, -4.92652072886401, -2.91456896850537, -1.98288634361427,
-1.46144222304258, -0.134825140512594, -0.914248308096406, -0.757004613587493,
-0.640237122682769, -0.550710808838492, -0.480281101895801, -0.423702729644989,
-0.377376715037024, -0.338737462201827, -0.313947943170122, -0.181056368180629,
-1.33429063719136, -9.22300430289411, -3.96894911856758, -2.34806196405088,
-1.59747120510386, -1.1773805779398, -0.914248308096406, 0.263454836328712,
-0.609865046592928, -0.515793742398798, -0.443668726799243, -0.386928495980074,
-0.341347305311537, -0.304025713672272, -0.272896802028025, -0.252925640811925,
-0.145864303115853, -1.07494354329344, -7.63671832542447, -3.28632032156067,
-1.94421332151746, -1.32271841427272, -0.974880151875275, -0.757004613587493,
-0.609865046592928, 0.49502706228917, -0.427081176084906, -0.367361109796115,
-0.320379763343788, -0.282638187752866, -0.251735623529173, -0.225960645854106,
-0.20942437114033, -0.120776762109996, -0.890061501249627, -6.45875927259913,
-2.77940745554879, -1.64431962567686, -1.11868992139981, -0.824505494674938,
-0.640237122682769, -0.515793742398798, -0.427081176084906, 0.638795829746987,
-0.310695887052516, -0.270961384075246, -0.239041423049733, -0.212905560140873,
-0.191106356744089, -0.177120792121878, -0.102147021659212, -0.752770068164062,
-5.55561122135773, -2.39075441536906, -1.41438938631211, -0.962260090249116,
-0.709212371131439, -0.550710808838492, -0.443668726799243, -0.367361109796115,
-0.310695887052516, 0.732749668522011, -0.233072025506421, -0.205615530199192,
-0.183134324889012, -0.164383370735693, -0.152353450363554, -0.0878634913931107,
-0.647507928579529, -4.84511114776556, -2.08500386509110, -1.23350492139501,
-0.839197867624813, -0.618512100395393, -0.480281101895801, -0.386928495980074,
-0.320379763343788, -0.270961384075246, -0.233072025506421, 0.79673526025864,
-0.179319620799233, -0.159713508325989, -0.143360589919778, -0.132869160807945,
-0.0766267409054455, -0.564698960749193, -4.2743443592478, -1.83938494659137,
-1.08819480958670, -0.740338159926247, -0.545649754324166, -0.423702729644989,
-0.341347305311537, -0.282638187752866, -0.239041423049733, -0.205615530199192,
-0.179319620799233, 0.841804700389767, -0.140898838558883, -0.126472336789350,
-0.11721682551686, -0.0675999100470134, -0.498175943531151, -3.80700411012573,
-1.63827372416224, -0.969215805869958, -0.659392454336117, -0.485990524583461,
-0.377376715037024, -0.304025713672272, -0.251735623529173, -0.212905560140873,
-0.183134324889012, -0.159713508325989, -0.140898838558883, 0.874506494465035,
-0.112644341566105, -0.104400792030969, -0.0602087978326573,
-0.443707316301163, -3.41720848020366, -1.47053239270528, -0.869978695887686,
-0.591877870776784, -0.436230404240456, -0.338737462201827, -0.272896802028025,
-0.225960645854106, -0.191106356744089, -0.164383370735693, -0.143360589919778,
-0.126472336789350, -0.112644341566105, 0.898889208387553, -0.093711291490154,
-0.0540440747067723, -0.398276534548492, -3.16712998547596, -1.36291574322473,
-0.806311827456003, -0.548563004901913, -0.404306146917881, -0.313947943170122,
-0.252925640811925, -0.20942437114033, -0.177120792121878, -0.152353450363554,
-0.132869160807945, -0.11721682551686, -0.104400792030969, -0.093711291490154,
0.91314669766989, -0.0500890157954074, -0.36912982113541, -1.82650998422218,
-0.786004750063787, -0.465006681127265, -0.316360809320458, -0.233166689531036,
-0.181056368180629, -0.145864303115853, -0.120776762109996, -0.102147021659212,
-0.0878634913931107, -0.0766267409054455, -0.0675999100470134,
-0.0602087978326573, -0.0540440747067723, -0.0500890157954074,
0.97111325147066, -0.212880212327834, -13.4604222716588, -5.79244347678379,
-3.4268557747748, -2.33141352658443, -1.71831642196528, -1.33429063719136,
-1.07494354329344, -0.890061501249627, -0.752770068164062, -0.647507928579529,
-0.564698960749193, -0.498175943531151, -0.443707316301163, -0.398276534548492,
-0.36912982113541, -0.212880212327834, -0.568815706437707), .Dim = c(17L,
17L)), structure(c(-0.147488313744484, -0.49380034767778, -0.292136225378409,
-0.198750806049694, -0.146484855655082, -0.113747019403655, -0.0916379240539453,
-0.0758769041999714, -0.0641729389109609, -0.0551994407089534,
-0.0481400542394349, -0.0424690297119616, -0.0378256305710806,
-0.0339526992400012, -0.0314679693889926, -0.0181478374856014,
-0.133740060543748, 1.06587386665492, -0.49380034767778, 0.787502164121392,
-0.125715415079386, -0.0855287290973073, -0.0630370451581924,
-0.0489489235367877, -0.0394346837491056, -0.0326522207031405,
-0.0276156359643709, -0.0237540571761934, -0.0207161809283170,
-0.0182757605337795, -0.0162775596957322, -0.0146109154128127,
-0.0135416579313926, -0.00780958581682367, -0.0575525585785231,
0.458679081634688, -0.292136225378409, -0.125715415079386, 0.925625757442486,
-0.0505994785086786, -0.0372932188446721, -0.0289585736940480,
-0.0233298735281012, -0.0193173142775157, -0.0163376305626254,
-0.0140530897426671, -0.0122558579173051, -0.0108120857414663,
-0.00962993418341185, -0.008643934128632, -0.00801135287175625,
-0.00462021327652922, -0.0340485528272058, 0.271358204178969,
-0.198750806049694, -0.0855287290973073, -0.0505994785086786,
0.965575350587667, -0.0253719212533990, -0.0197015616816650,
-0.0158721540361568, -0.0131422653195384, -0.0111150790664796,
-0.0095608235857291, -0.0083381019821821, -0.00735585172092681,
-0.00655159139774408, -0.0058807800137786, -0.00545041217927562,
-0.0031432976572564, -0.0231644579869104, 0.184614769150617,
-0.146484855655082, -0.0630370451581924, -0.0372932188446721,
-0.0253719212533990, 0.981300190442664, -0.0145205973071465,
-0.0116982176783742, -0.00968621399116252, -0.00819212150637007,
-0.00704659211570221, -0.0061454123863624, -0.00542146670484817,
-0.00482870454356629, -0.00433429795118548, -0.00401710492254439,
-0.00231669754078399, -0.0170728479143494, 0.136066204451331,
-0.113747019403655, -0.0489489235367877, -0.0289585736940480,
-0.0197015616816650, -0.0145205973071465, 0.988724604627131,
-0.00908378813154157, -0.00752144626742167, -0.00636126785786165,
-0.00547175232913994, -0.00477197686292545, -0.00420982548479058,
-0.00374953947939052, -0.00336562759986317, -0.00311932390230896,
-0.00179893982176863, -0.0132572446093801, 0.105656827995586,
-0.0916379240539453, -0.0394346837491056, -0.0233298735281012,
-0.0158721540361568, -0.0116982176783742, -0.00908378813154157,
0.9926818347304, -0.00605949699115956, -0.00512482334835401,
-0.00440820363477243, -0.00384444406231091, -0.00339155847843874,
-0.00302073861672209, -0.00271144798349074, -0.00251301852442438,
-0.00144927850970620, -0.0106804238128451, 0.0851202293510744,
-0.0758769041999714, -0.0326522207031405, -0.0193173142775157,
-0.0131422653195384, -0.00968621399116252, -0.00752144626742167,
-0.00605949699115956, 0.994982690000402, -0.00424339305215953,
-0.00365002643111701, -0.00318322917972687, -0.00280823644155891,
-0.00250119475097721, -0.00224509973365853, -0.00208079861912032,
-0.00120001372548902, -0.0088434728615772, 0.0704802029795981,
-0.0641729389109609, -0.0276156359643709, -0.0163376305626254,
-0.0111150790664796, -0.00819212150637007, -0.00636126785786165,
-0.00512482334835401, -0.00424339305215953, 0.996411147687394,
-0.00308701212387567, -0.00269221805823593, -0.00237506771674222,
-0.00211538701599975, -0.00189879449585052, -0.00175983672605966,
-0.00101491235455743, -0.00747937267196714, 0.0596086754979071,
-0.0551994407089534, -0.0237540571761934, -0.0140530897426671,
-0.0095608235857291, -0.00704659211570221, -0.00547175232913994,
-0.00440820363477243, -0.00365002643111701, -0.00308701212387567,
0.997344654217315, -0.00231575697798976, -0.00204295473816408,
-0.00181958598355893, -0.00163328025754927, -0.00151375337745326,
-0.000872994057789805, -0.00643350912943617, 0.0512734122002937,
-0.0481400542394349, -0.0207161809283170, -0.0122558579173051,
-0.0083381019821821, -0.0061454123863624, -0.00477197686292545,
-0.00384444406231091, -0.00318322917972687, -0.00269221805823593,
-0.00231575697798976, 0.997980402245132, -0.00178168384753176,
-0.00158688143968159, -0.00142440211670237, -0.00132016137772040,
-0.000761347954851451, -0.00561073580571119, 0.0447161205378424,
-0.0424690297119616, -0.0182757605337795, -0.0108120857414663,
-0.00735585172092681, -0.00542146670484817, -0.00420982548479058,
-0.00339155847843874, -0.00280823644155891, -0.00237506771674222,
-0.00204295473816408, -0.00178168384753176, 0.998428203178131,
-0.00139994264809098, -0.00125660381509209, -0.00116464290829702,
-0.00067165917086235, -0.00494977642637389, 0.0394484443719142,
-0.0378256305710806, -0.0162775596957322, -0.00962993418341185,
-0.00655159139774408, -0.00482870454356629, -0.00374953947939052,
-0.00302073861672209, -0.00250119475097721, -0.00211538701599975,
-0.00181958598355893, -0.00158688143968159, -0.00139994264809098,
0.998753121656263, -0.00111921162329961, -0.00103730536570428,
-0.000598222559804842, -0.00440858705233683, 0.035135304327322,
-0.0339526992400012, -0.0146109154128127, -0.008643934128632,
-0.0058807800137786, -0.00433429795118548, -0.00336562759986317,
-0.00271144798349074, -0.00224509973365853, -0.00189879449585052,
-0.00163328025754927, -0.00142440211670237, -0.00125660381509209,
-0.00111921162329961, 0.998995383419705, -0.000931096628663305,
-0.000536971105173494, -0.00395719590133669, 0.0315378330121886,
-0.0314679693889926, -0.0135416579313926, -0.00801135287175625,
-0.00545041217927562, -0.00401710492254439, -0.00311932390230896,
-0.00251301852442438, -0.00208079861912032, -0.00175983672605966,
-0.00151375337745326, -0.00132016137772040, -0.00116464290829702,
-0.00103730536570428, -0.000931096628663305, 0.999137042978473,
-0.000497674431741953, -0.0036675999928395, 0.0292298281443699,
-0.0181478374856014, -0.00780958581682367, -0.00462021327652922,
-0.0031432976572564, -0.00231669754078399, -0.00179893982176863,
-0.00144927850970620, -0.00120001372548902, -0.00101491235455743,
-0.000872994057789805, -0.000761347954851451, -0.00067165917086235,
-0.000598222559804842, -0.000536971105173494, -0.000497674431741953,
0.999712987050536, -0.00211513516520473, 0.0168570829702674,
-0.133740060543748, -0.0575525585785231, -0.0340485528272058,
-0.0231644579869104, -0.0170728479143494, -0.0132572446093801,
-0.0106804238128451, -0.0088434728615772, -0.00747937267196714,
-0.00643350912943617, -0.00561073580571119, -0.00494977642637389,
-0.00440858705233683, -0.00395719590133669, -0.0036675999928395,
-0.00211513516520473, 0.98441256126097, 0.124227875570478, 1.06587386665492,
0.458679081634688, 0.271358204178969, 0.184614769150617, 0.136066204451331,
0.105656827995586, 0.0851202293510744, 0.0704802029795981, 0.0596086754979071,
0.0512734122002937, 0.0447161205378424, 0.0394484443719142, 0.035135304327322,
0.0315378330121886, 0.0292298281443699, 0.0168570829702674, 0.124227875570478,
0.00993579977244408), .Dim = c(18L, 18L)), structure(c(0.986909145830112,
-0.00563340668751192, -0.00333276834139676, -0.00226740245367209,
-0.00167113848612564, -0.00129765647757549, -0.00104542999336255,
-0.00086562405546693, -0.00073210208319699, -0.000629730011125158,
-0.000549194638612487, -0.000484498071167057, -0.000431524929499496,
-0.000387341491064548, -0.000358995027103639, -0.000207035393020779,
-0.00152574244833668, 0.0121597746876762, -0.113760758601671,
-0.00563340668751192, 0.997575767746317, -0.00143419514255522,
-0.000975734660246872, -0.000719143502885652, -0.000558422436305338,
-0.000449881439324319, -0.000372505283433327, -0.000315046575105078,
-0.000270992649521639, -0.000236335743241396, -0.000208494773433292,
-0.000185698762824986, -0.000166685238243127, -0.000154486862371520,
-8.90938476938872e-05, -0.000656575010334409, 0.00523273387322272,
-0.0489548359462437, -0.00333276834139676, -0.00143419514255522,
0.99915151871121, -0.000577252409715612, -0.000425451033856926,
-0.000330367168585526, -0.000266153448797837, -0.000220377097641771,
-0.000186384067371393, -0.000160321413520357, -0.000139818111261425,
-0.000123347171399064, -0.000109860869649552, -9.86123168111311e-05,
-9.13956603230643e-05, -5.27086311140364e-05, -0.000388435014472783,
0.00309572710777136, -0.0289620715226532, -0.00226740245367209,
-0.000975734660246872, -0.000577252409715612, 0.999607274374903,
-0.000289449676445328, -0.000224760694993156, -0.000181073786426028,
-0.000149930484432251, -0.000126803800442418, -0.000109072437431967,
-9.51233017321236e-05, -8.39175275430447e-05, -7.47423102625689e-05,
-6.70895142403269e-05, -6.21797626608056e-05, -3.58595819676972e-05,
-0.00026426634397836, 0.00210613475676447, -0.0197039413805668,
-0.00167113848612564, -0.000719143502885652, -0.000425451033856926,
-0.000289449676445328, 0.999786667561676, -0.000165654865091598,
-0.000133456401987643, -0.000110502924777389, -9.34579173464037e-05,
-8.03894110958963e-05, -7.01085112589731e-05, -6.18495449321636e-05,
-5.5087155356755e-05, -4.94468324672185e-05, -4.58282093998552e-05,
-2.64295063390904e-05, -0.000194771623932370, 0.00155227972135950,
-0.0145223512112291, -0.00129765647757549, -0.000558422436305338,
-0.000330367168585526, -0.000224760694993156, -0.000165654865091598,
0.999871367268175, -0.000103630289141796, -8.58066745029985e-05,
-7.25710483195452e-05, -6.24232168088707e-05, -5.44399907749721e-05,
-4.80268172163228e-05, -4.27757511261853e-05, -3.83959815295955e-05,
-3.55860829471299e-05, -2.05227875396227e-05, -0.000151242198981189,
0.00120536140610419, -0.0112767572976958, -0.00104542999336255,
-0.000449881439324319, -0.000266153448797837, -0.000181073786426028,
-0.000133456401987643, -0.000103630289141796, 0.999916512409592,
-6.91283654081814e-05, -5.8465358031245e-05, -5.02899683097141e-05,
-4.38584480392465e-05, -3.86918079409531e-05, -3.44613955917501e-05,
-3.09329251687863e-05, -2.86691887276098e-05, -1.65337575946255e-05,
-0.000121845136836566, 0.000971074385678217, -0.00908488533799608,
-0.00086562405546693, -0.000372505283433327, -0.000220377097641771,
-0.000149930484432251, -0.000110502924777389, -8.58066745029985e-05,
-6.91283654081814e-05, 0.99994276118306, -4.84097650198004e-05,
-4.16404796054684e-05, -3.63151314762903e-05, -3.20371138343459e-05,
-2.85342999517672e-05, -2.56126993696976e-05, -2.37383082280997e-05,
-1.36900781420412e-05, -0.000100888708145964, 0.000804057041817938,
-0.00752235476278421, -0.00073210208319699, -0.000315046575105078,
-0.000186384067371393, -0.000126803800442418, -9.34579173464037e-05,
-7.25710483195452e-05, -5.8465358031245e-05, -4.84097650198004e-05,
0.999959057411131, -3.52174615203377e-05, -3.07135450285328e-05,
-2.70954089475854e-05, -2.41329019281796e-05, -2.16619564191054e-05,
-2.00766889455142e-05, -1.15783921017671e-05, -8.53266876518028e-05,
0.000680031743118085, -0.00636203621837947, -0.000629730011125158,
-0.000270992649521639, -0.000160321413520357, -0.000109072437431967,
-8.03894110958963e-05, -6.24232168088707e-05, -5.02899683097141e-05,
-4.16404796054684e-05, -3.52174615203377e-05, 0.999969707103771,
-2.64187761466959e-05, -2.33065750933159e-05, -2.07583244857749e-05,
-1.86328988400453e-05, -1.72693041628911e-05, -9.95935014310753e-06,
-7.33951961037987e-05, 0.00058494082586019, -0.00547241324745794,
-0.000549194638612487, -0.000236335743241396, -0.000139818111261425,
-9.51233017321236e-05, -7.01085112589731e-05, -5.44399907749721e-05,
-4.38584480392465e-05, -3.63151314762903e-05, -3.07135450285328e-05,
-2.64187761466959e-05, 0.999976959887631, -2.03259267615315e-05,
-1.81035686925521e-05, -1.62499610372355e-05, -1.50607547540609e-05,
-8.68566148354026e-06, -6.40087775523011e-05, 0.000510133485450369,
-0.00477255325723793, -0.000484498071167057, -0.000208494773433292,
-0.000123347171399064, -8.39175275430447e-05, -6.18495449321636e-05,
-4.80268172163228e-05, -3.86918079409531e-05, -3.20371138343459e-05,
-2.70954089475854e-05, -2.33065750933159e-05, -2.03259267615315e-05,
0.99998206852067, -1.59709208650355e-05, -1.43356730483957e-05,
-1.32865583813744e-05, -7.66246780233875e-06, -5.64683758388496e-05,
0.000450038424196685, -0.00421033397834277, -0.000431524929499496,
-0.000185698762824986, -0.000109860869649552, -7.47423102625689e-05,
-5.5087155356755e-05, -4.27757511261853e-05, -3.44613955917501e-05,
-2.85342999517672e-05, -2.41329019281796e-05, -2.07583244857749e-05,
-1.81035686925521e-05, -1.59709208650355e-05, 0.999985775277735,
-1.27682661081301e-05, -1.18338575734733e-05, -6.82468326495417e-06,
-5.02943424400313e-05, 0.000400832966797461, -0.00374999237622812,
-0.000387341491064548, -0.000166685238243127, -9.86123168111311e-05,
-6.70895142403269e-05, -4.94468324672185e-05, -3.83959815295955e-05,
-3.09329251687863e-05, -2.56126993696976e-05, -2.16619564191054e-05,
-1.86328988400453e-05, -1.62499610372355e-05, -1.43356730483957e-05,
-1.27682661081301e-05, 0.99998853906485, -1.06221998410871e-05,
-6.12591025727449e-06, -4.51447512323977e-05, 0.000359792050038065,
-0.00336603412501244, -0.000358995027103639, -0.000154486862371520,
-9.13956603230643e-05, -6.21797626608056e-05, -4.58282093998552e-05,
-3.55860829471299e-05, -2.86691887276098e-05, -2.37383082280997e-05,
-2.00766889455142e-05, -1.72693041628911e-05, -1.50607547540609e-05,
-1.32865583813744e-05, -1.18338575734733e-05, -1.06221998410871e-05,
0.999990155155056, -5.67760327663489e-06, -4.18409635066978e-05,
0.000333461712041493, -0.00311970067709386, -0.000207035393020779,
-8.90938476938872e-05, -5.27086311140364e-05, -3.58595819676972e-05,
-2.64295063390904e-05, -2.05227875396227e-05, -1.65337575946255e-05,
-1.36900781420412e-05, -1.15783921017671e-05, -9.95935014310753e-06,
-8.68566148354026e-06, -7.66246780233875e-06, -6.82468326495417e-06,
-6.12591025727449e-06, -5.67760327663489e-06, 0.999996725679363,
-2.41300287468228e-05, 0.000192310119632831, -0.00179915711089461,
-0.00152574244833668, -0.000656575010334409, -0.000388435014472783,
-0.00026426634397836, -0.000194771623932370, -0.000151242198981189,
-0.000121845136836566, -0.000100888708145964, -8.53266876518028e-05,
-7.33951961037987e-05, -6.40087775523011e-05, -5.64683758388496e-05,
-5.02943424400313e-05, -4.51447512323977e-05, -4.18409635066978e-05,
-2.41300287468228e-05, 0.999822174321977, 0.00141722489322909,
-0.0132588459164718, 0.0121597746876762, 0.00523273387322272,
0.00309572710777136, 0.00210613475676447, 0.00155227972135950,
0.00120536140610419, 0.000971074385678217, 0.000804057041817938,
0.000680031743118085, 0.00058494082586019, 0.000510133485450369,
0.000450038424196685, 0.000400832966797461, 0.000359792050038065,
0.000333461712041493, 0.000192310119632831, 0.00141722489322909,
0.988705082301263, 0.105669590001036, -0.113760758601671, -0.0489548359462437,
-0.0289620715226532, -0.0197039413805668, -0.0145223512112291,
-0.0112767572976958, -0.00908488533799608, -0.00752235476278421,
-0.00636203621837947, -0.00547241324745794, -0.00477255325723793,
-0.00421033397834277, -0.00374999237622812, -0.00336603412501244,
-0.00311970067709386, -0.00179915711089461, -0.0132588459164718,
0.105669590001036, 0.0114082679649871), .Dim = c(19L, 19L)),
structure(c(0.999763537353264, -0.000101757321423337, -6.02004432054978e-05,
-4.09565318239572e-05, -3.01860997276412e-05, -2.34398215166044e-05,
-1.88838054415657e-05, -1.56359357898275e-05, -1.32241024174084e-05,
-1.13749357549555e-05, -9.92020964670435e-06, -8.75158295708061e-06,
-7.79471878900636e-06, -6.99662474115785e-06, -6.48459704557545e-06,
-3.7397205993177e-06, -2.75597827987093e-05, 0.000219644376833678,
-0.00205488272381514, 0.0152378271392533, -0.000101757321423337,
0.999956210620975, -2.59061459965776e-05, -1.76248850747334e-05,
-1.29900290591234e-05, -1.00868931524314e-05, -8.12629599868944e-06,
-6.72863543515227e-06, -5.69074760346267e-06, -4.89499297145799e-06,
-4.26897852806357e-06, -3.76608167174732e-06, -3.35431289535463e-06,
-3.01086790024080e-06, -2.79052626270884e-06, -1.60931951118070e-06,
-1.18598422004994e-05, 9.45198903961047e-05, -0.000884280729749487,
0.0065573167491906, -6.02004432054978e-05, -2.59061459965776e-05,
0.999984673717341, -1.04270226270085e-05, -7.6850048298557e-06,
-5.96748646533859e-06, -4.80758154693301e-06, -3.98071440657522e-06,
-3.36669168475682e-06, -2.89591689568574e-06, -2.52556175643633e-06,
-2.22804396397264e-06, -1.98443827063980e-06, -1.78125347141982e-06,
-1.65089760070204e-06, -9.52086262464392e-07, -7.01637726731266e-06,
5.59187212673189e-05, -0.000523147534785553, 0.00387936090512672,
-4.09565318239572e-05, -1.76248850747334e-05, -1.04270226270085e-05,
0.999992906120598, -5.22838584106146e-06, -4.05989617871041e-06,
-3.27077104650367e-06, -2.70822352118653e-06, -2.29048172714453e-06,
-1.97019666604143e-06, -1.71823071298265e-06, -1.51581863283172e-06,
-1.35008489732705e-06, -1.21185095331786e-06, -1.12316515495475e-06,
-6.47738608413005e-07, -4.77349440529263e-06, 3.80435220272727e-05,
-0.000355916128124327, 0.00263926908021381, -3.01860997276412e-05,
-1.29900290591234e-05, -7.6850048298557e-06, -5.22838584106146e-06,
0.999996146534646, -2.99225606946377e-06, -2.41064896364807e-06,
-1.99603583737676e-06, -1.68814855069055e-06, -1.45208957877154e-06,
-1.26638368405138e-06, -1.11720036785219e-06, -9.95050008791466e-07,
-8.93167758664864e-07, -8.27803865908485e-07, -4.77401316963106e-07,
-3.51819775138321e-06, 2.80391307262553e-05, -0.000262320056405568,
0.00194521450219113, -2.34398215166044e-05, -1.00868931524314e-05,
-5.96748646533859e-06, -4.05989617871041e-06, -2.99225606946377e-06,
0.99999767648193, -1.87189408227378e-06, -1.54994266205298e-06,
-1.31086497025871e-06, -1.12756271461459e-06, -9.8336014899344e-07,
-8.67517746811155e-07, -7.7266671801293e-07, -6.93554087357608e-07,
-6.42798342373534e-07, -3.70707105666926e-07, -2.73191727638227e-06,
2.17726776772800e-05, -0.000203694261857279, 0.00151047936481568,
-1.88838054415657e-05, -8.12629599868944e-06, -4.80758154693301e-06,
-3.27077104650367e-06, -2.41064896364807e-06, -1.87189408227378e-06,
0.999998491947405, -1.24867911878328e-06, -1.05607114119849e-06,
-9.08397485486921e-07, -7.92223683078252e-07, -6.98897657402491e-07,
-6.22482895776034e-07, -5.58747447781805e-07, -5.17857135855069e-07,
-2.98652481387763e-07, -2.20091242133009e-06, 1.75407056281731e-05,
-0.000164102052046403, 0.00121688633287901, -1.56359357898275e-05,
-6.72863543515227e-06, -3.98071440657522e-06, -2.70822352118653e-06,
-1.99603583737676e-06, -1.54994266205298e-06, -1.24867911878328e-06,
0.99999896608411, -8.7443500751829e-07, -7.52160087576957e-07,
-6.55967287850068e-07, -5.78692622555433e-07, -5.15420613643696e-07,
-4.62647173700278e-07, -4.2878968169789e-07, -2.47286545971983e-07,
-1.82237237115369e-06, 1.45238388395322e-05, -0.000135877758151894,
0.00100759122006911, -1.32241024174084e-05, -5.69074760346267e-06,
-3.36669168475682e-06, -2.29048172714453e-06, -1.68814855069055e-06,
-1.31086497025871e-06, -1.05607114119849e-06, -8.7443500751829e-07,
0.999999260446049, -6.36139861796803e-07, -5.54784741610571e-07,
-4.89429645384605e-07, -4.35917304501986e-07, -3.91284134852828e-07,
-3.62649139937623e-07, -2.09142750030233e-07, -1.54127256614026e-06,
1.22835457301418e-05, -0.000114918698452158, 0.000852170900941155,
-1.13749357549555e-05, -4.89499297145799e-06, -2.89591689568574e-06,
-1.97019666604143e-06, -1.45208957877154e-06, -1.12756271461459e-06,
-9.08397485486921e-07, -7.52160087576957e-07, -6.36139861796803e-07,
0.99999945281352, -4.77207495409472e-07, -4.2099120205631e-07,
-3.74961655367699e-07, -3.36569678258473e-07, -3.11938802209363e-07,
-1.79897680017729e-07, -1.32575171208910e-06, 1.05658999842201e-05,
-9.88492655815788e-05, 0.00073300923907604, -9.92020964670435e-06,
-4.26897852806357e-06, -2.52556175643633e-06, -1.71823071298265e-06,
-1.26638368405138e-06, -9.8336014899344e-07, -7.92223683078252e-07,
-6.55967287850068e-07, -5.54784741610571e-07, -4.77207495409472e-07,
0.999999583821966, -3.67151171117363e-07, -3.27008284781072e-07,
-2.93526208936462e-07, -2.72045344388922e-07, -1.56890793862650e-07,
-1.15620300691998e-06, 9.2146404346865e-06, -8.62075583648741e-05,
0.000639265617077238, -8.75158295708061e-06, -3.76608167174732e-06,
-2.22804396397264e-06, -1.51581863283172e-06, -1.11720036785219e-06,
-8.67517746811155e-07, -6.98897657402491e-07, -5.78692622555433e-07,
-4.89429645384605e-07, -4.2099120205631e-07, -3.67151171117363e-07,
0.9999996761002, -2.88485851996580e-07, -2.58948052417241e-07,
-2.39997689998231e-07, -1.38408647255491e-07, -1.01999926318572e-06,
8.12913164699287e-06, -7.60520821057654e-05, 0.00056395845236188,
-7.79471878900636e-06, -3.35431289535463e-06, -1.98443827063980e-06,
-1.35008489732705e-06, -9.95050008791466e-07, -7.7266671801293e-07,
-6.22482895776034e-07, -5.15420613643696e-07, -4.35917304501986e-07,
-3.74961655367699e-07, -3.27008284781072e-07, -2.88485851996580e-07,
0.999999743056073, -2.30635675791684e-07, -2.13757272566765e-07,
-1.23275582099174e-07, -9.08476496254175e-07, 7.24032389315988e-06,
-6.77368421507386e-05, 0.00050229742052408, -6.99662474115785e-06,
-3.01086790024080e-06, -1.78125347141982e-06, -1.21185095331786e-06,
-8.93167758664864e-07, -6.93554087357608e-07, -5.58747447781805e-07,
-4.62647173700278e-07, -3.91284134852828e-07, -3.36569678258473e-07,
-2.93526208936462e-07, -2.58948052417241e-07, -2.30635675791684e-07,
0.999999792978898, -1.91870863122402e-07, -1.10653509259655e-07,
-8.15458428008617e-07, 6.4989938259641e-06, -6.08013295294488e-05,
0.000450867652187174, -6.48459704557545e-06, -2.79052626270884e-06,
-1.65089760070204e-06, -1.12316515495475e-06, -8.27803865908485e-07,
-6.42798342373534e-07, -5.17857135855069e-07, -4.2878968169789e-07,
-3.62649139937623e-07, -3.11938802209363e-07, -2.72045344388922e-07,
-2.39997689998231e-07, -2.13757272566765e-07, -1.91870863122402e-07,
0.99999982217065, -1.02555653014623e-07, -7.55781467304933e-07,
6.023383806073e-06, -5.63517605159536e-05, 0.000417872210313034,
-3.7397205993177e-06, -1.60931951118070e-06, -9.52086262464392e-07,
-6.47738608413005e-07, -4.77401316963106e-07, -3.70707105666926e-07,
-2.98652481387763e-07, -2.47286545971983e-07, -2.09142750030233e-07,
-1.79897680017729e-07, -1.56890793862650e-07, -1.38408647255491e-07,
-1.23275582099174e-07, -1.10653509259655e-07, -1.02555653014623e-07,
0.99999994085531, -4.35865405667931e-07, 3.47373512013943e-06,
-3.2498525063037e-05, 0.0002409903501801, -2.75597827987093e-05,
-1.18598422004994e-05, -7.01637726731266e-06, -4.77349440529263e-06,
-3.51819775138321e-06, -2.73191727638227e-06, -2.20091242133009e-06,
-1.82237237115369e-06, -1.54127256614026e-06, -1.32575171208910e-06,
-1.15620300691998e-06, -1.01999926318572e-06, -9.08476496254175e-07,
-8.15458428008617e-07, -7.55781467304933e-07, -4.35865405667931e-07,
0.999996787900168, 2.55996090800895e-05, -0.000239497114351035,
0.00177597270468821, 0.000219644376833678, 9.45198903961047e-05,
5.59187212673189e-05, 3.80435220272727e-05, 2.80391307262553e-05,
2.17726776772800e-05, 1.75407056281731e-05, 1.45238388395322e-05,
1.22835457301418e-05, 1.05658999842201e-05, 9.2146404346865e-06,
8.12913164699287e-06, 7.24032389315988e-06, 6.4989938259641e-06,
6.023383806073e-06, 3.47373512013943e-06, 2.55996090800895e-05,
0.999795977703284, 0.00190873037060222, -0.0141540454380189,
-0.00205488272381514, -0.000884280729749487, -0.000523147534785553,
-0.000355916128124327, -0.000262320056405568, -0.000203694261857279,
-0.000164102052046403, -0.000135877758151894, -0.000114918698452158,
-9.88492655815788e-05, -8.62075583648741e-05, -7.60520821057654e-05,
-6.77368421507386e-05, -6.08013295294488e-05, -5.63517605159536e-05,
-3.2498525063037e-05, -0.000239497114351035, 0.00190873037060222,
0.982142875135193, 0.132418156394250, 0.0152378271392533,
0.0065573167491906, 0.00387936090512672, 0.00263926908021381,
0.00194521450219113, 0.00151047936481568, 0.00121688633287901,
0.00100759122006911, 0.000852170900941155, 0.00073300923907604,
0.000639265617077238, 0.00056395845236188, 0.00050229742052408,
0.000450867652187174, 0.000417872210313034, 0.0002409903501801,
0.00177597270468821, -0.0141540454380189, 0.132418156394250,
0.0180631946294437), .Dim = c(20L, 20L)))
|
inla.output.indices = function(result, name=NULL, stack=NULL, tag=NULL, ...)
{
if (!is.null(name) && !is.null(tag)) {
stop("At most one of 'name' and 'tag' may be non-null.")
}
if (!is.null(tag)) {
if (is.null(stack)) {
stop("'tag' specified but 'stack' is NULL.")
}
tags <- names(stack$data$index)
if (!(tag %in% tags)) {
stop("'tag' not found in 'stack'.")
}
} else if (is.null(name) || (!is.null(name) && (name == ""))) {
if ("APredictor" %in% result$misc$configs$contents$tag) {
name <- "APredictor"
} else {
name <- "Predictor"
}
}
if (!is.null(name)) {
if (!(name %in% result$misc$configs$contents$tag)) {
stop("'name' not found in result.")
}
nameindex <- which(result$misc$configs$contents$tag == name)
index <- (result$misc$configs$contents$start[nameindex] - 1L +
seq_len(result$misc$configs$contents$length[nameindex]))
} else {
index <- stack$data$index[[tag]]
}
index
}
private.simconf.link <- function(res,links,trans=TRUE)
{
if(trans){
n = length(res$a)
res$a.marginal = sapply(1:n, function(i) private.link.function(
res$a.marginal[i],links[i],inv=TRUE))
res$b.marginal = sapply(1:n, function(i) private.link.function(
res$b.marginal[i],links[i],inv=TRUE))
res$a = sapply(1:n, function(i) private.link.function(
res$a[i],links[i],inv=TRUE))
res$b = sapply(1:n, function(i) private.link.function(
res$b[i],links[i],inv=TRUE))
}
return(res)
}
private.link.function <- function(x, link, inv=FALSE)
{
if (is.na(link)) {
link = "identity"
}
return(do.call(paste("inla.link.", link, sep=""),list(x=x, inv=inv)))
}
private.get.config <- function(result,i)
{
mu=result$misc$configs$config[[i]]$mean
Q=forceSymmetric(result$misc$configs$config[[i]]$Q)
vars = diag(result$misc$configs$config[[i]]$Qinv)
m <- max(unlist(lapply(result$misc$configs$config,
function(x) x$log.posterior)))
lp = result$misc$configs$config[[i]]$log.posterior -m
return(list(mu=mu,Q=Q,vars=vars,lp=lp))
}
inla.get.marginal <- function(i, u,result,effect.name=NULL, u.link, type)
{
if(is.null(effect.name) && u.link == TRUE){
marg.p = result$marginals.fitted.values[[i]]
} else if (is.null(effect.name)){
marg.p = result$marginals.linear.predictor[[i]]
} else {
marg.p = result$marginals.random[[effect.name]][[i]]
}
if(type=='<'){
return(INLA::inla.pmarginal(u,marg.p))
} else {
return(1-INLA::inla.pmarginal(u,marg.p))
}
}
inla.get.marginal.int <- function(i, a,b,result,effect.name=NULL)
{
if (is.null(effect.name)){
marg.p = result$marginals.linear.predictor[[i]]
} else {
marg.p = result$marginals.random[[effect.name]][[i]]
}
return(c(INLA::inla.pmarginal(a,marg.p),INLA::inla.pmarginal(b,marg.p)))
}
|
fragmentSeq <- function(sequ,minSize=3,maxSize=300,internFragments=TRUE,separTerm=FALSE,keepRedSeqs=TRUE,prefName=NULL,silent=FALSE,callFrom=NULL){
fxNa <- wrMisc::.composeCallName(callFrom,newNa="fragmentSeq")
tx <- c("argument '","minSize","' shoud be of length 1 (truncating !!)","sequ")
if(length(sequ) >1) {if(!silent) message(fxNa,tx[c(1,4,3)]); sequ <- sequ[1]}
if(length(minSize) <1) {minSize <- 3; if(silent) message(fxNa,"setting 'minSize' to default =3")}
maxSize <- c(minSize, maxSize)
minSize <- min(minSize, na.rm=TRUE)
maxSize <- max(maxSize, na.rm=TRUE)
if(is.null(prefName)) prefName <- if(length(unique(names(sequ)))==length(sequ)) names(sequ) else sequ
if(nchar(sequ) < minSize & !silent) {
message(fxNa," sequence given as 'sequ' already shorter than 'minSize'");return(NULL)}
cut1 <- .termPepCut(sequ, mi=minSize, ma=maxSize ,sepNC=TRUE, mainName=prefName)
if(!is.list(cut1)) cut1 <- list(cut1)
if(internFragments) { nCha <- nchar(sequ)
frTo <- cbind(from=2:floor(nCha/2), to=(nCha-1):ceiling(1+nCha/2))
frTo <- cbind(frTo,seqc=apply(frTo,1, function(x) substr(sequ,x[1],x[2])))
chLe <- nchar(frTo[,"seqc"]) <minSize
if(!all(chLe)) { if(any(chLe)) frTo <- frTo[which(!chLe),]
cut1$inter <- if(nrow(frTo) >1) {unlist(apply(frTo[,c(3,1)],1, function(x) .termPepCut(x[1], mi=minSize, ma=maxSize, indexOffs=as.numeric(x[2])-1, mainName=prefName,sepNC=FALSE)))
} else .termPepCut(frTo[1,3], mi=minSize, ma=maxSize, indexOffs=as.numeric(frTo[1,1])-1, mainName=prefName, sepNC=FALSE) }}
nFrag <- sum(sapply(cut1,length))
chRed <- unique(unlist(cut1))
if(nFrag > length(chRed) & !silent) message(fxNa,nFrag- length(chRed)," out of ",if(nFrag >10e3)c(" ~",signif(nFrag,4)) else nFrag," fragments not unique")
if(!keepRedSeqs) {
uniq <- wrMisc::naOmit(match(chRed,unique(cut1$Nter)))
if(length(cut1$Nter) >0) {
if(length(uniq) <length(cut1$Nter)) cut1$Nter <- cut1$Nter[uniq]
if(length(uniq) >0) chRed <- chRed[-1*uniq] }
uniq <- wrMisc::naOmit(match(chRed, unique(cut1$Cter)))
if(length(chRed) >0 & length(cut1$Cter) >0) {
if(length(uniq) <length(cut1$Cter)) cut1$Cter <- cut1$Cter[uniq]
if(length(uniq) >0) chRed <- chRed[-1*uniq] }
uniq <- wrMisc::naOmit(match(chRed, unique(cut1$inter)))
if(length(chRed) >0 & length(cut1$inter) >0) {
if(length(uniq) <length(cut1$inter)) cut1$inter <- cut1$inter[uniq] }
}
if(separTerm) cut1 else unlist(cut1) }
.termPepCut <- function(pe,mi,ma=1000,se1=".",se2="-",mainName=NULL,sepNC=FALSE,indexOffs=NULL) {
mi <- min(mi,nchar(pe))
if(nchar(pe) <ma) ma <- nchar(pe)
if(is.null(mainName)) mainName <- pe
indexOffs <- if(is.null(indexOffs)) 0 else as.numeric(indexOffs)
names(pe) <- paste(mainName,se1,indexOffs+1,se2,indexOffs+nchar(pe),sep="")
if(mi==nchar(pe) & ma==nchar(pe)) return(if(sepNC) list(full=pe) else pe)
x <- substring(pe,1,mi:min(ma,nchar(pe)-1))
chMa <- nchar(x) > ma
if(any(chMa)) x <- x[which(!chMa)]
y <- if(nchar(pe) > mi) substring(pe, (2:(nchar(pe)-mi+1)), nchar(pe)) else ""
chMa <- nchar(y) > ma
if(any(chMa)) y <- y[which(!chMa)]
basInd <- list(xL=1, xU=mi:min(nchar(pe)-1, ma), yL=max(nchar(pe)-ma+1,2):(nchar(pe)-mi+1), yU=nchar(pe))
indexNa <- if(indexOffs==0) basInd else lapply(basInd, function(x) x +indexOffs[1])
names(x) <- paste(mainName,se1,indexNa[[1]],se2,indexNa[[2]],sep="")
if(identical(y,"")) {if(sepNC) list(Nter=x) else x} else {
names(y) <- if(identical(y,"")) "" else paste(mainName,se1,indexNa[[3]],se2,indexNa[[4]],sep="")
fu <- if(nchar(pe) > ma) NULL else pe
if(length(fu)>0) names(fu) <- paste(mainName,se1,1+indexOffs,se2,nchar(fu)+indexOffs,sep="")
if(sepNC) list(full=fu, Nter=x, Cter=y) else c(fu, x, y)}
}
.CtermPepCut <- function(pe,mi,se1=".",se2="-",mainName=NULL,indexOffs=NULL) {
mi <- min(mi,nchar(pe))
y <- if(nchar(pe) > mi) substring(pe,(2:(nchar(pe)-mi+1)), nchar(pe)) else ""
namX <- paste(pe,se1,"1",se2,mi:nchar(pe),sep="")
if(is.null(mainName)) mainName <- if(length(names(pe)) >0) names(pe)[1] else pe
basInd <- list(xL=1, xU=mi:nchar(pe), yL=2:(nchar(pe) -mi +1), yU=nchar(pe))
indexNa <- if(is.null(indexOffs)) basInd else lapply(basInd, function(x) x +indexOffs[1])
names(y) <- if(identical(y,"")) "" else paste(mainName,se1,indexNa[[3]],se2,indexNa[[4]],sep="")
y }
.NtermPepCut <- function(pe,mi,se1=".",se2="-",mainName=NULL,sepNC=FALSE,indexOffs=NULL) {
mi <- min(mi, nchar(pe))
x <- substring(pe, 1, mi:(nchar(pe) -1))
namX <- paste(pe,se1,"1",se2,mi:(nchar(pe) -1), sep="")
if(is.null(mainName)) mainName <- pe
basInd <- list(xL=1, xU=mi:(nchar(pe)-1), yL=2:(nchar(pe)-mi), yU=nchar(pe))
indexNa <- if(is.null(indexOffs)) basInd else lapply(basInd, function(x) x+indexOffs[1])
names(x) <- paste(mainName,se1,indexNa[[1]],se2,indexNa[[2]],sep="")
x }
|
mineCARs <- function(formula, transactions, parameter = NULL, control = NULL, balanceSupport = FALSE, verbose = TRUE, ...) {
transactions <- prepareTransactions(formula, transactions)
vars <- .parseformula(formula, transactions)
control <- as(control, "APcontrol")
if(!verbose) control@verbose <- FALSE
if(is.null(parameter) || !is(parameter, "APparameter")) {
parameter <- c(parameter, list(...))
if(is.null(parameter$sup)) parameter$support <- .1
if(is.null(parameter$con)) parameter$confidence <- .5
if(is.null(parameter$maxlen)) parameter$maxlen <- 5L
if(is.null(parameter$originalSupport)) parameter$originalSupport <- FALSE
parameter <- as(parameter, "APparameter")
}
if(is.logical(balanceSupport) && !balanceSupport) {
suppressWarnings(
cars <- apriori(transactions, parameter = parameter,
appearance = list(rhs=vars$class_items, lhs=vars$var_items),
control=control)
)
}else{
if(is.numeric(balanceSupport)) {
if(length(balanceSupport) != length(vars$class_ids))
stop("balanceSupport requires One support value for each class label.")
support <- balanceSupport
if(is.null(names(support))) names(support) <- vars$class_items
}else{
classSupport <- itemFrequency(transactions)[vars$class_ids]
support <- parameter@support * classSupport/max(classSupport)
}
rs <- lapply(names(support), FUN = function(rhs) {
if(control@verbose) cat("\n*** Mining CARs for class", rhs, "***\n")
parameter@support <- support[[rhs]]
suppressWarnings(
apriori(transactions, parameter = parameter,
appearance = list(rhs = rhs, lhs=vars$var_items),
control=control)
)
})
cars <- do.call(c, rs)
}
cars
}
|
findCells <- function(inputMat, markers, nMarker = 50, method = "SVD", scale = TRUE){
if(!all(c("markers", "cell") %in% colnames(markers))){
stop("The markers argument must be a df with a column named marker s(gene symbols) and a column named cell (corresponding cell types).")
}
if(!any(markers$markers %in% rownames(inputMat))) stop("At least one marker gene symbol must be present in the rownames of the input matrix.")
if(!method %in% c("SVD", "PCA")) stop("The method argument must be either SVD or PCA.")
cell_types = unique(markers$cell)
for(i in 1:length(cell_types)){
top_markers_tmp = markers[markers$cell == cell_types[i], ]
top_markers_present = vector()
top_markers_present_count = 0
for(j in 1:nrow(top_markers_tmp)){
gene = top_markers_tmp[j, "markers"]
if(gene %in% rownames(inputMat)){
if(sum(inputMat[gene, ] > 0)){
top_markers_present = c(top_markers_present, gene)
top_markers_present_count = top_markers_present_count + 1
}
}
if(top_markers_present_count == nMarker) break
}
print(top_markers_present)
tmp_markers_top = data.frame(markers = top_markers_present,
cell = rep(cell_types[i], length(top_markers_present)), stringsAsFactors = FALSE)
if(i == 1){
markers_df = tmp_markers_top
}
if(i > 1){
markers_df = rbind(markers_df, tmp_markers_top)
}
}
for(i in 1:length(cell_types)){
genes = markers_df[markers_df$cell == cell_types[i], "markers"]
data = inputMat[genes, ]
if(scale){
means = apply(data, 1, mean)
data = sweep(data, 1, means, "-")
}
if(method == "PCA"){
pcres = prcomp(t(data))
props = pcres$x[ , 1]
}
if(method == "SVD"){
svdres = svd(data)
props = svdres$v[ , 1]
}
cor_res = cor(props, t(data[genes, ]))
print(cor_res)
if (mean(cor_res, na.rm = TRUE) < 0) {
props = -props
}
if(i == 1){
SPVs = props
} else {
SPVs = cbind(SPVs, props)
}
}
colnames(SPVs) = cell_types
rownames(SPVs) = colnames(inputMat)
return(SPVs)
}
|
if (.Platform$OS.type == "windows") {
WRITE_PATH = paste0(getwd(),"\\SAVE_SPARSE\\")
read_CHARS_ROWS = paste0(getwd(),"\\read_CHARS_ROWS\\write_rows_chars.txt")
PATH = paste0(getwd(), path.expand("\\test_text.txt"))
}
if (.Platform$OS.type == "unix") {
WRITE_PATH = paste0(getwd(),"/SAVE_SPARSE/")
PATH = paste0(getwd(), path.expand("/test_text.txt"))
read_CHARS_ROWS = paste0(getwd(),"/read_CHARS_ROWS/write_rows_chars.txt")
}
context('sparse functions AND read text')
while(T) {
testthat::test_that("in case that the dense_mat parameter is not a matrix it returns an error", {
dsm = data.frame(matrix(1:100, 10, 10))
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_error( dense_2sparse(dsm) )
})
testthat::test_that("it returns a sparse matrix", {
dsm = matrix(1:100, 10, 10)
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_true( inherits(dense_2sparse(dsm), "dgCMatrix") )
})
testthat::test_that("in case that the sparse_matrix parameter is not a sparse matrix it returns an error", {
dsm = matrix(1:100, 10, 10)
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_error( sparse_Sums(dsm, rowSums = FALSE) )
})
testthat::test_that("in case that the sparse_matrix parameter is not a sparse matrix it returns an error", {
dsm = dense_2sparse(matrix(1:100, 10, 10))
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_error( sparse_Sums(dsm, rowSums = 'FALSE') )
})
testthat::test_that("it returns the column sums of the sparse matrix", {
dsm = dense_2sparse(matrix(1, 10, 10))
sm = sparse_Sums(dsm, rowSums = FALSE)
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_true( is.vector(sm) && sum(sm) == 100 )
})
testthat::test_that("it returns the row sums of the sparse matrix", {
dsm = dense_2sparse(matrix(1, 10, 10))
sm = sparse_Sums(dsm, rowSums = TRUE)
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_true( is.vector(sm) && sum(sm) == 100 )
})
testthat::test_that("in case that the sparse_matrix parameter is not a sparse matrix it returns an error", {
dsm = matrix(1:100, 10, 10)
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_error( sparse_Means(dsm, rowMeans = FALSE) )
})
testthat::test_that("in case that the sparse_matrix parameter is not a sparse matrix it returns an error", {
dsm = dense_2sparse(matrix(1:100, 10, 10))
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_error( sparse_Means(dsm, rowMeans = 'FALSE') )
})
testthat::test_that("it returns the column means of the sparse matrix", {
dsm = dense_2sparse(matrix(1, 10, 10))
sm = sparse_Means(dsm, rowMeans = FALSE)
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_true( is.vector(sm) && sum(sm) == 10 )
})
testthat::test_that("it returns the row means of the sparse matrix", {
dsm = dense_2sparse(matrix(1, 10, 10))
sm = sparse_Means(dsm, rowMeans = TRUE)
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_true( is.vector(sm) && sum(sm) == 10 )
})
testthat::test_that("in case that the sparse_matrix parameter is not a sparse matrix it returns an error", {
dsm = matrix(1:100, 10, 10)
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_error( matrix_sparsity(dsm) )
})
testthat::test_that("it returns a float number", {
dsm = dense_2sparse(matrix(sample(0:1, 100, replace = T), 10, 10))
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_output( matrix_sparsity(dsm) )
})
testthat::test_that("in case that the sparse_matrix parameter is not a sparse matrix it returns an error", {
dsm = matrix(1:100, 10, 10)
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_error( save_sparse_binary(dsm, file_name = paste0(WRITE_PATH, "save_sparse.mat")) )
})
testthat::test_that("in case that the file_name parameter is NULL it returns an error", {
dsm = dense_2sparse(matrix(1:100, 10, 10))
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_error( save_sparse_binary(dsm, file_name = NULL) )
})
testthat::test_that("in case that the file_name parameter is not a character string it returns an error", {
dsm = dense_2sparse(matrix(1:100, 10, 10))
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_error( save_sparse_binary(dsm, file_name = list()) )
})
testthat::test_that("it saves the sparse matrix in a file", {
dsm = dense_2sparse(matrix(1:100, 10, 10))
res = save_sparse_binary(dsm, paste0(WRITE_PATH, "save_sparse.mat"))
lst = length(list.files(WRITE_PATH))
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_true( lst == 1 )
})
testthat::test_that("in case that the file_name parameter is not a character string it returns an error", {
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_error( load_sparse_binary(file_name = NULL) )
})
testthat::test_that("it loads the sparse matrix", {
mt = load_sparse_binary(file_name = paste0(WRITE_PATH, "save_sparse.mat"))
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_true( inherits(mt, "dgCMatrix") && nrow(mt) == 10 && ncol(mt) == 10 )
})
testthat::test_that("in case that the input_file parameter is not a character string it returns an error", {
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_error( read_characters(input_file = NULL, characters = 100, write_2file = "") )
})
testthat::test_that("in case that the input_file parameter is not a character string it returns an error", {
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_error( read_characters(input_file = PATH, characters = 10, write_2file = NULL) )
})
testthat::test_that("in case that the characters parameter is less than 1 it returns an error", {
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_error( read_characters(input_file = PATH, characters = 0, write_2file = "") )
})
testthat::test_that("it returns the correct output if write_2file is an empty string", {
NCHAR = 5
res = read_characters(input_file = PATH, characters = NCHAR, write_2file = "")
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_true( nchar(res$data) == NCHAR )
})
testthat::test_that("it returns the correct output if write_2file is a valid path to a file", {
NCHAR = 5
res = read_characters(input_file = PATH, characters = NCHAR, write_2file = read_CHARS_ROWS)
res_write = read_characters(input_file = read_CHARS_ROWS, characters = NCHAR * 2, write_2file = "")
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_true( nchar(res_write$data) == NCHAR )
})
testthat::test_that("in case that the input_file parameter is not a character string it returns an error", {
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_error( read_rows(input_file = NULL, read_delimiter = "\n", rows = 100, write_2file = "") )
})
testthat::test_that("in case that the read_delimiter parameter is not a character string it returns an error", {
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_error( read_rows(input_file = PATH, read_delimiter = NULL, rows = 100, write_2file = "") )
})
testthat::test_that("in case that the rows parameter is less than 1 it returns an error", {
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_error( read_rows(input_file = PATH, read_delimiter = "\n", rows = 0, write_2file = "") )
})
testthat::test_that("in case that the write_2file parameter is not a character string it returns an error", {
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_error( read_rows(input_file = PATH, read_delimiter = "\n", rows = 1, write_2file = NULL) )
})
testthat::test_that("it returns the correct output if write_2file is an empty string", {
NROW = 5
res = read_rows(input_file = PATH, read_delimiter = "\n", rows = NROW, write_2file = "")
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_true( length(res$data) == NROW )
})
testthat::test_that("it returns the correct output if write_2file is a valid path to a file", {
NROW = 5
res = read_rows(input_file = PATH, read_delimiter = "\n", rows = NROW, write_2file = read_CHARS_ROWS)
res_write = read_rows(input_file = read_CHARS_ROWS, read_delimiter = "\n", rows = NROW * 2, write_2file = "")
cat("test-sparse_functions_AND_read_text.R : test id", cnt_tsts, "\n")
cnt_tsts <<- cnt_tsts + 1
testthat::expect_true( length(res_write$data) == NROW )
})
break
}
|
createNoisyDataset = function (name, genotypes=NULL, covariance=NULL, phenotypes, strata=NULL, extraCovariates=NULL, ploidy=2, noiseInjector=noiseInjector.dummy, ...){
check.name(name)
check.ploidy(ploidy)
check.phenotypes(phenotypes)
check.genetic_data(genotypes, covariance, n=length(phenotypes), ploidy=ploidy)
check.strata(strata, n=length(phenotypes))
check.extraCovariates(extraCovariates, n=length(phenotypes))
check.noiseInjector(noiseInjector)
me = list(
name = name,
ploidy = ploidy,
genos = genotypes,
covs = covariance,
phenos = phenotypes,
strata = strata,
strata.available = !is.null(strata),
injector = noiseInjector,
extraParms = list(...)
)
if(!me$strata.available){
me$strata = rep('dummyStrata', length(me$phenos))
}
if (is.null(extraCovariates)){
me$extraCovs = NULL
}else{
if (is.null(dim(extraCovariates))){
extraCovariates = as.data.frame(extraCovariates)
}
if (length(dim(extraCovariates)) == 1){
extraCovariates = as.data.frame(extraCovariates)
}
me$extraCovs = model.matrix( ~ ., extraCovariates)
tmp.names = colnames(me$extraCovs)
tmp.names[1] = 'Intercept'
colnames(me$extraCovs) = tmp.names
me$extraCovsOriginalNames = colnames(extraCovariates)
}
class(me) = c("GROAN.NoisyDataset", class(me))
return(me)
}
check.phenotypes = function(phenotypes){
if(!is.numeric(phenotypes)){
stop(paste('Passed phenotypes is not a numeric array.'), call. = FALSE)
}
if(any(is.na(phenotypes))){
stop(paste('Passed phenotypes contains missing values.'), call. = FALSE)
}
}
check.ploidy = function(ploidy){
if (!is.naturalnumber(ploidy)){
stop(paste('Passed ploidy is not a positive integer:', ploidy), call. = FALSE)
}
}
check.extraCovariates = function(extraCovariates, n){
if (is.null(extraCovariates)) return()
if (is.null(dim(extraCovariates))){
extraCovariates = as.data.frame(extraCovariates)
}
if (length(dim(extraCovariates)) == 1){
extraCovariates = as.data.frame(extraCovariates)
}
if (nrow(extraCovariates) != n){
stop(paste('Passed extra covariates should have as many rows as phenotypes slots.'), call. = FALSE)
}
if (any(is.na(extraCovariates))){
stop(paste('Passed extra covariates contains missing values.'), call. = FALSE)
}
}
check.genetic_data = function(genotypes, covariance, n, ploidy){
if (all(is.null(genotypes), is.null(covariance))){
stop(paste('At least one among genotypes and covariance matrix need to be not NULL'), call. = FALSE)
}
if (!is.null(genotypes)){
check.genotypes(genotypes, n, ploidy)
}
if (!is.null(covariance)){
check.covariance(covariance, n)
}
}
check.genotypes = function(genotypes, n, ploidy){
if (nrow(genotypes) != n){
stop(paste('Passed genotypes should have as many rows as phenotypes slots.'), call. = FALSE)
}
if (any(is.na(genotypes))){
stop(paste('Passed genotypes contains missing values.'), call. = FALSE)
}
genotypes.max = as.matrix(genotypes)
if(!all(is.naturalnumber(genotypes.max, -1))){
stop(paste('Passed genotypes contains non integer or negative values.'), call. = FALSE)
}
if(max(genotypes.max > ploidy)){
stop(paste('Passed genotypes contains value(s) greater than ploidy.'), call. = FALSE)
}
}
check.covariance = function(covariance, n){
if (nrow(covariance) != n){
stop(paste('Passed covariance should have as many rows as phenotypes slots.'), call. = FALSE)
}
if (any(is.na(covariance))){
stop(paste('Passed covariance contains missing values.'), call. = FALSE)
}
}
check.strata = function(strata, n){
if(is.null(strata)){
return()
}
if (length(strata) != n){
stop(paste('Passed strata should have as many rows as phenotypes slots.'), call. = FALSE)
}
if(any(is.na(strata))){
stop(paste('Passed strata contains missing values.'), call. = FALSE)
}
}
check.noiseInjector = function(noiseInjector){
if (!is.function(noiseInjector)){
stop(paste('Passed noiseInjector is not a function'), call. = FALSE)
}
args.list = names(formals(noiseInjector))
if (!("phenotypes" %in% args.list)){
stop(paste('Passed noiseInjector function must (at least) accept arguments "phenotypes"'), call. = FALSE)
}
}
check.name = function(name){
if (!is.string(name)){
stop(paste('Passed name is not a valid string:', name), call. = FALSE)
}
}
getNoisyPhenotype = function(nds){
f = nds$injector
p = nds$phenos
ex = nds$extraParms
parms = list(phenotypes=p)
parms = c(parms, ex)
return (do.call(f, parms))
}
getExtraCovariatesNames = function(nds, separator=' '){
if (is.null(nds$extraCovs)){
return('')
}
return(paste(collapse=separator, nds$extraCovsOriginalNames))
}
print.GROAN.NoisyDataset = function(x, ...){
print(summary(x))
return(invisible(x))
}
summary.GROAN.NoisyDataset = function(object, ...){
res = data.frame()
res['dataset.name', 'value'] = object$name
res['ploidy', 'value'] = object$ploidy
res['samples', 'value'] = length(object$phenos)
res['SNPs.num', 'value'] = 'absent'
if (!is.null(object$genos)){
res['SNPs.num', 'value'] = ncol(object$genos)
}
res['covariance', 'value'] = 'present'
if (is.null(object$covs)){
res['covariance', 'value'] = 'absent'
}
res['extraCovariates', 'value'] = 'absent'
if (!is.null(object$extraCovs)){
res['extraCovariates', 'value'] = paste(collapse = ', ', object$extraCovsOriginalNames)
}
res['strata', 'value'] = 'absent'
if(object$strata.available){
res['strata', 'value'] = paste(collapse = ', ', unique(object$strata))
}
return(res)
}
are.compatible = function(nds1, nds2, verbose=FALSE){
if (!'GROAN.NoisyDataset' %in% class(nds1)) stop('First argument is not a GROAN.NoisyDataset')
if (!'GROAN.NoisyDataset' %in% class(nds2)) stop('Second argument is not a GROAN.NoisyDataset')
if (!is.boolean(verbose)) stop('Parameter "verbose" should be boolean')
nds1.sum = summary(nds1)
nds2.sum = summary(nds2)
check = nds1.sum$value == nds2.sum$value
names(check) = rownames(nds1.sum)
msg.tot = NULL
res = TRUE
msg = 'Comparing ploidy...'
if (check['ploidy']){
msg = paste(msg, 'OK')
}else{
res = FALSE
msg = paste(msg, 'ERROR')
}
msg.tot = c(msg.tot, msg)
msg = 'Comparing SNP number...'
if (check['SNPs.num']){
msg = paste(msg, 'OK')
}else{
res = FALSE
msg = paste(msg, 'ERROR: SNP number differs')
}
msg.tot = c(msg.tot, msg)
msg = 'Comparing SNP names...'
SNP.names.nds1 = colnames(nds1$genos)
SNP.names.nds2 = colnames(nds1$genos)
if (all(SNP.names.nds1 == SNP.names.nds1)){
msg = paste(msg, 'OK')
}else{
res = FALSE
msg = paste(msg, 'ERROR: SNP names differ')
}
msg.tot = c(msg.tot, msg)
msg = 'Comparing covariance matrix...'
if (check['covariance']){
msg = paste(msg, 'OK')
}else{
res = FALSE
msg = paste(msg, 'ERROR: covariance must be either present or absent in both datasets')
}
msg.tot = c(msg.tot, msg)
if (nds1.sum['covariance', 'value'] == 'present' & nds2.sum['covariance', 'value'] == 'present'){
msg = 'Comparing covariance size...'
if (ncol(nds1$covs) == ncol(nds2$covs)){
msg = paste(msg, 'OK')
}else{
res = FALSE
msg = paste(msg, 'ERROR: covariance matrices must have the same number of columns in the two datasets')
}
msg.tot = c(msg.tot, msg)
msg = 'Comparing covariance columns...'
if (all(colnames(nds1$covs) == colnames(nds2$covs))){
msg = paste(msg, 'OK')
}else{
res = FALSE
msg = paste(msg, 'ERROR: column names differ')
}
msg.tot = c(msg.tot, msg)
}
msg = paste(sep='', 'Comparing extra covariates...')
if (check['extraCovariates']){
msg = paste(msg, 'OK')
}else{
res = FALSE
msg = paste(msg, 'ERROR: extra covariates names differ')
}
msg.tot = c(msg.tot, msg)
if (verbose) writeLines(msg.tot)
return(res)
}
|
"Hamburger"
|
summary.snowprofile <- function(object, ...) {
Metadata <- data.frame(init = NA)
for (col in names(object)) {
Element <- object[col]
if (lengths(Element) == 1) {
Metadata[col] <- Element
} else if (col == "latlon") {
Metadata$lat <- object$latlon[1]
Metadata$lon <- object$latlon[2]
} else if (col == "layers") {
Metadata$nLayers <- nrow(object$layers)
}
}
Metadata$init <- NULL
return(Metadata)
}
|
subset_chr <-
function(chr, all_chr)
{
if(is.logical(chr)) {
if(length(chr) != length(all_chr))
stop("chr is logical but length [", length(chr), "] != n_chr is x [",
length(all_chr), "]")
chr <- all_chr[chr]
} else {
chr <- as.character(chr)
if(any(grepl("^\\-", chr))) {
if(!all(grepl("^\\-", chr)))
stop("Can't mix negative and positive chr subscripts")
chr <- sub("^\\-", "", chr)
if(!all(chr %in% all_chr)) {
if(!any(chr %in% all_chr))
stop("None of the chr found in the cross object")
warning("Some chr not found: ", paste(chr[!(chr %in% all_chr)], collapse=", "))
chr <- chr[chr %in% all_chr]
}
chr <- all_chr[!(all_chr %in% chr)]
}
if(!all(chr %in% all_chr)) {
if(!any(chr %in% all_chr)) stop("None of the chromosomes in cross")
warning("Some chr not in cross: ", paste(chr[!(chr %in% all_chr)], collapse=", "))
chr <- chr[chr %in% all_chr]
}
}
chr
}
|
random_hash <- function() {
tmp <- format(Sys.time(), "%Y%m%d%H%M%S%OS3") %>%
as.numeric() * stats::runif(1, 1, 1000000)
tmp %>%
as.character() %>%
openssl::sha1()
}
|
geom_crossbar_interactive <- function(...)
layer_interactive(geom_crossbar, ...)
GeomInteractiveCrossbar <- ggproto(
"GeomInteractiveCrossbar",
GeomCrossbar,
default_aes = add_default_interactive_aes(GeomCrossbar),
parameters = interactive_geom_parameters,
draw_key = interactive_geom_draw_key,
draw_panel = function(data,
panel_params,
coord,
fatten = 2.5,
width = NULL,
flipped_aes = FALSE,
.ipar = IPAR_NAMES) {
data <- flip_data(data, flipped_aes)
middle <-
transform(
data,
x = xmin,
xend = xmax,
yend = y,
size = size * fatten,
alpha = NA
)
has_notch <-
!is.null(data$ynotchlower) && !is.null(data$ynotchupper) &&
!is.na(data$ynotchlower) && !is.na(data$ynotchupper)
if (has_notch) {
if (data$ynotchlower < data$ymin || data$ynotchupper > data$ymax)
message("notch went outside hinges. Try setting notch=FALSE.")
notchindent <-
(1 - data$notchwidth) * (data$xmax - data$xmin) / 2
middle$x <- middle$x + notchindent
middle$xend <- middle$xend - notchindent
box <- new_data_frame(
list(
x = c(
data$xmin,
data$xmin,
data$xmin + notchindent,
data$xmin,
data$xmin,
data$xmax,
data$xmax,
data$xmax - notchindent,
data$xmax,
data$xmax,
data$xmin
),
y = c(
data$ymax,
data$ynotchupper,
data$y,
data$ynotchlower,
data$ymin,
data$ymin,
data$ynotchlower,
data$y,
data$ynotchupper,
data$ymax,
data$ymax
),
alpha = rep(data$alpha, 11),
colour = rep(data$colour, 11),
size = rep(data$size, 11),
linetype = rep(data$linetype, 11),
fill = rep(data$fill, 11),
group = rep(seq_len(nrow(data)), 11)
)
)
box <- copy_interactive_attrs(data, box, 11, ipar = .ipar)
} else {
box <- new_data_frame(
list(
x = c(data$xmin, data$xmin, data$xmax, data$xmax, data$xmin),
y = c(data$ymax, data$ymin, data$ymin, data$ymax, data$ymax),
alpha = rep(data$alpha, 5),
colour = rep(data$colour, 5),
size = rep(data$size, 5),
linetype = rep(data$linetype, 5),
fill = rep(data$fill, 5),
group = rep(seq_len(nrow(data)), 5)
)
)
box <- copy_interactive_attrs(data, box, 5, ipar = .ipar)
}
box <- flip_data(box, flipped_aes)
middle <- flip_data(middle, flipped_aes)
ggname("geom_interactive_crossbar", gTree(
children = gList(
GeomInteractivePolygon$draw_panel(box, panel_params, coord, .ipar = .ipar),
GeomInteractiveSegment$draw_panel(middle, panel_params, coord, .ipar = .ipar)
)
))
}
)
|
testData = createData(sampleSize = 40, family = gaussian())
fittedModel <- lm(observedResponse ~ Environment1, data = testData)
res = simulateResiduals(fittedModel)
testSpatialAutocorrelation(res, x = testData$x, y = testData$y)
dM = as.matrix(dist(cbind(testData$x, testData$y)))
testSpatialAutocorrelation(res, distMat = dM)
testData$x = as.numeric(testData$group)
testData$y = as.numeric(testData$group)
groupLocations = aggregate(testData[, 6:7], list(testData$group), mean)
res2 = recalculateResiduals(res, group = testData$group)
testSpatialAutocorrelation(res2, groupLocations$x, groupLocations$y)
clusters = 100
subsamples = 10
size = clusters * subsamples
testData = createData(sampleSize = size, family = gaussian(), numGroups = clusters )
testData$x = rnorm(clusters)[testData$group] + rnorm(size, sd = 0.01)
testData$y = rnorm(clusters)[testData$group] + rnorm(size, sd = 0.01)
library(lme4)
fittedModel <- lmer(observedResponse ~ Environment1 + (1|group), data = testData)
res = simulateResiduals(fittedModel)
testSpatialAutocorrelation(res, x = testData$x, y = testData$y)
res2 = recalculateResiduals(res, group = testData$group)
testSpatialAutocorrelation(res2,
x = aggregate(testData$x, list(testData$group), mean)$x,
y = aggregate(testData$y, list(testData$group), mean)$x)
res = simulateResiduals(fittedModel, re.form = NULL)
testSpatialAutocorrelation(res, x = testData$x, y = testData$y)
|
calculate_player_stats <- function(pbp, weekly = FALSE) {
con <- url("https://github.com/mrcaseb/nfl-data/blob/master/data/lateral_yards/multiple_lateral_yards.rds?raw=true")
mult_lats <- readRDS(con) %>%
dplyr::mutate(
season = substr(.data$game_id, 1, 4) %>% as.integer(),
week = substr(.data$game_id, 6, 7) %>% as.integer()
) %>%
dplyr::filter(.data$yards != 0) %>%
dplyr::group_by(.data$game_id, .data$play_id) %>%
dplyr::slice(seq_len(dplyr::n() - 1)) %>%
dplyr::ungroup()
close(con)
suppressMessages({
data <- pbp %>%
dplyr::filter(
!is.na(.data$down),
.data$play_type %in% c("pass", "qb_kneel", "qb_spike", "run")
) %>%
decode_player_ids()
if (!"qb_epa" %in% names(data)) data <- add_qb_epa(data)
two_points <- pbp %>%
dplyr::filter(.data$two_point_conv_result == "success") %>%
dplyr::select(
"week", "season", "posteam",
"pass_attempt", "rush_attempt",
"passer_player_name", "passer_player_id",
"rusher_player_name", "rusher_player_id",
"lateral_rusher_player_name", "lateral_rusher_player_id",
"receiver_player_name", "receiver_player_id",
"lateral_receiver_player_name", "lateral_receiver_player_id"
) %>%
decode_player_ids()
})
if (!"special" %in% names(pbp)) {
pbp <- pbp %>%
dplyr::mutate(
special = dplyr::if_else(
.data$play_type %in% c("extra_point","field_goal","kickoff","punt"),
1, 0
)
)
}
s_type <- pbp %>%
dplyr::select(.data$season, .data$season_type, .data$week) %>%
dplyr::distinct()
racr_ids <- nflreadr::qs_from_url("https://github.com/nflverse/nflfastR-roster/raw/master/data/nflfastR-RB_ids.qs")
pass_df <- data %>%
dplyr::filter(.data$play_type %in% c("pass", "qb_spike")) %>%
dplyr::group_by(.data$passer_player_id, .data$week, .data$season) %>%
dplyr::summarize(
passing_yards_after_catch = sum((.data$passing_yards - .data$air_yards) * .data$complete_pass, na.rm = TRUE),
name_pass = dplyr::first(.data$passer_player_name),
team_pass = dplyr::first(.data$posteam),
passing_yards = sum(.data$passing_yards, na.rm = TRUE),
passing_tds = sum(.data$touchdown == 1 & .data$td_team == .data$posteam & .data$complete_pass == 1),
interceptions = sum(.data$interception),
attempts = sum(.data$complete_pass == 1 | .data$incomplete_pass == 1 | .data$interception == 1),
completions = sum(.data$complete_pass == 1),
sack_fumbles = sum(.data$fumble == 1 & .data$fumbled_1_player_id == .data$passer_player_id),
sack_fumbles_lost = sum(.data$fumble_lost == 1 & .data$fumbled_1_player_id == .data$passer_player_id),
passing_air_yards = sum(.data$air_yards, na.rm = TRUE),
sacks = sum(.data$sack),
sack_yards = -1*sum(.data$yards_gained * .data$sack),
passing_first_downs = sum(.data$first_down_pass),
passing_epa = sum(.data$qb_epa, na.rm = TRUE),
pacr = .data$passing_yards / .data$passing_air_yards,
pacr = dplyr::case_when(
is.nan(.data$pacr) ~ NA_real_,
.data$passing_air_yards <= 0 ~ 0,
TRUE ~ .data$pacr
),
) %>%
dplyr::rename(player_id = .data$passer_player_id) %>%
dplyr::ungroup()
if (isTRUE(weekly)) pass_df <- add_dakota(pass_df, pbp = pbp, weekly = weekly)
pass_two_points <- two_points %>%
dplyr::filter(.data$pass_attempt == 1) %>%
dplyr::group_by(.data$passer_player_id, .data$week, .data$season) %>%
dplyr::summarise(
name_pass = custom_mode(.data$passer_player_name),
team_pass = custom_mode(.data$posteam),
passing_2pt_conversions = dplyr::n()
) %>%
dplyr::rename(player_id = .data$passer_player_id) %>%
dplyr::ungroup()
pass_df <- pass_df %>%
dplyr::full_join(pass_two_points, by = c("player_id", "week", "season", "name_pass", "team_pass")) %>%
dplyr::mutate(passing_2pt_conversions = dplyr::if_else(is.na(.data$passing_2pt_conversions), 0L, .data$passing_2pt_conversions)) %>%
dplyr::filter(!is.na(.data$player_id))
pass_df_nas <- is.na(pass_df)
epa_index <- which(dimnames(pass_df_nas)[[2]] %in% c("passing_epa", "dakota", "pacr"))
pass_df_nas[,epa_index] <- c(FALSE)
pass_df[pass_df_nas] <- 0
rushes <- data %>%
dplyr::filter(.data$play_type %in% c("run", "qb_kneel")) %>%
dplyr::group_by(.data$rusher_player_id, .data$week, .data$season) %>%
dplyr::summarize(
name_rush = dplyr::first(.data$rusher_player_name),
team_rush = dplyr::first(.data$posteam),
yards = sum(.data$rushing_yards, na.rm = TRUE),
tds = sum(.data$td_player_id == .data$rusher_player_id, na.rm = TRUE),
carries = dplyr::n(),
rushing_fumbles = sum(.data$fumble == 1 & .data$fumbled_1_player_id == .data$rusher_player_id & is.na(.data$lateral_rusher_player_id)),
rushing_fumbles_lost = sum(.data$fumble_lost == 1 & .data$fumbled_1_player_id == .data$rusher_player_id & is.na(.data$lateral_rusher_player_id)),
rushing_first_downs = sum(.data$first_down_rush & is.na(.data$lateral_rusher_player_id)),
rushing_epa = sum(.data$epa, na.rm = TRUE)
) %>%
dplyr::ungroup()
laterals <- data %>%
dplyr::filter(!is.na(.data$lateral_rusher_player_id)) %>%
dplyr::group_by(.data$lateral_rusher_player_id, .data$week, .data$season) %>%
dplyr::summarize(
lateral_yards = sum(.data$lateral_rushing_yards, na.rm = TRUE),
lateral_fds = sum(.data$first_down_rush, na.rm = TRUE),
lateral_tds = sum(.data$td_player_id == .data$lateral_rusher_player_id, na.rm = TRUE),
lateral_att = dplyr::n(),
lateral_fumbles = sum(.data$fumble, na.rm = TRUE),
lateral_fumbles_lost = sum(.data$fumble_lost, na.rm = TRUE)
) %>%
dplyr::ungroup() %>%
dplyr::rename(rusher_player_id = .data$lateral_rusher_player_id) %>%
dplyr::bind_rows(
mult_lats %>%
dplyr::filter(
.data$type == "lateral_rushing" & .data$season %in% data$season & .data$week %in% data$week
) %>%
dplyr::select("season", "week", "rusher_player_id" = .data$gsis_player_id, "lateral_yards" = .data$yards) %>%
dplyr::mutate(lateral_tds = 0L, lateral_att = 1L)
)
rush_df <- rushes %>%
dplyr::left_join(laterals, by = c("rusher_player_id", "week", "season")) %>%
dplyr::mutate(
lateral_yards = dplyr::if_else(is.na(.data$lateral_yards), 0, .data$lateral_yards),
lateral_tds = dplyr::if_else(is.na(.data$lateral_tds), 0L, .data$lateral_tds),
lateral_fumbles = dplyr::if_else(is.na(.data$lateral_fumbles), 0, .data$lateral_fumbles),
lateral_fumbles_lost = dplyr::if_else(is.na(.data$lateral_fumbles_lost), 0, .data$lateral_fumbles_lost),
lateral_fds = dplyr::if_else(is.na(.data$lateral_fds), 0, .data$lateral_fds)
) %>%
dplyr::mutate(
rushing_yards = .data$yards + .data$lateral_yards,
rushing_tds = .data$tds + .data$lateral_tds,
rushing_first_downs = .data$rushing_first_downs + .data$lateral_fds,
rushing_fumbles = .data$rushing_fumbles + .data$lateral_fumbles,
rushing_fumbles_lost = .data$rushing_fumbles_lost + .data$lateral_fumbles_lost
) %>%
dplyr::rename(player_id = .data$rusher_player_id) %>%
dplyr::select("player_id", "week", "season", "name_rush", "team_rush",
"rushing_yards", "carries", "rushing_tds", "rushing_fumbles",
"rushing_fumbles_lost", "rushing_first_downs", "rushing_epa") %>%
dplyr::ungroup()
rush_two_points <- two_points %>%
dplyr::filter(.data$rush_attempt == 1) %>%
dplyr::group_by(.data$rusher_player_id, .data$week, .data$season) %>%
dplyr::summarise(
name_rush = custom_mode(.data$rusher_player_name),
team_rush = custom_mode(.data$posteam),
rushing_2pt_conversions = dplyr::n()
) %>%
dplyr::rename(player_id = .data$rusher_player_id) %>%
dplyr::ungroup()
rush_df <- rush_df %>%
dplyr::full_join(rush_two_points, by = c("player_id", "week", "season", "name_rush", "team_rush")) %>%
dplyr::mutate(rushing_2pt_conversions = dplyr::if_else(is.na(.data$rushing_2pt_conversions), 0L, .data$rushing_2pt_conversions)) %>%
dplyr::filter(!is.na(.data$player_id))
rush_df_nas <- is.na(rush_df)
epa_index <- which(dimnames(rush_df_nas)[[2]] == "rushing_epa")
rush_df_nas[,epa_index] <- c(FALSE)
rush_df[rush_df_nas] <- 0
rec <- data %>%
dplyr::filter(!is.na(.data$receiver_player_id)) %>%
dplyr::group_by(.data$receiver_player_id, .data$week, .data$season) %>%
dplyr::summarize(
name_receiver = dplyr::first(.data$receiver_player_name),
team_receiver = dplyr::first(.data$posteam),
yards = sum(.data$receiving_yards, na.rm = TRUE),
receptions = sum(.data$complete_pass == 1),
targets = dplyr::n(),
tds = sum(.data$td_player_id == .data$receiver_player_id, na.rm = TRUE),
receiving_fumbles = sum(.data$fumble == 1 & .data$fumbled_1_player_id == .data$receiver_player_id & is.na(.data$lateral_receiver_player_id)),
receiving_fumbles_lost = sum(.data$fumble_lost == 1 & .data$fumbled_1_player_id == .data$receiver_player_id & is.na(.data$lateral_receiver_player_id)),
receiving_air_yards = sum(.data$air_yards, na.rm = TRUE),
receiving_yards_after_catch = sum(.data$yards_after_catch, na.rm = TRUE),
receiving_first_downs = sum(.data$first_down_pass & is.na(.data$lateral_receiver_player_id)),
receiving_epa = sum(.data$epa, na.rm = TRUE)
) %>%
dplyr::ungroup()
laterals <- data %>%
dplyr::filter(!is.na(.data$lateral_receiver_player_id)) %>%
dplyr::group_by(.data$lateral_receiver_player_id, .data$week, .data$season) %>%
dplyr::summarize(
lateral_yards = sum(.data$lateral_receiving_yards, na.rm = TRUE),
lateral_tds = sum(.data$td_player_id == .data$lateral_receiver_player_id, na.rm = TRUE),
lateral_att = dplyr::n(),
lateral_fds = sum(.data$first_down_pass, na.rm = T),
lateral_fumbles = sum(.data$fumble, na.rm = T),
lateral_fumbles_lost = sum(.data$fumble_lost, na.rm = T)
) %>%
dplyr::ungroup() %>%
dplyr::rename(receiver_player_id = .data$lateral_receiver_player_id) %>%
dplyr::bind_rows(
mult_lats %>%
dplyr::filter(
.data$type == "lateral_receiving" & .data$season %in% data$season & .data$week %in% data$week
) %>%
dplyr::select("season", "week", "receiver_player_id" = .data$gsis_player_id, "lateral_yards" = .data$yards) %>%
dplyr::mutate(lateral_tds = 0L, lateral_att = 1L)
)
rec_team <- data %>%
dplyr::filter(!is.na(.data$receiver_player_id)) %>%
dplyr::group_by(.data$posteam, .data$week, .data$season) %>%
dplyr::summarize(
team_targets = dplyr::n(),
team_air_yards = sum(.data$air_yards, na.rm = TRUE),
) %>%
dplyr::ungroup()
rec_df <- rec %>%
dplyr::left_join(laterals, by = c("receiver_player_id", "week", "season")) %>%
dplyr::left_join(rec_team, by = c("team_receiver" = "posteam", "week", "season")) %>%
dplyr::mutate(
lateral_yards = dplyr::if_else(is.na(.data$lateral_yards), 0, .data$lateral_yards),
lateral_tds = dplyr::if_else(is.na(.data$lateral_tds), 0L, .data$lateral_tds),
lateral_fumbles = dplyr::if_else(is.na(.data$lateral_fumbles), 0, .data$lateral_fumbles),
lateral_fumbles_lost = dplyr::if_else(is.na(.data$lateral_fumbles_lost), 0, .data$lateral_fumbles_lost),
lateral_fds = dplyr::if_else(is.na(.data$lateral_fds), 0, .data$lateral_fds)
) %>%
dplyr::mutate(
receiving_yards = .data$yards + .data$lateral_yards,
receiving_tds = .data$tds + .data$lateral_tds,
receiving_yards_after_catch = .data$receiving_yards_after_catch + .data$lateral_yards,
receiving_first_downs = .data$receiving_first_downs + .data$lateral_fds,
receiving_fumbles = .data$receiving_fumbles + .data$lateral_fumbles,
receiving_fumbles_lost = .data$receiving_fumbles_lost + .data$lateral_fumbles_lost,
racr = .data$receiving_yards / .data$receiving_air_yards,
racr = dplyr::case_when(
is.nan(.data$racr) ~ NA_real_,
.data$receiving_air_yards == 0 ~ 0,
.data$receiving_air_yards < 0 & !.data$receiver_player_id %in% racr_ids$gsis_id ~ 0,
TRUE ~ .data$racr
),
target_share = .data$targets / .data$team_targets,
air_yards_share = .data$receiving_air_yards / .data$team_air_yards,
wopr = 1.5 * .data$target_share + 0.7 * .data$air_yards_share
) %>%
dplyr::rename(player_id = .data$receiver_player_id) %>%
dplyr::select("player_id", "week", "season", "name_receiver", "team_receiver",
"receiving_yards", "receiving_air_yards", "receiving_yards_after_catch",
"receptions", "targets", "receiving_tds", "receiving_fumbles",
"receiving_fumbles_lost", "receiving_first_downs", "receiving_epa",
"racr", "target_share", "air_yards_share", "wopr")
rec_two_points <- two_points %>%
dplyr::filter(.data$pass_attempt == 1) %>%
dplyr::group_by(.data$receiver_player_id, .data$week, .data$season) %>%
dplyr::summarise(
name_receiver = custom_mode(.data$receiver_player_name),
team_receiver = custom_mode(.data$posteam),
receiving_2pt_conversions = dplyr::n()
) %>%
dplyr::rename(player_id = .data$receiver_player_id) %>%
dplyr::ungroup()
rec_df <- rec_df %>%
dplyr::full_join(rec_two_points, by = c("player_id", "week", "season", "name_receiver", "team_receiver")) %>%
dplyr::mutate(receiving_2pt_conversions = dplyr::if_else(is.na(.data$receiving_2pt_conversions), 0L, .data$receiving_2pt_conversions)) %>%
dplyr::filter(!is.na(.data$player_id))
rec_df_nas <- is.na(rec_df)
epa_index <- which(dimnames(rec_df_nas)[[2]] == c("receiving_epa", "racr", "target_share", "air_yards_share", "wopr"))
rec_df_nas[,epa_index] <- c(FALSE)
rec_df[rec_df_nas] <- 0
st_tds <- pbp %>%
dplyr::filter(.data$special == 1 & !is.na(.data$td_player_id)) %>%
dplyr::group_by(.data$td_player_id, .data$week, .data$season) %>%
dplyr::summarise(
name_st = custom_mode(.data$td_player_name),
team_st = custom_mode(.data$td_team),
special_teams_tds = sum(.data$touchdown, na.rm = TRUE)
) %>%
dplyr::rename(player_id = .data$td_player_id)
player_df <- pass_df %>%
dplyr::full_join(rush_df, by = c("player_id", "week", "season")) %>%
dplyr::full_join(rec_df, by = c("player_id", "week", "season")) %>%
dplyr::full_join(st_tds, by = c("player_id", "week", "season")) %>%
dplyr::left_join(s_type, by = c("season", "week")) %>%
dplyr::mutate(
player_name = dplyr::case_when(
!is.na(.data$name_pass) ~ .data$name_pass,
!is.na(.data$name_rush) ~ .data$name_rush,
!is.na(.data$name_receiver) ~ .data$name_receiver,
TRUE ~ .data$name_st
),
recent_team = dplyr::case_when(
!is.na(.data$team_pass) ~ .data$team_pass,
!is.na(.data$team_rush) ~ .data$team_rush,
!is.na(.data$team_receiver) ~ .data$team_receiver,
TRUE ~ .data$team_st
)
) %>%
dplyr::select(tidyselect::any_of(c(
"player_id", "player_name", "recent_team", "season", "week", "season_type",
"completions", "attempts", "passing_yards", "passing_tds", "interceptions",
"sacks", "sack_yards", "sack_fumbles", "sack_fumbles_lost", "passing_air_yards", "passing_yards_after_catch",
"passing_first_downs", "passing_epa", "passing_2pt_conversions", "pacr", "dakota",
"carries", "rushing_yards", "rushing_tds", "rushing_fumbles", "rushing_fumbles_lost",
"rushing_first_downs", "rushing_epa", "rushing_2pt_conversions",
"receptions", "targets", "receiving_yards", "receiving_tds", "receiving_fumbles",
"receiving_fumbles_lost", "receiving_air_yards", "receiving_yards_after_catch",
"receiving_first_downs", "receiving_epa", "receiving_2pt_conversions", "racr",
"target_share", "air_yards_share", "wopr",
"special_teams_tds"
))) %>%
dplyr::filter(!is.na(.data$player_id))
player_df_nas <- is.na(player_df)
epa_index <- which(dimnames(player_df_nas)[[2]] %in% c("passing_epa", "rushing_epa", "receiving_epa", "dakota", "racr", "target_share", "air_yards_share", "wopr", "pacr"))
player_df_nas[,epa_index] <- c(FALSE)
player_df[player_df_nas] <- 0
player_df <- player_df %>%
dplyr::mutate(
fantasy_points =
1 / 25 * .data$passing_yards +
4 * .data$passing_tds +
-2 * .data$interceptions +
1 / 10 * (.data$rushing_yards + .data$receiving_yards) +
6 * (.data$rushing_tds + .data$receiving_tds + .data$special_teams_tds) +
2 * (.data$passing_2pt_conversions + .data$rushing_2pt_conversions + .data$receiving_2pt_conversions) +
-2 * (.data$sack_fumbles_lost + .data$rushing_fumbles_lost + .data$receiving_fumbles_lost),
fantasy_points_ppr = .data$fantasy_points + .data$receptions
) %>%
dplyr::arrange(.data$player_id, .data$season, .data$week)
if (isFALSE(weekly)) {
player_df <- player_df %>%
dplyr::group_by(.data$player_id) %>%
dplyr::summarise(
player_name = custom_mode(.data$player_name),
games = dplyr::n(),
recent_team = dplyr::last(.data$recent_team),
completions = sum(.data$completions),
attempts = sum(.data$attempts),
passing_yards = sum(.data$passing_yards),
passing_tds = sum(.data$passing_tds),
interceptions = sum(.data$interceptions),
sacks = sum(.data$sacks),
sack_yards = sum(.data$sack_yards),
sack_fumbles = sum(.data$sack_fumbles),
sack_fumbles_lost = sum(.data$sack_fumbles_lost),
passing_air_yards = sum(.data$passing_air_yards),
passing_yards_after_catch = sum(.data$passing_yards_after_catch),
passing_first_downs = sum(.data$passing_first_downs),
passing_epa = dplyr::if_else(all(is.na(.data$passing_epa)), NA_real_, sum(.data$passing_epa, na.rm = TRUE)),
passing_2pt_conversions = sum(.data$passing_2pt_conversions),
pacr = .data$passing_yards / .data$passing_air_yards,
carries = sum(.data$carries),
rushing_yards = sum(.data$rushing_yards),
rushing_tds = sum(.data$rushing_tds),
rushing_fumbles = sum(.data$rushing_fumbles),
rushing_fumbles_lost = sum(.data$rushing_fumbles_lost),
rushing_first_downs = sum(.data$rushing_first_downs),
rushing_epa = dplyr::if_else(all(is.na(.data$rushing_epa)), NA_real_, sum(.data$rushing_epa, na.rm = TRUE)),
rushing_2pt_conversions = sum(.data$rushing_2pt_conversions),
receptions = sum(.data$receptions),
targets = sum(.data$targets),
receiving_yards = sum(.data$receiving_yards),
receiving_tds = sum(.data$receiving_tds),
receiving_fumbles = sum(.data$receiving_fumbles),
receiving_fumbles_lost = sum(.data$receiving_fumbles_lost),
receiving_air_yards = sum(.data$receiving_air_yards),
receiving_yards_after_catch = sum(.data$receiving_yards_after_catch),
receiving_first_downs = sum(.data$receiving_first_downs),
receiving_epa = dplyr::if_else(all(is.na(.data$receiving_epa)), NA_real_, sum(.data$receiving_epa, na.rm = TRUE)),
receiving_2pt_conversions = sum(.data$receiving_2pt_conversions),
racr = .data$receiving_yards / .data$receiving_air_yards,
target_share = dplyr::if_else(all(is.na(.data$target_share)), NA_real_, mean(.data$target_share, na.rm = TRUE)),
air_yards_share = dplyr::if_else(all(is.na(.data$air_yards_share)), NA_real_, mean(.data$air_yards_share, na.rm = TRUE)),
wopr = 1.5 * .data$target_share + 0.7 * .data$air_yards_share,
special_teams_tds = sum(.data$special_teams_tds),
fantasy_points = sum(.data$fantasy_points),
fantasy_points_ppr = sum(.data$fantasy_points_ppr)
) %>%
dplyr::ungroup() %>%
dplyr::mutate(
racr = dplyr::case_when(
is.nan(.data$racr) ~ NA_real_,
.data$receiving_air_yards == 0 ~ 0,
.data$receiving_air_yards < 0 & !.data$player_id %in% racr_ids$gsis_id ~ 0,
TRUE ~ .data$racr
),
pacr = dplyr::case_when(
is.nan(.data$pacr) ~ NA_real_,
.data$passing_air_yards <= 0 ~ 0,
TRUE ~ .data$pacr
)
) %>%
add_dakota(pbp = pbp, weekly = weekly) %>%
dplyr::select(
.data$player_id:.data$pacr,
.data$dakota,
dplyr::everything()
)
}
return(player_df)
}
add_dakota <- function(add_to_this, pbp, weekly) {
dakota_model <- NULL
con <- url("https://github.com/nflverse/nflfastR-data/blob/master/models/dakota_model.Rdata?raw=true")
try(load(con), silent = TRUE)
close(con)
if (is.null(dakota_model)) {
user_message("This function needs to download the model data from GitHub. Please check your Internet connection and try again!", "oops")
return(add_to_this)
}
if (!"id" %in% names(pbp)) pbp <- clean_pbp(pbp)
if (!"qb_epa" %in% names(pbp)) pbp <- add_qb_epa(pbp)
suppressMessages({
df <- pbp %>%
dplyr::filter(.data$pass == 1 | .data$rush == 1) %>%
dplyr::filter(!is.na(.data$posteam) & !is.na(.data$qb_epa) & !is.na(.data$id) & !is.na(.data$down)) %>%
dplyr::mutate(epa = dplyr::if_else(.data$qb_epa < -4.5, -4.5, .data$qb_epa)) %>%
decode_player_ids()
})
if (isTRUE(weekly)) {
relevant_players <- add_to_this %>%
dplyr::filter(.data$attempts >= 5) %>%
dplyr::mutate(filter_id = paste(.data$player_id, .data$season, .data$week, sep = "_")) %>%
dplyr::pull(.data$filter_id)
model_data <- df %>%
dplyr::group_by(.data$id, .data$week, .data$season) %>%
dplyr::summarize(
n_plays = n(),
epa_per_play = sum(.data$epa) / .data$n_plays,
cpoe = mean(.data$cpoe, na.rm = TRUE)
) %>%
dplyr::ungroup() %>%
dplyr::mutate(cpoe = dplyr::if_else(is.na(.data$cpoe), 0, .data$cpoe)) %>%
dplyr::rename(player_id = .data$id) %>%
dplyr::mutate(filter_id = paste(.data$player_id, .data$season, .data$week, sep = "_")) %>%
dplyr::filter(.data$filter_id %in% relevant_players)
model_data$dakota <- mgcv::predict.gam(dakota_model, model_data) %>% as.vector()
out <- add_to_this %>%
dplyr::left_join(
model_data %>%
dplyr::select(.data$player_id, .data$week, .data$season, .data$dakota),
by = c("player_id", "week", "season")
)
} else if (isFALSE(weekly)) {
relevant_players <- add_to_this %>%
dplyr::filter(.data$attempts >= 5) %>%
dplyr::pull(.data$player_id)
model_data <- df %>%
dplyr::group_by(.data$id) %>%
dplyr::summarize(
n_plays = n(),
epa_per_play = sum(.data$epa) / .data$n_plays,
cpoe = mean(.data$cpoe, na.rm = TRUE)
) %>%
dplyr::ungroup() %>%
dplyr::mutate(cpoe = dplyr::if_else(is.na(.data$cpoe), 0, .data$cpoe)) %>%
dplyr::rename(player_id = .data$id) %>%
dplyr::filter(.data$player_id %in% relevant_players)
model_data$dakota <- mgcv::predict.gam(dakota_model, model_data) %>% as.vector()
out <- add_to_this %>%
dplyr::left_join(
model_data %>%
dplyr::select(.data$player_id, .data$dakota),
by = "player_id"
)
}
return(out)
}
|
"manly.boot" <-
function (x, i, Epsilon=1)
{
reps <- 50
x <- x[i]
mean <- mean(x)
n <- length(x)
pmanly1.boot <- function(d, i)
{ randomize <- 1 - 2*rbinom(n, 1, 0.5)
d1.boot <- (d[i]+Epsilon)*randomize
return(mean(d1.boot) >= mean+Epsilon) }
pmanly2.boot <- function(d, i)
{ randomize <- 1 - 2*rbinom(n, 1, 0.5)
d2.boot <- (d[i]-Epsilon)*randomize
return(mean(d2.boot) <= mean-Epsilon) }
pvalue <- mean(boot(x, pmanly1.boot, reps)$t) +
mean(boot(x, pmanly2.boot, reps)$t)
result <- (pvalue < 0.05)
}
|
library(grid)
pushViewport(viewport(height = 0))
stopifnot(is.finite(convertHeight(unit(72, "bigpts"), "inches", valueOnly = TRUE)))
popViewport()
stopifnot(round(convertHeight(grobHeight(rectGrob(height=unit(1, "lines"),
gp=gpar(lineheight=2))),
"inches", valueOnly=TRUE) -
convertHeight(grobHeight(rectGrob(height=unit(1, "lines"),
vp=viewport(
gp=gpar(lineheight=2)))),
"inches", valueOnly=TRUE),
digits=5) == 0)
gf1 <- frameGrob(gp=gpar(fontsize=20))
gf1 <- packGrob(gf1, textGrob("howdy"))
gf1 <- packGrob(gf1, rectGrob(), col=1, row=1)
gf2 <- frameGrob()
gf2 <- packGrob(gf2, gf1)
gf2 <- packGrob(gf2, rectGrob(gp=gpar(col="red")), col=1, row=1)
stopifnot(round(convertWidth(grobWidth(gf1),
"inches", valueOnly=TRUE) -
convertWidth(grobWidth(gf2),
"inches", valueOnly=TRUE),
digits=5) == 0)
|
rd_text <- function(x, fragment = TRUE) {
con <- textConnection(x)
on.exit(close(con), add = TRUE)
set_classes(tools::parse_Rd(con, fragment = fragment, encoding = "UTF-8"))
}
rd_file <- function(path, pkg_path = NULL) {
if (getRversion() >= "3.4.0") {
macros <- tools::loadPkgRdMacros(pkg_path)
set_classes(tools::parse_Rd(path, macros = macros, encoding = "UTF-8"))
} else if (getRversion() >= "3.2.0") {
macros <- tools::loadPkgRdMacros(pkg_path, TRUE)
set_classes(tools::parse_Rd(path, macros = macros, encoding = "UTF-8"))
} else {
set_classes(tools::parse_Rd(path, encoding = "UTF-8"))
}
}
rd2html <- function(x, fragment = TRUE, ...) {
html <- as_html(rd_text(x, fragment = fragment), ...)
str_trim(strsplit(str_trim(html), "\n")[[1]])
}
print.Rd <- function(x, ...) {
utils::str(x)
}
print.tag <- function(x, ...) {
utils::str(x)
}
set_classes <- function(rd) {
if (is.list(rd)) {
rd[] <- lapply(rd, set_classes)
}
set_class(rd)
}
set_class <- function(x) {
structure(x,
class = c(attr(x, "class"), tag(x), "tag"),
Rd_tag = NULL,
srcref = NULL,
macros = NULL
)
}
tag <- function(x) {
tag <- attr(x, "Rd_tag")
if (is.null(tag)) return()
gsub("\\", "tag_", tag, fixed = TRUE)
}
`[.tag` <- function(x, ...) {
structure(NextMethod(), class = class(x))
}
|
linarpr <- function(Y, id = NULL, weight = NULL, Y_thres = NULL,
wght_thres = NULL, sort = NULL, Dom = NULL,
period = NULL, dataset = NULL, percentage = 60,
order_quant = 50, var_name = "lin_arpr",
checking = TRUE) {
if (min(dim(data.table(var_name)) == 1) != 1) {
stop("'var_name' must have defined one name of the linearized variable")}
if (checking) {
percentage <- check_var(vars = percentage, varn = "percentage",
varntype = "numeric0100")
order_quant <- check_var(vars = order_quant, varn = "order_quant",
varntype = "numeric0100")
Y <- check_var(vars = Y, varn = "Y", dataset = dataset,
ncols = 1, isnumeric = TRUE,
isvector = TRUE, grepls = "__")
Ynrow <- length(Y)
Y_thres <- check_var(vars = Y_thres, varn = "Y_thres",
dataset = dataset, ncols = 1,
Ynrow = Ynrow, mustbedefined = FALSE,
isnumeric = TRUE, isvector = TRUE)
weight <- check_var(vars = weight, varn = "weight",
dataset = dataset, ncols = 1,
Ynrow = Ynrow, isnumeric = TRUE,
isvector = TRUE)
wght_thres <- check_var(vars = wght_thres, varn = "wght_thres",
dataset = dataset, ncols = 1,
Ynrow = Ynrow, mustbedefined = FALSE,
isnumeric = TRUE, isvector = TRUE)
sort <- check_var(vars = sort, varn = "sort",
dataset = dataset, ncols = 1,
Ynrow = Ynrow, mustbedefined = FALSE,
isnumeric = TRUE, isvector = TRUE)
period <- check_var(vars = period, varn = "period",
dataset = dataset, Ynrow = Ynrow,
ischaracter = TRUE, mustbedefined = FALSE,
duplicatednames = TRUE)
Dom <- check_var(vars = Dom, varn = "Dom", dataset = dataset,
Ynrow = Ynrow, ischaracter = TRUE,
mustbedefined = FALSE, duplicatednames = TRUE,
grepls = "__")
id <- check_var(vars = id, varn = "id", dataset = dataset,
ncols = 1, Ynrow = Ynrow, ischaracter = TRUE,
periods = period)
}
dataset <- NULL
if (is.null(Y_thres)) Y_thres <- Y
if (is.null(wght_thres)) wght_thres <- weight
ind0 <- rep.int(1, length(Y))
period_agg <- period1 <- NULL
if (!is.null(period)) { period1 <- copy(period)
period_agg <- data.table(unique(period))
} else period1 <- data.table(ind = ind0)
period1_agg <- data.table(unique(period1))
quantile <- incPercentile(Y = Y_thres,
weights = wght_thres,
sort = sort, Dom = NULL,
period = period,
k = order_quant,
dataset = NULL,
checking = FALSE)
setnames(quantile, names(quantile)[ncol(quantile)], "quantile")
if (ncol(quantile) > 1) setkeyv(quantile, head(names(quantile), -1))
threshold <- copy(quantile)
threshold[, threshold := percentage / 100 * quantile]
threshold[, quantile := NULL]
arpr_id <- id
if (!is.null(period)) arpr_id <- data.table(arpr_id, period)
if (!is.null(Dom)) {
Dom_agg <- data.table(unique(Dom))
setkeyv(Dom_agg, names(Dom_agg))
arpr_v <- c()
arpr_m <- copy(arpr_id)
for(i in 1 : nrow(Dom_agg)) {
g <- c(var_name, paste(names(Dom), as.matrix(Dom_agg[i,]), sep = "."))
var_nams <- do.call(paste, as.list(c(g, sep = "__")))
ind <- as.integer(rowSums(Dom == Dom_agg[i,][ind0,]) == ncol(Dom))
arprl <- lapply(1 : nrow(period1_agg), function(j) {
if (!is.null(period)) {
rown <- cbind(period_agg[j], Dom_agg[i])
setkeyv(rown, names(rown))
rown2 <- copy(rown)
rown <- merge(rown, quantile, all.x = TRUE)
} else {rown <- quantile
rown2 <- Dom_agg[i] }
indj <- (rowSums(period1 == period1_agg[j,][ind0,]) == ncol(period1))
arpr_l <- arprlinCalc(Y1 = Y[indj],
ids = arpr_id[indj],
wght1 = weight[indj],
indicator = ind[indj],
Y_thresh = Y_thres[indj],
wght_thresh = wght_thres[indj],
percent = percentage,
order_quants = order_quant,
quant_val = rown[["quantile"]])
list(arpr = data.table(rown2, arpr = arpr_l$rate_val_pr), lin = arpr_l$lin)
})
arprs <- rbindlist(lapply(arprl, function(x) x[[1]]))
arprlin <- rbindlist(lapply(arprl, function(x) x[[2]]))
setnames(arprlin, names(arprlin), c(names(arpr_id), var_nams))
arpr_m <- merge(arpr_m, arprlin, all.x = TRUE, by = names(arpr_id))
arpr_v <- rbind(arpr_v, arprs)
}
} else { arprl <- lapply(1:nrow(period1_agg), function(j) {
if (!is.null(period)) {
rown <- period_agg[j]
rown <- merge(rown, quantile, all.x = TRUE,
by = names(rown))
} else rown <- quantile
ind2 <- (rowSums(period1 == period1_agg[j,][ind0,]) == ncol(period1))
arpr_l <- arprlinCalc(Y1 = Y[ind2],
ids = arpr_id[ind2],
wght1 = weight[ind2],
indicator = ind0[ind2],
Y_thresh = Y_thres[ind2],
wght_thresh = wght_thres[ind2],
percent = percentage,
order_quants = order_quant,
quant_val = rown[["quantile"]])
if (!is.null(period)) {
arprs <- data.table(period_agg[j], arpr = arpr_l$rate_val_pr)
} else arprs <- data.table(arpr = arpr_l$rate_val_pr)
list(arpr = arprs, lin = arpr_l$lin)
})
arpr_v <- rbindlist(lapply(arprl, function(x) x[[1]]))
arpr_m <- rbindlist(lapply(arprl, function(x) x[[2]]))
setnames(arpr_m, names(arpr_m), c(names(arpr_id), var_name))
}
arpr_m[is.na(arpr_m)] <- 0
setkeyv(arpr_m, names(arpr_id))
return(list(quantile = quantile, threshold = threshold, value = arpr_v, lin = arpr_m))
}
arprlinCalc <- function(Y1, ids, wght1, indicator,
Y_thresh, wght_thresh, percent,
order_quants = NULL, quant_val) {
N <- dat <- eqIncome1 <- NULL
arpt_calcs <- arptlinCalc(inco = Y_thresh, ids = ids,
wght = wght_thresh,
indicator = rep(1, length(ids)),
order_quants = order_quants,
quant_val = quant_val,
percentag = percent)
lin_thres <- arpt_calcs[[names(arpt_calcs)[2]]]
thres_val <- percent / 100 * quant_val
wt <- indicator * wght1
N <- sum(wt)
poor <- (Y1 <= thres_val)
rate_val <- sum(wt * poor) / N
rate_val_pr <- 100 * rate_val
h <- bandwith_plug(y = Y1, w = wt)
f_quant2 <- gaussian_kern(inco = Y1, wt = wt,
quant_val = quant_val, hh = h)
lin <- 100 * ((1 / N) * indicator * ((Y1 <= thres_val) - rate_val) + f_quant2 * lin_thres)
lin_id <- data.table(ids, lin)
return(list(rate_val = rate_val, rate_val_pr = rate_val_pr, lin = lin_id))
}
|
maxd<- function(x,o,g,n,d,s,ymax,xlab,color){
if(missing(s))
s <- 1
dm <- c()
t<-as.matrix(g)
dim(t)<-c(length(x),n)
for (i in 1:n){
dn <- assign(x=paste("rsd",i,sep=""),value=sqrt((o-t[,i])^2))
dm <- cbind(dm,dn)
}
mx<-c()
for (i in 1:length(x)){
m<- assign(x=paste("max",i,sep=""),value=max(dm[i,]))
mx <- rbind(mx,m,row.names=NULL)
}
mx2 <- cbind(x,mx/s)
mx3<- data.frame(mx2,row.names=NULL)
colnames(mx3)<- c("x","maxd")
if(missing(ymax))
ymax <- max((mx3[,2])+3)
if(missing(xlab))
xlab <- "Score Scale"
if(missing(color))
color <- "red"
plot<- plot(type="b",x=mx3[,1],y=mx3[,2],ylim=c(0,ymax),xlab=xlab,ylab="Maximum Difference",col=color,pch=19)
abline(d/s,0,col="black",lty=2)
legend(x=min(mx3[,1]),y=ymax,c("MaxD","DTM"),col=c(color,"black"),pch=c(19,-1),lty=c(0,5))
return(mx3)
return(plot)
}
|
margins.merMod <-
function(model,
data = find_data(model),
variables = NULL,
at = NULL,
type = c("response", "link"),
vcov = stats::vcov(model),
vce = c("delta", "simulation", "bootstrap", "none"),
iterations = 50L,
unit_ses = FALSE,
eps = 1e-7,
...) {
type <- match.arg(type)
vce <- match.arg(vce)
data_list <- build_datalist(data, at = at)
at_specification <- attr(data_list, "at_specification")
varslist <- find_terms_in_model(model, variables = variables)
out <- list()
for (i in seq_along(data_list)) {
out[[i]] <- build_margins(model = model,
data = data_list[[i]],
variables = variables,
type = type,
vcov = vcov,
vce = vce,
iterations = iterations,
unit_ses = unit_ses,
eps = eps,
varslist = varslist,
...)
out[[i]][["_at_number"]] <- i
}
if (vce == "delta") {
jac <- do.call("rbind", lapply(out, attr, "jacobian"))
rownames(jac) <- paste0(rownames(jac), ".", rep(seq_len(length(out)), each = length(unique(rownames(jac)))))
vc <- jac %*% vcov %*% t(jac)
} else {
jac <- NULL
vc <- NULL
}
structure(do.call("rbind", out),
class = c("margins", "data.frame"),
at = if (is.null(at)) NULL else at_specification,
type = type,
call = if ("call" %in% names(model)) model[["call"]] else NULL,
model_class = class(model),
vce = vce,
vcov = vc,
jacobian = jac,
weighted = FALSE,
iterations = if (vce == "bootstrap") iterations else NULL)
}
margins.lmerMod <- margins.merMod
|
context("fc_headers")
h <- fc_headers(path = "/user", public_key = "invalid", private_key = "invalid")
test_that("fc_headers works", {
expect_is(h, "request")
expect_equal(names(h$headers), c("Date", "Authorization"))
expect_true(grepl("^hmac invalid\\:", h$headers[["Authorization"]]))
})
|
setClass("methodObj",
slots = c( method = "ANY",
methodArgs = "list"))
setGeneric(name = "method",
def = function(object,...) { standardGeneric("method") })
setMethod(f = "method",
signature = c(object = "ANY"),
definition = function(object,...) { stop("not defined") })
setMethod(f = "method",
signature = c(object = "methodObj"),
definition = function(object,...) { return( object@method ) })
setGeneric(name = "methodArgs",
def = function(object,...) { standardGeneric("methodArgs") })
setMethod(f = "methodArgs",
signature = c(object = "ANY"),
definition = function(object,...) { stop("not defined") })
setMethod(f = "methodArgs",
signature = c(object = "methodObj"),
definition = function(object,...) { return( object@methodArgs ) })
setGeneric(name = "methodArgs<-",
def = function(object,value) { standardGeneric("methodArgs<-") })
setMethod(f = "methodArgs<-",
signature = c(object = "ANY",
value = "ANY"),
definition = function(object, value) { stop("not defined") })
setMethod(f = "methodArgs<-",
signature = c(object = "methodObj",
value = "list"),
definition = function(object, value) {
nms <- names(x = object@methodArgs)
nmsNew <- names(x = value)
fmls <- names(x = formals(fun = object@method))
tst <- nmsNew %in% fmls
if (!all(tst) && !("..." %in% fmls)) {
stop(paste0(nmsNew[!tst], collapse = ", "),
" not found in formal arguments of method",
call. = FALSE)
}
newArgs <- object@methodArgs
for (i in 1L:length(x = nmsNew)) {
newArgs[[ nmsNew[i] ]] <- value[[ i ]]
}
object@methodArgs <- newArgs
return( object )
})
setGeneric(name = ".newMethodObj",
def = function(method, args) { standardGeneric(".newMethodObj") })
setMethod(f = ".newMethodObj",
signature = c(method = 'ANY',
args = 'ANY'),
definition = function(method, args) { stop("not defined") })
setMethod(f = ".newMethodObj",
signature = c(method = 'character',
args = 'list'),
definition = function(method, args) {
if (!exists(x = method)) {
stop("method does not exist.", call. = FALSE)
}
nms <- names(x = args)
fmls <- names(x = formals(fun = method))
tst <- nms %in% fmls
if (!all(tst)) {
if (!("..." %in% fmls)) {
stop(paste(nms[!tst], collapse = ", "),
" not found in formal arguments of method",
call. = FALSE)
}
}
obj <- new("methodObj",
method = method,
methodArgs = args)
return( obj )
})
setMethod(f = ".newMethodObj",
signature = c(method = 'function',
args = 'list'),
definition = function(method, args) {
nms <- names(x = args)
fmls <- names(x = formals(fun = method))
tst <- nms %in% fmls
if (!all(tst)) {
if (!("..." %in% fmls)) {
stop(paste(nms[!tst], collapse = ", "),
" not found in formal arguments of method",
call. = FALSE)
}
}
obj <- new("methodObj",
method = method,
methodArgs = args)
return( obj )
})
setGeneric(name = ".fit",
def = function(object,...) { standardGeneric(".fit") })
setMethod(f = ".fit",
signature = c(object = "methodObj"),
definition = function(object, data, response, ...) {
mm <- tryCatch(expr = do.call(what = object@method,
args = object@methodArgs),
error = function(e) {
message(e$message)
return( e )
})
return( mm )
})
setGeneric(name = ".predict",
def = function(object,...) { standardGeneric(".predict") })
setMethod(f = ".predict",
signature = c(object = "ANY"),
definition = function(object, ...) { stop("not defined") })
setMethod(f = ".predict",
signature = c(object = "methodObj"),
definition = function(object, newdata, fitObj, ...) {
mm <- tryCatch(expr = do.call(what = object@method,
args = object@methodArgs),
error = function(e) {
message(e$message)
return( e )
})
return( mm )
})
|
k.points.max.cind <-
function(formula, cat.var, data, range, k, l.s.points = 100 , min.p.cat=1) {
point=NULL
mat=matrix(ncol=2,nrow=k)
colnames(mat)<- c("point","c-index")
for (i in 1:k){
cinds <- select.cutpoint.cind(formula = formula, cat.var = cat.var, data = data, range = range, point = point, l.s.points = l.s.points, min.p.cat = min.p.cat)
pos <- which(cinds[,2]==max(cinds[,2],na.rm=TRUE))
if(length(pos)> 1 & i > 1) {
if (cinds[pos[1],1] <= mat[i-1,1]) {
pos <- max(pos)
} else {
pos = min(pos)
}
} else {
pos = pos[1]
}
mat[i,1] <- cinds[pos,1]
mat[i,2] <- cinds[pos,2]
point <- c(point,mat[i,1])
}
mat
}
|
Bitset <- R6Class(
'Bitset',
public = list(
.bitset = NULL,
max_size = 0,
initialize = function(size, from = NULL) {
if (is.null(from)) {
self$.bitset <- create_bitset(size)
} else {
stopifnot(inherits(from, "externalptr"))
self$.bitset <- from
}
self$max_size <- bitset_max_size(self$.bitset)
},
insert = function(v) {
bitset_insert(self$.bitset, v)
self
},
remove = function(v) {
bitset_remove(self$.bitset, v)
self
},
size = function() bitset_size(self$.bitset),
or = function(other) {
bitset_or(self$.bitset, other$.bitset)
self
},
and = function(other) {
bitset_and(self$.bitset, other$.bitset)
self
},
not = function(inplace) {
if (missing(inplace)) {
warning(paste(
"DEPRECATED: Future versions of Bitset$not will be in place",
"to be consistent with other bitset operations.",
"To copy this bitset please use the copy method.",
"To suppress this warning, please set the `inplace` argument.",
sep = " "
))
inplace <- FALSE
}
Bitset$new(from = bitset_not(self$.bitset, inplace))
},
xor = function(other){
bitset_xor(self$.bitset, other$.bitset)
self
},
set_difference = function(other){
bitset_set_difference(self$.bitset, other$.bitset)
self
},
sample = function(rate) {
if (length(rate) == 1) {
bitset_sample(self$.bitset, rate)
} else {
stopifnot(all(is.finite(rate)))
bitset_sample_vector(self$.bitset, rate)
}
self
},
choose = function(k) {
stopifnot(is.finite(k))
stopifnot(k <= bitset_size(self$.bitset))
stopifnot(k >= 0)
if (k < self$max_size) {
bitset_choose(self$.bitset, as.integer(k))
}
self
},
copy = function() Bitset$new(from = bitset_copy(self$.bitset)),
to_vector = function() bitset_to_vector(self$.bitset)
)
)
filter_bitset = function(bitset, other) {
if ( inherits(other, "Bitset")) {
if (other$size() > 0) {
return(Bitset$new(from = filter_bitset_bitset(bitset$.bitset, other$.bitset)))
} else {
return(Bitset$new(size = bitset$max_size))
}
} else {
if (length(other) > 0) {
return(Bitset$new(from = filter_bitset_vector(bitset$.bitset, as.integer(other))))
} else {
return(Bitset$new(size = bitset$max_size))
}
}
}
|
cat("FeatSelWrapper")
test_that("FeatSelWrapper", {
outer = makeResampleDesc("CV", iters = 2L)
inner = makeResampleDesc("Holdout")
lrn1 = makeLearner("classif.rpart")
ctrl = makeFeatSelControlRandom(maxit = 3)
lrn2 = makeFeatSelWrapper(lrn1, resampling = inner, control = ctrl)
r = resample(lrn2, multiclass.task, outer, extract = function(model) {
getFeatSelResult(model)
})
expect_true(!is.na(r$aggr[[1]]))
feats = extractSubList(r$extract, "x", simplify = FALSE)
expect_true(is.list(feats) && length(feats) == 2L &&
all(sapply(feats, is.character)))
perfs = extractSubList(r$extract, "y")
expect_true(is.numeric(perfs) && length(perfs) == 2L && !any(is.na(perfs)))
})
test_that("FeatSelWrapper works with custom bits", {
bns = c("b1", "b2")
btf = function(x, task) {
fns = getTaskFeatureNames(task)
Reduce(c, list(fns[1:2], fns[3:4])[as.logical(x)], init = character(0))
}
lrn1 = makeLearner("classif.rpart")
ctrl = makeFeatSelControlRandom(maxit = 3)
lrn2 = makeFeatSelWrapper(lrn1, resampling = makeResampleDesc("Holdout"),
control = ctrl, bit.names = bns, bits.to.features = btf)
r = resample(lrn2, multiclass.task, cv2, extract = function(model) {
getFeatSelResult(model)
})
expect_true(!is.na(r$aggr[[1]]))
feats = extractSubList(r$extract, "x", simplify = FALSE)
expect_true(is.list(feats) && length(feats) == 2L &&
all(sapply(feats, is.character)))
bit.names = extractSubList(r$extract, "x.bit.names", simplify = FALSE)
expect_true(is.list(bit.names) && length(bit.names) == 2L &&
all(sapply(feats, is.character)))
})
|
bn.to.igraph <- function(bayesian.network){
g <- igraph.from.graphNEL(bnlearn::as.graphNEL(bayesian.network))
return(g)
}
|
context("logLikelihood.Guilds.Conditional")
test_that("logLikelihood.Guilds.Conditional: use", {
skip_on_cran()
set.seed(666)
J <- 20000
theta <- 100
alpha_x <- 0.1
alpha_y <- alpha_x
simul_data <- generate.Guilds.Cond(theta, alpha_x, alpha_y,
JX=J/2, JY = J/2)
LL1 <- logLikelihood.Guilds.Conditional(parameters=c(theta, alpha_x),
model = "D0",
simul_data$guildX, simul_data$guildY,
verbose = FALSE)
LL2 <- logLikelihood.Guilds.Conditional(parameters=c(3, 0.00001),
model = "D0",
simul_data$guildX, simul_data$guildY,
verbose = FALSE)
a <- LL1[[1]] > LL2[[1]]
expect_equal(a, TRUE)
set.seed(42+666)
alpha_y <- 0.01
simul_data <- generate.Guilds(theta, alpha_x, alpha_y, J)
LL1 <- logLikelihood.Guilds.Conditional( parameters =
c(theta, alpha_x, alpha_y),
model = "D1",
simul_data$guildX, simul_data$guildY,
verbose = FALSE)
LL2 <- logLikelihood.Guilds.Conditional(parameters=c(3, 0.99, 0.5),
model = "D1",
simul_data$guildX, simul_data$guildY,
verbose = FALSE)
a <- LL1[[1]] > LL2[[1]]
expect_equal(a, TRUE)
LL2 <- logLikelihood.Guilds.Conditional(parameters=c(3, 0.99, 0.5),
model = "D1",
simul_data$guildX, simul_data$guildY,
verbose = TRUE)
})
test_that("logLikelihood.Guilds.Conditional: abuse", {
skip_on_cran()
set.seed(666)
J <- 20000
theta <- 100
alpha_x <- 0.1
alpha_y <- alpha_x
simul_data <- generate.Guilds.Cond(theta, alpha_x, alpha_y, JX=J/2, JY = J/2)
expect_error(
logLikelihood.Guilds.Conditional(parameters = c(theta, alpha_x, alpha_x),
model = "D0",
simul_data$guildX, simul_data$guildY,
verbose = FALSE),
"Input vector is of incorrect length"
)
})
|
library (data.table)
cls <- c("numeric", "character", rep("numeric", 8))
filelist = list.files("/home/apourmok/My scripts/",pattern = "sitefiles.radius_0.075.*.css", full.names = TRUE)
mydata = fread(filelist, header=TRUE, colClasses = cls)
dbh2ca = 2.490154 * mydata$dbh ** 0.8068806
mydata [,c("Crown") := dbh2ca]
if (mydata$pft == 7) {
dbh2h = 0.3 + 27.14 * (1.0 - exp((-0.03884) * mydata$dbh))
}else if (mydata$pft == 8){
dbh2h = 0.3 + 22.79 * (1.0 - exp((-0.04445) * mydata$dbh))
}else if (mydata$pft == 9){
dbh2h = 0.3 + 22.6799 * (1.0 - exp((-0.06534) * mydata$dbh))
}else if (mydata$pft == 10){
dbh2h = 0.3 + 25.18 * (1.0 - exp((-0.04964) * mydata$dbh))
}else if (mydata$pft == 11){
dbh2h = 0.3 + 23.3874 * (1.0 - exp((-0.05404) * mydata$dbh))
}else if (mydata$pft == 18){
dbh2h = 0.3 + 25.18 * (1.0 - exp((-0.04964) * mydata$dbh))
}else if (mydata$pft == 19){
dbh2h = 0.3 + 25.18 * (1.0 - exp((-0.04964) * mydata$dbh))
}else {
dbh2h = 0.3 + 25.18 * (1.0 - exp((-0.04964) * mydata$dbh))
}
mydata [,c("Height") := dbh2h]
crown_plot_ratio = dbh2ca*mydata$n*100
mydata [,c("Area") := crown_plot_ratio]
md = mydata[order(patch,-rank(Height),decreasing=FALSE)]
patches = unique(mydata$patch)
pfts = unique(mydata$pft)
LandCover = matrix(numeric(1),length(patches),max(pfts))
Canopy = numeric(nrow(md))
md = cbind(md,Canopy)
grass = numeric(length(patches))
for(i in seq_along(patches)){
sel = which(md$patch == patches[i])
if(length(sel)>0){
CAsum = cumsum(md$Area[sel])
md$Canopy[sel] = CAsum < 100
patchCov = tapply(md$Area[sel]*md$Canopy[sel],md$pft[sel],sum)
LandCover[i,as.numeric(names(patchCov))]=patchCov
if(CAsum[length(CAsum)]<100){grass[i]=100-CAsum[length(CAsum)]}
}
}
LandCover = cbind(LandCover,grass)
LandCover <- data.table(LandCover)
row.names(LandCover) = patches
LandCover
setnames(LandCover,c(1:20,"grass"))
write.csv(LandCover,row.names=TRUE,file =paste0(filelist,".csv"))
apply(LandCover,2,mean)
write.table(mydata, filelist, row.names=FALSE, quote=FALSE)
|
drawLegend <- function(labels, colors, bottom, border.col, fontfamily.legend, reverse.legend) {
n <- length(labels)
lineNpc <- convertHeight(unit(0.8,"lines"), "npc", valueOnly = TRUE)
rl = if (reverse.legend) rev else function(x) x
if (bottom) {
cellWidth <- max(convertWidth(stringWidth(labels), "inches", valueOnly=TRUE))
totalWidth <- convertWidth(unit(1, "npc"), "inches", valueOnly=TRUE)
scale <- min(1, (cellWidth * n) / totalWidth * 1.5)
vpLeg_crop <- viewport(name = "legenda3",
width = scale,
height = 1)
pushViewport(vpLeg_crop)
legX <- seq(0,1*((n-1)/n), length.out=n)
legY <- rep(lineNpc,n)
legW <- rep(1/n,n)
legH <- rep(0.2,n)
leg <- data.frame(X=legX,Y=legY,W=legW,H=legH,Col=colors)
grid.rect(x=unit(leg$X,"npc"),
y=unit(leg$Y,"npc"),
width=unit(leg$W,"npc"),
height=unit(leg$H,"npc"),
just=c("left","bottom"),
gp = gpar(fill = rl(as.character(leg$Col)), col=border.col))
grid.text(rl(labels),
x=unit(leg$X+.5*leg$W, "npc"),
y=unit(0, "npc") + unit(0.5,"lines"),
gp=gpar(cex=0.8, fontfamily=fontfamily.legend))
upViewport()
} else {
legX <- rep(0.05, n)
legY <- 1-1.5*lineNpc-((0:(n-1))*(lineNpc*1.5))
legW <- convertWidth(
unit(max(0.2, convertWidth(unit(0.05, "npc"),
"inches",
valueOnly=TRUE)), "inches"), "npc", valueOnly=TRUE)
legH <- rep(lineNpc,n)
leg <- data.frame(X=legX,Y=legY,W=legW,H=legH,Col=colors)
grid.rect(x=unit(leg$X,"npc"),
y=unit(leg$Y,"npc"),
width=unit(leg$W,"npc"),
height=unit(leg$H,"npc"),
just=c("left","bottom"),
gp = gpar(fill = rl(as.character(leg$Col)), col=border.col))
grid.text(rl(labels),
x=unit(leg$X+leg$W+0.02, "npc"),
y=unit(leg$Y+.5*leg$H, "npc"),
gp=gpar(cex=1, fontfamily=fontfamily.legend), just=c("left", "center"))
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.