code
stringlengths
1
13.8M
continentality <- function(tmax, tmin, tempScale = 1) { res <- tmax - tmin res <- res / tempScale names(res) <- 'continentality' return(res) }
summary.l2.reg <- function (object, ...) { cat ("\n Call: \n") print (object$call) cat ("\n") cat ("\n Feature Matrix \n") print (object$X) cat ("\n") cat ("\n Outcome for Cases \n") print (object$Y) cat ("\n") cat ("\n Residuals \n") print (object$residual) cat ("\n") cat ("\n Sum of Residuals \n") print (object$L2) cat ("\n") cat (" cat (" cat ("\n Lambda used:", object$lambda, "\n") cat ("\n") cat ("\n Intercept: \n") print (object$intercept) cat ("\n Esimtated Coefficients: \n") print (object$estimate) cat ("\n") cat ("\n Number of Active Variables: \n") print (object$nonzeros) cat ("\n") cat ("\n Selected Variables with Nonzero Coefficients: \n") print (rownames(object$X)[object$selected+1]) }
context("Information value") test_that("test normal function", { X <- mtcars$gear Y <- mtcars$am expect_error(ExpInfoValue(X, Y)) }) test_that("test output object", { X <- mtcars$gear Y <- mtcars$am ivvaue <- ExpInfoValue(X, Y, valueOfGood = 1) expect_output(str(ivvaue), "List of 2") expect_equal(ivvaue$`Information values`, 0.44) })
library(h2o) h2o.init() iris.hex = h2o.uploadFile(path = system.file("extdata", "iris_wheader.csv", package="h2o"), destination_frame = "iris.hex") summary(iris.hex) iris.rf = h2o.randomForest(y = 5, x = c(1,2,3,4), training_frame = iris.hex, ntrees = 50, max_depth = 100) print(iris.rf)
chkSpectra <- function(spectra, confirm = FALSE) { UseMethod("chkSpectra") }
do.lapeig <- function(X, ndim=2, type=c("proportion",0.1), symmetric=c("union","intersect","asymmetric"), preprocess=c("null","center","scale","cscale","whiten","decorrelate"), weighted=FALSE, kernelscale=1.0){ aux.typecheck(X) n = nrow(X) p = ncol(X) ndim = as.integer(ndim) if (!check_ndim(ndim,p)){stop("* do.lapeig : 'ndim' is a positive integer in [1, nbdtype = type if (missing(symmetric)){ nbdsymmetric = "union" } else { nbdsymmetric = match.arg(symmetric) } if (missing(preprocess)){ algpreprocess = "null" } else { algpreprocess = match.arg(preprocess) } wflag = weighted if (!is.logical(wflag)){ stop("* do.lapeig : 'weighted' flag should be a logical input.") } t = kernelscale if (!is.numeric(t)||is.na(t)||(t<=0)){ stop("* do.lapeig : 'kernelscale' is a positive real value.") } if (t==Inf){ wflag = FALSE } tmplist = aux.preprocess.hidden(X,type=algpreprocess,algtype="nonlinear") trfinfo = tmplist$info pX = tmplist$pX n = nrow(pX) p = ncol(pX) nbdstruct = aux.graphnbd(pX,method="euclidean", type=nbdtype,symmetric=nbdsymmetric) if (wflag==FALSE){ W = matrix(as.double(nbdstruct$mask),nrow=nrow(nbdstruct$mask)) W = (W+t(W))/2 } else { W = exp((-(nbdstruct$mask*nbdstruct$dist)^2)/t) idxnan = which(is.nan(W)) W[idxnan] = 0 diag(W) = 0 W = (W+t(W))/2 } embedding = method_eigenmaps(W); eigvals = embedding$eigval eigvecs = embedding$eigvec result = list() result$Y = eigvecs[,2:(ndim+1)] result$eigvals = eigvals[2:(ndim+1)] trfinfo$algtype = "nonlinear" result$trfinfo = trfinfo return(result) }
context("Making plots") library(MOFA2) filepath <- system.file("extdata", "model.hdf5", package = "MOFA2") test_mofa2 <- load_model(filepath) test_that("plot data overview works", { expect_silent(p <- plot_data_overview(test_mofa2)) }) test_that("plot data heatmap", { expect_silent(p <- plot_data_heatmap(test_mofa2, view = 1, factor = 1, silent = TRUE)) }) test_that("plot data scatter", { expect_silent(p <- plot_data_scatter(test_mofa2, view = 1, factor = 1)) }) test_that("plot data ASCII in terminal", { expect_error(plot_ascii_data(test_mofa2), NA) }) test_that("plot weights heatmap", { expect_silent(p <- plot_weights_heatmap(test_mofa2, view = 1, silent = TRUE)) }) test_that("plot weights", { expect_silent(p <- plot_weights(test_mofa2, view = 1, factors = 1:2)) expect_silent(p <- plot_weights(test_mofa2, factors = 1)) }) test_that("plot top weights", { expect_silent(p <- plot_top_weights(test_mofa2, view = 1, factors = 1)) }) test_that("plot factor values", { expect_silent(p <- plot_factor(test_mofa2)) }) test_that("plot factor values", { expect_silent(p <- plot_factors(test_mofa2, factors = 1:2)) }) test_that("plot factors correlation", { expect_error({plot_factor_cor(test_mofa2); dev.off()}, NA) })
model_parameters.selection <- function(model, ci = .95, component = c("all", "selection", "outcome", "auxiliary"), bootstrap = FALSE, iterations = 1000, standardize = NULL, exponentiate = FALSE, p_adjust = NULL, verbose = TRUE, ...) { component <- match.arg(component) out <- .model_parameters_generic( model = model, ci = ci, bootstrap = bootstrap, iterations = iterations, component = component, merge_by = c("Parameter", "Component"), standardize = standardize, exponentiate = exponentiate, p_adjust = p_adjust, ... ) attr(out, "object_name") <- deparse(substitute(model), width.cutoff = 500) out } p_value.selection <- function(model, component = c("all", "selection", "outcome", "auxiliary"), ...) { component <- match.arg(component) s <- summary(model) rn <- row.names(s$estimate) estimates <- as.data.frame(s$estimate, row.names = FALSE) params <- data.frame( Parameter = rn, p = estimates[[4]], Component = "auxiliary", stringsAsFactors = FALSE, row.names = NULL ) params$Component[s$param$index$betaS] <- "selection" params$Component[s$param$index$betaO] <- "outcome" if (component != "all") { params <- params[params$Component == component, , drop = FALSE] } insight::text_remove_backticks(params, verbose = FALSE) } standard_error.selection <- function(model, component = c("all", "selection", "outcome", "auxiliary"), ...) { component <- match.arg(component) s <- summary(model) rn <- row.names(s$estimate) estimates <- as.data.frame(s$estimate, row.names = FALSE) params <- data.frame( Parameter = rn, SE = estimates[[2]], Component = "auxiliary", stringsAsFactors = FALSE, row.names = NULL ) params$Component[s$param$index$betaS] <- "selection" params$Component[s$param$index$betaO] <- "outcome" if (component != "all") { params <- params[params$Component == component, , drop = FALSE] } insight::text_remove_backticks(params, verbose = FALSE) } simulate_model.selection <- function(model, iterations = 1000, component = c("all", "selection", "outcome", "auxiliary"), ...) { component <- match.arg(component) out <- .simulate_model(model, iterations, component = component, effects = "fixed") class(out) <- c("parameters_simulate_model", class(out)) attr(out, "object_name") <- .safe_deparse(substitute(model)) out } ci.selection <- ci.default degrees_of_freedom.selection <- function(model, ...) { s <- summary(model) s$param$df }
plot.interv_multiple <- function(x, ...){ timser <- x$fit_H0$ts intervention <- x$interventions plot(timser, type="n", main="Time series with detected interventions", xlab="Time", ylab="Value", ...) if(nrow(intervention)==0){ lines(timser) legend("topleft", legend="No interventions detected ", bg="white") }else{ lines(x=time(timser)[seq(along=timser)], y=x$ts_cleaned[[nrow(intervention)]], lty="dashed", col="blue") abline(v=time(timser)[intervention[, "tau"]], col="red") lines(timser) legend("topleft", legend=paste("Intervention ", rownames(intervention), ": tau=", intervention[,"tau"], ", delta=", intervention[,"delta"], ", size=", round(intervention[,"size"],2), " ", sep=""), bg="white") } }
x2weight.covMcd <- function(xMat) { if(dim(xMat)[2]==3) { tmc = qchisq(0.95, ncol(xMat[,-1])) cov1 = cov.rob(xMat[,-1], method="mcd") dist = mahalanobis(xMat[,-1], cov1$center, cov1$cov) return(ifelse(dist<tmc, 1, tmc/dist)) } else { tmc1 = qchisq(0.95, 2) tmc2 = qchisq(0.95, ncol(xMat[,-1]) - 2) imrnr = dim(xMat)[2] part1 = c(1 + which(abs(cor(xMat[,imrnr], xMat[,-c(1,imrnr)])) == min(abs(cor(xMat[,imrnr], xMat[,-c(1,imrnr)])))), imrnr) part2 = c(-1, -part1) cov1 = cov.rob(xMat[, part1], method="mcd") dist = mahalanobis(xMat[, part1], cov1$center, cov1$cov) weight1 = ifelse(dist < tmc1, 1, tmc1 / dist) cov2 = cov.rob(xMat[, part2], method="mcd") dist = mahalanobis(as.matrix(xMat[, part2]), cov2$center, cov2$cov) weight2 = ifelse(dist < tmc2, 1, tmc2 / dist) xwght = weight1 * weight2 return(xwght) } }
ibeta = function(x,a,b){ stats::pbeta(x,a,b)*beta(a,b) } G = function(r, v, q){ p=v/(v+q^2) res = ifelse(q>0 | (r %% 2 != 0), ibeta(p,0.5*(v-r),0.5*(r+1)), 2*beta(0.5*(v-r),0.5*(r+1)) - ibeta(p,0.5*(v-r),0.5*(r+1))) return(res) } e_trunct_onesided = function(q,v,r){ v^(0.5*r) * G(r,v,q)/G(0,v,q) } e_trunct = function(a,b,df,r){ mult=ifelse(a>0 & b>0,-1,1) aa = ifelse(a>0 & b>0, -b, a) bb = ifelse(a>0 & b>0, -a, b) mult^r * ifelse(aa==bb,aa^r, (stats::pt(aa,df,lower.tail=FALSE)*e_trunct_onesided(aa,df,r) - stats::pt(bb,df,lower.tail=FALSE)*e_trunct_onesided(bb,df,r))/(stats::pt(bb,df)-stats::pt(aa,df))) }
list_projects <- function() { .Deprecated("bq_projects", package = "bigrquery") bq_projects() }
testthat::context(desc="Test getLogBoxsize() function") testthat::test_that(desc="Test, if getLogBoxsize throws errors/warnings on wrong arguments", { testthat::expect_error(object=getLogBoxsize()) testthat::expect_error(object=getLogBoxsize("aaa")) testthat::expect_error(getLogBoxsize(list(1,2))) testthat::expect_warning(getLogBoxsize(0)) testthat::expect_warning(getLogBoxsize(c(1,2,-3))) testthat::expect_warning(getLogBoxsize(c(1,2,3))) }) testthat::test_that(desc="Test, if getLogBoxsize returns results of same length as input", { testthat::expect_equivalent(object=length(getLogBoxsize(2)),expected=1) length <- 1+rpois(1,10) input <- rpois(length,30) testthat::expect_equivalent(object=length(getLogBoxsize(input)),expected=length) }) testthat::test_that(desc="Test, if getLogBoxsize returns appropriate results", { testthat::expect_equivalent(object=getLogBoxsize(1),expected=0.009950331) })
if (gargle:::secret_can_decrypt("bigrquery")) { json <- gargle:::secret_read("bigrquery", "bigrquery-testing.json") bq_auth(path = rawToChar(json)) }
"skewt.axis" <- function(BROWN = "brown", GREEN = "green", redo = FALSE, ...) { tmr <- function(w, p) { c1 <- 0.049864645499999999 c2 <- 2.4082965000000001 c3 <- 7.0747499999999999 c4 <- 38.9114 c5 <- 0.091499999999999998 c6 <- 1.2035 x <- log10((w * p)/(622. + w)) tmrk <- 10^(c1 * x + c2) - c3 + c4 * ((10.^(c5 * x) - c6)^ 2.) tmrk - 273.14999999999998 } tda <- function(o, p) { ok <- o + 273.14999999999998 tdak <- ok * ((p * 0.001)^0.28599999999999998) tdak - 273.14999999999998 } par(pty = "s", ... ) ymax <- skewty(1050) ymin <- skewty(100) xmin <- skewtx(-33, skewty(1050)) xmax <- skewtx(50, skewty(1000)) kinkx <- skewtx(5, skewty(400)) xc <- c(xmin, xmin, xmax, xmax, kinkx, kinkx, xmin) yc <- c(ymin, ymax, ymax, skewty(625), skewty(400), ymin, ymin) plot(xc, yc, type = "l", axes = FALSE, xlab = "", ylab = "", lwd = 0.10000000000000001) ypos <- skewty(1050) degc <- ((seq(-20, 100, by = 20) - 32) * 5)/9 axis(1, at = skewtx(degc, ypos), labels = seq(-20, 100, by = 20), pos = ymax) mtext(side = 1, line = 1, "Temperature (F)") pres <- c(1050, 1000, 850, 700, 500, 400, 300, 250, 200, 150, 100) NPRES <- length(pres) xpl <- rep(xmin, times = NPRES) xpr <- c(xmax, xmax, xmax, xmax, skewtx(20, skewty(500)), kinkx, kinkx, kinkx, kinkx, kinkx, kinkx) y <- skewty(pres) segments(xpl, y, xpr, y, col = BROWN, lwd = 0.10000000000000001, lty = 2) ypos <- skewty(pres[2:NPRES]) axis(2, at = ypos, labels = pres[2:NPRES], pos = xmin) mtext(side = 2, line = 1.5, "P (hPa)") temp <- seq(from = -100, to = 50, by = 10) NTEMP <- length(temp) lendt <- rep(1050, NTEMP) inds <- seq(1, length(temp))[temp < -30] exponent <- (132.18199999999999 - (xmin - 0.54000000000000004 * temp[ inds])/0.90691999999999995)/44.061 lendt[inds] <- 10^exponent rendt <- rep(100, NTEMP) inds <- seq(1, length(temp))[(temp >= -30) & (temp <= 0)] exponent <- (132.18199999999999 - (kinkx - 0.54000000000000004 * temp[ inds])/0.90691999999999995)/44.061 rendt[inds] <- 10^exponent inds <- seq(1, length(temp))[temp > 30] exponent <- (132.18199999999999 - (xmax - 0.54000000000000004 * temp[ inds])/0.90691999999999995)/44.061 rendt[inds] <- 10^exponent rendt[temp == 10] <- 430 rendt[temp == 20] <- 500 rendt[temp == 30] <- 580 yr <- skewty(rendt) xr <- skewtx(temp, yr) yl <- skewty(lendt) xl <- skewtx(temp, yl) segments(xl, yl, xr, yr, col = BROWN, lwd = 0.10000000000000001) text(xr[8:NTEMP], yr[8:NTEMP], labels = paste(" ", as.character(temp[ 8:NTEMP])), srt = 45, adj = 0, col = BROWN) mixrat <- c(20, 12, 8, 5, 3, 2, 1) NMIX <- length(mixrat) yr <- skewty(440.) tmix <- tmr(mixrat[1], 440.) xr <- skewtx(tmix, yr) yl <- skewty(1000.) tmix <- tmr(mixrat[1], 1000.) xl <- skewtx(tmix, yl) segments(xl, yl, xr, yr, lty = 2, col = GREEN, lwd = 0.10000000000000001) yl <- skewty(1025.) xl <- skewtx(tmix, yl) text(xl, yl, labels = as.character(mixrat[1]), col = GREEN, srt = 55, adj = 0.5, cex = 0.75) yr <- skewty(rep(400., NMIX - 1)) tmix <- tmr(mixrat[2:NMIX], 400.) xr <- skewtx(tmix, yr) yl <- skewty(rep(1000., NMIX - 1)) tmix <- tmr(mixrat[2:NMIX], 1000.) xl <- skewtx(tmix, yl) segments(xl, yl, xr, yr, lty = 2, col = GREEN, lwd = 0.10000000000000001) yl <- skewty(rep(1025., NMIX - 1)) xl <- skewtx(tmix, yl) text(xl, yl, labels = as.character(mixrat[2:NMIX]), col = GREEN, srt = 55, adj = 0.5, cex = 0.75) theta <- seq(from = -30, to = 170, by = 10) NTHETA <- length(theta) lendth <- rep(100, times = NTHETA) lendth[1:8] <- c(880, 670, 512, 388, 292, 220, 163, 119) rendth <- rep(1050, times = NTHETA) rendth[9:NTHETA] <- c(1003, 852, 728, 618, 395, 334, 286, 245, 210, 180, 155, 133, 115) for(itheta in 1:NTHETA) { p <- seq(from = lendth[itheta], to = rendth[itheta], length = 200) sy <- skewty(p) dry <- tda(theta[itheta], p) sx <- skewtx(dry, sy) lines(sx, sy, lty = 1, col = BROWN) } p <- seq(from = 1050, to = 240, by = -10) npts <- length(p) sy <- skewty(p) sx <- double(length = npts) if(redo) { pseudo <- c(32, 28, 24, 20, 16, 12, 8) NPSEUDO <- length(pseudo) holdx <- matrix(0, nrow = npts, ncol = NPSEUDO) holdy <- matrix(0, nrow = npts, ncol = NPSEUDO) for(ipseudo in 1:NPSEUDO) { for(ilen in 1:npts) { moist <- satlft(pseudo[ipseudo], p[ilen]) sx[ilen] <- skewtx(moist, sy[ilen]) } inds <- (sx < xmin) sx[inds] <- NA sy[inds] <- NA holdx[, ipseudo] <- sx holdy[, ipseudo] <- sy } } else { holdx <- skewt.data$pseudox holdy <- skewt.data$pseudoy pseudo <- skewt.data$pseudo NPSEUDO <- skewt.data$NPSEUDO } for(ipseudo in 1:NPSEUDO) { sx <- holdx[, ipseudo] sy <- holdy[, ipseudo] lines(sx, sy, lty = 1, col = GREEN) moist <- satlft(pseudo[ipseudo], 230) labely <- skewty(230) labelx <- skewtx(moist, labely) if (labelx > xmin) text(labelx, labely, labels = as.character(pseudo[ipseudo]), col = GREEN, adj = 0.5, cex = 0.75) moist <- satlft(pseudo[ipseudo], 1100) labely <- skewty(1100) labelx <- skewtx(moist, labely) text(labelx, labely, labels = as.character(pseudo[ipseudo]), col = GREEN, adj = 0.5, cex = 0.75) } invisible(list(pseudox=holdx, pseudoy=holdy, pseudo=pseudo, NPSEUDO=NPSEUDO, plt=par()$plt)) }
.pickands.fun.uni<-function(t, rho=0.5, alpha=c(1,1)) { if(t==0 && t==1){return(1)} a <- lgamma(alpha-rho)-lgamma(alpha) kappa <- exp((log(1-t)+a[2])/rho - log(exp((log(1-t)+a[2])/rho)+exp((log(t)+a[1])/rho))) exp(log(1-t)+ pbeta(kappa, alpha[1]-rho, alpha[2],log.p=TRUE))+ exp(log(t)+ pbeta(1-kappa, alpha[2]-rho,alpha[1],log.p=TRUE)) } .pickands.fun<-Vectorize(.pickands.fun.uni, vectorize.args=c("t")) .pickands.dir.uni<-function(t,alpha,rho){ if(t==0 && t==1){return(1)} k1=lbeta(alpha[1]+rho,alpha[2]) k2=lbeta(alpha[1],alpha[2]+rho) kappa<-exp((1/rho)*(log(1-t)+k1)-log(exp((1/rho)*(log(t)+k2))+exp((1/rho)*(k1+log(1-t))))) exp(log(1-t)+ pbeta(kappa, alpha[1], alpha[2]+rho,log.p=T))+ exp(log(t)+ pbeta(1-kappa, alpha[2],alpha[1]+rho,log.p=T)) } .pickands.dir<-Vectorize(.pickands.dir.uni, "t") pickands.liouv<-function(t, rho=0.5, alpha=c(1,1),CDA=c("C","S")){ if(missing(CDA)==TRUE){ CDA="C" warning("Setting default to Liouville CDA. Use CDA=`S` for the Dirichlet model") } if(any(t<0) || any(t>1)){ stop("t must be a vector whose elements are between 0 and 1") } if(any(rho<=0)){ stop("rho must be positive") } if(length(rho)>1){ stop("Argument `rho' must be of length 1") } if(CDA=="C" && any(c(rho >= min(alpha), rho <= 0))){ stop("`rho must be between (0,min(alpha))") } if(any(alpha<=0)){ stop("alpha must be positive") } if(length(alpha)!=2){ stop("Not implemented except in the bivariate case") } if(CDA=="C"){ return(.pickands.fun(t,rho=rho,alpha=alpha)) } else if(CDA=="S"){ return(.pickands.dir(t,rho=rho,alpha=alpha)) } else{ return(NA) } } pickands.plot<-function(rho, alpha, plot.new=T,CDA=c("C","S"), tikz=F, ...){ if(missing(CDA)==TRUE){ CDA="C" warning("Setting default to Liouville CDA. Use CDA=`S` for the Dirichlet model") } if(length(rho)!=1){stop("rho must be 1-dimensional")} if(length(alpha)!=2){ stop("Not implemented beyond bivariate case") } if(plot.new==TRUE){ plot.new() plot.window(c(0,1), c(0.5,1)) axis(side=2, at=seq(0.5,1,by=0.1), pos=0,las=2,tck=0.01) axis(side=1, at=seq(0,1,by=0.1), pos=0.5,las=0,tck=0.01) lines(c(0,0.5),c(1,0.5),lty=3,col="gray") lines(c(0.5,1),c(0.5,1),lty=3,col="gray") lines(c(0,1),c(1,1),lty=3,col="gray") if(tikz==TRUE){ mtext("$t$", side=1, line=2) mtext("$\\mathrm{A}(t)$", side=2, line=2) } else{ mtext(expression(t), side=1, line=2) mtext(expression(A(t)), side=2, line=2) } } x = seq(0,1,by=0.001) if(CDA=="C"){ lines(x=x,y=c(1,.pickands.fun(x[-c(1,length(x))],alpha=alpha, rho=rho),1),type="l",...) } if(CDA=="S"){ lines(x=x,y=.pickands.dir(x,alpha=alpha,rho=rho),type="l",...) } } K.plot <- function(data, add=F, ...){ if(is.null(dim(data)) || ncol(data)<2){ stop("Invalid input matrix") } H <- function(data){ n <- dim(data)[1] d <- dim(data)[2] out <- rep(NA,n) tmp <- paste("(data[,",1:d,"] <= data[i,",1:d,"])") cmnd <- parse(text=paste(tmp,collapse=" & ")) for (i in 1:n){ subb <- sum(eval(cmnd))-1 out[i] <- subb/(n-1) } out } W <- function(n, d){ fun <- function(w,i,d){ K0 <- w+w*rowSums(sapply(1:(d-1), function(k){ exp(k*log(-log(w))-lgamma(k+1)) })) dK0 <- exp((d-1)*log(-log(w))-lgamma(d)) exp(log(w)+log(dK0)+(i-1)*log(K0)+(n-i)*log(1-K0)) } sapply(1:n, function(i){ n*choose(n-1,i-1)*integrate(fun,lower=0,upper=1,i=i,d=d,subdivisions=10000, rel.tol=.Machine$double.eps^0.001)$value }) } n <- nrow(data) d <- ncol(data) W <- W(n, d) Hs <- sort(H(data)) seq <- seq(from=0.01,to=1,by=0.01) if(n < 200) { if(add==F){ plot(W,Hs,xlim=c(0,1),ylim=c(0,1),xlab="Independence",ylab="Data",pch=4,cex=0.8) lines(c(0,1),c(0,1),lty=2) K0 <- seq-seq*log(seq) lines(c(0,seq),c(0,K0),lty=2) lines(c(1,0),c(0,0),lty=2) } else{ points(W,Hs,xlim=c(0,1),ylim=c(0,1),pch=4,cex=0.8, ...) } } else { ind <- matrix(runif(n*d),nrow=n,ncol=d) Wind <- sort(H(ind)) if(add==F){ plot(Wind,Hs,xlim=c(0,1),ylim=c(0,1),xlab="Independence",ylab="Data",pch=4,cex=0.5) lines(c(0,1),c(0,1),lty=2) K0 <- seq-seq*log(seq) lines(c(0,seq),c(0,K0),lty=2) lines(c(1,0),c(0,0),lty=2) } else{ points(Wind, Hs,xlim=c(0,1),ylim=c(0,1),pch=4,cex=0.5, ...) } } } hmvevdliouv <- function(w, alpha, rho, CDA=c("C","S"), logdensity=FALSE){ if(any(w<0) || any(w>1)){ stop("w must contain elements between 0 and 1") } w <- as.matrix(w) if(ncol(w)!=length(alpha)){ w <- cbind(w, 1-rowSums(w)) } else{ if(rowSums(w)!=rep(1, nrow(w))){ stop("Components must sum to 1") } } if(length(rho)>1){ rho <- rho[1] warning("Using only first coordinate of rho") } if(rho<=0){ CDA <- "C" rho <- -rho } if(CDA=="C" && rho> min(alpha)){ stop("`abs(rho)` must be smaller than `min(alpha)`") } if(any(alpha<=0)){ stop("alpha must be positive") } if(missing(CDA)){ warning("Invalid input for argument `CDA`. Defaulting to `C`, the `negdir` family") CDA = "C" } if(!(CDA %in% c("C","S"))){ stop("Invalid input for argument `CDA`") } h <- apply(w, 1, function(wrow){ switch(CDA, C=negdirspecdens(dat=t(as.matrix(wrow)), param=c(alpha, rho), d=length(alpha), transform=FALSE), S=dirspecdens(dat=t(as.matrix(wrow)),param=c(alpha, rho), d=length(alpha), transform=FALSE) )}) if(logdensity){ return(h) } else{ return(exp(h)) } }
traitglm = function( L, R, Q=NULL, family="negative.binomial", formula = NULL, method="manyglm", composition=FALSE, col.intercepts = TRUE, ... ) { L = as.data.frame(L) allargs <- match.call(expand.dots = FALSE) dots <- allargs$... if( "best" %in% names(dots) ) best <- dots$best else best = "1se" if( "plot" %in% names(dots) ) plot <- dots$plot else plot=TRUE if( "prop.test" %in% names(dots) ) prop.test <- dots$prop.test else prop.test = 0.2 if( "n.split" %in% names(dots) ) n.split <- dots$n.split else n.split=10 if( "seed" %in% names(dots) ) seed <- dots$seed else seed=NULL if( "show.progress" %in% names(dots) ) show.progress <- dots$show.progress else show.progress = FALSE if( "get.fourth" %in% names(dots) ) get.fourth <- dots$get.fourth else get.fourth = TRUE deactive <- c("best", "plot", "prop.test", "n.split", "seed", "show.progress", "get.fourth") deactivate <- (1:length(dots))[names(dots) %in% deactive ] for (i in length(deactivate):1) dots[ deactivate[i] ]<-NULL dots <- lapply( dots, eval, parent.frame() ) n.sites = dim(L)[1] n.spp = dim(L)[2] if(is.null(formula)) R.des = get_polys(R) else R.des = list(X=R) if(is.null(Q)) { cat(paste("No traits matrix entered, so will fit SDMs with different env response for each spp","\n")) Q.des = list(X=data.frame(as.factor(names(L))),X.squ=NULL,var.type="factor") } else { if(is.null(formula)) Q.des = get_polys(Q) else Q.des = list(X=Q) } any.penalty = method=="cv.glm1path" || method=="glm1path" marg.penalty = TRUE X.des = get_design( R.des, Q.des, names(L), formula=formula, marg.penalty=marg.penalty, composition = composition, col.intercepts = col.intercepts, any.penalty=any.penalty, get.fourth=get.fourth ) X = X.des$X l <- as.vector(as.matrix(L)) if( method=="cv.glm1path" || method=="glm1path" ) { if( "block" %in% names(dots) ) blockID <- dots$block else blockID = 1:n.sites block = factor(rep(blockID,n.spp)) ft = do.call(glm1path,c(list(y=l, X=X, family=family, penalty = X.des$penalty), k=log(n.sites), dots)) if( method=="cv.glm1path" ) ft = do.call(cv.glm1path,c(list(object=ft, block=block, best=best, plot=plot, prop.test=prop.test, n.split=n.split, seed=seed, show.progress=show.progress), dots)) id.use = which(ft$lambdas==ft$lambda) ft$deviance = -2*ft$logL[id.use] ft$phi = ft$glm1$phi if(ft$df[1]==1) null.deviance = ft$logL[1] } else ft = do.call( method, c(list(formula=l~., family=family, data=data.frame(X)), dots) ) ft$fourth.corner = matrix( coef(ft)[X.des$is.4th.corner], length(X.des$names.Q), length(X.des$names.R) ) ft$fourth.corner = provideDimnames(ft$fourth,base=list(X.des$names.Q,X.des$names.R)) ft$R.des = R.des ft$Q.des = Q.des ft$any.penalty = any.penalty ft$L = L ft$scaling = X.des$scaling ft$call=match.call() if(is.null(formula)==FALSE & get.fourth==FALSE) ft$formula = X.des$formula else ft$formula = formula class(ft)=c("traitglm",class(ft)) return( ft ) } get_design = function( R.des, Q.des, L.names, formula = formula, marg.penalty=TRUE, composition = FALSE, col.intercepts = TRUE, any.penalty=TRUE, scaling=NULL, get.fourth=TRUE ) { n.sites = dim(R.des$X)[1] n.spp = length(L.names) is.scaling.given = is.null(scaling)==F if(col.intercepts==TRUE) { spp = rep(L.names,each=n.sites) spp = as.factor(spp) mod = as.formula("~spp-1") X.spp = model.matrix(mod) if(marg.penalty==FALSE || any.penalty==FALSE) X.spp = X.spp[,-1] X.spp[X.spp==0] = -1 if(is.scaling.given==F) { scaling = list() X.spp = scale(X.spp) scaling$spp$center = attr(X.spp,"scaled:center") scaling$spp$scale = attr(X.spp,"scaled:scale") } if(is.scaling.given) X.spp = scale(X.spp,center=scaling$spp$center, scale=scaling$spp$scale) X.spp = cbind(1,X.spp) } else { X.spp = as.matrix( rep(1,n.sites*n.spp) ) if(is.scaling.given==F) scaling = list() } if(composition==TRUE) { site = rep(dimnames(R.des$X)[[1]],n.spp) site = as.factor(site) mod = as.formula("~site-1") X.site = model.matrix(mod) if(marg.penalty==FALSE || any.penalty==FALSE) X.site = X.site[,-1] X.site[X.site==0] = -1 if(is.scaling.given==F) { X.site = scale(X.site) scaling$site$center = attr(X.site,"scaled:center") scaling$site$scale = attr(X.site,"scaled:scale") } if(is.scaling.given) X.site = scale(X.site,center=scaling$site$center, scale=scaling$site$scale) } else X.site = X.spp[,0] if(is.null(formula)) { X.R = X.spp[,0] if( is.null(R.des$X.squ) ) { R.small = R.des$X var.type= R.des$var.type is.lin.small = rep( TRUE,NCOL(R.des$X) ) } else { R.small = cbind( R.des$X, R.des$X.squ ) var.type= c( R.des$var.type, rep("quantitative",dim(R.des$X.squ)[2]) ) is.lin.small = c( rep( TRUE,NCOL(R.des$X) ), rep( FALSE, NCOL(R.des$X.squ) ) ) } names.R = c() is.lin.R= c() for( iR in 1:NCOL(R.small) ) { R.i = rep( R.small[,iR], times=n.spp ) mod = as.formula("~0+R.i") mm = model.matrix(mod) names.i = dimnames(R.small)[[2]][iR] if(var.type[iR]=="factor") { if(any.penalty==TRUE) names.i = paste(dimnames(R.small)[[2]][iR], levels(R.small[,iR]),sep="") else { mm = mm[,-1] names.i = paste(dimnames(R.small)[[2]][iR], dimnames(contrasts(R.small[,iR]))[[2]],sep="") } } names.R = c( names.R, names.i ) is.lin.R= c( is.lin.R, rep( is.lin.small[iR] , dim(mm)[2] ) ) X.R = cbind( X.R, mm ) } dimnames(X.R)[[2]]=names.R if(is.scaling.given==F) { X.R = scale(X.R) scaling$R$center = attr(X.R,"scaled:center") scaling$R$scale = attr(X.R,"scaled:scale") } if(is.scaling.given) X.R = scale(X.R,center=scaling$R$center, scale=scaling$R$scale) X.Q = X.spp[,0] if( is.null(Q.des$X.squ) ) { Q.small = Q.des$X var.type= Q.des$var.type is.lin.small = rep( TRUE,NCOL(Q.des$X) ) } else { Q.small = cbind( Q.des$X, Q.des$X.squ ) var.type= c( Q.des$var.type, rep("quantitative",dim(Q.des$X.squ)[2]) ) is.lin.small = c( rep( TRUE,NCOL(Q.des$X) ), rep( FALSE, NCOL(Q.des$X.squ) ) ) } names.Q = c() is.lin.Q= c() for( iQ in 1:NCOL(Q.small) ) { Q.i = rep( Q.small[,iQ], each=n.sites ) mod = as.formula("~0+Q.i") mm = model.matrix(mod) names.i = dimnames(Q.small)[[2]][iQ] if(var.type[iQ]=="factor") { if(any.penalty==TRUE) names.i = paste(dimnames(Q.small)[[2]][iQ], levels(Q.small[,iQ]),sep="") else { mm = mm[,-1] names.i = paste(dimnames(Q.small)[[2]][iQ], dimnames(contrasts(Q.small[,iQ]))[[2]],sep="") } } names.Q = c( names.Q, names.i ) is.lin.Q= c( is.lin.Q, rep( is.lin.small[iQ] , dim(mm)[2] ) ) X.Q = cbind( X.Q, mm ) } dimnames(X.Q)[[2]]=names.Q if(is.scaling.given==F) { X.Q = scale(X.Q) scaling$Q$center = attr(X.Q,"scaled:center") scaling$Q$scale = attr(X.Q,"scaled:scale") } if(is.scaling.given) X.Q = scale(X.Q, center=scaling$Q$center, scale=scaling$Q$scale) if(get.fourth==TRUE) { X.RQ = X.spp[,0] n.R = sum(is.lin.R) n.Q = sum(is.lin.Q) ref.R = rep(1:n.R,each=n.Q) ref.Q = rep(1:n.Q,n.R) X.RQ = as.matrix( X.R[,ref.R] * X.Q[,ref.Q] ) dimnames(X.RQ)[[2]] = paste(dimnames(X.R)[[2]][ref.R], dimnames(X.Q)[[2]][ref.Q], sep=":") if(is.scaling.given==F) { X.RQ = scale(X.RQ) scaling$RQ$center = attr(X.RQ,"scaled:center") scaling$RQ$scale = attr(X.RQ,"scaled:scale") } if(is.scaling.given) X.RQ = scale(X.RQ,center=scaling$RQ$center, scale=scaling$RQ$scale) } else X.RQ=X.R[,0] if(any.penalty) { if(composition==TRUE) X = cbind(X.spp,X.site,X.R,X.Q,X.RQ) else X = cbind(X.spp,X.R,X.Q,X.RQ) } else { if(composition==TRUE) X = cbind(X.spp,X.site,X.RQ) else X = cbind(X.spp,X.R,X.RQ) } n.X = dim(X)[2] if(get.fourth==TRUE) is.4th.corner = c( rep(F,n.X-n.R*n.Q), rep(T,n.R*n.Q) ) else is.4th.corner = rep(F,n.X) names.R = dimnames(X.R)[[2]][is.lin.R] names.Q = dimnames(X.Q)[[2]][is.lin.Q] } else { rowReps = rep(1:n.sites, times=n.spp) R.i = data.frame(R.des$X[rowReps,]) names(R.i) = names(R.des$X) colReps = rep(1:n.spp, each=n.sites) Q.i = data.frame(Q.des$X[colReps,]) names(Q.i) = names(Q.des$X) X = model.matrix(formula,cbind(R.i,Q.i)) tt = terms(formula) facts = attr(tt,"factors") which.env = charmatch(names(R.des$X),dimnames(facts)[[1]]) which.env = which.env[is.na(which.env)==FALSE] which.trait = charmatch(names(Q.des$X),dimnames(facts)[[1]]) which.trait = which.trait[is.na(which.trait)==FALSE] if(length(which.env)==1) is.env = facts[which.env,]>0 else { if(length(which.env)==0) is.env = logical(0) else is.env = apply(facts[which.env,],2,sum)>0 } if(length(which.trait)==1) is.trait = facts[which.trait,]>0 else { if(length(which.trait)==0) is.trait = logical(0) else is.trait = apply(facts[which.trait,],2,sum)>0 } is.4th.term = is.env & is.trait if(get.fourth==TRUE) is.4th.corner = is.4th.term[attr(X,"assign")] else is.4th.corner = rep( FALSE, length(attr(X,"assign")) ) if(attr(tt,"intercept")==1) { names.Q = dimnames(X)[[2]][c(FALSE,is.4th.corner)] X = as.matrix(X[,-1]) } else names.Q = dimnames(X)[[2]][is.4th.corner] names.R = "coef" if(get.fourth==FALSE) { X = as.matrix(X[,-which(is.4th.term==TRUE)]) is.4th.corner = c() if(sum(is.4th.term==FALSE)>0) { formula = paste0(dimnames(facts)[[2]][is.4th.term==FALSE],collapse="+") formula = as.formula(paste0("~",formula)) } else formula=as.formula("~1") } X = cbind(X.spp,X.site,X) is.4th.corner = c(rep(FALSE, dim(X.spp)[2]+dim(X.site)[2]), is.4th.corner) } if(any.penalty) { penalty = c( 0, rep(1,dim(X)[2]-1) ) if (col.intercepts==TRUE & marg.penalty==FALSE) penalty = c( rep( 0,dim(X.spp)[2]+dim(X.site)[2] ), rep( 1, dim(X)[2]-dim(X.spp)[2]-dim(X.site)[2] ) ) } else penalty = NULL return(list(X=X, is.4th.corner=is.4th.corner, names.R=names.R, names.Q=names.Q, penalty=penalty, any.penalty=any.penalty, scaling=scaling, formula=formula) ) }
library(dplyr) library(httr) test_that("okresy", { skip_on_cran() Sys.setenv("NETWORK_UP" = FALSE) expect_message(okresy(), "internet") Sys.setenv("NETWORK_UP" = TRUE) Sys.setenv("AWS_UP" = FALSE) expect_message(okresy(), "source") Sys.setenv("AWS_UP" = TRUE) expect_true(is.data.frame(okresy())) expect_true(is.data.frame(okresy("low"))) expect_true(is.data.frame(okresy("high"))) expect_s3_class(okresy(), "sf") expect_s3_class(okresy("high"), "sf") expect_s3_class(okresy("low"), "sf") expect_equal(nrow(okresy()), 77) expect_equal(nrow(okresy("low")), 77) expect_equal(nrow(okresy("high")), 77) expect_equal(st_crs(okresy("low"))$input, "EPSG:4326") expect_equal(st_crs(okresy("high"))$input, "EPSG:4326") expect_true(all(st_is_valid(okresy("high")))) expect_true(all(st_is_valid(okresy("low")))) expect_equal(colnames(okresy()), c("KOD_OKRES", "KOD_LAU1", "NAZ_LAU1", "KOD_KRAJ", "KOD_CZNUTS3", "NAZ_CZNUTS3", "geometry")) expect_equal(colnames(okresy("low")), colnames(okresy("high"))) expect_error(okresy("bflm")) expect_true(object.size(okresy("low")) < object.size(okresy("high"))) })
ggplot_na_intervals <- function(x, number_intervals = NULL, interval_size = NULL, measure = "percent", color_missing = "indianred2", color_existing = "steelblue", alpha_missing = 0.8, alpha_existing = 0.3, title = "Missing Values per Interval", subtitle = "Amount of NA and non-NA for successive intervals", xlab = "Time Lapse (Interval Size: XX)", ylab = NULL, color_border = "white", theme = ggplot2::theme_linedraw()) { data <- x if (any(class(data) == "tbl_ts")) { data <- as.vector(as.data.frame(data)[, 2]) } else if (any(class(data) == "tbl")) { data <- as.vector(as.data.frame(data)[, 1]) } if (!is.null(dim(data)[2]) && dim(data)[2] > 1) { stop("x is not univariate. The function only works with univariate input for x. For data types with multiple variables/columns only input the column you want to plot as parameter x.") } if (!is.null(dim(data)[2])) { data <- data[, 1] } data <- as.vector(data) if (!is.numeric(data)) { stop("Input x is not numeric") } missindx <- is.na(data) if (all(missindx)) { stop("Input data consists only of NAs. At least one non-NA numeric value is needed for creating a meaningful ggplot_na_distribution plot)") } if (is.null(number_intervals)) { number_intervals <- grDevices::nclass.Sturges(data) } if (!is.null(interval_size)) { breaks <- seq(from = 0, to = length(data) - 1, by = interval_size) breaks <- c(breaks, length(data)) } else { breaks <- seq(from = 0, to = length(data) - 1, by = floor(length(data) / number_intervals)) breaks <- c(breaks, length(data)) } binwidth <- breaks[2] color_missing <- ggplot2::alpha(color_missing, alpha_missing) color_existing <- ggplot2::alpha(color_existing, alpha_existing) if ( (!is.null(subtitle)) && (subtitle == "Amount of NA and non-NA for successive intervals")) { subtitle <- paste0("Amount of <b style='color:", color_missing, ";' >NA</b> and <b style='color:", color_existing, "' >non-NA</b> for successive intervals") } if (is.null(ylab)) { ifelse(measure == "percent", ylab <- "Percent", ylab <- "Count") } if (xlab == "Time Lapse (Interval Size: XX)") { xlab <- paste("Time Lapse (Interval Size:", binwidth, ")") } index <- seq_along(data) miss <- as.factor(is.na(data)) df <- data.frame(index, miss) gg <- ggplot2::ggplot(df, ggplot2::aes(index, fill = miss)) + ggplot2::scale_fill_manual( values = c(color_existing, color_missing), labels = c("NAs", "non-NAs") ) + theme + ggplot2::theme( legend.position = "none", legend.title = ggplot2::element_blank(), plot.subtitle = ggtext::element_markdown(), panel.grid.major = ggplot2::element_blank(), panel.grid.minor.x = ggplot2::element_blank(), ) + ggplot2::scale_x_continuous(expand = c(0, 0)) + ggplot2::labs(title = title, subtitle = subtitle) + ggplot2::xlab(xlab) + ggplot2::ylab(ylab) count <- NULL if (measure == "percent") { gg <- gg + ggplot2::stat_bin(ggplot2::aes(y = ggplot2::after_stat(count / binwidth)), col = color_border, breaks = breaks, closed = "right" ) + ggplot2::scale_y_continuous(expand = c(0, 0), labels = function(x) paste0(x*100, "%")) } else { gg <- gg + ggplot2::stat_bin(ggplot2::aes(y = ggplot2::after_stat(count)), col = color_border, breaks = breaks, closed = "right" ) + ggplot2::scale_y_continuous(expand = c(0, 0)) } return(gg) }
cluster_freedman_lane <- function(args){ switch(args$test, "fisher"= {funT = function(qr_rdx, qr_mm, prdy){ colSums(qr.fitted(qr_rdx, prdy)^2)/colSums(qr.resid(qr_mm, prdy)^2)* (NROW(prdy)-qr_mm$rank)/(qr_rdx$rank)} }, "t" = {funT = function(qr_rdx, qr_mm, prdy){ as.numeric(qr.coef(qr_rdx, prdy))/sqrt(colSums(qr.resid(qr_mm, prdy)^2)/sum(rdx^2)) * sqrt(NROW(args$y)-qr_mm$rank)} }) select_x <- c(1:length(attr(args$mm,"assign"))) %in% args$colx qr_mm <- qr(args$mm) qr_d <- qr(args$mm[,!select_x, drop = F]) rdx <- qr.resid(qr_d, args$mm[, select_x, drop = F]) qr_rdx <- qr(rdx) rdy <- qr.resid(qr_d, args$y) type = attr(args$P,"type") out = apply(args$P,2,function(pi){ funT(qr_rdx = qr_rdx, qr_mm = qr_mm, prdy = Pmat_product(x = rdy,P = pi,type = type))}) return(out)} cluster_kennedy <- function(args){ switch(args$test, "fisher"= {funT = function(qr_rdx, qr_mm, prdy){ colSums(qr.fitted(qr_rdx, prdy)^2)/colSums(qr.resid(qr_rdx, prdy)^2)* (NROW(prdy)-qr_mm$rank)/(qr_rdx$rank)} }, "t" = {funT = function(qr_rdx, qr_mm, prdy){ as.numeric(qr.coef(qr_rdx, prdy))/sqrt(colSums(qr.resid(qr_rdx, prdy)^2)/sum(rdx^2)) * sqrt(NROW(args$y)-qr_mm$rank)} }) select_x <- c(1:length(attr(args$mm,"assign"))) %in% args$colx qr_mm <- qr(args$mm) qr_d <- qr(args$mm[,!select_x, drop = F]) rdx <- qr.resid(qr_d, args$mm[, select_x, drop = F]) qr_rdx <- qr(rdx) rdy <- qr.resid(qr_d, args$y) type = attr(args$P,"type") out = apply(args$P,2,function(pi){ funT(qr_rdx = qr_rdx, qr_mm = qr_mm, prdy = Pmat_product(x = rdy,P = pi,type = type))}) return(out)} cluster_terBraak <- function(args){ switch(args$test, "fisher"= {funT = function(qr_rdx, qr_mm, pry){ colSums(qr.fitted(qr_rdx, pry)^2)/colSums(qr.resid(qr_mm, pry)^2)* (NROW(pry)-qr_mm$rank)/(qr_rdx$rank)} }, "t" = {funT = function(qr_rdx, qr_mm, pry){ as.numeric(qr.coef(qr_rdx, pry))/sqrt(colSums(qr.resid(qr_mm, pry)^2)/sum(rdx^2)) * sqrt(NROW(args$y)-qr_mm$rank)} }) select_x <- c(1:length(attr(args$mm,"assign"))) %in% args$colx qr_mm <- qr(args$mm) qr_d <- qr(args$mm[,!select_x, drop = F]) rdx <- qr.resid(qr_d, args$mm[, select_x, drop = F]) qr_rdx <- qr(rdx) rdy <- qr.resid(qr_d, args$y) rmmy <- qr.resid(qr_mm, args$y) type = attr(args$P,"type") out = apply(args$P,2,function(pi){ funT(qr_rdx = qr_rdx, qr_mm = qr_mm, pry = Pmat_product(x = rmmy,P = pi,type = type))}) out[,1] = funT(qr_rdx = qr_rdx, qr_mm = qr_mm, pry = rdy) return(out)} cluster_manly <- function(args){ switch(args$test, "fisher"= {funT = function(qr_rdx, qr_mm, py){ colSums(qr.fitted(qr_rdx, py)^2)/colSums(qr.resid(qr_mm, py)^2)* (NROW(py)-qr_mm$rank)/(qr_rdx$rank)} }, "t" = {funT = function(qr_rdx, qr_mm, py){ as.numeric(qr.coef(qr_rdx, py))/sqrt(colSums(qr.resid(qr_mm, py)^2)/sum(rdx^2)) * sqrt(NROW(args$y)-qr_mm$rank)} }) select_x <- c(1:length(attr(args$mm,"assign"))) %in% args$colx qr_mm <- qr(args$mm) qr_d <- qr(args$mm[,!select_x, drop = F]) rdx <- qr.resid(qr_d, args$mm[, select_x, drop = F]) qr_rdx <- qr(rdx) qr_1 <- qr(rep(1,NROW(args$y))) r1y <- qr.resid(qr_1,args$y) h1y <- qr.fitted(qr_1,args$y) type = attr(args$P,"type") out = apply(args$P,2,function(pi){ funT(qr_rdx = qr_rdx, qr_mm = qr_mm, py = Pmat_product(x = r1y,P = pi,type = type)+h1y) }) return(out)} cluster_draper_stoneman <- function(args){ switch(args$test, "fisher"= {funT = function(qr_rdpx, qr_pmm, y, qr_mm, qr_rdx, rdpx){ colSums(qr.fitted(qr_rdpx, y)^2)/colSums(qr.resid(qr_pmm, y)^2)* (NROW(y)-qr_mm$rank)/(qr_rdx$rank)} }, "t" = {funT = function(qr_rdpx, qr_pmm, y, qr_mm, qr_rdx, rdpx){ as.numeric(qr.coef(qr_rdpx, y))/sqrt(colSums(qr.resid(qr_pmm, y)^2)/sum(rdpx^2)) * sqrt(NROW(y)-qr_mm$rank)} }) select_x <- c(1:length(attr(args$mm,"assign"))) %in% args$colx qr_mm <- qr(args$mm) qr_d <- qr(args$mm[,!select_x, drop = F]) rdx <- qr.resid(qr_d, args$mm[, select_x, drop = F]) qr_rdx <- qr(rdx) type = attr(args$P,"type") out = apply(args$P,2,function(pi){ px = Pmat_product(x = args$mm[,select_x, drop=F],P =pi,type = type) rdpx = qr.resid(qr_d,px) qr_rdpx = qr(rdpx) qr_pmm = qr(cbind(args$mm[,!select_x, drop=F],px)) funT(qr_rdpx = qr_rdpx, qr_pmm = qr_pmm, y = args$y, qr_mm = qr_mm, qr_rdx = qr_rdx, rdpx = rdpx)}) return(out)} cluster_dekker <- function(args){ switch(args$test, "fisher"= {funT = function(qr_rdprx, ry, qr_mm,qr_rdx,rdprx){ colSums(qr.fitted(qr_rdprx, ry)^2)/colSums(qr.resid(qr_rdprx, ry)^2)* (NROW(ry)-qr_mm$rank)/(qr_rdx$rank)} }, "t" = {funT = function(qr_rdprx, ry, qr_mm,qr_rdx,rdprx){ as.numeric(qr.coef(qr_rdprx, ry))/sqrt(colSums(qr.resid(qr_rdprx, ry)^2)/sum(rdprx^2)) * sqrt(NROW(ry)-qr_mm$rank)} }) select_x <- c(1:length(attr(args$mm,"assign"))) %in% args$colx qr_mm <- qr(args$mm) qr_d <- qr(args$mm[,!select_x, drop = F]) rdx <- qr.resid(qr_d, args$mm[, select_x, drop = F]) qr_rdx <- qr(rdx) ry = qr.resid(qr_d,args$y) type = attr(args$P,"type") out = apply(args$P,2,function(pi){ rdprx = qr.resid(qr_d,Pmat_product(x = rdx,P = pi,type = type)) qr_rdprx = qr(rdprx) funT(qr_rdprx = qr_rdprx, ry = ry, qr_mm = qr_mm, qr_rdx = qr_rdx, rdprx = rdprx)}) return(out)} cluster_huh_jhun <- function(args){ switch(args$test, "fisher"= {funT = function(qr_vx, qr_mm, pvy, rdx){ colSums(qr.fitted(qr_vx, pvy)^2)/colSums(qr.resid(qr_vx, pvy)^2)* (NROW(args$y)-qr_mm$rank)/(qr_vx$rank)} }, "t" = {funT = function(qr_vx, qr_mm, pvy, rdx){ as.numeric(qr.coef(qr_vx, pvy))/sqrt(colSums(qr.resid(qr_vx, pvy)^2)/sum(rdx^2)) * sqrt(NROW(args$y)-qr_mm$rank)} }) select_x <- c(1:length(attr(args$mm,"assign")))%in%args$colx qr_mm <- qr(args$mm) qr_d <- qr(args$mm[,!select_x, drop = F]) rdx <- qr.resid(qr_d, args$mm[, select_x, drop = F]) qr_o= qr(args$rnd_rotation[1:(NROW(args$y)-qr_d$rank),1:(NROW(args$y)-qr_d$rank)]) omega = qr.Q(qr_o)%*%diag(sign(diag(qr.R(qr_o)))) qcd = qr.Q(qr_d,complete = T)[,-c(1:qr_d$rank),drop=F] v = omega%*%t(qcd) vx <- v%*%(args$mm[,select_x, drop = F]) qr_vx <-qr(vx) vy <- v%*%args$y type = attr(args$P,"type") out = apply(args$P,2,function(pi){ funT(qr_vx = qr_vx, qr_mm = qr_mm, pvy = Pmat_product(x = vy,P = pi,type = type), rdx = rdx)}) return(out)}
expect_invisible <- function(call, label = NULL) { lab <- label %||% expr_label(enexpr(call)) vis <- withVisible(call) expect( identical(vis$visible, FALSE), sprintf("%s does not return invisibly", lab) ) invisible(vis$value) } expect_visible <- function(call, label = NULL) { lab <- label %||% expr_label(enexpr(call)) vis <- withVisible(call) expect( identical(vis$visible, TRUE), sprintf("%s does not invisibly", lab) ) invisible(vis$value) }
approx2 <- function( x, fill=NULL, n=length(x), quiet=FALSE, ... ) { if(all(is.na(x))) { if(!quiet) warning("There are no non-NA values in x.") return(rep(NA,n)) } L <- length(x) if(is.na(x[1])) x[1] <- if(is.null(fill)) head(x[!is.na(x)],1) else fill(x, na.rm=TRUE) if(is.na(x[L])) x[L] <- if(is.null(fill)) tail(x[!is.na(x)],1) else fill(x, na.rm=TRUE) approx(x, n=n, ...)$y }
modif_canevas <- function(xmin,xmax,ymin,ymax,projproj,nbfonds) { canevas<-balises_qgis()[[1]] modifs=data.frame(c("XXXMIN","XXXMAX","YYYMIN","YYYMAX","PROJECTIONPROJET","NOMBREDEFONDS"),stringsAsFactors=F) modifs[1,2]=xmin modifs[2,2]=xmax modifs[3,2]=ymin modifs[4,2]=ymax modifs[5,2]=projproj modifs[6,2]=nbfonds modifs[,2]=as.character(modifs[,2]) qgs=modification(canevas,modifs) return(qgs) }
matching <- function( x, p = 2, match_between = NULL, match_within = NULL, match_extreme_first = TRUE, target_group = NULL, sort_output = TRUE ) { input_validation_matching(x, p, match_between, match_within, match_extreme_first, target_group) data <- to_matrix(x) match_between <- merge_into_one_variable(match_between) target_group <- get_target_group(data, match_between, target_group) if (argument_exists(match_within)) { cl <- match_within(data, p, match_between, match_within, match_extreme_first, target_group) } else { cl <- nn_centroid_clustering(data, p, match_between, match_extreme_first, target_group) } if (sort_output) { return(sort_by_objective(cl, data)) } cl } get_target_group <- function(data, match_between, target_group) { if (!argument_exists(match_between)) { return(FALSE) } tab <- table(match_between) if (!argument_exists(target_group)) { if (all(tab == tab[1])) { return(FALSE) } return(which.min(tab)) } if (target_group == "smallest") { return(which.min(tab)) } else if (target_group == "diverse") { return(which.max(diversity_objective_by_group(match_between, data))) } else if (target_group == "none") { return(FALSE) } else { stop("argument `target_group` must be one of 'smallest', 'diverse' or 'none'") } } match_within <- function(data, p, match_between, match_within, match_extreme_first, target_group) { match_within <- merge_into_one_variable(match_within) N <- nrow(data) cl <- rep(NA, N) c <- length(unique(match_within)) for (i in 1:c) { tmp_data <- subset_data_matrix(data, match_within == i) cl_tmp <- nn_centroid_clustering( tmp_data, p, match_between[match_within == i], match_extreme_first ) cl[match_within == i] <- ifelse(is.na(cl_tmp), NA, paste0(cl_tmp, "_", i)) } to_numeric(cl) } sort_by_objective <- function(cl, data, N) { N <- nrow(data) selected <- (1:N)[!is.na(cl)] cl_sub <- cl[selected] cl_sub <- order_cluster_vector(cl_sub) objectives <- diversity_objective_by_group(cl_sub, subset_data_matrix(data, selected)) N <- length(cl_sub) one <- data.frame(match = cl_sub, order_matches = 1:length(cl_sub)) two <- data.frame(match = order(objectives), objective_id = 1:length(objectives)) merged <- merge(one, two) new <- rep(NA, N) new[merged$order_matches] <- merged$objective_id cl[!is.na(cl)] <- new cl }
tbr_binom <- function(.tbl, x, tcolumn, unit = "years", n, alpha = 0.05) { .tbl <- .tbl %>% arrange(!! rlang::enquo(tcolumn)) %>% mutate("temp" := purrr::map(row_number(), ~tbr_binom_window(x = !! rlang::enquo(x), tcolumn = !! rlang::enquo(tcolumn), unit = unit, n = n, alpha = alpha, i = .x))) %>% tidyr::unnest(.data$temp) .tbl <- tibble::as_tibble(.tbl) return(.tbl) } tbr_binom_window <- function(x, tcolumn, unit = "years", n, i, alpha) { u <- (c("years", "months", "weeks", "days", "hours", "minutes", "seconds")) if (!unit %in% u) { stop("unit must be one of ", paste(u, collapse = ", ")) } window <- open_window(x, tcolumn, unit = unit, n, i) df <- tibble(window) %>% summarise(n = n(), successes = as.integer(sum(window))) results <- binom_ci(x = df$successes, n = df$n, alpha = alpha, return.df = TRUE) return(results) } binom_ci <- function(x, n, alpha = 0.05, method = c("wilson","exact","asymptotic"), return.df = FALSE) { method <- match.arg(method) bc <- function(x, n, alpha, method) { nu1 <- 2 * (n - x + 1) nu2 <- 2 * x ll <- if (x > 0) x/(x + qf(1 - alpha/2, nu1, nu2) * (n - x + 1)) else 0 nu1p <- nu2 + 2 nu2p <- nu1 - 2 pp <- if (x < n) qf(1 - alpha/2, nu1p, nu2p) else 1 ul <- ((x + 1) * pp)/(n - x + (x + 1) * pp) zcrit <- -qnorm(alpha/2) z2 <- zcrit * zcrit p <- x/n cl <- (p + z2/2/n + c(-1, 1) * zcrit * sqrt((p * (1 - p) + z2/4/n)/n))/(1 + z2/n) if (x == 1) cl[1] <- -log(1 - alpha)/n if (x == (n - 1)) cl[2] <- 1 + log(1 - alpha)/n asymp.lcl <- x/n - qnorm(1 - alpha/2) * sqrt(((x/n) * (1 - x/n))/n) asymp.ucl <- x/n + qnorm(1 - alpha/2) * sqrt(((x/n) * (1 - x/n) )/n) res <- rbind(c(ll, ul), cl, c(asymp.lcl, asymp.ucl)) res <- cbind(rep(x/n, 3), res) switch(method, wilson = res[2, ], exact = res[1, ], asymptotic = res[3, ]) } if ((length(x) != length(n)) & length(x) == 1) x <- rep(x, length(n)) if ((length(x) != length(n)) & length(n) == 1) n <- rep(n, length(x)) mat <- matrix(ncol = 3, nrow = length(x)) for (i in 1:length(x)) mat[i, ] <- bc(x[i], n[i], alpha = alpha, method = method) dimnames(mat) <- list(rep("", dim(mat)[1]), c("PointEst", "Lower", "Upper")) if (return.df) mat <- as.data.frame(mat, row.names = NULL) mat }
library(nlsr) fnDeriv(quote(1 + x + y), c("x", "y")) nlsDeriv( ~ log(x), "x") nlsDeriv( ~ log(x, base=3), "x" ) nlsDeriv( ~ exp(x), "x") nlsDeriv( ~ sin(x), "x") nlsDeriv( ~ cos(x), "x") nlsDeriv( ~ tan(x), "x") nlsDeriv( ~ sinh(x), "x") nlsDeriv( ~ cosh(x), "x") nlsDeriv( ~ sqrt(x), "x") nlsDeriv( ~ pnorm(q), "q") nlsDeriv( ~ dnorm(x, mean), "mean") nlsDeriv( ~ asin(x), "x") nlsDeriv( ~ acos(x), "x") nlsDeriv( ~ atan(x), "x") nlsDeriv( ~ gamma(x), "x") nlsDeriv( ~ lgamma(x), "x") nlsDeriv( ~ digamma(x), "x") nlsDeriv( ~ trigamma(x), "x") nlsDeriv( ~ psigamma(x, deriv = 5), "x") nlsDeriv( ~ x*y, "x") nlsDeriv( ~ x/y, "x") nlsDeriv( ~ x^y, "x") nlsDeriv( ~ (x), "x") nlsDeriv( ~ +x, "x") nlsDeriv( ~ -x, "x") nlsDeriv( ~ abs(x), "x") nlsDeriv( ~ sign(x), "x") nlsSimplify(quote(+(a+b))) nlsSimplify(quote(-5)) nlsSimplify(quote(--(a+b))) nlsSimplify(quote(exp(log(a+b)))) nlsSimplify(quote(exp(1))) nlsSimplify(quote(log(exp(a+b)))) nlsSimplify(quote(log(1))) nlsSimplify(quote(!TRUE)) nlsSimplify(quote(!FALSE)) nlsSimplify(quote((a+b))) nlsSimplify(quote(a + b + 0)) nlsSimplify(quote(0 + a + b)) nlsSimplify(quote((a+b) + (a+b))) nlsSimplify(quote(1 + 4)) nlsSimplify(quote(a + b - 0)) nlsSimplify(quote(0 - a - b)) nlsSimplify(quote((a+b) - (a+b))) nlsSimplify(quote(5 - 3)) nlsSimplify(quote(0*(a+b))) nlsSimplify(quote((a+b)*0)) nlsSimplify(quote(1L * (a+b))) nlsSimplify(quote((a+b) * 1)) nlsSimplify(quote((-1)*(a+b))) nlsSimplify(quote((a+b)*(-1))) nlsSimplify(quote(2*5)) nlsSimplify(quote((a+b) / 1)) nlsSimplify(quote((a+b) / (-1))) nlsSimplify(quote(0/(a+b))) nlsSimplify(quote(1/3)) nlsSimplify(quote((a+b) ^ 1)) nlsSimplify(quote(2^10)) nlsSimplify(quote(log(exp(a), 3))) nlsSimplify(quote(FALSE && b)) nlsSimplify(quote(a && TRUE)) nlsSimplify(quote(TRUE && b)) nlsSimplify(quote(a || TRUE)) nlsSimplify(quote(FALSE || b)) nlsSimplify(quote(a || FALSE)) nlsSimplify(quote(if (TRUE) a+b)) nlsSimplify(quote(if (FALSE) a+b)) nlsSimplify(quote(if (TRUE) a+b else a*b)) nlsSimplify(quote(if (FALSE) a+b else a*b)) nlsSimplify(quote(if (cond) a+b else a+b)) nlsSimplify(quote(--(a+b))) modelformula <- y ~ ms * b1/(1 + b2 * exp(-b3 * tt)) pvec <- c(b1=1, b2=1, b3=1) cat("model2rjfunx: modelformula = ") print(modelformula) print(class(modelformula)) if (length(modelformula) == 2) { residexpr <- modelformula[[2]] } else if (length(modelformula) == 3) { residexpr <- call("-", modelformula[[3]], modelformula[[2]]) } else stop("Unrecognized formula") if (is.null(names(pvec))) names(pvec) <- paste0("p", seq_along(pvec)) residexpr1 <- nlsDeriv( ~ residexpr, names(pvec)) cat("residexpr1:\n") print(residexpr1) residexpr2 <- fnDeriv(residexpr, names(pvec)) cat("residexpr2:\n") print(residexpr2)
test_that("attaches the butcher class", { skip_if_not_installed("butcher") model <- parsnip::linear_reg() model <- parsnip::set_engine(model, "lm") wf <- workflow() wf <- add_model(wf, model) wf <- add_formula(wf, mpg ~ cyl + disp) fit <- fit(wf, mtcars) fit <- butcher::butcher(fit) expect_s3_class(fit, "butchered_workflow") }) test_that("fails if not a fitted workflow", { skip_if_not_installed("butcher") expect_error(butcher::butcher(workflow())) }) test_that("can axe the call", { skip_if_not_installed("butcher") model <- parsnip::linear_reg() model <- parsnip::set_engine(model, "lm") wf <- workflow() wf <- add_model(wf, model) wf <- add_formula(wf, mpg ~ cyl + disp) fit <- fit(wf, mtcars) fit <- butcher::axe_call(fit) expect_identical(fit$fit$fit$fit$call, rlang::expr(dummy_call())) }) test_that("can axe the fitted bits", { skip_if_not_installed("butcher") model <- parsnip::linear_reg() model <- parsnip::set_engine(model, "lm") wf <- workflow() wf <- add_model(wf, model) wf <- add_formula(wf, mpg ~ cyl + disp) fit <- fit(wf, mtcars) fit <- butcher::axe_fitted(fit) expect_identical(fit$fit$fit$fit$fitted.values, numeric()) }) test_that("axing the data removes the outcomes/predictors", { skip_if_not_installed("butcher") model <- parsnip::linear_reg() model <- parsnip::set_engine(model, "lm") wf <- workflow() wf <- add_model(wf, model) wf <- add_formula(wf, mpg ~ cyl + disp) fit <- fit(wf, mtcars) expect_s3_class(fit$pre$mold$outcomes, "tbl_df") expect_s3_class(fit$pre$mold$predictors, "tbl_df") fit <- butcher::axe_data(fit) expect_null(fit$pre$mold$outcomes) expect_null(fit$pre$mold$predictors) }) test_that("axing the env - recipe", { skip_if_not_installed("butcher") model <- parsnip::linear_reg() model <- parsnip::set_engine(model, "lm") rec <- recipes::recipe(mpg ~ cyl + disp, mtcars) rec <- recipes::step_center(rec, cyl, disp) wf <- workflow() wf <- add_model(wf, model) wf <- add_recipe(wf, rec) fit <- fit(wf, mtcars) fit <- butcher::axe_env(fit) expect_s3_class(fit$pre$actions$recipe$recipe, "butchered_recipe") }) test_that("axing the env - formula", { skip_if_not_installed("butcher") model <- parsnip::linear_reg() model <- parsnip::set_engine(model, "lm") wf <- workflow() wf <- add_model(wf, model) wf <- add_formula(wf, mpg ~ cyl + disp) fit <- fit(wf, mtcars) fit <- butcher::axe_env(fit) expect_s3_class(fit$pre$actions$formula$formula, "butchered_formula") }) test_that("axing the env - variables", { skip_if_not_installed("butcher") model <- parsnip::linear_reg() model <- parsnip::set_engine(model, "lm") wf <- workflow() wf <- add_model(wf, model) wf <- add_variables(wf, mpg, c(cyl, disp)) fit <- fit(wf, mtcars) axed <- butcher::axe_env(fit) expect_s3_class(axed, "butchered_workflow") original_outcomes <- fit$pre$actions$variables$variables$outcomes original_predictors <- fit$pre$actions$variables$variables$predictors axed_outcomes <- axed$pre$actions$variables$variables$outcomes axed_predictors <- axed$pre$actions$variables$variables$predictors expect_s3_class(axed_outcomes, "quosure") expect_s3_class(axed_predictors, "quosure") expect_false(identical(original_outcomes, axed_outcomes)) expect_false(identical(original_predictors, axed_predictors)) }) test_that("can still predict after butcher - recipe", { skip_if_not_installed("butcher") model <- parsnip::linear_reg() model <- parsnip::set_engine(model, "lm") rec <- recipes::recipe(mpg ~ cyl + disp, mtcars) rec <- recipes::step_center(rec, cyl, disp) wf <- workflow() wf <- add_model(wf, model) wf <- add_recipe(wf, rec) fit <- fit(wf, mtcars) axed <- butcher::axe_env(fit) expect_identical( predict(fit, mtcars), predict(axed, mtcars) ) }) test_that("can still predict after butcher - formula", { skip_if_not_installed("butcher") model <- parsnip::linear_reg() model <- parsnip::set_engine(model, "lm") wf <- workflow() wf <- add_model(wf, model) wf <- add_formula(wf, mpg ~ cyl + disp) fit <- fit(wf, mtcars) axed <- butcher::axe_env(fit) expect_identical( predict(fit, mtcars), predict(axed, mtcars) ) }) test_that("can still predict after butcher - variables", { skip_if_not_installed("butcher") model <- parsnip::linear_reg() model <- parsnip::set_engine(model, "lm") wf <- workflow() wf <- add_model(wf, model) wf <- add_variables(wf, mpg, c(cyl, disp)) fit <- fit(wf, mtcars) axed <- butcher::axe_env(fit) expect_identical( predict(fit, mtcars), predict(axed, mtcars) ) })
rxodeTest( { context("Test PythonFsum") test_that("Fsum", { et <- eventTable() %>% add.sampling(0) rx <- RxODE({ s1 <- sum(1e100, 1.0, -1e100, 1e-100, 1e50, -1.0, -1e50) s2 <- sum(2.0^53, -0.5, -2.0^-54) s3 <- sum(2.0^53, 1.0, 2.0^-100) s4 <- sum(2.0^53 + 10.0, 1.0, 2.0^-100) s5 <- sum(2.0^53 - 4.0, 0.5, 2.0^-54) s6 <- sum(1e16, 1., 1e-16) s7 <- sum(a, b, c, d) s8 <- sum(1e100, 1, -1e100, 1) s9 <- sum(R_pow(prod(2, 3), 2), 6) }) s <- rxSolve(rx, params = c( a = 1e16 - 2., b = 1. - 2.^-53, c = -(1e16 - 2.), d = -(1. - 2.^-53) ), et, sumType = "fsum" ) expect_identical(s$s1, 1e-100) expect_identical(s$s2, 2.0^53 - 1.0) expect_identical(s$s3, 2.0^53 + 2.0) expect_identical(s$s4, 2.0^53 + 12.0) expect_identical(s$s5, 2.0^53 - 3.0) expect_identical(s$s6, 10000000000000002.0) expect_identical(s$s7, 0.0) expect_identical(s$s8, 2.0) expect_error(rxSetSum("c")) expect_error(rxSetProd("double")) }) }, test = "cran" )
library(pipenostics) test_that("water's function errs in water states paths", { expect_equal( ps_t(), c(.353658941e-2, .263889776e1, .123443146e2), tolerance = 1e-8 ) expect_equal( cp1_tp(), c(.417301218, .401008987, 0.465580682)*10, tolerance = 1e-8 ) expect_equal( v1_tp(), c(.100215168e-2, .971180894e-3, .120241800e-2), tolerance = 1e-8 ) expect_equal( fric_romeo(2118517, c(0, 70e-3/1, 7e-3/1)), fric_buzelli(2118517, c(0, 70e-3/1, 7e-3/1)), tolerance = 1e-3 ) expect_equal( fric_romeo(2118517, c(0, 70e-3/1, 7e-3/1)), fric_vatankhan(2118517, c(0, 70e-3/1, 7e-3/1)), tolerance = 1e-3 ) expect_equal( all( fric_romeo(2118517, c(0, 70e-3/1, 7e-3/1)) < .2 & fric_romeo(2118517, c(0, 70e-3/1, 7e-3/1)) > 0 ), TRUE ) with(pipenostics:::r12t4, { expect_equal( dynvisc(temperature, density), dynvisc, tolerance = 1e-8 ) }) })
pcmvtruncnorm <- function( lowerY, upperY, mean, sigma, lower, upper, dependent.ind, given.ind, X.given, ... ) { params <- condtMVN( mean = mean, sigma = sigma, lower = lower, upper = upper, dependent.ind = dependent.ind, given.ind = given.ind, X.given = X.given, init = 0 ) d <- length(lowerY) if (length(lowerY) != length(dependent.ind)) stop("Error: `lowerY` refers to the lower probability of Y|X and must equal to length of dependent.ind.", call. = FALSE) if (length(upperY) != length(dependent.ind)) stop("Error: `upperY` refers to the upper probability of Y|X and must equal to length of dependent.ind.", call. = FALSE) when.equal <- lowerY == upperY if (identical(lowerY, upperY)) { warning("Warning: lowerY and upperY are equal in all dimenseions. Returning zero") prob <- 0 return(prob) } else if (0 < sum(when.equal) & sum(when.equal) < d) { stop("Error: lowerY is equal to upperY in at least one dimension; tmvtnorm does not calculate the CDF", call. = FALSE) } else if (any(lowerY > upperY)) { stop("Error: lowerY is higher than to upperY in at least one dimension. Did you mean to switch them?", call. = FALSE) } if (length(dependent.ind) == 1) { message("univariate CDF: using truncnorm::ptruncnorm") prob <- truncnorm::ptruncnorm( upperY, mean = params$condMean, sd = params$condVar, a = params$condLower, b = params$condUpper ) - truncnorm::ptruncnorm( lowerY, mean = params$condMean, sd = params$condVar, a = params$condLower, b = params$condUpper ) } else { prob <- tmvtnorm::ptmvnorm( lowerY, upperY, mean = params$condMean, sigma = params$condVar, lower = params$condLower, upper = params$condUpper, ... ) } return(prob) }
cat("doExtras is ", simsalapar:::doExtras(), "\n", "nCores4test(): ", simsalapar:::nCores4test(), "\n", sep="")
check_arg_test_phevis <- function(train_param, df_test, surparam, model, START_DATE, PATIENT_NUM, ENCOUNTER_NUM){ if(!is.character(START_DATE)) stop("START_DATE should be character") if(length(START_DATE) != 1) stop("START_DATE should be of length 1") if(!is.character(PATIENT_NUM)) stop("PATIENT_NUM should be character") if(length(PATIENT_NUM) != 1) stop("PATIENT_NUM should be of length 1") if(!is.character(ENCOUNTER_NUM)) stop("ENCOUNTER_NUM should be character") if(length(ENCOUNTER_NUM) != 1) stop("ENCOUNTER_NUM should be of length 1") if(!is.data.frame(df_test)) stop("df_test should be a data.frame object") if(!is.list(train_param)) stop("train_param should be a list") if(!is.list(surparam)) stop("surparam should be a list") if(!is.list(model)) stop("model should be a list") message("-- Arguments passed check -> PheVis begins --") return(NULL) }
library(datamart) test_strxxcrypt <- function() { print(strencrypt("")) print(strdecrypt("")) print(strdecrypt(strencrypt("abc"))) print(strencrypt("abc")) } test_strxxcrypt()
trim_model <- function(model, maxit = 0, return_loglik=FALSE, zerotol=1e-8, verbose = TRUE, ...){ ll_original <- logLik(model) model_original <- model if(inherits(model, "hmm")){ if(model$n_channels==1){ if(!(any(model$initial_probs < zerotol & model$initial_probs > 0) || any(model$transition_probs < zerotol & model$transition_probs > 0) || any(model$emission_probs < zerotol & model$emission_probs > 0))){ if(verbose) print("Nothing to trim.") if(return_loglik){ return(list(model=model,loglik=logLik(model))) } else return(model) } model$initial_probs[model$initial_probs < zerotol] <- 0 model$initial_probs <- model$initial_probs/sum(model$initial_probs) model$transition_probs[model$transition_probs < zerotol] <- 0 model$transition_probs <- model$transition_probs/rowSums(model$transition_probs) model$emission_probs[model$emission_probs < zerotol] <- 0 model$emission_probs <- model$emission_probs/rowSums(model$emission_probs) if(!is.finite(ll0 <- logLik(model))){ warning("Trimming resulted in non-finite log-likelihood; returning the original model. Try changing the zerotol parameter.") return(model_original) } if (!isTRUE(all.equal(ll0,ll_original)) && ll0 < ll_original) { warning("Trimming resulted model with smaller log-likelihood; returning the original model. ") return(model_original) } if(maxit > 0){ for(ii in 1:maxit){ fit <- fit_model(model, ...) ll <- fit$logLik if(ll > ll0){ model <- fit$model ll0 <- ll } else break if(!(any(model$initial_probs < zerotol & model$initial_probs > 0) || any(model$transition_probs < zerotol & model$transition_probs > 0) || any(model$emission_probs < zerotol & model$emission_probs > 0))) break model$initial_probs[model$initial_probs < zerotol] <- 0 model$initial_probs <- model$initial_probs/sum(model$initial_probs) model$transition_probs[model$transition_probs < zerotol] <- 0 model$transition_probs <- model$transition_probs/rowSums(model$transition_probs) model$emission_probs[model$emission_probs < zerotol] <- 0 model$emission_probs <- model$emission_probs/rowSums(model$emission_probs) } } } else { if(!(any(model$initial_probs < zerotol & model$initial_probs > 0) || any(model$transition_probs < zerotol & model$transition_probs > 0) || any(sapply(model$emission_probs,function(x) any(x < zerotol & x > 0))))){ if(verbose) print("Nothing to trim.") if(return_loglik){ return(list(model=model,loglik=logLik(model))) } else return(model) } model$initial_probs[model$initial_probs < zerotol] <- 0 model$initial_probs <- model$initial_probs/sum(model$initial_probs) model$transition_probs[model$transition_probs < zerotol] <- 0 model$transition_probs <- model$transition_probs/rowSums(model$transition_probs) for(i in 1:model$n_channels){ model$emission_probs[[i]][model$emission_probs[[i]] < zerotol] <- 0 model$emission_probs[[i]] <- model$emission_probs[[i]]/ rowSums(model$emission_probs[[i]]) } if(!is.finite(ll0 <- logLik(model))){ warning("Trimming resulted in non-finite log-likelihood; returning the original model. Try changing the zerotol parameter.") return(model_original) } if (!isTRUE(all.equal(ll0,ll_original)) && ll0 < ll_original) { warning("Trimming resulted model with smaller log-likelihood; returning the original model. ") return(model_original) } if(maxit > 0){ for(ii in 1:maxit){ fit <- fit_model(model, ...) ll <- fit$logLik if(ll > ll0){ model <- fit$model ll0 <- ll } else break if(!(any(model$initial_probs < zerotol & model$initial_probs > 0) || any(model$transition_probs < zerotol & model$transition_probs > 0) || any(sapply(model$emission_probs,function(x) any(x < zerotol & x > 0))))) break model$initial_probs[model$initial_probs < zerotol] <- 0 model$initial_probs <- model$initial_probs/sum(model$initial_probs) model$transition_probs[model$transition_probs < zerotol] <- 0 model$transition_probs <- model$transition_probs/rowSums(model$transition_probs) for(i in 1:model$n_channels){ model$emission_probs[[i]][model$emission_probs[[i]] < zerotol] <- 0 model$emission_probs[[i]] <- model$emission_probs[[i]]/ rowSums(model$emission_probs[[i]]) } } } } }else if(inherits(model, "mhmm")){ if(model$n_channels==1){ if(!(any(unlist(model$initial_probs) < zerotol & unlist(model$initial_probs) > 0) || any(unlist(model$transition_probs) < zerotol & unlist(model$transition_probs) > 0) || any(unlist(model$emission_probs) < zerotol & unlist(model$emission_probs) > 0))){ if(verbose) print("Nothing to trim.") if(return_loglik){ return(list(model=model,loglik=logLik(model))) } else return(model) } for(m in 1:model$n_clusters){ model$initial_probs[[m]][model$initial_probs[[m]] < zerotol] <- 0 model$initial_probs[[m]] <- model$initial_probs[[m]]/sum(model$initial_probs[[m]]) model$transition_probs[[m]][model$transition_probs[[m]] < zerotol] <- 0 model$transition_probs[[m]] <- model$transition_probs[[m]]/rowSums(model$transition_probs[[m]]) model$emission_probs[[m]][model$emission_probs[[m]] < zerotol] <- 0 model$emission_probs[[m]] <- model$emission_probs[[m]]/rowSums(model$emission_probs[[m]]) } if(!is.finite(ll0 <- logLik(model))){ warning("Trimming resulted in non-finite log-likelihood; returning the original model. Try changing the zerotol parameter.") return(model_original) } if (!isTRUE(all.equal(ll0,ll_original)) && ll0 < ll_original) { warning("Trimming resulted model with smaller log-likelihood.") return(model_original) } if(maxit > 0){ for(ii in 1:maxit){ fit <- fit_model(model, ...) ll <- fit$logLik if(ll > ll0){ model <- fit$model ll0 <- ll } else break if(!(any(unlist(model$initial_probs) < zerotol & unlist(model$initial_probs) > 0) || any(unlist(model$transition_probs) < zerotol & unlist(model$transition_probs) > 0) || any(unlist(model$emission_probs) < zerotol & unlist(model$emission_probs) > 0))) break for(m in 1:model$n_clusters){ model$initial_probs[[m]][model$initial_probs[[m]] < zerotol] <- 0 model$initial_probs[[m]] <- model$initial_probs[[m]]/sum(model$initial_probs[[m]]) model$transition_probs[[m]][model$transition_probs[[m]] < zerotol] <- 0 model$transition_probs[[m]] <- model$transition_probs[[m]]/rowSums(model$transition_probs[[m]]) model$emission_probs[[m]][model$emission_probs[[m]] < zerotol] <- 0 model$emission_probs[[m]] <- model$emission_probs[[m]]/rowSums(model$emission_probs[[m]]) } } } } else { if(!(any(unlist(model$initial_probs) < zerotol & unlist(model$initial_probs) > 0) || any(unlist(model$transition_probs) < zerotol & unlist(model$transition_probs) > 0) || any(unlist(model$emission_probs) < zerotol & unlist(model$emission_probs) > 0))){ if(verbose) print("Nothing to trim.") if(return_loglik){ return(list(model=model,loglik=logLik(model))) } else return(model) } for(m in 1:model$n_clusters){ model$initial_probs[[m]][model$initial_probs[[m]] < zerotol] <- 0 model$initial_probs[[m]] <- model$initial_probs[[m]]/sum(model$initial_probs[[m]]) model$transition_probs[[m]][model$transition_probs[[m]] < zerotol] <- 0 model$transition_probs[[m]] <- model$transition_probs[[m]]/rowSums(model$transition_probs[[m]]) for(i in 1:model$n_channels){ model$emission_probs[[m]][[i]][model$emission_probs[[m]][[i]] < zerotol] <- 0 model$emission_probs[[m]][[i]] <- model$emission_probs[[m]][[i]]/ rowSums(model$emission_probs[[m]][[i]]) } } if(!is.finite(ll0 <- logLik(model))){ warning("Trimming resulted in non-finite log-likelihood; returning the original model. Try changing the zerotol parameter.") return(model_original) } if (!isTRUE(all.equal(ll0,ll_original)) && ll0 < ll_original) { warning("Trimming resulted model with smaller log-likelihood.") return(model_original) } if(maxit > 0){ for(ii in 1:maxit){ fit <- fit_model(model, ...) ll <- fit$logLik if(ll > ll0){ model <- fit$model ll0 <- ll } else break if(!(any(unlist(model$initial_probs) < zerotol & unlist(model$initial_probs) > 0) || any(unlist(model$transition_probs) < zerotol & unlist(model$transition_probs) > 0) || any(unlist(model$emission_probs) < zerotol & unlist(model$emission_probs) > 0))) break for(m in 1:model$n_clusters){ model$initial_probs[[m]][model$initial_probs[[m]] < zerotol] <- 0 model$initial_probs[[m]] <- model$initial_probs[[m]]/sum(model$initial_probs[[m]]) model$transition_probs[[m]][model$transition_probs[[m]] < zerotol] <- 0 model$transition_probs[[m]] <- model$transition_probs[[m]]/rowSums(model$transition_probs[[m]]) for(i in 1:model$n_channels){ model$emission_probs[[m]][[i]][model$emission_probs[[m]][[i]] < zerotol] <- 0 model$emission_probs[[m]][[i]] <- model$emission_probs[[m]][[i]]/ rowSums(model$emission_probs[[m]][[i]]) } } } } } }else{ stop("An object of class hmm or mhmm required.") } if (verbose) { if(maxit > 0) print(paste(ii,"iteration(s) used.")) if(ll0 > ll_original){ print(paste("Trimming improved log-likelihood, ll_trim-ll_orig =", signif(ll0-ll_original, 3))) } } if(return_loglik){ list(model=model,loglik=ll0) } else model }
create_trend <- function(data, metric, hrvar = "Organization", mingroup = 5, return = "plot", legend_title = "Hours"){ required_variables <- c("Date", metric, "PersonId") data %>% check_inputs(requirements = required_variables) if(is.null(hrvar)){ data <- totals_col(data) hrvar <- "Total" } clean_nm <- us_to_space(metric) myTable <- data %>% mutate(Date = as.Date(Date, "%m/%d/%Y")) %>% rename(group = !!sym(hrvar)) %>% select(PersonId, Date, group, !!sym(metric)) %>% group_by(group) %>% mutate(Employee_Count = n_distinct(PersonId)) %>% filter(Employee_Count >= mingroup) myTable <- myTable %>% group_by(Date, group) %>% summarize(Employee_Count = mean(Employee_Count, na.rm = TRUE), !!sym(metric) := mean(!!sym(metric), na.rm = TRUE)) myTable_plot <- myTable %>% select(Date, group, !!sym(metric)) myTable_return <- myTable_plot %>% tidyr::spread(Date, !!sym(metric)) plot_object <- myTable_plot %>% ggplot(aes(x = Date , y = group , fill = !!sym(metric))) + geom_tile(height=.5) + scale_x_date(position = "top") + scale_fill_gradientn(name = legend_title, colours = c("steelblue4", "aliceblue", "white", "mistyrose1", "tomato1")) + theme_wpa_basic() + theme(axis.line.y = element_blank(), axis.title.y = element_blank()) + labs(title = clean_nm, subtitle = paste("Hotspots by", tolower(camel_clean(hrvar)))) + xlab("Date") + ylab(hrvar) + labs(caption = extract_date_range(data, return = "text")) if(return == "table"){ myTable_return } else if(return == "plot"){ plot_object } else { stop("Please enter a valid input for `return`.") } }
KellyRatio <- function (R, Rf = 0, method = "half") { R = checkData(R) if(!is.null(dim(Rf))) Rf = checkData(Rf) kr <- function (R, Rf, method) { xR = Return.excess(R, Rf) KR = mean(xR, na.rm=TRUE)/StdDev(R, na.rm=TRUE)^2 if (method == "half") { KR = KR/2 } return(KR) } result = sapply(R, kr, Rf = Rf, method = method) dim(result) = c(1,NCOL(R)) colnames(result) = colnames(R) rownames(result) = "Kelly Ratio" return (result) }
test_that("can parse versions", { out <- .rlang_downstream_parse_deps(c("foo (>= 1.0)")) expect_equal(out, list( c(pkg = "foo", min = "1.0") )) out <- .rlang_downstream_parse_deps(c("foo (>= 1.0)", "bar (>= 2.0.0)")) expect_equal(out, list( c(pkg = "foo", min = "1.0"), c(pkg = "bar", min = "2.0.0") )) expect_error( .rlang_downstream_parse_deps("foo"), "Parsing error" ) expect_error( .rlang_downstream_parse_deps("foo (1.0)"), "Parsing error" ) expect_error( .rlang_downstream_parse_deps("foo (< 1.0)"), "Can only check `>=` requirements" ) }) test_that("can check downstream versions", { local_interactive(FALSE) ok_deps <- .rlang_downstream_parse_deps(c( "base (>= 1.0)", "utils (>= 1.1)" )) expect_no_warning( expect_true( .rlang_downstream_check( pkg = "rlang", pkg_ver = "0.5.0", deps = ok_deps, info = "Consequences.", env = env(checked = FALSE) ) ) ) bad_deps <- .rlang_downstream_parse_deps(c( "base (>= 1.0)", "utils (>= 100.10)" )) expect_snapshot({ (expect_warning({ expect_false( .rlang_downstream_check( pkg = "rlang", pkg_ver = "0.5.0", deps = bad_deps, info = "Consequences.", env = env(checked = FALSE) ) ) NULL })) }) missing_deps <- .rlang_downstream_parse_deps(c( "base (>= 1.0)", "foobar (>= 100.10)" )) expect_no_warning({ expect_true( .rlang_downstream_check( pkg = "rlang", pkg_ver = "0.5.0", deps = missing_deps, info = "Consequences.", env = env(checked = FALSE) ) ) NULL }) }) test_that("setting `rlib_downstream_check` disables the check", { local_options(rlib_downstream_check = FALSE) local_interactive(FALSE) bad_deps <- .rlang_downstream_parse_deps(c( "base (>= 1.0)", "utils (>= 100.10)" )) expect_no_warning( expect_null( .rlang_downstream_check( pkg = "rlang", pkg_ver = "0.5.0", deps = bad_deps, info = "Consequences.", env = env(checked = FALSE) ) ) ) }) test_that("check_downstream() saves status in global env", { local_interactive(TRUE) local_options("rlang:::no_downstream_prompt" = TRUE) bad_deps <- .rlang_downstream_parse_deps(c( "base (>= 1.0)", "utils (>= 100.10)" )) key <- as.character(runif(1)) check <- function() { .rlang_downstream_check( pkg = "rlang", pkg_ver = "0.5.0", deps = bad_deps, info = "Consequences.", deps_key = key, env = env(checked = FALSE) ) } expect_warning(expect_false(check())) expect_no_warning(expect_null(check())) })
context("palettes") library(ggplot2) test_that("trek_pal returns as expected", { expect_error(trek_pal("a"), "Invalid palette name.") x <- trek_pal() expect_is(x, "character") expect_equal(length(x), 35) expect_equal(length(trek_pal("lcars_series")), 31) expect_equal(trek_pal("starfleet", reverse = TRUE), rev(trek_pal("starfleet"))) }) test_that("view_trek_pals returns as expected", { file <- file.path(tempdir(), "test-plot.png") png(file) expect_is(p <- view_trek_pals(), "NULL") expect_is(view_trek_pals(c("starfleet", "starfleet2")), "NULL") dev.off() unlink(file, recursive = TRUE, force = TRUE) }) test_that("trek scale functions return as expected", { p <- ggplot(diamonds, aes(carat, stat(count), color = cut, fill = cut)) + geom_density(position = "fill") expect_is(p + scale_color_trek("andorian") + scale_fill_trek("klingon"), "ggplot") p <- ggplot(diamonds, aes(carat, price)) + geom_bin2d() expect_is(p + scale_fill_trek("klingon", discrete = FALSE), "ggplot") p <- ggplot(diamonds, aes(carat, price)) + geom_density_2d(aes(color = ..level..)) expect_is(p + scale_color_trek("andorian", discrete = FALSE), "ggplot") }) test_that("LCARS helpers return as expected", { expect_equal(length(lcars_colors()), 31) expect_equal(length(lcars_2357()), 9) expect_equal(length(lcars_2357("tanoi")), 1) expect_equal(as.character(lcars_2357(c("a", "tanoi"))), c(NA, " expect_equal(length(lcars_2369()), 8) expect_equal(length(lcars_2369("tanoi")), 1) expect_equal(as.character(lcars_2369(c("a", "melrose"))), c(NA, " expect_equal(length(lcars_2375()), 8) expect_equal(length(lcars_2375("tanoi")), 1) expect_equal(as.character(lcars_2375(c("a", "danub"))), c(NA, " expect_equal(length(lcars_2379()), 8) expect_equal(length(lcars_2379("tanoi")), 1) expect_equal(as.character(lcars_2379(c("a", "husk"))), c(NA, " x <- lcars_pals() expect_is(x, "list") expect_equal(length(x), 12) expect_equal(lcars_pal(), as.character(lcars_2357())) expect_equal(lcars_pal("2369"), as.character(lcars_2369())) expect_equal(lcars_pal("2375"), as.character(lcars_2375())) expect_equal(lcars_pal("2379"), as.character(lcars_2379())) expect_error(lcars_pal(c("2357", "2365")), "Invalid LCARS palette name.") expect_error(lcars_pal("a"), "Invalid LCARS palette name.") expect_equal(lcars_pal(reverse = TRUE), rev(lcars_pal())) expect_is(lcars_colors_pal("2357"), "function") expect_is(lcars_colors_pal("2357", reverse = TRUE), "function") expect_is(lcars_colors_pal("blue-bell"), "function") }) test_that("lcars scale functions return as expected", { p <- ggplot(diamonds, aes(carat, stat(count), color = cut, fill = cut)) + geom_density(position = "fill") expect_is(p + scale_fill_lcars("2357") + scale_color_lcars("2357"), "ggplot") expect_is(p + scale_fill_lcars1("atomic-tangerine", dark = TRUE, reverse = TRUE) + scale_color_lcars1("atomic-tangerine", dark = TRUE, reverse = TRUE), "ggplot") expect_is(p + scale_fill_lcars2("pale-canary", "danub", reverse = TRUE) + scale_color_lcars2("pale-canary", "danub", reverse = TRUE), "ggplot") p <- ggplot(diamonds, aes(carat, stat(count), color = cut, fill = cut)) + geom_density(position = "fill") expect_is(p + scale_fill_lcars2("pale-canary", "danub") + scale_color_lcars2("pale-canary", "danub"), "ggplot") expect_is(p + scale_fill_lcars2("pale-canary", "danub", divergent = TRUE) + scale_fill_lcars2("pale-canary", "danub", divergent = TRUE), "ggplot") expect_is( p + scale_fill_lcars2("pale-canary", "danub", dark = TRUE, divergent = TRUE) + scale_fill_lcars2("pale-canary", "danub", dark = TRUE, divergent = TRUE), "ggplot") p <- ggplot(diamonds, aes(carat, price)) + geom_bin2d() expect_is(p + scale_fill_lcars("2357", discrete = FALSE), "ggplot") expect_is(p + scale_fill_lcars1("rust", discrete = FALSE), "ggplot") expect_is(p + scale_fill_lcars2("rust", "danub", discrete = FALSE), "ggplot") p <- ggplot(diamonds, aes(carat, price)) + geom_density_2d(aes(color = ..level..)) expect_is(p + scale_color_lcars("2357", discrete = FALSE), "ggplot") expect_is(p + scale_color_lcars1("tanoi", discrete = FALSE), "ggplot") expect_is(p + scale_color_lcars2("tanoi", "rust", discrete = FALSE), "ggplot") })
find_parameters.BGGM <- function(x, component = c("correlation", "conditional", "intercept", "all"), flatten = FALSE, ...) { component <- match.arg(component) l <- switch(component, "correlation" = list(correlation = colnames(get_parameters(x, component = "correlation"))), "conditional" = list(conditional = colnames(get_parameters(x, component = "conditional"))), "intercept" = list(intercept = colnames(x$Y)), "all" = list( intercept = colnames(x$Y), correlation = colnames(get_parameters(x, component = "correlation")), conditional = colnames(get_parameters(x, component = "conditional")) ) ) l <- .compact_list(l) if (flatten) { unique(unlist(l)) } else { l } } find_parameters.BFBayesFactor <- function(x, effects = c("all", "fixed", "random"), component = c("all", "extra"), flatten = FALSE, ...) { conditional <- NULL random <- NULL extra <- NULL effects <- match.arg(effects) component <- match.arg(component) if (.classify_BFBayesFactor(x) == "correlation") { conditional <- "rho" } else if (.classify_BFBayesFactor(x) %in% c("ttest1", "ttest2")) { conditional <- "Difference" } else if (.classify_BFBayesFactor(x) == "meta") { conditional <- "Effect" } else if (.classify_BFBayesFactor(x) == "proptest") { conditional <- "p" } else if (.classify_BFBayesFactor(x) == "linear") { posteriors <- as.data.frame(suppressMessages( BayesFactor::posterior(x, iterations = 20, progress = FALSE, index = 1, ...) )) params <- colnames(posteriors) vars <- find_variables(x, effects = "all", verbose = FALSE) interactions <- find_interactions(x) dat <- get_data(x, verbose = FALSE) if ("conditional" %in% names(vars)) { conditional <- unlist(lapply(vars$conditional, function(i) { if (is.factor(dat[[i]])) { sprintf("%s-%s", i, levels(dat[[i]])) } else { sprintf("%s-%s", i, i) } })) } if ("conditional" %in% names(interactions)) { for (i in interactions$conditional) { conditional <- c(conditional, params[grepl(paste0("^\\Q", i, "\\E"), params)]) } } if ("random" %in% names(vars)) { random <- unlist(lapply(vars$random, function(i) { if (is.factor(dat[[i]])) { sprintf("%s-%s", i, levels(dat[[i]])) } else { sprintf("%s-%s", i, i) } })) } extra <- setdiff(params, c(conditional, random)) } elements <- .get_elements(effects, component = component) l <- lapply(.compact_list(list(conditional = conditional, random = random, extra = extra)), .remove_backticks_from_string) l <- .compact_list(l[elements]) if (flatten) { unique(unlist(l)) } else { l } } find_parameters.MCMCglmm <- function(x, effects = c("all", "fixed", "random"), flatten = FALSE, ...) { sc <- summary(x) effects <- match.arg(effects) l <- .compact_list(list( conditional = rownames(sc$solutions), random = rownames(sc$Gcovariances) )) .filter_parameters(l, effects = effects, flatten = flatten, recursive = FALSE ) } find_parameters.mcmc.list <- function(x, flatten = FALSE, ...) { l <- list(conditional = colnames(x[[1]])) if (flatten) { unique(unlist(l)) } else { l } } find_parameters.bamlss <- function(x, flatten = FALSE, component = c("all", "conditional", "location", "distributional", "auxiliary"), parameters = NULL, ...) { component <- match.arg(component) cn <- colnames(as.data.frame(unclass(x$samples))) ignore <- grepl("(\\.alpha|logLik|\\.accepted|\\.edf)$", cn) cond <- cn[grepl("^(mu\\.p\\.|pi\\.p\\.)", cn) & !ignore] sigma <- cn[grepl("^sigma\\.p\\.", cn) & !ignore] smooth_terms <- cn[grepl("^mu\\.s\\.(.*)(\\.tau\\d+|\\.edf)$", cn)] alpha <- cn[grepl("\\.alpha$", cn)] elements <- .get_elements(effects = "all", component = component) l <- .compact_list(list( conditional = cond, smooth_terms = smooth_terms, sigma = sigma, alpha = alpha )[elements]) l <- .filter_pars(l, parameters) if (flatten) { unique(unlist(l)) } else { l } } find_parameters.brmsfit <- function(x, effects = "all", component = "all", flatten = FALSE, parameters = NULL, ...) { effects <- match.arg(effects, choices = c("all", "fixed", "random")) component <- match.arg(component, choices = c("all", .all_elements())) fe <- colnames(as.data.frame(x)) pattern <- c("^[A-z]_\\d\\.\\d\\.(.*)") fe <- fe[!grepl(pattern, fe, perl = TRUE)] is_mv <- NULL fe <- fe[!grepl("^Intercept", fe)] cond <- fe[grepl("^(b_|bs_|bsp_|bcs_)(?!zi_)(.*)", fe, perl = TRUE)] zi <- fe[grepl("^(b_zi_|bs_zi_|bsp_zi_|bcs_zi_)", fe, perl = TRUE)] rand <- fe[grepl("(?!.*__(zi|sigma|beta))(?=.*^r_)", fe, perl = TRUE) & !grepl("^prior_", fe, perl = TRUE)] randzi <- fe[grepl("^r_(.*__zi)", fe, perl = TRUE)] rand_sd <- fe[grepl("(?!.*_zi)(?=.*^sd_)", fe, perl = TRUE)] randzi_sd <- fe[grepl("^sd_(.*_zi)", fe, perl = TRUE)] rand_cor <- fe[grepl("(?!.*_zi)(?=.*^cor_)", fe, perl = TRUE)] randzi_cor <- fe[grepl("^cor_(.*_zi)", fe, perl = TRUE)] simo <- fe[grepl("^simo_", fe, perl = TRUE)] car_struc <- fe[fe %in% c("car", "sdcar")] smooth_terms <- fe[grepl("^sds_", fe, perl = TRUE)] priors <- fe[grepl("^prior_", fe, perl = TRUE)] sigma <- fe[grepl("^sigma_", fe, perl = TRUE) | grepl("sigma", fe, fixed = TRUE)] randsigma <- fe[grepl("^r_(.*__sigma)", fe, perl = TRUE)] beta <- fe[grepl("beta", fe, fixed = TRUE)] randbeta <- fe[grepl("^r_(.*__beta)", fe, perl = TRUE)] mix <- fe[grepl("mix", fe, fixed = TRUE)] shiftprop <- fe[grepl("shiftprop", fe, fixed = TRUE)] dispersion <- fe[grepl("dispersion", fe, fixed = TRUE)] auxiliary <- fe[grepl("(shape|phi|precision|_ndt_)", fe)] sigma <- setdiff(sigma, c(cond, rand, rand_sd, rand_cor, randsigma, car_struc, "prior_sigma")) beta <- setdiff(beta, c(cond, rand, rand_sd, randbeta, rand_cor, car_struc)) auxiliary <- setdiff(auxiliary, c(cond, rand, rand_sd, rand_cor, car_struc)) l <- .compact_list(list( conditional = cond, random = c(rand, rand_sd, rand_cor, car_struc), zero_inflated = zi, zero_inflated_random = c(randzi, randzi_sd, randzi_cor), simplex = simo, smooth_terms = smooth_terms, sigma = sigma, sigma_random = randsigma, beta = beta, beta_random = randbeta, dispersion = dispersion, mix = mix, shiftprop = shiftprop, auxiliary = auxiliary, priors = priors )) elements <- .get_elements(effects = effects, component = component) elements <- c(elements, "priors") if (is_multivariate(x)) { rn <- names(find_response(x)) l <- lapply(rn, function(i) { if (.obj_has_name(l, "conditional")) { conditional <- l$conditional[grepl(sprintf("^(b_|bs_|bsp_|bcs_)\\Q%s\\E_", i), l$conditional)] } else { conditional <- NULL } if (.obj_has_name(l, "random")) { random <- l$random[grepl(sprintf("__\\Q%s\\E\\[", i), l$random) | grepl(sprintf("^sd_(.*)\\Q%s\\E\\_", i), l$random) | grepl("^cor_", l$random) | l$random %in% c("car", "sdcar")] } else { random <- NULL } if (.obj_has_name(l, "zero_inflated")) { zero_inflated <- l$zero_inflated[grepl(sprintf("^(b_zi_|bs_zi_|bsp_zi_|bcs_zi_)\\Q%s\\E_", i), l$zero_inflated)] } else { zero_inflated <- NULL } if (.obj_has_name(l, "zero_inflated_random")) { zero_inflated_random <- l$zero_inflated_random[grepl(sprintf("__zi_\\Q%s\\E\\[", i), l$zero_inflated_random) | grepl(sprintf("^sd_(.*)\\Q%s\\E\\_", i), l$zero_inflated_random) | grepl("^cor_", l$zero_inflated_random)] } else { zero_inflated_random <- NULL } if (.obj_has_name(l, "simplex")) { simplex <- l$simplex } else { simplex <- NULL } if (.obj_has_name(l, "sigma")) { sigma <- l$sigma[grepl(sprintf("^sigma_\\Q%s\\E$", i), l$sigma)] } else { sigma <- NULL } if (.obj_has_name(l, "beta")) { beta <- l$beta[grepl(sprintf("^beta_\\Q%s\\E$", i), l$sigma)] } else { beta <- NULL } if (.obj_has_name(l, "dispersion")) { dispersion <- l$dispersion[grepl(sprintf("^dispersion_\\Q%s\\E$", i), l$dispersion)] } else { dispersion <- NULL } if (.obj_has_name(l, "mix")) { mix <- l$mix[grepl(sprintf("^mix_\\Q%s\\E$", i), l$mix)] } else { mix <- NULL } if (.obj_has_name(l, "shape") || .obj_has_name(l, "precision")) { aux <- l$aux[grepl(sprintf("^(shape|precision)_\\Q%s\\E$", i), l$aux)] } else { aux <- NULL } if (.obj_has_name(l, "smooth_terms")) { smooth_terms <- l$smooth_terms } else { smooth_terms <- NULL } if (.obj_has_name(l, "priors")) { priors <- l$priors } else { priors <- NULL } pars <- .compact_list(list( conditional = conditional, random = random, zero_inflated = zero_inflated, zero_inflated_random = zero_inflated_random, simplex = simplex, smooth_terms = smooth_terms, sigma = sigma, beta = beta, dispersion = dispersion, mix = mix, priors = priors, auxiliary = aux )) .compact_list(pars[elements]) }) names(l) <- rn is_mv <- "1" } else { l <- .compact_list(l[elements]) } l <- .filter_pars(l, parameters, !is.null(is_mv) && is_mv == "1") attr(l, "is_mv") <- is_mv if (flatten) { unique(unlist(l)) } else { l } } find_parameters.bayesx <- function(x, component = c("all", "conditional", "smooth_terms"), flatten = FALSE, parameters = NULL, ...) { cond <- rownames(stats::coef(x)) smooth_terms <- rownames(x$smooth.hyp) l <- .compact_list(list( conditional = cond, smooth_terms = smooth_terms )) l <- .filter_pars(l, parameters) component <- match.arg(component) elements <- .get_elements(effects = "all", component) l <- .compact_list(l[elements]) if (flatten) { unique(unlist(l)) } else { l } } find_parameters.stanreg <- function(x, effects = c("all", "fixed", "random"), component = c("location", "all", "conditional", "smooth_terms", "sigma", "distributional", "auxiliary"), flatten = FALSE, parameters = NULL, ...) { fe <- colnames(as.data.frame(x)) cond <- fe[grepl("^(?!(b\\[|sigma|Sigma))", fe, perl = TRUE) & .grep_non_smoothers(fe)] rand <- fe[grepl("^b\\[", fe, perl = TRUE)] rand_sd <- fe[grepl("^Sigma\\[", fe, perl = TRUE)] smooth_terms <- fe[grepl("^smooth_sd", fe, perl = TRUE)] sigma <- fe[grepl("sigma", fe, fixed = TRUE)] auxiliary <- fe[grepl("(shape|phi|precision)", fe)] cond <- setdiff(cond, auxiliary) l <- .compact_list(list( conditional = cond, random = c(rand, rand_sd), smooth_terms = smooth_terms, sigma = sigma, auxiliary = auxiliary )) l <- .filter_pars(l, parameters) effects <- match.arg(effects) component <- match.arg(component) elements <- .get_elements(effects, component) l <- .compact_list(l[elements]) if (flatten) { unique(unlist(l)) } else { l } } find_parameters.bcplm <- function(x, flatten = FALSE, parameters = NULL, ...) { l <- .filter_pars(list(conditional = dimnames(x$sims.list[[1]])[[2]]), parameters) if (flatten) { unique(unlist(l)) } else { l } } find_parameters.stanmvreg <- function(x, effects = c("all", "fixed", "random"), component = c("all", "conditional", "sigma"), flatten = FALSE, parameters = NULL, ...) { fe <- colnames(as.data.frame(x)) rn <- names(find_response(x)) cond <- fe[grepl("^(?!(b\\[|sigma|Sigma))", fe, perl = TRUE) & .grep_non_smoothers(fe) & !grepl("\\|sigma$", fe, perl = TRUE)] rand <- fe[grepl("^b\\[", fe, perl = TRUE)] sigma <- fe[grepl("\\|sigma$", fe, perl = TRUE) & .grep_non_smoothers(fe)] l <- .compact_list(list( conditional = cond, random = rand, sigma = sigma )) if (.obj_has_name(l, "conditional")) { x1 <- sub("(.*)(\\|)(.*)", "\\1", l$conditional) x2 <- sub("(.*)(\\|)(.*)", "\\3", l$conditional) l.cond <- lapply(rn, function(i) { list(conditional = x2[which(x1 == i)]) }) names(l.cond) <- rn } else { l.cond <- NULL } if (.obj_has_name(l, "random")) { x1 <- sub("b\\[(.*)(\\|)(.*)", "\\1", l$random) x2 <- sub("(b\\[).*(.*)(\\|)(.*)", "\\1\\4", l$random) l.random <- lapply(rn, function(i) { list(random = x2[which(x1 == i)]) }) names(l.random) <- rn } else { l.random <- NULL } if (.obj_has_name(l, "sigma")) { l.sigma <- lapply(rn, function(i) { list(sigma = "sigma") }) names(l.sigma) <- rn } else { l.sigma <- NULL } l <- mapply(c, l.cond, l.random, l.sigma, SIMPLIFY = FALSE) l <- .filter_pars(l, parameters, is_mv = TRUE) effects <- match.arg(effects) component <- match.arg(component) elements <- .get_elements(effects, component) l <- lapply(l, function(i) .compact_list(i[elements])) attr(l, "is_mv") <- "1" if (flatten) { unique(unlist(l)) } else { l } } find_parameters.sim.merMod <- function(x, effects = c("all", "fixed", "random"), flatten = FALSE, parameters = NULL, ...) { fe <- colnames(.get_armsim_fixef_parms(x)) re <- colnames(.get_armsim_ranef_parms(x)) l <- .compact_list(list( conditional = fe, random = re )) l <- .filter_pars(l, parameters) effects <- match.arg(effects) elements <- .get_elements(effects, component = "all") l <- .compact_list(l[elements]) if (flatten) { unique(unlist(l)) } else { l } } find_parameters.sim <- function(x, flatten = FALSE, parameters = NULL, ...) { l <- .filter_pars( list(conditional = colnames(.get_armsim_fixef_parms(x))), parameters ) if (flatten) { unique(unlist(l)) } else { l } } find_parameters.mcmc <- function(x, flatten = FALSE, parameters = NULL, ...) { l <- .filter_pars(list(conditional = colnames(x)), parameters) if (flatten) { unique(unlist(l)) } else { l } } find_parameters.bayesQR <- function(x, flatten = FALSE, parameters = NULL, ...) { l <- .filter_pars(list(conditional = x[[1]]$names), parameters) if (flatten) { unique(unlist(l)) } else { l } } find_parameters.stanfit <- function(x, effects = c("all", "fixed", "random"), flatten = FALSE, parameters = NULL, ...) { fe <- colnames(as.data.frame(x)) cond <- fe[grepl("^(?!(b\\[|sigma|Sigma|lp__))", fe, perl = TRUE) & .grep_non_smoothers(fe)] rand <- fe[grepl("^b\\[", fe, perl = TRUE)] l <- .compact_list(list( conditional = cond, random = rand )) l <- .filter_pars(l, parameters) effects <- match.arg(effects) elements <- .get_elements(effects, component = "all") l <- .compact_list(l[elements]) if (flatten) { unique(unlist(l)) } else { l } }
team.and.score.filters = function(x,...){ if(!all(c("scores","teams") %in% names(x))) stop("team.and.score.filters function requires a list with scores and teams data frames.\n", call.=FALSE) team.data = x$teams scores=x$scores names(team.data)=tolower(names(team.data)) names(scores)=tolower(names(scores)) if(!any(names(team.data)=="name")) stop("The teams data frame requires a column named \"name\" for the team (display) name.\n",call.=FALSE) if(!all(c("home.team","away.team") %in% names(scores))) stop("The scores data frame requires columns named \"home.team\" and \"away.team\".\n",call.=FALSE) cc = names(team.data)=="name" all.team.names=team.data[,cc] nteams = length(all.team.names) extra=list(...) names(extra)=tolower(names(extra)) if(any(duplicated(names(extra)))){ duplicated.extra=names(extra)[duplicated(names(extra))] stop(paste("There are duplicated column names passed in for filtering. Names are case insensitive.\nThe duplicated names are:",paste(duplicated.extra,collapse=", ")),call.=FALSE) } if(any(!(names(extra) %in% c(names(team.data),names(scores)))) ){ cat("Extra arguments (besides team and venue) passed in should correspond to columns in the team or match files.\n") cat("The following extra arguments are not in the team or match files (names are not case sensitive): ") bad.vals = names(extra)[!(names(extra) %in% c(names(team.data),names(scores)))] cat(paste(bad.vals,collapse=", ")) cat("\n") stop(call.=FALSE) } if(any((names(extra) %in% names(team.data)) & (names(extra) %in% names(scores))) ){ cat("You cannot filter on names that appear as column names in BOTH the team file and match file.\n") cat("The following appear as column names in both team or match files (names are case sensitive): ") bad.vals = names(extra)[(names(extra) %in% names(team.data)) & (names(extra) %in% names(scores))] cat(paste(bad.vals,collapse=", ")) cat("\n") stop(call.=FALSE) } extra.team = extra[names(extra) %in% names(team.data)] extra.scores = extra[names(extra) %in% names(scores)] extra.team.filter = extra.team for(j in names(extra.team)){ cc = names(team.data)==j if(identical(tolower(extra.team.filter[[j]]),"all")){ extra.team.filter[[j]] = unique(as.vector(as.matrix(team.data[,cc]))) } if(all(!(extra.team.filter[[j]] %in% unique(as.vector(as.matrix(team.data[,cc])))))){ cat(paste("None of the values passed in for ", j, " are in the team file.\n",sep="")) cat("Exiting since nothing would be printed.\n") stop(call.=FALSE) } if(any(!(extra.team.filter[[j]] %in% unique(as.vector(as.matrix(team.data[,cc])))))){ bad.vals = extra.team.filter[[j]][!(extra.team.filter[[j]] %in% unique(as.vector(as.matrix(team.data[,cc]))))] cat(paste("FYI: values ", paste(bad.vals, collapse=",")," passed in for ", j, " are not found in the ", j," column of the ", as.character(match.call()$x),"$teams dataframe.", sep="")) } } extra.scores.filter = extra.scores for(j in names(extra.scores)){ cc = names(scores)==j if(identical(tolower(extra.scores.filter[[j]]),"all")){ extra.scores.filter[[j]] = unique(as.vector(as.matrix(scores[,cc]))) } if(all(!(extra.scores.filter[[j]] %in% unique(as.vector(as.matrix(scores[,cc])))))){ cat(paste("None of the values passed in for ", j, " are in the ", as.character(match.call()$x),"$scores dataframe.\n",sep="")) cat("Exiting since nothing would be printed.\n") stop(call.=FALSE) } if(any(!(extra.scores.filter[[j]] %in% unique(as.vector(as.matrix(scores[,cc])))))){ bad.vals = extra.scores.filter[[j]][!(extra.scores.filter[[j]] %in% unique(as.vector(as.matrix(scores[,cc]))))] cat(paste("FYI: values ", paste(bad.vals, collapse=",")," passed in for ", j, " are not found in the ", j," column of the ", as.character(match.call()$x),"$scores dataframe.", sep="")) cat("\nProceeding using the other values.\n\n") } } team.filter = "all" if(identical(tolower(team.filter),"all")){ cc = tolower(names(team.data))=="name" team.filter = unique(as.vector(as.matrix(team.data[,cc]))) } tmp.fun=function(x,y){ any(x %in% y) } include.extra.team = rep(TRUE,nteams) for(j in names(extra.team)){ filt=extra.team.filter[[j]] include.extra.team = include.extra.team & (team.data[[j]] %in% filt) } include.extra.scores = rep(TRUE,nteams) label.extra.scores = list() for(j in names(extra.scores)){ label.extra.scores[[j]]=list() label.extra.scores[[j]][all.team.names]="" teams.in.this.filter = list() for(i in extra.scores.filter[[j]]){ rows.to.include = scores[scores[[j]]==i,c("home.team", "away.team")] teams.in.this.filter[[i]] = unique(as.vector(as.matrix(rows.to.include))) label.extra.scores[[j]][ teams.in.this.filter[[i]] ]=lapply(label.extra.scores[[j]][teams.in.this.filter[[i]]],paste,i,sep=",") } label.extra.scores[[j]]=lapply(label.extra.scores[[j]],str_sub,2) teams.in.this.filter=unique(unlist(teams.in.this.filter)) include.extra.scores = include.extra.scores & (all.team.names %in% teams.in.this.filter) } cc = tolower(names(team.data))=="name" include.team = apply(team.data[,cc,drop=FALSE], 1, tmp.fun, team.filter) include.teams=all.team.names[(include.team & include.extra.scores & include.extra.team)] scores.filter = names(extra)[names(extra) %in% names(scores)] include.scores=scores$home.team %in% include.teams | scores$away.team %in% include.teams for(sfil in scores.filter){ include.scores=include.scores & (scores[[sfil]] %in% extra[[sfil]]) } return(list(include.teams=include.teams, include.scores=include.scores)) }
thorn <- function( shader, width = NULL, height = NULL, elementId = NULL ) { x = list( shader = match.arg(shader, c( "thorn", "thorn-color", "ikeda", "biomorph1", "biomorph2", "biomorph3", "sweet", "apollony", "smoke", "plasma" )) ) htmlwidgets::createWidget( name = "thorn", x, width = width, height = height, package = "thorn", elementId = elementId ) } thornOutput <- function(outputId, width = "100%", height = "100%"){ htmlwidgets::shinyWidgetOutput( outputId, "thorn", width, height, package = "thorn" ) } renderThorn <- function(expr, env = parent.frame(), quoted = FALSE) { if (!quoted) { expr <- substitute(expr) } htmlwidgets::shinyRenderWidget(expr, thornOutput, env, quoted = TRUE) }
library(amap) url = 'https://docs.google.com/spreadsheets/d/1PWWoMqE5o3ChwJbpexeeYkW6p4BHL9hubVb1fkKSBgA/edit library(gsheet) data = as.data.frame(gsheet2tbl(url)) str(data) head(data) names(data) summary(data) colnames(data) class(data$Age) apply(data, 2, FUN= class) dim(data) head(data) summary(data) names(data) k1 <- amap::Kmeans(data[,-1],centers=3, iter.max = 200,nstart = 1, method = c("euclidean")) k1$centers k1$size k1$withinss k1$cluster k1$centers k1$cluster[9000:9800] table(k1$cluster) k1$size data_clus_2 <- data[ k1$cluster == 2,] (data_clus_2) mean(data_clus_2$Age) data_clus_2$Cust_id write.csv(data_clus_2[,1], file = "./data/data_clus_2.csv")
survfit.rpsftm <- function(object, ...){ if(class(object)[2] != "coxph"){ stop(paste( "No applicable method for 'survfit' applied to an object of class", class(object)[2],"\n") ) }else{ coxfit <- attr( object$ans$f.root, "fit") survival::survfit(coxfit, ...=...) } }
expected <- eval(parse(text="TRUE")); test(id=0, code={ argv <- eval(parse(text="list(list(structure(c(0.445983387275159, 0.0291424961297979, 0.305722673636889, 0.0640910333172597, 6.1841587262516e-05, 0.000608774190997193, 0.00533346072966287, 1.87468589092225, 0.00776943250876635, 0.00695873604736988), .Names = c(\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"10\")), 0), \"any\")")); .Internal(`is.vector`(argv[[1]], argv[[2]])); }, o=expected);
rray_flip <- function(x, axis) { axis <- vec_cast(axis, integer()) validate_axis(axis, x) res <- rray__flip(x, as_cpp_idx(axis)) vec_cast_container(res, x) }
knitr::opts_chunk$set(echo = TRUE) set.seed(1) X <- cbind(1, rnorm(100)) theta_true <- c(1, 1, 1) y <- X %*% theta_true[1:2] + rnorm(100) metropolis <- function(y, X, theta0, S, n_iter, n_burnin, adapt = FALSE) { p <- length(theta0) theta <- matrix(NA, n_iter, p) accept <- numeric(n_iter) mu <- X %*% theta0[1:(p - 1)] posterior <- sum(dnorm(y, mean = mu, sd = theta0[p], log = TRUE)) theta[1, ] <- theta0 for (i in 2:n_iter){ u <- rnorm(p) theta_prop <- theta[i - 1, ] + S %*% u if (theta_prop[p] > 0) { mu <- X %*% theta_prop[1:(p - 1)] posterior_prop <- sum(dnorm(y, mean = mu, sd = theta_prop[p], log = TRUE)) acceptance_prob <- min(1, exp(posterior_prop - posterior)) if (runif(1) < acceptance_prob) { accept[i] <- 1 theta[i, ] <- theta_prop posterior <- posterior_prop }else{ theta[i, ] <- theta[i - 1, ] } } else { theta[i, ] <- theta[i - 1, ] acceptance_prob <- 0 } if(adapt & i <= n_burnin) { S <- ramcmc::adapt_S(S, u, acceptance_prob, i - 1) } } list(theta = theta[(n_burnin + 1):n_iter, ], S = S, acceptance_rate = sum(accept[(n_burnin + 1):n_iter]) / (n_iter - n_burnin)) } mcmc <- metropolis(y, X, c(0, 0, 1), diag(1, 3), 1e4, 1e4/2) mcmc_adapt <- metropolis(y, X, c(0, 0, 1), diag(1, 3), 1e4, 1e4/2, adapt = TRUE) mcmc$acceptance_rate mcmc_adapt$acceptance_rate mcmc_adapt$S hist(mcmc$theta[, 2], main = "theta_2") hist(mcmc_adapt$theta[, 2], main = "theta_2") acf(mcmc$theta) acf(mcmc_adapt$theta)
rcircmix<-function(n,model=NULL,dist=NULL,param=NULL){ if (!is.numeric(n)) stop("argument 'n' must be numeric") if (is.null(model) & is.null(dist)) stop("No model specified") if (!is.null(dist)){ if (length(param)<3 | length(param)>4) stop ("Length of argument 'param' must be 3 or 4") for (i in 1:length(param)){ if (length(dist)!=length(param[[i]])) stop ("Length of the objects of the list 'param' must be equal to the length of argument 'dist'") } if (sum(param[[1]])!=1){ warning ("Proportions must sum 1. Proportions were normalized by the sum") ndist<-length(dist) param[[1]]<-param[[1]]/sum(param[[1]]) } } if (!is.null(model)){ if (!is.numeric(model)) stop("argument 'model' must be numeric") if (!any(model==1:20)) stop("Value specified for argument 'model' is not valid") if (model==1){ dist<-"unif" param <- list(p=1,mu=0,con=0) }else if (model==2){ dist<-"vm" param <- list(p=1,mu=pi,con=1) }else if (model==3){ dist<-"wn" param <- list(p=1,mu=pi,con=0.9) }else if (model==4){ dist<-"car" param <- list(p=1,mu=pi,con=0.5) }else if (model==5){ dist<-"wc" param <- list(p=1,mu=pi,con=0.8) }else if (model==6){ dist<-"wsn" param <- list(p=1,mu=pi,con=1,sk=20) }else if (model==7){ dist<-c("vm","vm") param <- list(p=c(1/2,1/2),mu=c(0,pi),con=c(4,4)) }else if (model==8){ dist<-c("vm","vm") param <- list(p=c(1/2,1/2),mu=c(2,4),con=c(5,5)) }else if (model==9){ dist<-c("vm","vm") param <- list(p=c(1/4,3/4),mu=c(0,pi/sqrt(3)),con=c(2,2)) }else if (model==10){ dist<-c("vm","wc") param <- list(p=c(4/5,1/5),mu=c(pi,4*pi/3),con=c(5,0.9)) }else if (model==11){ dist<-c("vm","vm","vm") param <- list(p=c(1/3,1/3,1/3),mu=c(pi/3,pi,5*pi/3),con=c(6,6,6)) }else if (model==12){ dist<-c("vm","vm","vm") param <- list(p=c(2/5,1/5,2/5),mu=c(pi/2,pi,3*pi/2),con=c(4,4,4)) }else if (model==13){ dist<-c("vm","vm","vm") param <- list(p=c(2/5,2/5,1/5),mu=c(0.5,3,5),con=c(6,6,24)) }else if (model==14){ dist<-c("vm","vm","vm","vm") param <- list(p=c(1/4,1/4,1/4,1/4),mu=c(0,pi/2,pi,3*pi/2),con=c(12,12,12,12)) }else if (model==15){ dist<-c("vm","wc","wn","wsn") param <- list(p=c(1/4,3/10,1/4,1/5),mu=c(pi+2,pi-1,pi+0.5,6),con=c(3,0.6,0.9,1),sk=c(0,0,0,1)) }else if (model==16){ dist<-c("vm","vm","vm","vm","vm") param <- list(p=c(1/5,1/5,1/5,1/5,1/5),mu=c(pi/5,3*pi/5,pi,7*pi/5,9*pi/5),con=c(18,18,18,18,18)) }else if (model==17){ dist<-c("car","wc") param <- list(p=c(2/3,1/3),mu=c(pi,pi),con=c(0.5,0.9),sk=c(0,0)) }else if (model==18){ dist<-c("vm","vm","vm","vm") param <- list(p=c(1/2,1/6,1/6,1/6),mu=c(pi,pi-0.8,pi,pi+0.8),con=c(1,30,30,30)) }else if (model==19){ dist<-c("vm","vm","vm","vm","vm") param <- list(p=c(4/9,5/36,5/36,5/36,5/36),mu=c(2,4,3.5,4,4.5),con=c(3,3,50,50,50)) }else if (model==20){ dist<-c("wc","wc","wsn","wsn") param <- list(p=c(1/6,1/6,1/3,1/3),mu=c(3*pi/4,7*pi/4,0,pi),con=c(0.9,0.9,0.7,0.7),sk=c(0,0,20,20)) } } p <- param[[1]] ind <- as.numeric(cut(runif(n), c(0, cumsum(p)), include.lowest=TRUE)) pos <- split(seq_len(n), ind) nms <- names(pos) result <- rep(NA, n) for (i in seq_along(pos)){ j <- as.numeric(nms[i]) distribution <- dist[j] position <- pos[[i]] npos<-length(position) if (distribution=="unif"){ result[position] <- rcircularuniform(npos) }else if (distribution=="vm"){ result[position] <- rvonmises(npos,mu=circular(param[[2]][j]),kappa=param[[3]][j]) }else if (distribution=="car"){ result[position] <- rcardioid(npos, mu=circular(param[[2]][j]), rho=param[[3]][j]) }else if (distribution=="wc"){ result[position] <- rwrappedcauchy(npos,mu=circular(param[[2]][j]),rho=param[[3]][j]) }else if (distribution=="wn"){ result[position] <- rwrappednormal(npos,mu=circular(param[[2]][j]),rho=param[[3]][j]) }else if (distribution=="wsn"){ result[position] <- rwsn(npos,xi=circular(param[[2]][j]),eta=param[[3]][j],lambda=param[[4]][j]) } } return(circular(result)) }
plot.regsubsets<-function(x,labels=obj$xnames,main=NULL, scale=c("bic","Cp","adjr2","r2"), col=gray(seq(0,0.9,length=10)),...){ obj<-x lsum<-summary(obj) par(mar=c(7,5,6,3)+0.1) nmodels<-length(lsum$rsq) np<-obj$np propscale<-FALSE sscale<-pmatch(scale[1],c("bic","Cp","adjr2","r2"),nomatch=0) if (sscale==0) stop(paste("Unrecognised scale=",scale)) if (propscale) stop(paste("Proportional scaling only for probabilities")) yscale<-switch(sscale,lsum$bic,lsum$cp,lsum$adjr2,lsum$rsq) up<-switch(sscale,-1,-1,1,1) index<-order(yscale*up) colorscale<- switch(sscale, yscale,yscale, -log(pmax(yscale,0.0001)),-log(pmax(yscale,0.0001))) image(z=t(ifelse(lsum$which[index,], colorscale[index],NA+max(colorscale)*1.5)), xaxt="n",yaxt="n",x=(1:np),y=1:nmodels,xlab="",ylab=scale[1],col=col) laspar<-par("las") on.exit(par(las=laspar)) par(las=2) axis(1,at=1:np,labels=labels) axis(2,at=1:nmodels,labels=signif(yscale[index],2)) if (!is.null(main)) title(main=main) box() invisible(NULL) }
hysteresis_plot <- function(dataframe, datetime, q, ssc, base_font_size = 12, legend = "bottom", ...) { stopifnot("Table must be of class 'data.frame'" = "data.frame" %in% class(dataframe)) if (missing(datetime)) { q <- dplyr::enquo(q) ssc <- dplyr::enquo(ssc) dataframe %>% tidyr::drop_na(!!q, !!ssc) %>% dplyr::mutate(Limb = ifelse(dplyr::row_number() %in% c(1:which.max(!!q)), "Rising limb", "Falling limb" )) %>% ggplot2::ggplot(ggplot2::aes(x = !!q, y = !!ssc)) + ggplot2::geom_path(arrow = ggplot2::arrow( length = ggplot2::unit(3, "mm"), ends = "last" )) + ggplot2::geom_point(aes(color = Limb), size = 2 ) + ggplot2::labs( x = expression(italic("Q") * "," ~ m^3 %.% s^-1), y = expression(italic("SSC") * "," ~ g %.% m^-3), color = "" ) + ggplot2::theme( legend.background = ggplot2::element_blank(), legend.key = ggplot2::element_blank(), legend.position = legend, strip.background = ggplot2::element_blank() ) } else { q <- dplyr::enquo(q) datetime <- dplyr::enquo(datetime) ssc <- dplyr::enquo(ssc) dataframe %>% dplyr::arrange(!!datetime) %>% tidyr::drop_na(!!q, !!ssc) %>% dplyr::mutate(Limb = ifelse(dplyr::row_number() %in% c(1:which.max(!!q)), "Rising limb", "Falling limb" )) %>% ggplot2::ggplot(ggplot2::aes(x = !!q, y = !!ssc)) + ggplot2::geom_path(arrow = ggplot2::arrow( length = unit(3, "mm"), ends = "last" )) + ggplot2::geom_point(aes(color = Limb), size = 2 ) + ggplot2::labs( x = expression(italic("Q") * "," ~ m^3 %.% s^-1), y = expression(italic("SSC") * "," ~ g %.% m^-3), color = "" ) + ggplot2::theme( legend.background = ggplot2::element_blank(), legend.key = ggplot2::element_blank(), legend.position = legend, strip.background = ggplot2::element_blank() ) } }
centipede_plot <- function(x, spp, minN2 = 1, mult = 1) { stopifnot(inherits(x, "WA")) N2 <- Hill.N2(spp) %>% enframe(name = "Taxon", value = "n2") opt_tol <- coef(x) %>% as_tibble(rownames = "Taxon") %>% verify(has_all_names("Optima", "Tolerances")) %>% inner_join(N2, by = "Taxon") %>% filter(.data$n2 >= minN2) %>% mutate( Taxon = factor(.data$Taxon), Taxon = fct_reorder(.data$Taxon, .data$Optima), ymin = .data$Optima - .data$Tolerances * mult, ymax = .data$Optima + .data$Tolerances * mult ) g <- ggplot(opt_tol, aes(x = .data$Taxon, y = .data$Optima, ymin = .data$ymin, ymax = .data$ymax)) + geom_errorbar() + geom_point() + coord_flip() return(g) }
BinaryVectorCheck <- function (x) { for (i in 1:length(x)) if (!((x[i] == 0) | (x[i] == 1))) return(FALSE) return(TRUE) }
NULL "CFT15"
plain_tweets <- function(x) { if (is.data.frame(x)) { if (has_name_(x, "text")) { x$text <- plain_tweets_(x$text) } else { stop("Couldn't find \"text\" variable.", call. = FALSE) } } else if (is.list(x)) { if (has_name_(x, "text")) { x$text <- plain_tweets_(x$text) } else { stop("Couldn't find \"text\" variable.", call. = FALSE) } } else { x <- plain_tweets_(x) } x } plain_tweets_ <- function(x) { if (is.factor(x)) { x <- as.character(x) } stopifnot(is.character(x)) x <- rm_links(x) x <- rm_linebreaks(x) x <- rm_fancy_spaces(x) x <- rm_fancy_apostrophes(x) x <- rm_amp(x) x <- enc2ascii(x) trim_ws(x) } rm_fancy_apostrophes <- function(x) gsub(intToUtf8(8217), "'", x) rm_fancy_spaces <- function(x) { gsub("\\t", " ", gsub(intToUtf8(65039), " ", x)) } rm_links <- function(x) { x <- gsub("\\s?https?[[:graph:]]", "", x) gsub("\\s?\\b[[:graph:]]+(\\.com|\\.net|\\.gov|\\.io|\\.org)\\b", "", x) } rm_linebreaks <- function(x, y = " ") { gsub("\\n", y, x) } enc2ascii <- function(x, y = "") { iconv(x, to = "ascii", sub = y) } rm_amp <- function(x, y = "&") { if (is.null(y)) { y <- "" } gsub("&amp;", y, x) } trim_ws <- function(x) { x <- gsub("[ ]{2,}", " ", x) gsub("^[ ]+|[ ]+$", "", x) }
summary.bootnet <- function( object, graph, statistics = c("edge", "intercept", "strength", "closeness", "betweenness","distance"), perNode = FALSE, rank = FALSE, tol = sqrt(.Machine$double.eps), ... ){ if (length(unique(object$sampleTable$graph)) > 1 && missing(graph)){ stop("Argument 'graph' can not be missing when multiple graphs have been estimated.") } if (!missing(graph)){ object$sampleTable <- object$sampleTable[object$sampleTable$graph %in% graph,] object$bootTable <- object$bootTable[object$bootTable$graph %in% graph,] } naTo0 <- function(x){ x[is.na(x)] <- 0 x } if (rank){ object$bootTable$value <- object$bootTable$rank_avg object$sampleTable$value <- object$sampleTable$rank_avg object$bootTable$value_min <- object$bootTable$rank_min object$sampleTable$rank_min <- object$sampleTable$rank_min object$bootTable$value_max <- object$bootTable$rank_max object$sampleTable$value_max <- object$sampleTable$rank_max } else { object$bootTable$value_min <- object$bootTable$value object$sampleTable$rank_min <- object$sampleTable$value object$bootTable$value_max <- object$bootTable$value object$sampleTable$value_max <- object$sampleTable$value } if (!object$type %in% c("person","node")){ if (object$type == "jackknife"){ N <- object$sampleSize tab <- object$bootTable %>% dplyr::filter(.data[['type']] %in% statistics) %>% dplyr::left_join(object$sampleTable %>% dplyr::select(.data[['type']],.data[['id']],.data[['node1']],.data[['node2']],sample = .data[['value']]), by=c("id","type","node1","node2")) %>% dplyr::mutate(PS = N*.data[['sample']] - (N-1)*.data[['value']]) %>% dplyr::group_by(.data[['type']], .data[['node1']], .data[['node2']], .data[['id']]) %>% dplyr::summarize( mean = mean(.data[['value']]), sample = mean(.data[['PS']]), var = (1/(N-1)) * sum((.data[['PS']] - .data[['value']])^2), CIlower = .data[['sample']] - 2 * sqrt(.data[['var']]/N), CIupper = .data[['sample']] + 2 * sqrt(.data[['var']]/N) )%>% dplyr::select(.data[['type']], .data[['id']], .data[['node1']], .data[['node2']], .data[['sample']], .data[['mean']], .data[['CIlower']], .data[['CIupper']]) } else { tab <- object$bootTable %>% dplyr::filter(.data[['type']] %in% statistics) %>% dplyr::group_by(.data[['type']], .data[['node1']], .data[['node2']], .data[['id']]) %>% dplyr::summarize( mean = mean(.data[['value']],na.rm=TRUE), var = var(.data[['value']],na.rm=TRUE), sd = sd(.data[['value']],na.rm=TRUE), prop0 = mean(abs(.data[['value']]) < tol) %>% naTo0, q2.5 = quantile(.data[['value_min']], 2.5/100, na.rm = TRUE, type = 6) %>% naTo0, q97.5 = quantile(.data[['value_max']], 97.5/100, na.rm = TRUE, type = 6) %>% naTo0, q2.5_non0 = quantile(.data[['value_min']][!abs(.data[['value_min']]) < tol], 2.5/100, na.rm = TRUE, type = 6) %>% naTo0, mean_non0 = mean(.data[['value']][!abs(.data[['value']]) < tol], na.rm = TRUE) %>% naTo0, q97.5_non0 = quantile(.data[['value_max']][!abs(.data[['value_max']]) < tol], 97.5/100, na.rm = TRUE, type = 6) %>% naTo0, var_non0 = var(.data[['value']][!abs(.data[['value']]) < tol],na.rm=TRUE) %>% naTo0, sd_non0 = sd(.data[['value']][!abs(.data[['value']]) < tol],na.rm=TRUE) %>% naTo0 ) %>% dplyr::left_join(object$sampleTable %>% dplyr::select(.data[['type']],.data[['id']],.data[['node1']],.data[['node2']],sample = .data[['value']]), by=c("id","type","node1","node2")) %>% dplyr::mutate( CIlower = .data[['sample']]-2*.data[['sd']], CIupper = .data[['sample']] + 2*.data[['sd']], CIlower_non0 = .data[['mean_non0']] - 2*.data[['sd_non0']], CIupper_non0 = .data[['mean_non0']] + 2*.data[['sd_non0']]) %>% dplyr::select(.data[['type']], .data[['id']], .data[['node1']], .data[['node2']], .data[['sample']], .data[['mean']], .data[['sd']], .data[['CIlower']], .data[['CIupper']], .data[['q2.5']], .data[['q97.5']], .data[['q2.5_non0']], .data[['mean_non0']], .data[['q97.5_non0']], .data[['var_non0']], .data[['sd_non0']], .data[['prop0']]) } } else { tab <- object$bootTable %>% dplyr::filter(.data[['type']] %in% statistics) %>% dplyr::left_join(object$sampleTable %>% dplyr::select(.data[['type']],.data[['id']],.data[['node1']],.data[['node2']],sample = .data[['value']]), by=c("id","type","node1","node2")) if (perNode){ tab <- tab %>% group_by(.data[['id']], .data[['type']], .data[['nNode']], .data[['nPerson']]) %>% dplyr::summarize( mean = mean(.data[['value']],na.rm=TRUE), var = var(.data[['value']],na.rm=TRUE), sd = sd(.data[['value']],na.rm=TRUE), q1 = quantile(.data[['value']],1/100, na.rm = TRUE, type = 6) %>% naTo0, q2.5 = quantile(.data[['value']], 2.5/100, na.rm = TRUE, type = 6) %>% naTo0, q5 = quantile(.data[['value']], 5/100, na.rm = TRUE, type = 6) %>% naTo0, q25 = quantile(.data[['value']], 25/100, na.rm = TRUE, type = 6) %>% naTo0, q50 = quantile(.data[['value']], 50/100, na.rm = TRUE, type = 6) %>% naTo0, q75 = quantile(.data[['value']], 75/100, na.rm = TRUE, type = 6) %>% naTo0, q95 = quantile(.data[['value']], 95/100, na.rm = TRUE, type = 6) %>% naTo0, q97.5 = quantile(.data[['value']], 97.5/100, na.rm = TRUE, type = 6) %>% naTo0, q99 = quantile(.data[['value']], 99/100, na.rm = TRUE, type = 6) %>% naTo0, prop0 = mean(abs(.data[['value']]) < tol), q2.5_non0 = quantile(.data[['value']][!abs(.data[['value']]) < tol], 2.5/100, na.rm = TRUE, type = 6) %>% naTo0, mean_non0 = mean(.data[['value']][!abs(.data[['value']]) < tol], na.rm = TRUE) %>% naTo0, q97.5_non0 = quantile(.data[['value']][!abs(.data[['value']]) < tol], 97.5/100, na.rm = TRUE, type = 6) %>% naTo0, var_non0 = var(.data[['value']][!abs(.data[['value']]) < tol],na.rm=TRUE) %>% naTo0, sd_non0 = sd(.data[['value']][!abs(.data[['value']]) < tol],na.rm=TRUE) %>% naTo0 ) %>% mutate( CIlower = .data[['mean']] - 2*.data[['sd']], CIupper = .data[['mean']] + 2*.data[['sd']], CIlower_non0 = .data[['mean_non0']] - 2*.data[['sd_non0']], CIupper_non0 = .data[['mean_non0']] + 2*.data[['sd_non0']] ) %>% arrange(.data[['nNode']],.data[['nPerson']]) } else { tab <- tab %>% group_by(.data[['name']], .data[['type']], .data[['nNode']], .data[['nPerson']]) %>% summarize(cor = suppressWarnings(cor(.data[['value']],sample, use = "pairwise.complete.obs"))) %>% dplyr::group_by(.data[['nNode']], .data[['nPerson']], .data[['type']]) %>% dplyr::summarize( mean = mean(.data[['cor']],na.rm=TRUE), var = var(.data[['cor']],na.rm=TRUE), sd = sd(.data[['cor']],na.rm=TRUE), q1 = quantile(.data[['cor']],1/100, na.rm = TRUE, type = 6) %>% naTo0, q2.5 = quantile(.data[['cor']], 2.5/100, na.rm = TRUE, type = 6) %>% naTo0, q5 = quantile(.data[['cor']], 5/100, na.rm = TRUE, type = 6) %>% naTo0, q25 = quantile(.data[['cor']], 25/100, na.rm = TRUE, type = 6) %>% naTo0, q50 = quantile(.data[['cor']], 50/100, na.rm = TRUE, type = 6) %>% naTo0, q75 = quantile(.data[['cor']], 75/100, na.rm = TRUE, type = 6) %>% naTo0, q95 = quantile(.data[['cor']], 95/100, na.rm = TRUE, type = 6) %>% naTo0, q97.5 = quantile(.data[['cor']], 97.5/100, na.rm = TRUE, type = 6) %>% naTo0, q99 = quantile(.data[['cor']], 99/100, na.rm = TRUE, type = 6) %>% naTo0 ) %>% arrange(.data[['nNode']], .data[['nPerson']]) } } return(tab) }
context("names") test_that("", { x <- c("---", b=2, c=3) y <- c(c=3) out <- iSEE:::.setdiffWithNames(x, y) expect_identical(out, c("---", b = "2")) })
sort_loop_index <- function(loop_list){ sorted_loop_list <- loop_list sorted_loops <- lapply(sorted_loop_list$loop,function(x){ ind_min <- which.min(x) if (ind_min>1){ return(x[c(ind_min:length(x),(2:ind_min))]) } else { return(x) } }) sorted_loop_list$loop <- sorted_loops return(sorted_loop_list) } find_edge <- function(loop_list,source_node,target_node){ vec_is_edge <- vapply(loop_list$loop,function(x){ source_ind <- which(x==source_node) if (length(source_ind)==0){ return(FALSE) } else { if (target_node==x[source_ind[1]+1]){ return(TRUE) } else { return(FALSE) } }},logical(1)) return(which(vec_is_edge)) } loop_summary <- function(loop_list,column_val='length'){ res_mat <- table(loop_list$length) loop_tab <- data.frame( matrix(0,ncol=as.numeric(names(res_mat))[length(names(res_mat))],nrow=3), row.names=c('all','pos','neg')) loop_tab[1,as.numeric(row.names(res_mat))] <- res_mat res_mat_temp <- table(loop_list$length[loop_list$sign==1]) loop_tab[2,as.numeric(row.names(res_mat_temp))] <- res_mat_temp res_mat_temp <- table(loop_list$length[loop_list$sign==-1]) loop_tab[3,as.numeric(row.names(res_mat_temp))] <- res_mat_temp colnames(loop_tab) <- paste0('len_',1:length(loop_tab)) if (column_val == 'sign') { loop_tab <- t(loop_tab[2:3,]) } return(loop_tab) } compare_loop_list <- function(loop_list_a, loop_list_b){ sorted_loop_list_a <- sort_loop_index(loop_list_a) sorted_loop_list_b <- sort_loop_index(loop_list_b) inds_a_in_b <- match(sorted_loop_list_a$loop,sorted_loop_list_b$loop) ind_a_notin <- which(is.na(inds_a_in_b)) ind_a_in <- which(!is.na(inds_a_in_b)) logvec_a_id <- sorted_loop_list_a$sign[ind_a_in] == sorted_loop_list_b$sign[inds_a_in_b[ind_a_in]] return(list('ind_a_id' = ind_a_in[logvec_a_id], 'ind_a_switch' = ind_a_in[!logvec_a_id], 'ind_a_notin' = ind_a_notin, 'ind_b_id' = inds_a_in_b[ind_a_in[logvec_a_id]], 'ind_b_switch' = inds_a_in_b[ind_a_in[!logvec_a_id]])) }
f_weekday <- function(x, distinct = FALSE, ...) { UseMethod('f_weekday') } f_weekday.default <- function(x, distinct = FALSE, ...) { if (distinct){ locs <- match( gsub("(^.)(.)(.+)", "\\U\\1\\L\\2", as.character(x), perl = TRUE), short_weekdays_key ) return(names(short_weekdays_key)[locs]) } toupper(gsub("(^.)(.+)", "\\1", as.character(x))) } f_weekday.numeric <- function(x, distinct = FALSE, ...) { if (distinct) return(names(short_weekdays_key)[x]) c("S", "M", "T", "W", "T", "F", "S")[x] } f_weekday.Date <- function(x, distinct = FALSE, ...) { if (distinct){ locs <- match( gsub("(^.)(.)(.+)", "\\U\\1\\L\\2", weekdays(x), perl = TRUE), short_weekdays_key ) return(names(short_weekdays_key)[locs]) } toupper(gsub("(^.)(.+)", "\\1", weekdays(x))) } f_weekday.POSIXt <- function(x, distinct = FALSE, ...) { if (distinct){ locs <- match( gsub("(^.)(.)(.+)", "\\U\\1\\L\\2", weekdays(x), perl = TRUE), short_weekdays_key ) return(names(short_weekdays_key)[locs]) } toupper(gsub("(^.)(.+)", "\\1", weekdays(x))) } f_weekday.hms <- function(x, distinct = FALSE, ...) { f_weekday.POSIXt(as.POSIXct(x)) } ff_weekday <- function(distinct = FALSE, ...) { function(x) {f_weekday(x, distinct = distinct)} } short_weekdays_key <- structure(c("Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"), .Names = c("Su", "M", "T", "W", "Th", "F", "S")) f_weekday_name <- function(x, ...) { UseMethod('f_weekday_name') } f_weekday_name.default <- function(x, ...) { gsub("(^.)(.+)", "\\U\\1\\L\\2", as.character(x), perl = TRUE) } f_weekday_name.numeric <- function(x, ...) { constant_weekdays[x] } f_weekday_name.Date <- function(x, ...) { weekdays(x) } f_weekday_name.POSIXt <- function(x, ...) { weekdays(x) } f_weekday_name.hms <- function(x, ...) { f_weekday_name.POSIXt(as.POSIXct(x)) } ff_weekday_name <- function(...) { function(x) {f_weekday_name(x)} } f_weekday_abbreviation <- function(x, ...) { UseMethod('f_weekday_abbreviation') } f_weekday_abbreviation.default <- function(x, ...) { gsub("(^.)(.{2})", "\\U\\1\\L\\2", as.character(x), perl = TRUE) } f_weekday_abbreviation.numeric <- function(x, ...) { constant_weekdays_abbreviation[x] } f_weekday_abbreviation.Date <- function(x, ...) { substring(weekdays(x), 1, 3) } f_weekday_abbreviation.POSIXt <- function(x, ...) { substring(weekdays(x), 1, 3) } f_weekday_abbreviation.hms <- function(x, ...) { f_weekday_abbreviation.POSIXt(as.POSIXct(x)) } ff_weekday_abbreviation <- function(...) { function(x) {f_weekday_abbreviation(x)} }
context("stats-smooth.spline") skip_if_not_installed("modeltests") library(modeltests) fit <- smooth.spline(mtcars$wt, mtcars$mpg) test_that("smooth.spline tidier arguments", { check_arguments(glance.smooth.spline) check_arguments(augment.smooth.spline) }) test_that("glance.smooth.spline", { gl <- glance(fit) check_glance_outputs(gl) }) test_that("augment.smooth.spline", { check_augment_function( aug = augment.smooth.spline, model = fit, data = mtcars, strict = FALSE ) })
library(methods) library(ggplot2) library(grid) library(gridExtra) args <- commandArgs(trailingOnly=T) outdir <- 'out' if (length(args) < 2) { cat('Error: please supply at least two commits to generate comparison.\n') quit() } read.stats <- function(rvm, version, timestamp) { filename <- paste(outdir, '/', rvm, '-', version, '.csv', sep='') if (file.exists(filename)) { df <- read.csv(filename) df$rvm <- rvm df$version <- version df$timestamp <- strptime(timestamp, "%Y-%m-%d %H:%M:%S") df } } merge.stats <- function(prev, rvm, version, timestamp) { if (is.data.frame(prev)) { rbind(prev, read.stats(rvm, version, timestamp)) } else { read.stats(rvm, version, timestamp) } } versions <- read.csv(paste(outdir, '/versions', sep=''), header=F) colnames(versions) <- c('commit', 'timestamp') versions <- subset(versions, commit %in% args) cr <- NA cr.jit <- NA rho <- NA rho.jit <- NA for (i in seq_len(nrow(versions))) { commit <- versions$commit[i] timestamp <- versions$timestamp[i] cr <- merge.stats(cr, 'cr', commit, timestamp) cr.jit <- merge.stats(cr.jit, 'cr-jit', commit, timestamp) rho <- merge.stats(rho, 'rho', commit, timestamp) rho.jit <- merge.stats(rho.jit, 'rho-jit', commit, timestamp) } cols <- c('benchmark', 'rvm', 'version', 'timestamp', 'time') report <- rbind(cr[cols], cr.jit[cols], rho[cols], rho.jit[cols]) report <- report[order(report$timestamp),] report$version <- factor(report$version, unique(report$version)) report$time <- report$time / 1000 pdf('comparison.pdf') for (vm in unique(report$rvm)) { report.subset <- subset(report, rvm == vm) print(ggplot(report.subset, aes(x=benchmark, y=time, group=version, fill=version)) + geom_bar(stat='identity', width=0.5, position=position_dodge(0.5)) + expand_limits(y=0) + labs(title=paste('Version Comparison for RVM', vm), y='time (seconds)') + theme(axis.text.x=element_text(angle=90, hjust=1))) } invisible(dev.off())
identify_column <- function(std_name, alt_names, header) { return(which(header %in% c(alt_names[ which(alt_names[ ,1]==std_name), 2], std_name))) }
print.funreg <- function(x, digits=4, show.fits=FALSE, ...) { stopifnot(class(x)=="funreg"); summary1 <- summary(x,digits=digits); cat("funreg Functional Regression\n\n"); cat("Call:\n"); print(x$call.info); cat("\n"); cat("Intercept estimate: "); cat(x$intercept.estimate.uncentered); cat("\n"); if (!is.null(x$other.covariates.estimate)) { cat("Subject-level coefficients:\n"); print(summary1$subject.level.covariates.table,...); } if (show.fits) { cat("Functional coefficients:\n"); print(summary1$functional.covariates.table,...); } if (!show.fits) { cat("\nTo view functional coefficients, use print(...,show.fits=TRUE)"); cat(" or plot(...).\n\n"); } }
GetNetworkGeneMappingResultTable<-function(mSetObj=NA){ load_rsqlite() mSetObj <- .get.mSet(mSetObj); qvec <- mSetObj$dataSet$gene; enIDs <- mSetObj$dataSet$gene.name.map$hit.values; match.state<-mSetObj$dataSet$gene.name.map$match.state; if(length(qvec) > 0){ if(mSetObj$dataSet$q.type.gene == "kos"){ hit.kos <- mSetObj$dataSet$kos.name.map } else{ hit.kos <- doGene2KONameMapping(enIDs) } match.state[is.na(hit.kos) & match.state!=0] <- 2 match.state[!is.na(hit.kos) & match.state==0] <- 2 } else{ mSetObj$dataSet$q.type.gene = "" hit.kos = NULL } pre.style<-NULL; post.style<-NULL; if(mSetObj$dataSet$q.type.gene == "name"){ no.prestyle<-"<strong style=\"background-color:yellow; font-size=125%; color=\"black\">"; no.poststyle<-"</strong>"; } else{ nokos.prestyle<-"<strong style=\"background-color:lightgrey; font-size=125%; color=\"black\">"; nokos.poststyle<-"</strong>"; no.prestyle<-"<strong style=\"background-color:red; font-size=125%; color=\"black\">"; no.poststyle<-"</strong>"; } html.res<-matrix("", nrow=length(qvec), ncol=6); csv.res<-matrix("", nrow=length(qvec), ncol=6); colnames(csv.res)<-c("Query", "Entrez", "Symbol", "KO", "Name", "Comment"); org.code <- mSetObj$org; sqlite.path <- paste0(url.pre, org.code, "_genes.sqlite"); con <- .get.sqlite.con(sqlite.path); ; gene.db <- dbReadTable(con, "entrez") hit.inx <- match(enIDs, gene.db[, "gene_id"]); hit.values<-mSetObj$dataSet$gene.name.map$hit.values; mSetObj$dataSet$gene.name.map$hit.inx <- hit.inx; mSetObj$dataSet$gene.name.map$hit.kos <- hit.kos; hit.kos[is.na(hit.kos)] <- ""; if(length(qvec) > 0){ for (i in 1:length(qvec)){ if(match.state[i]==1){ pre.style<-""; post.style=""; }else if(match.state[i]==2){ pre.style<-nokos.prestyle; post.style<-nokos.poststyle; }else{ pre.style<-no.prestyle; post.style<-no.poststyle; } hit <-gene.db[hit.inx[i], ,drop=F]; html.res[i, ]<-c(paste(pre.style, qvec[i], post.style, sep=""), paste(ifelse(match.state[i]==0 || is.na(hit$gene_id),"-", paste("<a href=http://www.ncbi.nlm.nih.gov/gene/", hit$gene_id, " target='_blank'>",hit$gene_id,"</a>", sep="")), sep=""), paste(ifelse(match.state[i]==0 || is.na(hit$symbol), "-", paste("<a href=http://www.ncbi.nlm.nih.gov/gene/", hit$gene_id, " target='_blank'>", hit$symbol,"</a>", sep="")), sep=""), paste(ifelse(is.na(hit.kos[i]), "-", paste("<a href=http://www.ncbi.nlm.nih.gov/gene/", hit$gene_id, " target='_blank'>", hit.kos[i],"</a>", sep="")), sep=""), paste(ifelse(match.state[i]==0 || is.na(hit$name),"-", paste("<a href=http://www.ncbi.nlm.nih.gov/gene/", hit$gene_id, " target='_blank'>",hit$name,"</a>", sep="")), sep=""), ifelse(match.state[i]!=1,"View","")); csv.res[i, ]<-c(qvec[i], ifelse(match.state[i]==0, "NA", hit$gene_id), ifelse(match.state[i]==0, "NA", hit$symbol), ifelse(is.na(hit.kos[i]), "NA", hit.kos[i]), ifelse(match.state[i]==0, "NA", hit$name), match.state[i]); } } mSetObj$dataSet$gene.map.table <- csv.res; fast.write.csv(csv.res, file="gene_name_map.csv", row.names=F); dbDisconnect(con); if(.on.public.web){ .set.mSet(mSetObj) return(as.vector(html.res)); }else{ return(.set.mSet(mSetObj)); } } PrepareNetworkData <- function(mSetObj=NA){ mSetObj <- .get.mSet(mSetObj); if(!is.null(mSetObj$dataSet$gene.mat)){ gene.mat <- mSetObj$dataSet$gene.mat; enIDs <- mSetObj$dataSet$gene.name.map$hit.values; kos <- mSetObj$dataSet$gene.name.map$hit.kos; rownames(gene.mat) <- enIDs; na.inx <- is.na(kos); gene.mat.clean <- gene.mat[!na.inx, ,drop=F]; kos.clean <- kos[!na.inx] gene.names <- rownames(gene.mat.clean) gene.mat.clean <- RemoveDuplicates(gene.mat.clean); if(nrow(gene.mat.clean) < length(kos.clean)){ mSetObj$dataSet$gene.name.map$hit.kos <- kos.clean[!duplicated(gene.names)] } else{ mSetObj$dataSet$gene.name.map$hit.kos <- kos.clean } AddMsg(paste("A total of ", nrow(gene.mat.clean), "unique genes were uploaded.")); if(!exists("pathinteg.imps", where = mSetObj$dataSet)){ mSetObj$dataSet$pathinteg.imps <- list(); } mSetObj$dataSet$pathinteg.imps$gene.mat <- gene.mat.clean; done <- 1; } if(!is.null(mSetObj$dataSet$gene.mat)){ if(mSetObj$dataSet$q.type.gene == "kos"){ rownames(gene.mat) <- kos gene.mat <- RemoveDuplicates(gene.mat); mSetObj$dataSet$gene.name.map$hit.kos <- rownames(gene.mat) AddMsg(paste("A total of ", nrow(gene.mat), "unique KOs were uploaded.")); if(!exists("pathinteg.imps", where = mSetObj$dataSet)){ mSetObj$dataSet$pathinteg.imps <- list(); } mSetObj$dataSet$pathinteg.imps$kos.mat <- gene.mat; done <- 1; } else{ mSetObj$dataSet$pathinteg.imps$kos.mat <- mSetObj$dataSet$pathinteg.imps$gene.mat; } } if((!is.null(mSetObj$dataSet$cmpd.mat) || (!is.null(mSetObj$dataSet$cmpd)))){ nm.map <- GetFinalNameMap(mSetObj); my.ids <- ifelse(is.na(nm.map$kegg), paste("unmapped", rownames(nm.map), sep = "_"), nm.map$kegg); mSetObj$dataSet$orig.var.ids <- my.ids; valid.inx <- !(is.na(nm.map$kegg)| duplicated(nm.map$kegg)); cmpd.vec <- nm.map$query[valid.inx]; kegg.id <- nm.map$kegg[valid.inx]; cmpd.mat <- mSetObj$dataSet$cmpd.mat; if(is.null(mSetObj$dataSet$cmpd.mat)){ cmpd <- as.matrix(mSetObj$dataSet$cmpd); cmpd.mat <- cbind(cmpd, rep("0", nrow(cmpd))) } hit.inx <- match(cmpd.vec, rownames(cmpd.mat)); cmpd.mat <- cmpd.mat[hit.inx, ,drop=F]; rownames(cmpd.mat) <- kegg.id; cmpd.mat <- RemoveDuplicates(cmpd.mat); AddMsg(paste("A total of ", nrow(cmpd.mat), "unique compounds were found.")); mSetObj$dataSet$pathinteg.imps$cmpd.mat <- cmpd.mat; done <- 1; } return(.set.mSet(mSetObj)); } PrepareQueryJson <- function(mSetObj=NA){ mSetObj <- .get.mSet(mSetObj); kos <- mSetObj$dataSet$gene.name.map$hit.kos expr.mat <- mSetObj$dataSet$pathinteg.imps$kos.mat kos <- cbind(kos, expr.mat) cmpds.expr <- mSetObj$dataSet$pathinteg.imps$cmpd.mat cmpds <- cbind(rownames(cmpds.expr), cmpds.expr) enrich.type <- "hyper"; gene.mat <- list() if(length(kos) > 0){ dataSet.gene <- PerformMapping(kos, "ko") if(length(dataSet.gene)==0){ return(0); } if(enrich.type == "hyper"){ exp.vec <- dataSet.gene$data[,1]; }else{ genemat <- as.data.frame(t(otu_table(dataSet.gene$norm.phyobj))); exp.vec <- rep(2, ncol(genemat)); names(exp.vec) <- colnames(genemat); } gene.mat <- MapKO2KEGGEdges(exp.vec); } cmpd.mat <- list() if(length(cmpds) > 1){ dataSet.cmpd <- PerformMapping(cmpds, "cmpd") if(length(dataSet.cmpd)==0){ return(0); } if(enrich.type == "hyper"){ exp.vec <- dataSet.cmpd$data[,1]; }else{ genemat <- as.data.frame(t(otu_table(dataSet.cmpd$norm.phyobj))); exp.vec <- rep(2, ncol(genemat)); names(exp.vec) <- colnames(genemat); } cmpd.mat <- MapCmpd2KEGGNodes(exp.vec); } if(length(cmpd.mat) != 0 && length(gene.mat) != 0){ edge.mat <- as.data.frame(rbind(as.matrix(cmpd.mat), as.matrix(gene.mat))); dataSet <<- MergeDatasets(dataSet.cmpd, dataSet.gene); idtype <<- "gene&cmpd"; } else if(length(cmpd.mat) != 0){ edge.mat <- cmpd.mat; dataSet <<- dataSet.cmpd; idtype <<- "cmpd"; } else{ edge.mat <- gene.mat; dataSet <<- dataSet.gene; idtype <<- "gene"; } row.names(edge.mat) <- eids <- rownames(edge.mat); query.ko <- edge.mat[,1]; net.orig <- edge.mat[,2]; query.res <- edge.mat[,3]; names(query.res) <- eids; json.mat <- RJSONIO::toJSON(query.res, .na='null'); sink("network_query.json"); cat(json.mat); sink(); return(.set.mSet(mSetObj)); } doGene2KONameMapping <- function(enIDs){ if(.on.public.web){ ko.dic <- .readDataTable("../../libs/network/ko_dic.csv"); }else{ ko.dic <- .readDataTable("https://www.metaboanalyst.ca/resources/libs/network/ko_dic.csv"); } ko.dic.enIDs <- as.integer(ko.dic[, "Entrez_hsa"]) ko.dic.enIDs[is.na(ko.dic.enIDs)] <- -1 hit.inx <- match(as.integer(enIDs), ko.dic.enIDs); kos <- ko.dic[hit.inx, "KO"]; na.inx <- is.na(kos); kos[na.inx] <- NA return(kos); } MatchQueryOnKEGGMap <- function(query, ko.map){ hits <- lapply(query, function(x) { as.character(unique(ko.map$edge[ko.map$queryid%in%unlist(x)])); } ); return(hits) } Save2KEGGJSON <- function(hits.query, res.mat, file.nm, hits.all){ resTable <- data.frame(Pathway=rownames(res.mat), res.mat); AddMsg("Functional enrichment analysis was completed"); if(!exists("ko.edge.map")){ if(.on.public.web){ ko.edge.path <- paste("../../libs/network/ko_edge.csv", sep=""); ko.edge.map <- .readDataTable(ko.edge.path); }else{ ko.edge.path <- paste("https://www.metaboanalyst.ca/resources/libs/network/ko_edge.csv", sep=""); download.file(ko.edge.path, destfile = "ko_edge.csv", method="libcurl", mode = "wb") ko.edge.map <- .readDataTable("ko_edge.csv"); } ko.edge.map <- ko.edge.map[ko.edge.map$net=="ko01100",]; ko.edge.map <<- ko.edge.map; } hits.edge <- list(); hits.node <- list(); hits.edge.all <- list(); hits.node.all <- list(); if(idtype == "gene"){ ko.map <- ko.edge.map; colnames(ko.map) <- c("queryid", "edge", "net") hits.edge <- MatchQueryOnKEGGMap(hits.query, ko.map) hits.inx <- unlist(lapply(hits.edge, length))>0; hits.edge.all <- MatchQueryOnKEGGMap(hits.all, ko.map) hits.inx.all <- unlist(lapply(hits.edge.all, length))>0; }else if(idtype == "cmpd"){ ko.map <- ko.node.map.global; colnames(ko.map) <- c("queryid", "edge", "net") hits.node <- MatchQueryOnKEGGMap(hits.query, ko.map) hits.inx <- unlist(lapply(hits.node, length))>0; hits.node.all <- MatchQueryOnKEGGMap(hits.all, ko.map) hits.inx.all <- unlist(lapply(hits.node.all, length))>0; }else{ ko.map1 <- ko.edge.map; colnames(ko.map1) <- c("queryid", "edge", "net"); rownames(ko.map1)<-NULL; hits.edge <- MatchQueryOnKEGGMap(hits.query, ko.map1) hits.edge.all <- MatchQueryOnKEGGMap(hits.all, ko.map1) ko.map2 <- ko.node.map.global; colnames(ko.map2) <- c("queryid", "edge", "net"); rownames(ko.map2)<-NULL; hits.node <- MatchQueryOnKEGGMap(hits.query, ko.map2) hits.node.all <- MatchQueryOnKEGGMap(hits.all, ko.map2) ko.map <- rbind(ko.map1, ko.map2) hits.both <- MatchQueryOnKEGGMap(hits.query, ko.map) hits.inx <- unlist(lapply(hits.both, length))>0; hits.both <- MatchQueryOnKEGGMap(hits.all, ko.map) hits.inx.all <- unlist(lapply(hits.both, length))>0; } hits.query <- hits.query[hits.inx]; hits.all <- hits.all[hits.inx.all]; resTable <- resTable[hits.inx, ]; fun.pval = resTable$Pval; if(length(fun.pval) ==1) { fun.pval <- matrix(fun.pval) }; hit.num = resTable$Hits; if(length(hit.num) ==1) { hit.num <- matrix(hit.num) }; fun.ids <- as.vector(current.setids[names(hits.query)]); if(length(fun.ids) ==1) { fun.ids <- matrix(fun.ids) }; rm.ids <- which(is.na(fun.ids)) if(length(rm.ids) != 0){ fun.ids <- fun.ids[-rm.ids] fun.pval <- fun.pval[-rm.ids] hit.num <- hit.num[-rm.ids] hits.query <- hits.query[-rm.ids] } expr = as.list(dataSet$data) names(expr) <- rownames(dataSet$data) json.res <- list( expr.mat = expr, hits.query = hits.query, hits.edge = hits.edge, hits.node = hits.node, hits.all = hits.all, hits.edge.all = hits.edge.all, hits.node.all = hits.node.all, path.id = fun.ids, fun.pval = fun.pval, hit.num = hit.num ); json.mat <- RJSONIO::toJSON(json.res, .na='null'); json.nm <- paste(file.nm, ".json", sep=""); sink(json.nm) cat(json.mat); sink(); fun.hits <<- hits.query; fun.pval <<- resTable[,5]; hit.num <<- resTable[,4]; csv.nm <- paste(file.nm, ".csv", sep=""); fast.write.csv(resTable, file=csv.nm, row.names=F); } LoadKEGGKO_lib<-function(category){ if(category == "module"){ kegg.anot <- .get.my.lib("ko_modules.qs", "network"); current.setlink <- kegg.anot$link; current.mset <- kegg.anot$sets$"Pathway module"; }else{ kegg.anot <- .get.my.lib("ko_pathways.qs", "network"); current.setlink <- kegg.anot$link; current.mset <- kegg.anot$sets$Metabolism; } if(!exists("ko.edge.map")){ if(.on.public.web){ ko.edge.path <- paste("../../libs/network/ko_edge.csv", sep=""); ko.edge.map <<- .readDataTable(ko.edge.path); }else{ ko.edge.path <- paste("https://www.metaboanalyst.ca/resources/libs/network/ko_edge.csv", sep=""); download.file(ko.edge.path, destfile = "ko_edge.csv", method="libcurl", mode = "wb") ko.edge.map <<- .readDataTable("ko_edge.csv"); } } kos.01100 <- ko.edge.map$gene[ko.edge.map$net == "ko01100"]; current.mset <- lapply(current.mset, function(x) { as.character(unique(x[x %in% kos.01100])); } ); mset.ln <- lapply(current.mset, length); current.mset <- current.mset[mset.ln > 0]; set.ids<- names(current.mset); names(set.ids) <- names(current.mset) <- kegg.anot$term[set.ids]; current.setlink <<- current.setlink; current.setids <<- set.ids; current.geneset <<- current.mset; } .preparePhenoListSeeds <- function(mSetObj, table.nm){ if(.on.public.web){ libs.path <<- "../../libs/"; }else{ libs.path <<- "https://www.metaboanalyst.ca/resources/libs/"; } table.nm <<- table.nm; mSetObj <- .get.mSet(mSetObj); cmpds <- rownames(mSetObj$dataSet$pathinteg.imps$cmpd.mat); seed.compounds <- cmpds; seed.expr.compounds <- as.vector(mSetObj$dataSet$pathinteg.imps$cmpd.mat[,1]); genes <- rownames(mSetObj$dataSet$pathinteg.imps$gene.mat); if(length(genes) == 0){ seed.genes <- c(); seed.expr.genes <- c(); } else { seed.genes <- genes; seed.expr.genes <- as.vector(mSetObj$dataSet$pathinteg.imps$gene.mat[,1]); } if((table.nm == "metabo_phenotypes") || (table.nm == "metabo_metabolites")){ seed.graph <<- seed.compounds; seed.expr <<- seed.expr.compounds; } else { seed.graph <<- c(seed.compounds, seed.genes); seed.expr <<- c(seed.expr.compounds, seed.expr.genes); } list( genes = genes, cmpds = cmpds ); } doKOFiltering <- function(ko.vec, type){ if(.on.public.web){ ko.dic <- .readDataTable("../../libs/network/ko_dic.csv"); }else{ ko.dic <- .readDataTable("https://www.metaboanalyst.ca/resources/libs/network/ko_dic.csv"); } hit.inx <- match(ko.vec, ko.dic$KO); return(ko.dic$KO[hit.inx]); } MapKO2KEGGEdges<- function(kos, net="ko01100"){ if(!exists("ko.edge.map")){ if(.on.public.web){ ko.edge.path <- paste("../../libs/network/ko_edge.csv", sep=""); ko.edge.map <<- .readDataTable(ko.edge.path); }else{ ko.edge.path <- paste("https://www.metaboanalyst.ca/resources/libs/network/ko_edge.csv", sep=""); ko.edge.map <<- .readDataTable(ko.edge.path); } } all.hits <- ko.edge.map$gene %in% names(kos) & ko.edge.map$net == net; my.map <- ko.edge.map[all.hits, ]; q.map <- data.frame(gene=names(kos), expr=as.numeric(kos)); dat <- merge(my.map, q.map, by="gene"); dup.inx <- duplicated(dat[,2]); dat <- dat[!dup.inx,]; rownames(dat) <- dat[,2]; return(dat[,-2]); } MapCmpd2KEGGNodes <- function(cmpds, net="ko01100"){ lib <- "hsa_kegg.qs" if(!exists("ko.node.map.global")){ if(.on.public.web){ pathway.lib <- qs::qread(paste("../../libs/mummichog/", lib, sep="")); }else{ if(!file.exists(lib)){ path.url <- paste("https://www.metaboanalyst.ca/resources/libs/mummichog/", lib, sep="") download.file(path.url, destfile = lib, method="libcurl", mode = "wb") pathway.lib <- qs::qread(lib); }else{ pathway.lib <- qs::qread(lib); } } pathways <- pathway.lib$pathways; names(pathways$cpds) <- pathways$name current.cmpd.set <<- pathways$cpds; if(.on.public.web){ ko.pathway.names <- .readDataTable(paste("../../libs/network/ko01100_compounds_ids.csv", sep="")); }else{ ko.pathway.names <- .readDataTable(paste("https://www.metaboanalyst.ca/resources/libs/network/ko01100_compounds_ids.csv", sep="")); } ko.node.map.global <<- data.frame(cmpd = ko.pathway.names[,1], edge = ko.pathway.names[,2], net = rep("ko01100", nrow(ko.pathway.names))) } all.hits <- ko.node.map.global$cmpd %in% names(cmpds) & ko.node.map.global$net == net; my.map <- ko.node.map.global[all.hits, ]; q.map <- data.frame(cmpd=names(cmpds), expr=as.numeric(cmpds)); dat <- merge(my.map, q.map, by="cmpd"); dup.inx <- duplicated(dat[,2]); dat <- dat[!dup.inx,]; rownames(dat) <- dat[,2]; return(dat[,-2]); } PerformMapping <- function(inputIDs, type){ dataSet <- list(); dataSet$orig <- inputIDs; data.mat <- as.matrix(inputIDs); if(dim(data.mat)[2] == 1){ data.only <- 1; data.mat <- cbind(data.mat, rep(1, nrow(data.mat))); }else { data.only <- 0; data.mat <- data.mat[,1:2]; } if(!is.matrix(data.mat)){ data.mat <- as.matrix(t(data.mat)) } rownames(data.mat) <- data.mat[,1]; data.mat <- data.mat[,-1, drop=F]; dataSet$id.orig <- data.mat; dataSet$data.only <- data.only; data.mat <- RemoveDuplicates(data.mat, "sum", quiet=F); dataSet$id.uniq <- data.mat; if(type == "ko"){ kos <- doKOFiltering(rownames(data.mat), type); if(sum(!is.na(kos)) < 2){ AddErrMsg("Less than two hits found in the database. "); dataSet <- list(); return(dataSet); } rownames(data.mat) <- kos; gd.inx <- (!is.na(kos)) & data.mat[,1] > -Inf; data.mat <- data.mat[gd.inx, ,drop=F]; AddMsg(paste("A total of unqiue", nrow(data.mat), "KO genes were mapped to KEGG network!")); } dataSet$id.mapped <- dataSet$data <- data.mat; return(dataSet); } MergeDatasets <- function(dataSet1, dataSet2){ dataSet <- list(); dataSet$orig <- c(dataSet1$orig, dataSet2$orig); dataSet$id.orig <- rbind(dataSet1$id.orig, dataSet2$id.orig) dataSet$id.uniq <- rbind(dataSet1$id.uniq, dataSet2$id.uniq) dataSet$data <- rbind(dataSet1$data, dataSet2$data) dataSet$id.mapped <- rbind(dataSet1$id.mapped, dataSet2$id.mapped) return(dataSet); }
"LongDat_cont_master_table"
DLR <- function(basemodel, augmentedmodel, diseasestatus, dataset, clustervar=NULL, alpha=0.05) { d <- diseasestatus x <- formula(basemodel) v <- formula(augmentedmodel) dat <- dataset dat[,d] <- as.numeric(as.character(dat[,d])) xterms <- paste(attr(terms(x),"term.labels"),collapse="+") yterms <- paste(setdiff(attr(terms(v),"term.labels"),attr(terms(x),"term.labels")),collapse="+") v <- formula(paste("~",paste(xterms,yterms,sep="+"))) if (!is.null(clustervar)) dat$subjid <- dat[,clustervar] else dat$subjid <- 1:nrow(dat) datdup <- rbind(dat,dat) datdup$indicator <- rep(1:0,each=nrow(dat)) x.modelmatrix <- model.matrix(x, datdup) colnames(x.modelmatrix) <- make.names(gsub(".Intercept.","intercept",paste("x",colnames(x.modelmatrix),sep="."))) dim.x <- ncol(x.modelmatrix) v.modelmatrix <- model.matrix(v, datdup) colnames(v.modelmatrix) <- make.names(gsub(".Intercept.","intercept",paste("v",colnames(v.modelmatrix),sep="."))) dim.v <- ncol(v.modelmatrix) z <- data.frame((1 - datdup$indicator) * x.modelmatrix, datdup$indicator * v.modelmatrix) datdup <- cbind(datdup,z) datdup <- datdup[order(datdup$subjid),] gee_xv <- gee(as.formula(paste("d ~ ", paste(colnames(z),collapse="+"),"-1")), data=datdup, corstr="independence",family=binomial, id=datdup$subjid, maxiter=100, tol=1e-5) coefs <- coef(gee_xv) robvcov <- gee_xv$robust.variance coef_logDLR <- coefs[colnames(v.modelmatrix)] coef_logDLR[1:dim.x] <- coef_logDLR[1:dim.x] - coefs[colnames(x.modelmatrix)] names(coef_logDLR) <- substr(names(coef_logDLR),3,100) I.x.matrix <- diag(1,dim.x) Z.x.matrix <- diag(0,nrow=dim.x, ncol=dim.v - dim.x) I.v.matrix <- diag(1,dim.v - dim.x) Z.v.matrix <- diag(0,ncol=dim.x, nrow=dim.v - dim.x) A.matrix <- rbind(cbind(-I.x.matrix,I.x.matrix,Z.x.matrix),cbind(Z.v.matrix,Z.v.matrix,I.v.matrix)) robSE_logDLR <- sqrt(diag(A.matrix %*% robvcov %*% t(A.matrix))) robZstat_logDLR <- coef_logDLR/robSE_logDLR pvalues <- 2 * pnorm(abs(robZstat_logDLR), lower.tail = FALSE) lowerci_logDLR <- coef_logDLR - qnorm(1-alpha/2) * robSE_logDLR upperci_logDLR <- coef_logDLR + qnorm(1-alpha/2) * robSE_logDLR logPreTestResults <- summary(gee_xv)$coefficients[colnames(x.modelmatrix),,drop=F] logPostTestResults <- summary(gee_xv)$coefficients[colnames(v.modelmatrix),,drop=F] logDLRResults <- data.frame(coefs=coef_logDLR,robustSE=robSE_logDLR,Zstat=robZstat_logDLR,pvalue=pvalues,lowerCI=lowerci_logDLR,upperCI=upperci_logDLR) xoneyone <- rep(1,ncol(v.modelmatrix)) xoneyzero <- c(rep(1,ncol(x.modelmatrix)),rep(0,ncol(v.modelmatrix)-ncol(x.modelmatrix))) logDLR_pos <- coef_logDLR %*% xoneyone logDLR_neg <- coef_logDLR %*% xoneyzero DLRy_pos <- exp(logDLR_pos) DLRy_neg <- exp(logDLR_neg) SE_logDLR_pos <- sqrt(xoneyone %*% A.matrix %*% robvcov %*% t(A.matrix) %*% xoneyone) SE_logDLR_neg <- sqrt(xoneyzero %*% A.matrix %*% robvcov %*% t(A.matrix) %*% xoneyzero) lowerCI_DLRy_pos <- exp(logDLR_pos - qnorm(1-alpha/2) * SE_logDLR_pos) upperCI_DLRy_pos <- exp(logDLR_pos + qnorm(1-alpha/2) * SE_logDLR_pos) lowerCI_DLRy_neg <- exp(logDLR_neg - qnorm(1-alpha/2) * SE_logDLR_neg) upperCI_DLRy_neg <- exp(logDLR_neg + qnorm(1-alpha/2) * SE_logDLR_neg) DLR_results <- data.frame(rbind(c(DLRy_pos,lowerCI_DLRy_pos,upperCI_DLRy_pos), c(DLRy_neg,lowerCI_DLRy_neg,upperCI_DLRy_neg))) colnames(DLR_results) <- c("DLR","lowerCI","upperCI") rownames(DLR_results) <- c("DLR(Y=1|X=1)","DLR(Y=0|X=1)") return(list("logPreTestModel" = logPreTestResults, "logPostTestModel" = logPostTestResults, "logDLRModel" = logDLRResults, "DLR" = DLR_results)) }
context("test-Gapfill") test_that("Gapfill demo",{ data <- ndvi[,,2:4,2:4] expect_message(fill <- Gapfill(data)$fill, "data has 3969 values: 3301 \\(83%\\) observed\n 668 \\(17%\\) missing\n 668 \\(17%\\) to predict\n") ref <- c(0.5174, 0.4835, 0.4992, 0.4933, 0.5401, 0.5348, 0.5484, 0.5189, 0.5161, 0.5044, 0.5449, 0.5391, 0.5376, 0.5401, 0.5599, 0.5784, 0.5606, 0.5794, 0.5618, 0.549, 0.5527, 0.528, 0.5639, 0.5186, 0.5327, 0.5046, 0.5117, 0.5283, 0.5359, 0.5265, 0.5484, 0.5316, 0.5475, 0.5387, 0.5026, 0.5554, 0.5165, 0.5469, 0.5327, 0.5173, 0.5194, 0.5205, 0.5114, 0.5049, 0.6921, 0.6417, 0.6258, 0.5182, 0.5268, 0.5145, 0.5119, 0.6025, 0.6023, 0.6451, 0.6608, 0.6474, 0.1218, 0.6017, 0.5877, 0.5938, 0.5896, 0.5986, 0.5624, 0.5225, 0.6061, 0.6154, 0.6206, 0.538, 0.5798, 0.5975, 0.483, 0.3553, 0.106, 0.1356, 0.5996, 0.6154, 0.6068, 0.6003, 0.5892, 0.5627, 0.4892, 0.4969, 0.5023, 0.4835, 0.5152, 0.5015, 0.5026, 0.5634, 0.589, 0.5513, 0.5566, 0.5488, 0.498, 0.5086, 0.5359, 0.4947, 0.513, 0.5157, 0.5154, 0.5118, 0.5147, 0.4978, 0.5092, 0.5193, 0.517, 0.53, 0.5105, 0.5714, 0.5994, 0.5891, 0.5479, 0.5, 0.4909, 0.5048, 0.5172, 0.5265, 0.5139, 0.5419, 0.5306, 0.5454, 0.5418, 0.5147, 0.51, 0.5225, 0.4955, 0.5066, 0.4783, 0.55, 0.5435, 0.5617, 0.5341, 0.5305, 0.575, 0.5799, 0.6121, 0.5891, 0.5742, 0.5238, 0.5259, 0.5112, 0.5139, 0.5094, 0.4944, 0.4971, 0.5021, 0.5086, 0.521, 0.5484, 0.5463, 0.5306, 0.5619, 0.5345, 0.5191, 0.474, 0.4882, 0.5132, 0.5639, 0.5304, 0.5082, 0.5171, 0.5433, 0.5166, 0.5481, 0.5154, 0.4917, 0.5335, 0.5291, 0.501, 0.4922, 0.5021, 0.5027, 0.5031, 0.4912, 0.4912, 0.5, 0.4662, 0.513, 0.5086, 0.5439, 0.534, 0.5404, 0.56, 0.5291, 0.5154, 0.5328, 0.4734, 0.4885, 0.48, 0.503, 0.4896, 0.4752, 0.4971, 0.5097, 0.5115, 0.5576, 0.4911, 0.5161, 0.5591, 0.5358, 0.5429, 0.4597, 0.4793, 0.4903, 0.509, 0.5074, 0.4967, 0.4847, 0.4967, 0.5123, 0.4974, 0.5013, 0.498, 0.5123, 0.5082, 0.5395, 0.5772, 0.4417, 0.4627, 0.452, 0.4895, 0.4881, 0.4886, 0.5082, 0.5334, 0.5033, 0.4896, 0.4862, 0.4904, 0.5129, 0.5154, 0.5434, 0.5611, 0.5449, 0.5651, 0.515, 0.4517, 0.4686, 0.4963, 0.4941, 0.5121, 0.522, 0.5307, 0.5221, 0.4562, 0.5129, 0.5382, 0.5382, 0.5125, 0.4859, 0.5577, 0.5401, 0.5024, 0.543, 0.515, 0.4834, 0.5006, 0.4966, 0.5089, 0.5131, 0.5121, 0.4965, 0.4476, 0.4553, 0.4488, 0.4939, 0.5068, 0.4816, 0.483, 0.4852, 0.5604, 0.5286, 0.4978, 0.5539, 0.531, 0.5184, 0.5112, 0.5125, 0.5014, 0.4891, 0.4968, 0.4632, 0.4674, 0.4323, 0.4288, 0.4335, 0.4388, 0.4708, 0.5581, 0.5765, 0.6183, 0.5994, 0.6213, 0.6343, 0.6095, 0.6081, 0.6284, 0.6953, 0.6971, 0.6904, 0.6906, 0.6709, 0.6804, 0.6813, 0.69, 0.6829, 0.681, 0.6687, 0.6595, 0.7472, 0.692, 0.6792, 0.6774, 0.6672, 0.6771, 0.6724, 0.6667, 0.6676, 0.6674, 0.6769, 0.6811, 0.6715, 0.6882, 0.6779, 0.6735, 0.6752, 0.6834, 0.6688, 0.6972, 0.6797, 0.7078, 0.6988, 0.7209, 0.336, 0.6807, 0.6741, 0.6751, 0.6575, 0.6856, 0.7248, 0.6562, 0.5671, 0.4942, 0.3961, 0.5152, 0.661, 0.6663, 0.6503, 0.6672, 0.6625, 0.6682, 0.6961, 0.7043, 0.6805, 0.6782, 0.7169, 0.7082, 0.6794, 0.6649, 0.6733, 0.676, 0.6746, 0.6721, 0.681, 0.6737, 0.69, 0.6868, 0.6754, 0.6798, 0.6817, 0.6833, 0.6735, 0.6673, 0.6746, 0.6547, 0.6617, 0.6418, 0.7021, 0.7069, 0.6906, 0.6809, 0.6682, 0.666, 0.6676, 0.6589, 0.6573, 0.662, 0.6732, 0.6802, 0.6941, 0.69, 0.6952, 0.6819, 0.6755, 0.6791, 0.6933, 0.6756, 0.6596, 0.6847, 0.6759, 0.6777, 0.6811, 0.6598, 0.6426, 0.673, 0.6887, 0.7013, 0.6828, 0.6744, 0.6813, 0.7273, 0.7482, 0.6751, 0.6795, 0.7043, 0.6786, 0.6592, 0.6593, 0.6797, 0.6816, 0.6676, 0.6782, 0.6639, 0.6624, 0.673, 0.6689, 0.6691, 0.6715, 0.672, 0.6438, 0.6362, 0.6569, 0.6612, 0.6698, 0.6828, 0.6929, 0.7029, 0.6924, 0.6832, 0.64, 0.6497, 0.6659, 0.6754, 0.6755, 0.6948, 0.6884, 0.6702, 0.6922, 0.6795, 0.6759, 0.66, 0.6622, 0.6749, 0.671, 0.6814, 0.6834, 0.6829, 0.6841, 0.6581, 0.6946, 0.684, 0.6775, 0.683, 0.6867, 0.6764, 0.6618, 0.6656, 0.6814, 0.6764, 0.6935, 0.7244, 0.7547, 0.684, 0.6912, 0.7071, 0.7163, 0.711, 0.7157, 0.7234, 0.7245, 0.7238, 0.7137, 0.5642, 0.5782, 0.4921, 0.5331, 0.6679, 0.6728, 0.6439, 0.6262, 0.6396, 0.6421, 0.6514, 0.6543, 0.6587, 0.6606, 0.6716, 0.7027, 0.7399, 0.7617, 0.7475, 0.4389, 0.5384, 0.3841, 0.4055, 0.3929, 0.7325, 0.7033, 0.7022, 0.7005, 0.7518, 0.7401, 0.6875, 0.6867, 0.6853, 0.6947, 0.6957, 0.6844, 0.6741, 0.6972, 0.7087, 0.7049, 0.7015, 0.6993, 0.7212, 0.7298, 0.7366, 0.7053, 0.6669, 0.6736, 0.6943, 0.697, 0.6984, 0.6981, 0.6864, 0.6899, 0.6765, 0.662, 0.6898, 0.6937, 0.7049, 0.7017, 0.7418, 0.6769, 0.6605, 0.68, 0.6936, 0.6996, 0.7174, 0.6985, 0.6757, 0.6779, 0.7019, 0.7186, 0.702, 0.7, 0.6772, 0.6902, 0.6946, 0.6884, 0.6837, 0.6968, 0.6928, 0.6931, 0.6961, 0.6947, 0.6813, 0.6831, 0.6896, 0.708, 0.7152, 0.7186, 0.7083, 0.7128, 0.6656, 0.6731, 0.694, 0.7164, 0.7052, 0.6951, 0.7041, 0.6942, 0.7171, 0.7012, 0.692, 0.6777, 0.6901, 0.7004, 0.6946, 0.6999, 0.7086, 0.6993, 0.6618, 0.7309, 0.7093, 0.6983, 0.709, 0.7094, 0.6975, 0.6831, 0.6993, 0.7102, 0.7004, 0.6995, 0.7146, 0.6473, 0.5199, 0.6292, 0.6086, 0.6381, 0.5974, 0.6101, 0.6164, 0.5966, 0.6076, 0.6109, 0.6173, 0.6029, 0.6106, 0.6315, 0.6254, 0.6099, 0.6166, 0.6455, 0.6316, 0.5838, 0.5751, 0.596, 0.6728, 0.6825, 0.6727, 0.6577, 0.671, 0.6674, 0.6474, 0.6824, 0.693, 0.6301, 0.6577, 0.7057, 0.6963, 0.6478, 0.6178, 0.6104, 0.6186, 0.6454, 0.6531, 0.6392, 0.6525, 0.6456, 0.6525, 0.664, 0.6513, 0.6696, 0.6544, 0.6067, 0.6874, 0.6637, 0.6503, 0.6646, 0.6642, 0.649, 0.6285, 0.6314, 0.6094, 0.6637, 0.6511, 0.6503, 0.6672) expect_equal(fill[is.na(data)], ref, tolerance=1e-4) }) test_that("Gapfill prediction interval",{ toFill <- c(1741L, 1785L, 1809L, 1816L, 1887L, 1888L, 1919L, 1939L, 2107L, 2124L, 2126L, 2131L, 2132L, 2133L, 2159L, 2193L, 2283L, 2405L, 2466L, 2513L, 2577L, 2741L, 2845L, 2990L, 3600L, 3601L, 3611L, 3724L, 3778L, 3858L, 3861L, 3932L, 4653L, 5035L, 5107L, 5108L, 5180L, 5222L, 5224L, 5293L, 5349L, 5359L, 5443L, 5482L, 5527L, 5573L, 5582L, 5596L, 6694L, 6846L) ref.pred <- c(0.6886, 0.4716, 0.479, 0.4279, 0.4646, 0.4759, 8e-04, 0.4867, 0.4318, 0.4212, 0.4203, 0.4293, 0.4298, 0.4185, 0.4326, 0.375, 0.523, 0.5198, 0.5667, 0.5264, 0.5278, 0.661, 0.6445, 0.6923, 0.4971, 0.497, 0.4831, 0.4545, 0.4485, 0.4865, 0.5192, 0.4862, 0.6623, 0.4371, 0.6952, 0.716, 0.7008, 0.6843, 0.7131, 0.424, 0.4868, 0.4562, 0.5438, 0.5163, 0.5147, 0.5202, 0.5253, 0.4763, 0.6889, 0.6511) ref.lo <- c(0.6216, 0.4392, 0.4692, 0.3491, 0.4379, 0.4497, -0.033, 0.4805, 0.393, 0.366, 0.3878, 0.3685, 0.4085, 0.3905, 0.3905, 0.3445, 0.4228, 0.4016, 0.4761, 0.3975, 0.3869, 0.5172, 0.5142, 0.5422, 0.4349, 0.4352, 0.4264, 0.4152, 0.3589, 0.3983, 0.453, 0.4398, 0.5544, 0.3885, 0.5982, 0.6452, 0.6219, 0.6032, 0.6369, 0.4061, 0.4505, 0.4196, 0.4826, 0.4235, 0.4239, 0.4255, 0.4541, 0.3685, 0.6579, 0.6234) ref.up <- c(0.7454, 0.623, 0.6886, 0.6118, 0.6393, 0.6381, 0.4627, 0.6513, 0.5874, 0.5897, 0.5754, 0.5818, 0.5819, 0.5772, 0.5882, 0.545, 0.7036, 0.7153, 0.7819, 0.7058, 0.7106, 0.7216, 0.701, 0.7356, 0.6144, 0.6304, 0.6089, 0.5857, 0.5892, 0.5982, 0.632, 0.6451, 0.7387, 0.5842, 0.716, 0.7439, 0.7206, 0.704, 0.7373, 0.678, 0.6419, 0.6247, 0.7061, 0.6343, 0.6631, 0.6421, 0.62, 0.5826, 0.7577, 0.7112) fill <- Gapfill(ndvi, nPredict = 3, subset = toFill, predictionInterval = TRUE)$fill pred <- fill[toFill] lo <- fill[toFill + length(ndvi)] up <- fill[toFill + 2*length(ndvi)] expect_identical(pred, fill[,,,,1][!is.na(fill[,,,,2])]) expect_identical(lo, fill[,,,,2][!is.na(fill[,,,,2])]) expect_identical(up, fill[,,,,3][!is.na(fill[,,,,3])]) expect_true(all(lo <= pred)) expect_true(all(pred <= up)) expect_equal(pred, ref.pred, tolerance = 1e-4) expect_equal(lo, ref.lo, tolerance = 1e-4) expect_equal(up, ref.up, tolerance = 1e-4) }) test_that("Gapfill subset",{ data <- ndvi[,,2:3,2:3] PredictMean <- function (a, i) mean(a, na.rm = TRUE) ref <- structure(c(0.6279, 0.6241, 0.6228, 0.6215, 0.6211, 0.619, 0.6173, 0.6159, 0.6152, 0.6142, 0.615, 0.6134, 0.6125, 0.6096, 0.6072, 0.6063, 0.6061, 0.6045, 0.6039, 0.602, 0.6009, 0.6273, 0.6237, 0.6227, 0.6216, 0.6212, 0.6192, 0.6175, 0.6161, 0.6154, 0.6144, 0.6151, 0.6137, 0.6128, 0.6098, 0.6075, 0.6067, 0.6065, 0.605, 0.6044, 0.6026, 0.6016, 0.6284, 0.625, 0.624, 0.6228, 0.6223, 0.6203, 0.6187, 0.6173, 0.6166, 0.6156, 0.6163, 0.6151, 0.6143, 0.6115, 0.6093, 0.6084, 0.6082, 0.6065, 0.6057, 0.6039, 0.6028, 0.6282, 0.6251, 0.6242, 0.6231, 0.6226, 0.6206, 0.6191, 0.6178, 0.617, 0.6162, 0.6168, 0.6157, 0.615, 0.6123, 0.6102, 0.6095, 0.6094, 0.6076, 0.6068, 0.6051, 0.6041, 0.6266, 0.6239, 0.6232, 0.6223, 0.6221, 0.6203, 0.6189, 0.6176, 0.617, 0.6164, 0.6172, 0.6164, 0.6159, 0.6135, 0.6117, 0.611, 0.611, 0.6095, 0.6089, 0.6073, 0.6067, 0.6255, 0.623, 0.6225, 0.6216, 0.6211, 0.6195, 0.6182, 0.6172, 0.6168, 0.6163, 0.617, 0.6163, 0.616, 0.6139, 0.6122, 0.6117, 0.6117, 0.6103, 0.6097, 0.6083, 0.6077, 0.6244, 0.6221, 0.6215, 0.6206, 0.6199, 0.6183, 0.6172, 0.6163, 0.6159, 0.6156, 0.6165, 0.6159, 0.6157, 0.6138, 0.6123, 0.6118, 0.6119, 0.6103, 0.6098, 0.6083, 0.6078, 0.623, 0.621, 0.6203, 0.6194, 0.6189, 0.6174, 0.6164, 0.6157, 0.6153, 0.6153, 0.6161, 0.6158, 0.616, 0.6143, 0.6129, 0.6126, 0.6126, 0.6113, 0.6108, 0.6094, 0.6086, 0.6233, 0.6213, 0.6208, 0.6198, 0.6194, 0.618, 0.617, 0.6162, 0.6159, 0.6158, 0.6165, 0.6162, 0.6165, 0.6148, 0.6136, 0.6133, 0.6133, 0.6119, 0.6114, 0.6102, 0.6094, 0.6225, 0.6207, 0.6201, 0.6192, 0.6188, 0.6176, 0.6167, 0.6161, 0.6158, 0.6158, 0.6165, 0.6163, 0.6165, 0.615, 0.6139, 0.6136, 0.6136, 0.6123, 0.6118, 0.6109, 0.6103, 0.621, 0.6193, 0.6189, 0.6182, 0.6179, 0.617, 0.6162, 0.6157, 0.6155, 0.6155, 0.6163, 0.6161, 0.6163, 0.6149, 0.6138, 0.6136, 0.6136, 0.6124, 0.6122, 0.6116, 0.6113, 0.6211, 0.6192, 0.6187, 0.6179, 0.6175, 0.6165, 0.6158, 0.6152, 0.6149, 0.6149, 0.6156, 0.6154, 0.6157, 0.6143, 0.6132, 0.6128, 0.6128, 0.6114, 0.6113, 0.6104, 0.61, 0.6179, 0.6159, 0.6154, 0.6147, 0.6144, 0.6134, 0.6128, 0.6122, 0.6121, 0.6123, 0.6133, 0.6133, 0.6136, 0.6123, 0.6112, 0.6109, 0.6109, 0.6096, 0.6097, 0.6091, 0.6087, 0.6155, 0.6134, 0.6129, 0.6122, 0.6119, 0.6108, 0.6103, 0.6098, 0.6098, 0.6102, 0.6113, 0.6116, 0.6123, 0.611, 0.6096, 0.6093, 0.6093, 0.6081, 0.6083, 0.6076, 0.6072, 0.6131, 0.6108, 0.6103, 0.6095, 0.6092, 0.6081, 0.6076, 0.6073, 0.6074, 0.6079, 0.6093, 0.6098, 0.6107, 0.6093, 0.6079, 0.6075, 0.6076, 0.6064, 0.6066, 0.6059, 0.6057, 0.6123, 0.6101, 0.6099, 0.6093, 0.6091, 0.6079, 0.6074, 0.6071, 0.6071, 0.6077, 0.6092, 0.61, 0.6114, 0.6102, 0.609, 0.6085, 0.6087, 0.6073, 0.6076, 0.607, 0.6067, 0.6122, 0.6101, 0.6101, 0.6096, 0.6094, 0.6081, 0.6075, 0.6072, 0.6071, 0.6075, 0.6092, 0.6096, 0.6098, 0.609, 0.6083, 0.6081, 0.6088, 0.6077, 0.6081, 0.6076, 0.6069, 0.6154, 0.6129, 0.6126, 0.6121, 0.6117, 0.6103, 0.6093, 0.6083, 0.6081, 0.6085, 0.6098, 0.6107, 0.6113, 0.6107, 0.6102, 0.6092, 0.6078, 0.6058, 0.6065, 0.6056, 0.6046, 0.6158, 0.6167, 0.6176, 0.617, 0.6164, 0.6146, 0.6135, 0.6123, 0.6117, 0.6116, 0.6125, 0.6138, 0.6147, 0.6146, 0.6145, 0.6142, 0.6135, 0.6118, 0.6108, 0.6103, 0.6098, 0.6125, 0.6133, 0.6139, 0.6141, 0.614, 0.6143, 0.6148, 0.6151, 0.6154, 0.6167, 0.6172, 0.6189, 0.6203, 0.6206, 0.6209, 0.6211, 0.6211, 0.6204, 0.6206, 0.6214, 0.6226, 0.6109, 0.612, 0.6129, 0.6132, 0.6132, 0.6136, 0.6142, 0.6149, 0.6155, 0.6168, 0.6173, 0.6193, 0.6211, 0.6217, 0.6225, 0.6231, 0.6232, 0.6226, 0.6229, 0.6239, 0.6251), .Dim = c(21L, 21L)) ref <- abind::abind(ref, ref, along=3); ref <- abind::abind(ref, ref, along=4) expect_equal(Gapfill(data, fnPredict=PredictMean, subset="all")$fill, ref, check.attributes = FALSE, tolerance=1e-4) ref_m <- data; ref_m[is.na(data)] <- ref[is.na(data)] expect_equal(Gapfill(data, fnPredict=PredictMean, subset="missings")$fill, ref_m, check.attributes = FALSE, tolerance=1e-4) ref_o <- ref; ref_o[is.na(data)] <- NA expect_equal(Gapfill(data, fnPredict=PredictMean, subset="observed")$fill, ref_o, check.attributes = FALSE, tolerance=1e-4) sub1 <- sample(seq_along(data), 100) ref_sub1 <- data; ref_sub1[sub1] <- ref[sub1] expect_equal(Gapfill(data, fnPredict=PredictMean, subset=sub1)$fill, ref_sub1, check.attributes = FALSE, tolerance=1e-4) sub2 <- array(FALSE, dim(data)); sub2[sample(seq_along(data), 100)] <- TRUE ref_sub2 <- data; ref_sub2[sub2] <- ref[sub2] expect_equal(Gapfill(data, fnPredict=PredictMean, subset=sub2)$fill, ref_sub2, check.attributes = FALSE, tolerance=1e-4) }) test_that("Gapfill args",{ expect_error(Gapfill(), "argument \"data\" is missing, with no default") expect_error(Gapfill(matrix(1)), "identical\\(length\\(dim\\(data\\)\\), 4L\\) is not TRUE") expect_error(Gapfill(array(TRUE)), "identical\\(length\\(dim\\(data\\)\\), 4L\\) is not TRUE") expect_error(Gapfill(array(1, c(1,2,3,4,5))), "identical\\(length\\(dim\\(data\\)\\), 4L\\) is not TRUE") data <- ndvi[,,1:2,1:2] expect_error(Gapfill(data = data, fnSubset = 1), "is.function\\(fnSubset\\) is not TRUE") expect_error(Gapfill(data = data, fnSubset = function(x) x), "all\\(names\\(fnSubset_formals\\)\\[1:3\\] == c\\(\"data\", \"mp\", \"i\"\\)\\) is not TRUE") expect_error(Gapfill(data = data, fnSubset = function(data, mp, k) x), "all\\(names\\(fnSubset_formals\\)\\[1:3\\] == c\\(\"data\", \"mp\", \"i\"\\)\\) is not TRUE") expect_equal(Gapfill(data = data, fnSubset = function(data, mp, i) array(1, c(1,1,1,1)))$fill, data) expect_error(Gapfill(data = data, fnPredict = 1), "is.function\\(fnPredict\\) is not TRUE") expect_error(Gapfill(data = data, fnPredict = function(x) x), "all\\(names\\(fnPredict_formals\\)\\[1:2\\] == c\\(\"a\", \"i\"\\)\\) is not TRUE") expect_error(Gapfill(data = data, fnPredict = function(n, k) x), "all\\(names\\(fnPredict_formals\\)\\[1:2\\] == c\\(\"a\", \"i\"\\)\\) is not TRUE") expect_equal(Gapfill(data = data, fnPredict = function(a, i) NA)$fill, data) expect_error(Gapfill(data = data, iMax = TRUE), "is.numeric\\(iMax\\) is not TRUE") expect_error(Gapfill(data = data, iMax = c(1, 1)), "identical\\(length\\(iMax\\), 1L\\) is not TRUE") expect_error(Gapfill(data = data, iMax = -1), "iMax >= 0L is not TRUE") expect_error(Gapfill(data = data, nPredict = TRUE), "is.numeric\\(nPredict\\) is not TRUE") expect_error(Gapfill(data = data, nPredict = c(1, 1)), "identical\\(length\\(nPredict\\), 1L\\) is not TRUE") expect_error(Gapfill(data = data, nPredict = -1), "nPredict >= 1L is not TRUE") expect_error(Gapfill(data = data, subset = "a"), "subset\\[1\\] == \"missings\" || \\(identical\\(dim\\(subset\\), dim\\(data\\)\\) && .... is not TRUE") expect_error(Gapfill(data = data, subset = c(1, 1)), "subset\\[1\\] == \"missings\" || \\(identical\\(dim\\(subset\\), dim\\(data\\)\\) && .... is not TRUE") expect_error(Gapfill(data = data, subset = c(8, 8)), "Argument \"subset\" contains duplicated values.") expect_equal(Gapfill(data = data, subset = 155)$fill[155], 0.1527, tolerance = 1e-3) data2 <- data[1:5,1:5,,] fill2_obs <- Gapfill(data = data2, fnPredict=function(a, i) mean(a, na.rm=TRUE), subset = "observed")$fill expect_equal(fill2_obs[!is.na(fill2_obs)], rep(mean(data2, na.rm=TRUE), sum(!is.na(data2)))) expect_equal(!is.na(fill2_obs), !is.na(data2)) fill2_all <- Gapfill(data = data2, fnPredict=function(a, i) mean(a, na.rm=TRUE), subset = "all")$fill expect_true(all(!is.na(fill2_all))) expect_equal(fill2_all, array(mean(data2, na.rm=TRUE), dim(data2), dimnames=dimnames(data2))) expect_error(Gapfill(data = data, clipRange = TRUE), "is.numeric\\(clipRange\\) is not TRUE") expect_error(Gapfill(data = data, clipRange = 1), "identical\\(length\\(clipRange\\), 2L\\) is not TRUE") expect_error(Gapfill(data = data, clipRange = c(5,4)), "clipRange\\[1\\] < clipRange\\[2\\] is not TRUE") expect_error(Gapfill(data = data, dopar = c(1)), "is.logical\\(dopar\\) is not TRUE") expect_error(Gapfill(data = data, dopar = c(TRUE, TRUE)), "identical\\(length\\(dopar\\), 1L\\) is not TRUE") expect_error(Gapfill(data = data, verbose = 1), "is.logical\\(verbose\\) is not TRUE") expect_error(Gapfill(data = data, verbose = c(TRUE, TRUE)), "identical\\(length\\(verbose\\), 1L\\) is not TRUE") expect_error(Gapfill(data = data, notExtistent = 1), "is/are not used by fnSubset\\(\\) or fnPredict\\(\\)") fnS <- function(data, mp, i, e) e expect_error(Gapfill(data = data, fnSubset = fnS), "argument \"e\" is missing, with no default") })
mpsedist <- function (data, distr, start = NULL, fix.arg = NULL, optim.method = "default", lower = -Inf, upper = Inf, custom.optim = NULL, weights = NULL, silent = TRUE, gradient = NULL, ...) { if (!is.character(distr)) stop("distr must be a character string naming a distribution") else distname <- distr ddistname <- paste("d", distname, sep = "") if (!exists(ddistname, mode = "function")) stop(paste("The ", ddistname, " function must be defined")) pdistname <- paste("p", distname, sep = "") if (!exists(pdistname, mode = "function")) stop(paste("The ", pdistname, " function must be defined")) if (is.null(custom.optim)) optim.method <- match.arg(optim.method, c("default", "Nelder-Mead", "BFGS", "CG", "L-BFGS-B", "SANN", "Brent")) start.arg <- start if (is.vector(start.arg)) start.arg <- as.list(start.arg) txt1 <- "data must be a numeric vector of length greater than 1 for non censored data" if (!is.null(weights)) { if (any(weights <= 0)) stop("weights should be a vector of numbers greater than 0") if (length(weights) != NROW(data) + 1) stop("weights should be a vector with a length equal to the observation number") warning("weights are not taken into account in the default initial values") } if (is.vector(data)) { cens <- FALSE if (!(is.numeric(data) & length(data) > 1)) stop(txt1) } else { stop("Maximum product of spacing estimation is not yet available for censored data.") } argpdistname <- names(formals(pdistname)) chfixstt <- checkparam(start.arg = start.arg, fix.arg = fix.arg, argdistname = argpdistname, errtxt = NULL, data10 = head(data, 10), distname = distname) if (!chfixstt$ok) stop(chfixstt$txt) if (is.function(chfixstt$start.arg)) vstart <- unlist(chfixstt$start.arg(data)) else vstart <- unlist(chfixstt$start.arg) if (is.function(fix.arg)) { fix.arg.fun <- fix.arg fix.arg <- fix.arg(data) } else fix.arg.fun <- NULL if (distname == "unif") { n <- length(data) data <- sort(data) par <- c(min = (n*data[1]-data[n])/(n-1), max = (n*data[n] - data[1])/(n-1)) par <- c(par[!names(par) %in% names(fix.arg)], unlist(fix.arg)) value <- unname(sum(log(diff(c(par["min"],data,par["max"])))) - (n+1)*log(par["max"]-par["min"])) res <- list(estimate = par[!names(par) %in% names(fix.arg)], convergence = 0, value = value, loglik = .loglik(par[!names(par) %in% names(fix.arg)], fix.arg, data, ddistname), hessian = NA, optim.function = NA, fix.arg = fix.arg) return(res) } if (!cens && is.null(weights)) { fnobj <- function(par, fix.arg, obs, pdistnam, ddistnam) { obs <- sort(obs) spacing <- diff(c(0, do.call(pdistnam, c(list(obs), as.list(par), as.list(fix.arg))), 1)) if(any(is.nan(spacing))) return(NaN) ind <- abs(spacing) < .epsilon if(any(ind)){ aux <- c(obs[1],obs)[ind] spacing[ind] <- do.call(ddistnam, c(list(aux), as.list(par), as.list(fix.arg))) } -sum(log(spacing)) } } else if (!cens && !is.null(weights)) { fnobj <- function(par, fix.arg, obs, pdistnam, ddistnam) { obs <- sort(obs) spacing <- diff(c(0, do.call(pdistnam, c(list(obs), as.list(par), as.list(fix.arg))), 1)) if(any(is.nan(spacing))) return(NaN) ind <- abs(spacing) < .epsilon if(any(ind)){ aux <- c(obs[1],obs)[ind] spacing[ind] <- do.call(ddistnam, c(list(aux), as.list(par), as.list(fix.arg))) } -sum(weights * log(spacing)) } } owarn <- getOption("warn") if (is.null(custom.optim)) { hasbound <- any(is.finite(lower) | is.finite(upper)) if (optim.method == "default") { meth <- ifelse(length(vstart) > 1, "Nelder-Mead", "BFGS") } else meth <- optim.method if (meth == "BFGS" && hasbound && is.null(gradient)) { meth <- "L-BFGS-B" txt1 <- "The BFGS method cannot be used with bounds without provided the gradient." txt2 <- "The method is changed to L-BFGS-B." warning(paste(txt1, txt2)) } options(warn = ifelse(silent, -1, 0)) if (hasbound) { if (!is.null(gradient)) { opt.fun <- "constrOptim" } else { if (meth == "Nelder-Mead") opt.fun <- "constrOptim" else if (meth %in% c("L-BFGS-B", "Brent")) opt.fun <- "optim" else { txt1 <- paste("The method", meth, "cannot be used by constrOptim() nor optim() without gradient and bounds.") txt2 <- "Only optimization methods L-BFGS-B, Brent and Nelder-Mead can be used in such case." stop(paste(txt1, txt2)) } } if (opt.fun == "constrOptim") { npar <- length(vstart) lower <- as.double(rep_len(lower, npar)) upper <- as.double(rep_len(upper, npar)) haslow <- is.finite(lower) Mat <- diag(npar)[haslow, ] hasupp <- is.finite(upper) Mat <- rbind(Mat, -diag(npar)[hasupp, ]) colnames(Mat) <- names(vstart) rownames(Mat) <- paste0("constr", 1:NROW(Mat)) Bnd <- c(lower[is.finite(lower)], -upper[is.finite(upper)]) names(Bnd) <- paste0("constr", 1:length(Bnd)) initconstr <- Mat %*% vstart - Bnd if (any(initconstr < 0)) stop("Starting values must be in the feasible region.") opttryerror <- try(opt <- constrOptim(theta = vstart, f = fnobj, ui = Mat, ci = Bnd, grad = gradient, fix.arg = fix.arg, obs = data, pdistnam = pdistname, ddistnam = ddistname, hessian = !is.null(gradient), method = meth, ...), silent = TRUE) if (!inherits(opttryerror, "try-error")) if (length(opt$counts) == 1) opt$counts <- c(opt$counts, NA) } else { opttryerror <- try(opt <- optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs = data, pdistnam = pdistname, ddistnam = ddistname, gr = gradient, hessian = TRUE, method = meth, lower = lower, upper = upper, ...), silent = TRUE) } } else { opt.fun <- "optim" opttryerror <- try(opt <- optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs = data, pdistnam = pdistname, ddistnam = ddistname, gr = gradient, hessian = TRUE, method = meth, lower = lower, upper = upper, ...), silent = TRUE) } options(warn = owarn) if (inherits(opttryerror, "try-error")) { warnings("The function optim encountered an error and stopped.") if (getOption("show.error.messages")) print(attr(opttryerror, "condition")) return(list(estimate = rep(NA, length(vstart)), convergence = 100, value=NA, loglik = NA, hessian = NA, optim.function = opt.fun, fix.arg = fix.arg, optim.method = meth, fix.arg.fun = fix.arg.fun, counts = c(NA, NA))) } if (opt$convergence > 0) { warnings("The function optim failed to converge, with the error code ", opt$convergence) } if (is.null(names(opt$par))) names(opt$par) <- names(vstart) res <- list(estimate = opt$par, convergence = opt$convergence, value = -opt$value, loglik = .loglik(opt$par, fix.arg, data, ddistname), hessian = opt$hessian, optim.function = opt.fun, fix.arg = fix.arg, optim.method = meth, fix.arg.fun = fix.arg.fun, weights = weights, counts = opt$counts, optim.message = opt$message) } else { options(warn = ifelse(silent, -1, 0)) opttryerror <- try(opt <- custom.optim(fn = fnobj, fix.arg = fix.arg, obs = data, pdistnam = pdistname, ddistnam = ddistname, par = vstart, ...), silent = TRUE) options(warn = owarn) if (inherits(opttryerror, "try-error")) { warnings("The customized optimization function encountered an error and stopped.") if (getOption("show.error.messages")) print(attr(opttryerror, "condition")) return(list(estimate = rep(NA, length(vstart)), convergence = 100, value = NA, loglik = NA, hessian = NA, optim.function = custom.optim, fix.arg = fix.arg, fix.arg.fun = fix.arg.fun, counts = c(NA, NA))) } if (opt$convergence > 0) { warnings("The customized optimization function failed to converge, with the error code ", opt$convergence) } argdot <- list(...) method.cust <- argdot[argdot == "method"] if (length(method.cust) == 0) { method.cust <- NULL } if (is.null(names(opt$par))) names(opt$par) <- names(vstart) res <- list(estimate = opt$par, convergence = opt$convergence, value = -opt$value, loglik = .loglik(opt$par, fix.arg, data, ddistname), hessian = opt$hessian, optim.function = custom.optim, fix.arg = fix.arg, method = method.cust, fix.arg.fun = fix.arg.fun, weights = weights, counts = opt$counts, optim.message = opt$message) } return(res) }
LogL.pss1Ic2.aux<- function(parameters, X, Z, data, trace) { loglik1 <- function(param, X, Z, y,trace) { npar <-as.integer(length(param)-2) beta<- as.double(param[1:(npar-1)]) bt<- as.double(param[1:(npar-1)]) rho<-as.double(param[npar]) y<- as.integer(y) n <- as.integer(length(y)) x<-matrix(as.double(X),nrow=n,ncol=npar-1) theta<- work<-as.double(rep(0,n)) logL <- as.double(0) eta<-i.fit<- fit<-as.vector(npar-1) eta<-x%*%beta ui<-y-exp(eta) pos.r2<-as.double(0) names.Z <- dimnames(Z)[[2]] names.X <- dimnames(X)[[2]] for (i in 2:ncol(X)) { if (!is.na(match(names.Z[2],names.X[i]))) pos.r2<-i } m<-glm(as.numeric(y)~ offset(eta) + Z[,2], family=poisson, maxit=100) b1i<-coef(m)[1] b2i<-coef(m)[2] beta[1]<-beta[1]+b1i beta[pos.r2]<-beta[pos.r2]+b2i y[is.na(y)]<-(-1) y<- as.integer(y) link <- as.integer(1) m <- max(y) fact <- rep(1, m + 1) if(m > 0) {for(i in 2:(m + 1)) fact[i] <- fact[i - 1] * (i - 1)} fact <- as.double(fact) bi<-c(b1i,b2i) results <- .Fortran("psslik",logL,beta,rho, npar,x,y,theta,work,n,fact,link,PACKAGE="cold") i.fit<-x%*%beta return(list(loglik=results[[1]], fit=i.fit, bi.est=bi))} if(trace) cat(paste(format(parameters[length(parameters)-2], digit=4), collapse=" "), "\t") if(trace) cat(paste(format(parameters[length(parameters)-1], digit=4), collapse=" "), "\t") if(trace) cat(paste("\t",(format(parameters[length(parameters)], digit=4)), collapse=" "), "\t") nparam<-length(parameters) omega1<-as.double(parameters[nparam]-1) omega2<-as.double(parameters[nparam]) ti.repl<-data[[1]] cumti.repl<-cumsum(ti.repl) n.cases<- length(ti.repl) y<-data[[2]] fitted<-as.double(rep(0,length(y))) bi.estimate<-matrix(as.double(0),nrow=n.cases,ncol=2) gi.estimate<-as.double(rep(0,length(n.cases))) logL1<-as.double(0) k1<-1 for (i in 1:n.cases) { k2<-cumti.repl[i] z1<-loglik1(param=parameters,X=X[k1:k2,], Z=Z[k1:k2,], y=y[k1:k2],trace=trace) fitted[k1:k2]<-z1$fit bi.estimate[i,]<-z1$bi.est k1<-k2+1 } return(list(fit=fitted,bi.est=bi.estimate))}
genCov_buildTrack <- function(name, bg_fill="black", text_fill="white", border="black", size=10) { background <- geom_rect(colour=border, fill=bg_fill) label <- geom_text(aes(x=.5, y=.5), label=name, colour=text_fill, angle=90, size=size) scale_x <- scale_x_continuous(expand=c(0,0)) scale_y <- scale_y_continuous(expand=c(0,0)) labels <- labs(x=NULL, y=NULL) theme <- theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank(), axis.title.y=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank(), plot.margin=unit(c(0, 0, 0, 0), "null"), axis.ticks.length=unit(0,"null"), panel.spacing=unit(0,"null")) label <- ggplot(mapping=aes(xmin=0, xmax=1, ymin=0, ymax=1)) + background + label + theme + scale_x + scale_y + labels return(label) }
superbarplot <- function(x, names = 1:dim(x)[2], names_height=NULL, col = gray(seq(.8,.5,length=dim(x)[1]/2)), ...) { plot.bar <- function(x,min,max,width=1,...) { alpha <- (1-width)/2 polygon(x + c(alpha,alpha,1-alpha,1-alpha,alpha), c(min,max,max,min,min), ...) } n = dim(x)[2] m = dim(x)[1] no.bars = dim(x)[1]/2 y.range = c(min(x),max(x)) x.range = c(1,n+1) plot.new() plot.window(xlim=x.range,ylim=y.range, xaxt="n", bty="n",ann=FALSE) title(...) for(i in 1:no.bars) { for(j in 1:n) { plot.bar(j,x[2*i-1,j],x[2*i,j],width=1 - i/(3*no.bars),col=col[i]) } } if(!is.null(names)) { if(is.null(names_height)) { f = par("yaxp") names_height= f[1] + (f[2]-f[1])*(f[3]-1)/f[3] } text(0.5 + 1:n,rep(names_height,n),format(names)) } }
NULL .organizations$accept_handshake_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(HandshakeId = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$accept_handshake_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Handshake = structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Parties = structure(list(structure(list(Id = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Type = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list")), State = structure(logical(0), tags = list(type = "string")), RequestedTimestamp = structure(logical(0), tags = list(type = "timestamp")), ExpirationTimestamp = structure(logical(0), tags = list(type = "timestamp")), Action = structure(logical(0), tags = list(type = "string")), Resources = structure(list(structure(list(Value = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Type = structure(logical(0), tags = list(type = "string")), Resources = structure(logical(0), tags = list(type = "list"))), tags = list(type = "structure"))), tags = list(type = "list"))), tags = list(type = "structure"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$attach_policy_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(PolicyId = structure(logical(0), tags = list(type = "string")), TargetId = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$attach_policy_output <- function(...) { list() } .organizations$cancel_handshake_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(HandshakeId = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$cancel_handshake_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Handshake = structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Parties = structure(list(structure(list(Id = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Type = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list")), State = structure(logical(0), tags = list(type = "string")), RequestedTimestamp = structure(logical(0), tags = list(type = "timestamp")), ExpirationTimestamp = structure(logical(0), tags = list(type = "timestamp")), Action = structure(logical(0), tags = list(type = "string")), Resources = structure(list(structure(list(Value = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Type = structure(logical(0), tags = list(type = "string")), Resources = structure(logical(0), tags = list(type = "list"))), tags = list(type = "structure"))), tags = list(type = "list"))), tags = list(type = "structure"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$create_account_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Email = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), AccountName = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), RoleName = structure(logical(0), tags = list(type = "string")), IamUserAccessToBilling = structure(logical(0), tags = list(type = "string")), Tags = structure(list(structure(list(Key = structure(logical(0), tags = list(type = "string")), Value = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$create_account_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(CreateAccountStatus = structure(list(Id = structure(logical(0), tags = list(type = "string")), AccountName = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), State = structure(logical(0), tags = list(type = "string")), RequestedTimestamp = structure(logical(0), tags = list(type = "timestamp")), CompletedTimestamp = structure(logical(0), tags = list(type = "timestamp")), AccountId = structure(logical(0), tags = list(type = "string")), GovCloudAccountId = structure(logical(0), tags = list(type = "string")), FailureReason = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$create_gov_cloud_account_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Email = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), AccountName = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), RoleName = structure(logical(0), tags = list(type = "string")), IamUserAccessToBilling = structure(logical(0), tags = list(type = "string")), Tags = structure(list(structure(list(Key = structure(logical(0), tags = list(type = "string")), Value = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$create_gov_cloud_account_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(CreateAccountStatus = structure(list(Id = structure(logical(0), tags = list(type = "string")), AccountName = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), State = structure(logical(0), tags = list(type = "string")), RequestedTimestamp = structure(logical(0), tags = list(type = "timestamp")), CompletedTimestamp = structure(logical(0), tags = list(type = "timestamp")), AccountId = structure(logical(0), tags = list(type = "string")), GovCloudAccountId = structure(logical(0), tags = list(type = "string")), FailureReason = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$create_organization_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(FeatureSet = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$create_organization_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Organization = structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), FeatureSet = structure(logical(0), tags = list(type = "string")), MasterAccountArn = structure(logical(0), tags = list(type = "string")), MasterAccountId = structure(logical(0), tags = list(type = "string")), MasterAccountEmail = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), AvailablePolicyTypes = structure(list(structure(list(Type = structure(logical(0), tags = list(type = "string")), Status = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list"))), tags = list(type = "structure"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$create_organizational_unit_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(ParentId = structure(logical(0), tags = list(type = "string")), Name = structure(logical(0), tags = list(type = "string")), Tags = structure(list(structure(list(Key = structure(logical(0), tags = list(type = "string")), Value = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$create_organizational_unit_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(OrganizationalUnit = structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Name = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$create_policy_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Content = structure(logical(0), tags = list(type = "string")), Description = structure(logical(0), tags = list(type = "string")), Name = structure(logical(0), tags = list(type = "string")), Type = structure(logical(0), tags = list(type = "string")), Tags = structure(list(structure(list(Key = structure(logical(0), tags = list(type = "string")), Value = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$create_policy_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Policy = structure(list(PolicySummary = structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Name = structure(logical(0), tags = list(type = "string")), Description = structure(logical(0), tags = list(type = "string")), Type = structure(logical(0), tags = list(type = "string")), AwsManaged = structure(logical(0), tags = list(type = "boolean"))), tags = list(type = "structure")), Content = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$decline_handshake_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(HandshakeId = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$decline_handshake_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Handshake = structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Parties = structure(list(structure(list(Id = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Type = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list")), State = structure(logical(0), tags = list(type = "string")), RequestedTimestamp = structure(logical(0), tags = list(type = "timestamp")), ExpirationTimestamp = structure(logical(0), tags = list(type = "timestamp")), Action = structure(logical(0), tags = list(type = "string")), Resources = structure(list(structure(list(Value = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Type = structure(logical(0), tags = list(type = "string")), Resources = structure(logical(0), tags = list(type = "list"))), tags = list(type = "structure"))), tags = list(type = "list"))), tags = list(type = "structure"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$delete_organization_input <- function(...) { list() } .organizations$delete_organization_output <- function(...) { list() } .organizations$delete_organizational_unit_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(OrganizationalUnitId = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$delete_organizational_unit_output <- function(...) { list() } .organizations$delete_policy_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(PolicyId = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$delete_policy_output <- function(...) { list() } .organizations$deregister_delegated_administrator_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(AccountId = structure(logical(0), tags = list(type = "string")), ServicePrincipal = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$deregister_delegated_administrator_output <- function(...) { list() } .organizations$describe_account_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(AccountId = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$describe_account_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Account = structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Email = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Name = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Status = structure(logical(0), tags = list(type = "string")), JoinedMethod = structure(logical(0), tags = list(type = "string")), JoinedTimestamp = structure(logical(0), tags = list(type = "timestamp"))), tags = list(type = "structure"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$describe_create_account_status_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(CreateAccountRequestId = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$describe_create_account_status_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(CreateAccountStatus = structure(list(Id = structure(logical(0), tags = list(type = "string")), AccountName = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), State = structure(logical(0), tags = list(type = "string")), RequestedTimestamp = structure(logical(0), tags = list(type = "timestamp")), CompletedTimestamp = structure(logical(0), tags = list(type = "timestamp")), AccountId = structure(logical(0), tags = list(type = "string")), GovCloudAccountId = structure(logical(0), tags = list(type = "string")), FailureReason = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$describe_effective_policy_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(PolicyType = structure(logical(0), tags = list(type = "string")), TargetId = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$describe_effective_policy_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(EffectivePolicy = structure(list(PolicyContent = structure(logical(0), tags = list(type = "string")), LastUpdatedTimestamp = structure(logical(0), tags = list(type = "timestamp")), TargetId = structure(logical(0), tags = list(type = "string")), PolicyType = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$describe_handshake_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(HandshakeId = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$describe_handshake_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Handshake = structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Parties = structure(list(structure(list(Id = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Type = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list")), State = structure(logical(0), tags = list(type = "string")), RequestedTimestamp = structure(logical(0), tags = list(type = "timestamp")), ExpirationTimestamp = structure(logical(0), tags = list(type = "timestamp")), Action = structure(logical(0), tags = list(type = "string")), Resources = structure(list(structure(list(Value = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Type = structure(logical(0), tags = list(type = "string")), Resources = structure(logical(0), tags = list(type = "list"))), tags = list(type = "structure"))), tags = list(type = "list"))), tags = list(type = "structure"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$describe_organization_input <- function(...) { list() } .organizations$describe_organization_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Organization = structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), FeatureSet = structure(logical(0), tags = list(type = "string")), MasterAccountArn = structure(logical(0), tags = list(type = "string")), MasterAccountId = structure(logical(0), tags = list(type = "string")), MasterAccountEmail = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), AvailablePolicyTypes = structure(list(structure(list(Type = structure(logical(0), tags = list(type = "string")), Status = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list"))), tags = list(type = "structure"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$describe_organizational_unit_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(OrganizationalUnitId = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$describe_organizational_unit_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(OrganizationalUnit = structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Name = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$describe_policy_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(PolicyId = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$describe_policy_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Policy = structure(list(PolicySummary = structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Name = structure(logical(0), tags = list(type = "string")), Description = structure(logical(0), tags = list(type = "string")), Type = structure(logical(0), tags = list(type = "string")), AwsManaged = structure(logical(0), tags = list(type = "boolean"))), tags = list(type = "structure")), Content = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$detach_policy_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(PolicyId = structure(logical(0), tags = list(type = "string")), TargetId = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$detach_policy_output <- function(...) { list() } .organizations$disable_aws_service_access_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(ServicePrincipal = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$disable_aws_service_access_output <- function(...) { list() } .organizations$disable_policy_type_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(RootId = structure(logical(0), tags = list(type = "string")), PolicyType = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$disable_policy_type_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Root = structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Name = structure(logical(0), tags = list(type = "string")), PolicyTypes = structure(list(structure(list(Type = structure(logical(0), tags = list(type = "string")), Status = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list"))), tags = list(type = "structure"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$enable_aws_service_access_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(ServicePrincipal = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$enable_aws_service_access_output <- function(...) { list() } .organizations$enable_all_features_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$enable_all_features_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Handshake = structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Parties = structure(list(structure(list(Id = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Type = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list")), State = structure(logical(0), tags = list(type = "string")), RequestedTimestamp = structure(logical(0), tags = list(type = "timestamp")), ExpirationTimestamp = structure(logical(0), tags = list(type = "timestamp")), Action = structure(logical(0), tags = list(type = "string")), Resources = structure(list(structure(list(Value = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Type = structure(logical(0), tags = list(type = "string")), Resources = structure(logical(0), tags = list(type = "list"))), tags = list(type = "structure"))), tags = list(type = "list"))), tags = list(type = "structure"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$enable_policy_type_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(RootId = structure(logical(0), tags = list(type = "string")), PolicyType = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$enable_policy_type_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Root = structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Name = structure(logical(0), tags = list(type = "string")), PolicyTypes = structure(list(structure(list(Type = structure(logical(0), tags = list(type = "string")), Status = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list"))), tags = list(type = "structure"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$invite_account_to_organization_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Target = structure(list(Id = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Type = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")), Notes = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Tags = structure(list(structure(list(Key = structure(logical(0), tags = list(type = "string")), Value = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$invite_account_to_organization_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Handshake = structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Parties = structure(list(structure(list(Id = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Type = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list")), State = structure(logical(0), tags = list(type = "string")), RequestedTimestamp = structure(logical(0), tags = list(type = "timestamp")), ExpirationTimestamp = structure(logical(0), tags = list(type = "timestamp")), Action = structure(logical(0), tags = list(type = "string")), Resources = structure(list(structure(list(Value = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Type = structure(logical(0), tags = list(type = "string")), Resources = structure(logical(0), tags = list(type = "list"))), tags = list(type = "structure"))), tags = list(type = "list"))), tags = list(type = "structure"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$leave_organization_input <- function(...) { list() } .organizations$leave_organization_output <- function(...) { list() } .organizations$list_aws_service_access_for_organization_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(NextToken = structure(logical(0), tags = list(type = "string")), MaxResults = structure(logical(0), tags = list(type = "integer", box = TRUE))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_aws_service_access_for_organization_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(EnabledServicePrincipals = structure(list(structure(list(ServicePrincipal = structure(logical(0), tags = list(type = "string")), DateEnabled = structure(logical(0), tags = list(type = "timestamp"))), tags = list(type = "structure"))), tags = list(type = "list")), NextToken = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_accounts_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(NextToken = structure(logical(0), tags = list(type = "string")), MaxResults = structure(logical(0), tags = list(type = "integer", box = TRUE))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_accounts_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Accounts = structure(list(structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Email = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Name = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Status = structure(logical(0), tags = list(type = "string")), JoinedMethod = structure(logical(0), tags = list(type = "string")), JoinedTimestamp = structure(logical(0), tags = list(type = "timestamp"))), tags = list(type = "structure"))), tags = list(type = "list")), NextToken = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_accounts_for_parent_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(ParentId = structure(logical(0), tags = list(type = "string")), NextToken = structure(logical(0), tags = list(type = "string")), MaxResults = structure(logical(0), tags = list(type = "integer", box = TRUE))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_accounts_for_parent_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Accounts = structure(list(structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Email = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Name = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Status = structure(logical(0), tags = list(type = "string")), JoinedMethod = structure(logical(0), tags = list(type = "string")), JoinedTimestamp = structure(logical(0), tags = list(type = "timestamp"))), tags = list(type = "structure"))), tags = list(type = "list")), NextToken = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_children_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(ParentId = structure(logical(0), tags = list(type = "string")), ChildType = structure(logical(0), tags = list(type = "string")), NextToken = structure(logical(0), tags = list(type = "string")), MaxResults = structure(logical(0), tags = list(type = "integer", box = TRUE))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_children_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Children = structure(list(structure(list(Id = structure(logical(0), tags = list(type = "string")), Type = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list")), NextToken = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_create_account_status_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(States = structure(list(structure(logical(0), tags = list(type = "string"))), tags = list(type = "list")), NextToken = structure(logical(0), tags = list(type = "string")), MaxResults = structure(logical(0), tags = list(type = "integer", box = TRUE))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_create_account_status_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(CreateAccountStatuses = structure(list(structure(list(Id = structure(logical(0), tags = list(type = "string")), AccountName = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), State = structure(logical(0), tags = list(type = "string")), RequestedTimestamp = structure(logical(0), tags = list(type = "timestamp")), CompletedTimestamp = structure(logical(0), tags = list(type = "timestamp")), AccountId = structure(logical(0), tags = list(type = "string")), GovCloudAccountId = structure(logical(0), tags = list(type = "string")), FailureReason = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list")), NextToken = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_delegated_administrators_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(ServicePrincipal = structure(logical(0), tags = list(type = "string")), NextToken = structure(logical(0), tags = list(type = "string")), MaxResults = structure(logical(0), tags = list(type = "integer", box = TRUE))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_delegated_administrators_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(DelegatedAdministrators = structure(list(structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Email = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Name = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Status = structure(logical(0), tags = list(type = "string")), JoinedMethod = structure(logical(0), tags = list(type = "string")), JoinedTimestamp = structure(logical(0), tags = list(type = "timestamp")), DelegationEnabledDate = structure(logical(0), tags = list(type = "timestamp"))), tags = list(type = "structure"))), tags = list(type = "list")), NextToken = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_delegated_services_for_account_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(AccountId = structure(logical(0), tags = list(type = "string")), NextToken = structure(logical(0), tags = list(type = "string")), MaxResults = structure(logical(0), tags = list(type = "integer", box = TRUE))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_delegated_services_for_account_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(DelegatedServices = structure(list(structure(list(ServicePrincipal = structure(logical(0), tags = list(type = "string")), DelegationEnabledDate = structure(logical(0), tags = list(type = "timestamp"))), tags = list(type = "structure"))), tags = list(type = "list")), NextToken = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_handshakes_for_account_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Filter = structure(list(ActionType = structure(logical(0), tags = list(type = "string")), ParentHandshakeId = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")), NextToken = structure(logical(0), tags = list(type = "string")), MaxResults = structure(logical(0), tags = list(type = "integer", box = TRUE))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_handshakes_for_account_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Handshakes = structure(list(structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Parties = structure(list(structure(list(Id = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Type = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list")), State = structure(logical(0), tags = list(type = "string")), RequestedTimestamp = structure(logical(0), tags = list(type = "timestamp")), ExpirationTimestamp = structure(logical(0), tags = list(type = "timestamp")), Action = structure(logical(0), tags = list(type = "string")), Resources = structure(list(structure(list(Value = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Type = structure(logical(0), tags = list(type = "string")), Resources = structure(logical(0), tags = list(type = "list"))), tags = list(type = "structure"))), tags = list(type = "list"))), tags = list(type = "structure"))), tags = list(type = "list")), NextToken = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_handshakes_for_organization_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Filter = structure(list(ActionType = structure(logical(0), tags = list(type = "string")), ParentHandshakeId = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")), NextToken = structure(logical(0), tags = list(type = "string")), MaxResults = structure(logical(0), tags = list(type = "integer", box = TRUE))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_handshakes_for_organization_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Handshakes = structure(list(structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Parties = structure(list(structure(list(Id = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Type = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list")), State = structure(logical(0), tags = list(type = "string")), RequestedTimestamp = structure(logical(0), tags = list(type = "timestamp")), ExpirationTimestamp = structure(logical(0), tags = list(type = "timestamp")), Action = structure(logical(0), tags = list(type = "string")), Resources = structure(list(structure(list(Value = structure(logical(0), tags = list(type = "string", sensitive = TRUE)), Type = structure(logical(0), tags = list(type = "string")), Resources = structure(logical(0), tags = list(type = "list"))), tags = list(type = "structure"))), tags = list(type = "list"))), tags = list(type = "structure"))), tags = list(type = "list")), NextToken = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_organizational_units_for_parent_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(ParentId = structure(logical(0), tags = list(type = "string")), NextToken = structure(logical(0), tags = list(type = "string")), MaxResults = structure(logical(0), tags = list(type = "integer", box = TRUE))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_organizational_units_for_parent_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(OrganizationalUnits = structure(list(structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Name = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list")), NextToken = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_parents_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(ChildId = structure(logical(0), tags = list(type = "string")), NextToken = structure(logical(0), tags = list(type = "string")), MaxResults = structure(logical(0), tags = list(type = "integer", box = TRUE))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_parents_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Parents = structure(list(structure(list(Id = structure(logical(0), tags = list(type = "string")), Type = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list")), NextToken = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_policies_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Filter = structure(logical(0), tags = list(type = "string")), NextToken = structure(logical(0), tags = list(type = "string")), MaxResults = structure(logical(0), tags = list(type = "integer", box = TRUE))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_policies_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Policies = structure(list(structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Name = structure(logical(0), tags = list(type = "string")), Description = structure(logical(0), tags = list(type = "string")), Type = structure(logical(0), tags = list(type = "string")), AwsManaged = structure(logical(0), tags = list(type = "boolean"))), tags = list(type = "structure"))), tags = list(type = "list")), NextToken = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_policies_for_target_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(TargetId = structure(logical(0), tags = list(type = "string")), Filter = structure(logical(0), tags = list(type = "string")), NextToken = structure(logical(0), tags = list(type = "string")), MaxResults = structure(logical(0), tags = list(type = "integer", box = TRUE))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_policies_for_target_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Policies = structure(list(structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Name = structure(logical(0), tags = list(type = "string")), Description = structure(logical(0), tags = list(type = "string")), Type = structure(logical(0), tags = list(type = "string")), AwsManaged = structure(logical(0), tags = list(type = "boolean"))), tags = list(type = "structure"))), tags = list(type = "list")), NextToken = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_roots_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(NextToken = structure(logical(0), tags = list(type = "string")), MaxResults = structure(logical(0), tags = list(type = "integer", box = TRUE))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_roots_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Roots = structure(list(structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Name = structure(logical(0), tags = list(type = "string")), PolicyTypes = structure(list(structure(list(Type = structure(logical(0), tags = list(type = "string")), Status = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list"))), tags = list(type = "structure"))), tags = list(type = "list")), NextToken = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_tags_for_resource_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(ResourceId = structure(logical(0), tags = list(type = "string")), NextToken = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_tags_for_resource_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Tags = structure(list(structure(list(Key = structure(logical(0), tags = list(type = "string")), Value = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list")), NextToken = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_targets_for_policy_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(PolicyId = structure(logical(0), tags = list(type = "string")), NextToken = structure(logical(0), tags = list(type = "string")), MaxResults = structure(logical(0), tags = list(type = "integer", box = TRUE))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$list_targets_for_policy_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Targets = structure(list(structure(list(TargetId = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Name = structure(logical(0), tags = list(type = "string")), Type = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list")), NextToken = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$move_account_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(AccountId = structure(logical(0), tags = list(type = "string")), SourceParentId = structure(logical(0), tags = list(type = "string")), DestinationParentId = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$move_account_output <- function(...) { list() } .organizations$register_delegated_administrator_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(AccountId = structure(logical(0), tags = list(type = "string")), ServicePrincipal = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$register_delegated_administrator_output <- function(...) { list() } .organizations$remove_account_from_organization_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(AccountId = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$remove_account_from_organization_output <- function(...) { list() } .organizations$tag_resource_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(ResourceId = structure(logical(0), tags = list(type = "string")), Tags = structure(list(structure(list(Key = structure(logical(0), tags = list(type = "string")), Value = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "list"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$tag_resource_output <- function(...) { list() } .organizations$untag_resource_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(ResourceId = structure(logical(0), tags = list(type = "string")), TagKeys = structure(list(structure(logical(0), tags = list(type = "string"))), tags = list(type = "list"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$untag_resource_output <- function(...) { list() } .organizations$update_organizational_unit_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(OrganizationalUnitId = structure(logical(0), tags = list(type = "string")), Name = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$update_organizational_unit_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(OrganizationalUnit = structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Name = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$update_policy_input <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(PolicyId = structure(logical(0), tags = list(type = "string")), Name = structure(logical(0), tags = list(type = "string")), Description = structure(logical(0), tags = list(type = "string")), Content = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure")) return(populate(args, shape)) } .organizations$update_policy_output <- function(...) { args <- c(as.list(environment()), list(...)) shape <- structure(list(Policy = structure(list(PolicySummary = structure(list(Id = structure(logical(0), tags = list(type = "string")), Arn = structure(logical(0), tags = list(type = "string")), Name = structure(logical(0), tags = list(type = "string")), Description = structure(logical(0), tags = list(type = "string")), Type = structure(logical(0), tags = list(type = "string")), AwsManaged = structure(logical(0), tags = list(type = "boolean"))), tags = list(type = "structure")), Content = structure(logical(0), tags = list(type = "string"))), tags = list(type = "structure"))), tags = list(type = "structure")) return(populate(args, shape)) }
"d2p" <- function (depth, lat=40) { ndepth <- length(depth) nlat <- length(lat) nmax <- max(ndepth, nlat) if(ndepth < nmax){depth <- rep(depth[1], nmax)} if(nlat < nmax){lat <- rep(lat[1], nmax)} pi <- 3.141592654 pressure <- rep(NA,nmax) for(i in (1:nmax)){ lat[i] <- abs(lat[i]) plat <- abs(lat[i]*pi)/180 d <- sin(plat) c1 <- 5.92e-3 + d^2 * 5.25e-3 pressure[i] <- ((1-c1)-sqrt(((1-c1)^2)-(8.84e-6*depth[i]))) / 4.42e-6 } return(pressure) }
parallelMap = function(fun, ..., more.args = list(), simplify = FALSE, use.names = FALSE, impute.error = NULL, level = NA_character_, show.info = NA) { assertFunction(fun) assertList(more.args) assertFlag(simplify) assertFlag(use.names) if (!is.null(impute.error)) { if (is.function(impute.error)) { impute.error.fun = impute.error } else { impute.error.fun = function(x) impute.error } } assertString(level, na.ok = TRUE) assertFlag(show.info, na.ok = TRUE) if (!is.na(level) && level %nin% unlist(getPMOption("registered.levels", list()))) { stopf("Level '%s' not registered", level) } cpus = getPMOptCpus() load.balancing = getPMOptLoadBalancing() logging = getPMOptLogging() reproducible = getPMOptReproducible() logdir = ifelse(logging, getNextLogDir(), NA_character_) if (isModeLocal() || !isParallelizationLevel(level) || getPMOptOnSlave()) { if (!is.null(impute.error)) { fun2 = function(...) { res = try(fun(...), silent = getOption("parallelMap.suppress.local.errors")) if (BBmisc::is.error(res)) { res = list(try.object = res) class(res) = "parallelMapErrorWrapper" } return(res) } } else { fun2 = fun } assignInFunctionNamespace(fun, env = PKG_LOCAL_ENV) res = mapply(fun2, ..., MoreArgs = more.args, SIMPLIFY = FALSE, USE.NAMES = FALSE) } else { iters = seq_along(..1) showInfoMessage("Mapping in parallel%s: mode = %s; level = %s; cpus = %i; elements = %i.", ifelse(load.balancing, " (load balanced)", ""), getPMOptMode(), level, getPMOptCpus(), length(iters), show.info = show.info) if (isModeMulticore()) { more.args = c(list(.fun = fun, .logdir = logdir), more.args) if (reproducible) { old.seed = .Random.seed old.rng.kind = RNGkind() seed = sample(1:100000, 1) rm(.Random.seed, envir = globalenv()) set.seed(seed, "L'Ecuyer-CMRG") } res = MulticoreClusterMap(slaveWrapper, ..., .i = iters, MoreArgs = more.args, mc.cores = cpus, SIMPLIFY = FALSE, USE.NAMES = FALSE) if (reproducible) { .Random.seed = old.seed RNGkind(old.rng.kind[1], old.rng.kind[2], old.rng.kind[3]) } } else if (isModeSocket() || isModeMPI()) { more.args = c(list(.fun = fun, .logdir = logdir), more.args) if (load.balancing) { res = clusterMapLB(cl = NULL, slaveWrapper, ..., .i = iters, MoreArgs = more.args) } else { res = clusterMap(cl = NULL, slaveWrapper, ..., .i = iters, MoreArgs = more.args, SIMPLIFY = FALSE, USE.NAMES = FALSE) } } else if (isModeBatchJobs()) { more.args = c(list(.fun = fun, .logdir = NA_character_), more.args) suppressMessages({ reg = getBatchJobsReg() asNamespace("BatchJobs")$dbRemoveJobs(reg, BatchJobs::getJobIds(reg)) BatchJobs::batchMap(reg, slaveWrapper, ..., more.args = more.args) BatchJobs::submitJobs(reg, resources = getPMOptBatchJobsResources(), max.retries = 15) ok = BatchJobs::waitForJobs(reg, stop.on.error = is.null(impute.error)) }) if (!is.na(logdir)) { term = BatchJobs::findTerminated(reg) fns = BatchJobs::getLogFiles(reg, term) dests = file.path(logdir, sprintf("%05i.log", term)) file.copy(from = fns, to = dests) } ids = BatchJobs::getJobIds(reg) ids.err = BatchJobs::findErrors(reg) ids.exp = BatchJobs::findExpired(reg) ids.done = BatchJobs::findDone(reg) ids.notdone = c(ids.err, ids.exp) msgs = rep("Job expired!", length(ids.notdone)) msgs[ids.err] = BatchJobs::getErrorMessages(reg, ids.err) if (is.null(impute.error) && length(c(ids.notdone)) > 0) { extra.msg = sprintf("Please note that remaining jobs were killed when 1st error occurred to save cluster time.\nIf you want to further debug errors, your BatchJobs registry is here:\n%s", reg$file.dir) onsys = BatchJobs::findOnSystem(reg) suppressMessages( BatchJobs::killJobs(reg, onsys) ) onsys = BatchJobs::findOnSystem(reg) if (length(onsys) > 0L) { warningf("Still %i jobs from operation on system! kill them manually!", length(onsys)) } if (length(ids.notdone) > 0L) { stopWithJobErrorMessages(ids.notdone, msgs, extra.msg) } } res = vector("list", length(ids)) res[ids.done] = BatchJobs::loadResults(reg, simplify = FALSE, use.names = FALSE) res[ids.notdone] = lapply(msgs, function(s) impute.error.fun(simpleError(s))) } else if (isModeBatchtools()) { more.args = insert(more.args, list(.fun = fun, .logdir = NA_character_)) old = getOption("batchtools.verbose") options(batchtools.verbose = FALSE) on.exit(options(batchtools.verbose = old)) reg = getBatchtoolsReg() if (nrow(reg$status) > 0L) { batchtools::clearRegistry(reg = reg) } ids = batchtools::batchMap(fun = slaveWrapper, ..., more.args = more.args, reg = reg) batchtools::submitJobs(ids = ids, resources = getPMOptBatchtoolsResources(), reg = reg) ok = batchtools::waitForJobs(ids = ids, stop.on.error = is.null(impute.error), reg = reg) if (!is.na(logdir)) { x = batchtools::findStarted(reg = reg) x$log.file = file.path(reg$file.dir, "logs", sprintf("%s.log", x$job.hash)) .mapply(function(id, fn) writeLines(batchtools::getLog(id, reg = reg), con = fn), x, NULL) } if (ok) { res = batchtools::reduceResultsList(ids, reg = reg) } else { if (is.null(impute.error)) { extra.msg = sprintf("Please note that remaining jobs were killed when 1st error occurred to save cluster time.\nIf you want to further debug errors, your batchtools registry is here:\n%s", reg$file.dir) batchtools::killJobs(reg = reg) ids.notdone = batchtools::findNotDone(reg = reg) stopWithJobErrorMessages( inds = ids.notdone$job.id, batchtools::getErrorMessages(ids.notdone, missing.as.error = TRUE, reg = reg)$message, extra.msg) } else { res = batchtools::findJobs(reg = reg) res$result = list() ids.complete = batchtools::findDone(reg = reg) ids.incomplete = batchtools::findNotDone(reg = reg) res[ids.complete, data.table::`:=`("result", batchtools::reduceResultsList(ids.complete, reg = reg)), with = FALSE] ids[ids.complete, data.table::`:=`("result", lapply(batchtools::getErrorMessages(ids.incomplete, reg = reg)$message, simpleError)), with = FALSE] } } } } if (is.null(impute.error)) { checkResultsAndStopWithErrorsMessages(res) } else { res = lapply(res, function(x) { if (inherits(x, "parallelMapErrorWrapper")) { impute.error.fun(attr(x$try.object, "condition")) } else { x } }) } if (use.names && !is.null(names(..1))) { names(res) = names(..1) } else if (use.names && is.character(..1)) { names(res) = ..1 } else if (!use.names) { names(res) = NULL } if (isTRUE(simplify) && length(res) > 0L) { res = simplify2array(res, higher = simplify) } options(parallelMap.nextmap = (getPMOptNextMap() + 1L)) return(res) } slaveWrapper = function(..., .i, .fun, .logdir = NA_character_) { if (!is.na(.logdir)) { options(warning.length = 8170L, warn = 1L) .fn = file.path(.logdir, sprintf("%05i.log", .i)) .fn = file(.fn, open = "wt") .start.time = as.integer(Sys.time()) sink(.fn) sink(.fn, type = "message") on.exit(sink(NULL)) } options(parallelMap.on.slave = TRUE) on.exit(options(parallelMap.on.slave = FALSE)) res = try(.fun(...)) if (BBmisc::is.error(res)) { res = list(try.object = res) class(res) = "parallelMapErrorWrapper" } if (!is.na(.logdir)) { .end.time = as.integer(Sys.time()) print(gc()) message(sprintf("Job time in seconds: %i", .end.time - .start.time)) sink(NULL) } return(res) } assignInFunctionNamespace = function(fun, li = list(), env = new.env()) { ee = environment(fun) ns = ls(env) for (n in ns) { assign(n, get(n, envir = env), envir = ee) } ns = names(li) for (n in ns) { assign(n, li[[n]], envir = ee) } }
library(relatable) context("relation() reports properties of given mapping correctly for report_properties = TRUE") test_that("report_properties can correctly determine properties of a given relation", { A1 <- c("a", "b", "c") A2 <- c("a", "a", "c", "d") A3 <- c("a", "a", "c", "d", "e") A4 <- c("a", "b", "c", "d") B1 <- c(1, 2, 3) B1.1 <- list("apple", c("banana", "berry"), list("cherry", "coconut")) B2 <- c(1, 2, 2, 3, 4) B3 <- c(1, 2, 2, 3) B4 <- c(1, 2, 3, 4) expect_message(relation(A1, B1, atomic = FALSE, relation_type = NULL, report_properties = TRUE), "Relation properties:\nmin_one_y_per_x: TRUE\nmin_one_x_per_y: TRUE\nmax_one_y_per_x: TRUE\nmax_one_x_per_y: TRUE") expect_message(relation(A1, B1.1, atomic = FALSE, relation_type = NULL, report_properties = TRUE), "Relation properties:\nmin_one_y_per_x: TRUE\nmin_one_x_per_y: TRUE\nmax_one_y_per_x: TRUE\nmax_one_x_per_y: TRUE") expect_message(relation(B1.1, A1, atomic = FALSE, relation_type = NULL, report_properties = TRUE), "Relation properties:\nmin_one_y_per_x: TRUE\nmin_one_x_per_y: TRUE\nmax_one_y_per_x: TRUE\nmax_one_x_per_y: TRUE") expect_message(relation(A2, B2, atomic = FALSE, relation_type = NULL, report_properties = TRUE), "Relation properties:\nmin_one_y_per_x: TRUE\nmin_one_x_per_y: FALSE\nmax_one_y_per_x: FALSE\nmax_one_x_per_y: FALSE") expect_message(relation(A3, B3, atomic = FALSE, relation_type = NULL, report_properties = TRUE), "Relation properties:\nmin_one_y_per_x: FALSE\nmin_one_x_per_y: TRUE\nmax_one_y_per_x: FALSE\nmax_one_x_per_y: FALSE") expect_message(relation(A3, B2, atomic = FALSE, relation_type = NULL, report_properties = TRUE), "Relation properties:\nmin_one_y_per_x: TRUE\nmin_one_x_per_y: TRUE\nmax_one_y_per_x: FALSE\nmax_one_x_per_y: FALSE") expect_message(relation(A4, B2, atomic = FALSE, relation_type = NULL, report_properties = TRUE), "Relation properties:\nmin_one_y_per_x: TRUE\nmin_one_x_per_y: FALSE\nmax_one_y_per_x: TRUE\nmax_one_x_per_y: FALSE") expect_message(relation(A3, B4, atomic = FALSE, relation_type = NULL, report_properties = TRUE), "Relation properties:\nmin_one_y_per_x: FALSE\nmin_one_x_per_y: TRUE\nmax_one_y_per_x: FALSE\nmax_one_x_per_y: TRUE") expect_message(relation(A2, B4, atomic = FALSE, relation_type = NULL, report_properties = TRUE), "Relation properties:\nmin_one_y_per_x: TRUE\nmin_one_x_per_y: TRUE\nmax_one_y_per_x: FALSE\nmax_one_x_per_y: TRUE") expect_message(relation(B4, A2, atomic = FALSE, relation_type = NULL, report_properties = TRUE), "Relation properties:\nmin_one_y_per_x: TRUE\nmin_one_x_per_y: TRUE\nmax_one_y_per_x: TRUE\nmax_one_x_per_y: FALSE") })
short_summary <- function(x) { x <- summary(x) cmat <- coef(x) printCoefmat(cmat) } logisticfn <- function(x) exp(x) / (1 + exp(x)) curve(logisticfn, -5, 5, main="Logistic function") points(0, logisticfn(0), pch=15, cex=2) x1 <- rep(1:10, 2) x2 <- rchisq(20, df=2) y <- rnorm(20, mean=x1 + 2*x2, sd=2) res.lm <- lm(y ~ x1 + x2) short_summary(res.lm) res.glm <- glm(y ~ x1 + x2, family="gaussian") summary(res.glm) babies.prem = subset(babies, subset= gestation < 999 & wt1 < 999 & ht < 99 & smoke < 9, select=c("gestation","smoke","wt1","ht")) babies.prem$preemie = with(babies.prem, as.numeric(gestation < 7*37)) table(babies.prem$preemie) babies.prem$BMI = with(babies.prem, (wt1/2.2) / (ht*2.54/100)^2) hist(babies.prem$BMI) res <- glm(preemie ~ factor(smoke) + BMI, family=binomial, data=babies.prem) short_summary(res) library(MASS) stepAIC(res, trace=0) first.name <- gl(2, 2500, 5000, labels=c("yes", "no")) offer <- gl(2, 1250, 5000, labels=c("yes", "no")) opened <- c(rep(1:0, c(20, 1250-20)), rep(1:0, c(15, 1250-15)), rep(1:0, c(17, 1250-17)), rep(1:0, c( 8, 1250-8))) xtabs(opened ~ first.name + offer) f <- function(x) rep(1:0, c(x, 1250-x)) opened <- c(sapply(c(20, 15, 17, 8), f)) res.glm <- glm(opened ~ first.name + offer, family="binomial") short_summary(res.glm) opened <- c(8,15,17,20) opened.mat <- cbind(opened=opened, not.opened=1250 - opened) opened.mat offer <- c(0, 0, 1, 1) first.name <- c(0, 1, 0, 1) glm(opened.mat ~ first.name + offer, family="binomial") plot(count ~ year, data=yellowfin) f <- function(t, N, r, d) N*(exp(-r*(t-1952))*(1-d) + d) res.yf <- nls(count ~ f(year, N, r, d), start=c(N=6, r=1/10, d=0.1), data=yellowfin) res.yf plot(count ~ year, data=yellowfin) title(main="Mean catch per 100 hooks") curve(f(x, N=6, r=1/10, d=0.1), add=TRUE) curve(f(x, N=6.02, r=0.0939, d=0.0539), add=TRUE, lty=2, lwd=2) legend(1980, 6, legend=c("exploratory", "exponential"), lty=1:2) logistic <- function(t, Y, k, t0, m) Y * (1 + exp(-k * (t-t0)))^(-1) richards <- function(t, Y, k, t0, m) Y * (1 - exp(-k * (t-t0)))^m plot(jitter(size) ~ jitter(age,3), data=urchin.growth, xlab="age", ylab="size", main="Urchin growth by age") res.logistic <- nls(size ~ logistic(age, Y, k, t0), start = c(Y=60, k=1, t0=2), data = urchin.growth) res.logistic AIC(res.logistic) res.logistic <- nls(size ~ logistic(age,Y,k,t0,m), data = urchin.growth, start = c(Y=53, k=1.393, t0=1.958, m=1)) res.richards <- nls(size ~ richards(age, Y, k, t0, m), data = urchin.growth, start = c(Y=53, k=0.5, t0=0, m=1)) res.richards AIC(res.richards) plot(jitter(size) ~ jitter(age,3), data=urchin.growth, xlab="age", ylab="size", main="Urchin growth by age") curve(logistic(x, Y=53.903, k=1.393, t0=1.958), add=TRUE) curve(richards(x, Y=57.26, k=0.78, t0=-0.8587, m = 6.0636), add=TRUE, lty=2) legend(5, 30, lty=1:2, legend=c("Logistic", "Richards")) res <- glm(enjoyed ~ gender + age, data=tastesgreat, family=binomial) summary(res) library(MASS) stepAIC(glm(healthy ~ p + g, healthy, family=binomial)) library(MASS) res.glm <- glm(low ~ age + lwt + smoke + ht + ui, data=birthwt, family = binomial) summary(res.glm) stepAIC(res.glm, trace=0) hfm = hall.fame$Hall.Fame.Membership != "not a member" hfm <- hall.fame$Hall.Fame.Membership != "not a member" res <- glm(hfm ~ BA + HR + hits + games, data=hall.fame, family="binomial") stepAIC(res, trace=0) res.full <- glm(cbind(ncases, ncontrols) ~ agegp + tobgp * alcgp, data = esoph, family = binomial()) res.add <- glm(cbind(ncases, ncontrols) ~ agegp + tobgp + alcgp, data = esoph, family = binomial()) res.full <- glm(cbind(ncases, ncontrols) ~ agegp + tobgp * alcgp, data = esoph, family = binomial()) res.add <- glm(cbind(ncases, ncontrols) ~ agegp + tobgp + alcgp, data = esoph, family = binomial()) AIC(res.full) AIC(res.add) plot(circumference ~ age, data=Orange, subset = Tree == 1) g <- function(t, Y, k, t_0) Y*( 1 + exp(-k*(t-t_0)))^(-1) res.tree <- nls(circumference ~ g(age, Y, k, t0), start=c(Y=150, k=1/300, t0=750), data=Orange, subset=Tree == 1) res.tree age <- 0:1500 plot(circumference ~ age, data=Orange, subset = Tree == 1) lines(age, predict(res.tree, data.frame(age=age))) f <- function(t,Y,k,t0) Y * (1 + exp(-k*(t-t0)))^(-1) plot(weight ~ Time, data=ChickWeight, subset= Chick == 1) nls(weight ~ f(Time, Y, k, t0), start=c(Y=400, k=1/10, t0=20), subset= Chick == 1, data=ChickWeight) curve(f(x, Y=937, k=.08768, t0=35.22270), add=T) library(MASS) example(wtloss) wtloss.fm plot(Weight ~ Days, wtloss) lines(predict(wtloss.fm) ~ Days, data = wtloss) predict(wtloss.fm, newdata=data.frame(Days=365)) l <- function(t, a, b, k, t0) (a + b*t) * (1 - exp(-k*(t-t0))) l1 <- function(t, a, k, t0) l(t, a, 0, k, t0) res.l <- nls(length ~ l(age,a,b,k,t0), data=reddrum, start=c(a=32,b=.25,k=.5,t0=0)) res.l1 <- nls(length ~ l1(age,a,k,t0), data=reddrum, start <- c(a=32,k=.5,t0=0)) AIC(res.l) AIC(res.l1) year <- with(midsize, 2004-Year) f <- function(x, N, r) N * exp(-r*x) with(midsize, nls(Accord ~ f(year,N,r), start=c(N=Accord[1], r=1/5))) with(midsize, nls(Camry ~ f(year,N,r), start=c(N=Camry[1], r=1/5))) with(midsize, nls(Taurus ~ f(year,N,r), start=c(N=Taurus[1], r=1/5)))
mxAlgebraObjective <- function(algebra, numObs = NA, numStats = NA) { if (missing(algebra) || typeof(algebra) != "character") { stop("Algebra argument is not a string (the name of the algebra)") } if (single.na(numObs)) { numObs <- as.numeric(NA) } if (single.na(numStats)) { numStats <- as.numeric(NA) } expectation <- NULL fitfunction <- mxFitFunctionAlgebra(algebra, numObs, numStats) msg <- paste("Objective functions like mxAlgebraObjective() have been deprecated in favor of expectation and fit functions.\n", "Please use mxFitFunctionAlgebra(algebra = ...). See examples at help(mxFitFunctionAlgebra)") warning(msg) return(list(expectation = expectation, fitfunction = fitfunction)) }
plot.BBSGoF <- function(x, ...){ Adjusted.pvalues=x$Adjusted.pvalues data=x$data ss=seq(0.001,0.999,by=0.001) plot(x$n.blocks,x$Tarone.pvalues,ylab="pvalue",ylim=c(0,1),xlim=c(x$kmin,x$kmax),xlab="blocks",main="Tarone's test");abline(h=0.05,col=2,lty=2) rug(x$n.blocks) par(ask=T) plot(x$n.blocks,x$cor,ylab="cor",xlim=c(x$kmin,x$kmax),xlab="blocks",main="Within-block correlation") rug(x$n.blocks) par(ask=T) plot(ss,dbeta(ss,x$beta.parameters[1],x$beta.parameters[2]),type="l",ylab="density",xlab="probability",main="Beta density"); abline(v=x$p,col=2,lty=2) par(ask=T) plot(x$n.blocks,x$effects,ylab="effects",xlab="blocks",xlim=c(x$kmin,x$kmax),main="Decision plot",ylim=c(min(x$effects)-5,x$SGoF));abline(h=x$SGoF,col=2,lty=2) rug(x$n.blocks) if(x$adjusted.pvalues==TRUE){ par(ask=T) plot(sort(data),sort(Adjusted.pvalues),main="BB-SGoF Adjusted p-values",xlab="Unadjusted p-values",ylab="Adjusted p-values",xlim=c(0,1),ylim=c(0,1)) abline(0,1,lty=2,lwd=1.5) par(ask=F) } }
Gold_Wald_CIs_1xc <- function(n, alpha=0.05, printresults=TRUE) { c0 <- length(n) N <- sum(n) pihat <- n / N L <- rep(0, c0) U <- rep(0, c0) Scheffe <- qchisq(1 - alpha, c0 - 1) for (i in 1:c0) { L[i] = pihat[i] - sqrt(Scheffe * pihat[i] * (1-pihat[i]) / N) U[i] = pihat[i] + sqrt(Scheffe * pihat[i] * (1-pihat[i]) / N) } if (printresults) { print(sprintf('The Gold Wald simultaneous intervals'), quote=FALSE) for (i in 1:c0) { print( sprintf( ' pi_%i: estimate = %6.4f (%6.4f to %6.4f)', i, pihat[i], L[i], U[i] ), quote=FALSE ) } } res <- data.frame(lower=L, upper=U, estimate=pihat) invisible(res) }
context("Mosaic Plot") test_that("Mosaic Plot", { set.seed(1619) env = globalenv() createCSEnvir(titanic , strPreds = c("Class", "Age", "Sex", "Survived") , env = env ) createCSFunctions(env = env) expect_true(mosaicPlot()) res = mosaicPlot(return.results = TRUE) expect_list(res, len = 1) expect_data_frame(res$long.contingency) expect_equal(sum(res$long.contingency$Freq), 2201) createCSEnvir(titanic , strPreds = c("Age", "Sex", "Survived"), strResps = "Class" , env = env ) expect_true(mosaicPlot()) createCSEnvir(titanic , strPreds = c("Class", "Age"), strResps = c("Survived", "Sex") , env = env ) expect_true(mosaicPlot()) titanic[, Survived := as.numeric(Survived)] createCSEnvir(titanic , strPreds = c("Class", "Age", "Sex"), strResps = c("Survived") , env = env ) expect_true(mosaicPlot()) data("titanic") })
print.BinaryEPPM <- function (x, digits = max(3, getOption("digits") - 3), ...) { cat("\nCall:", deparse(x$call, width.cutoff = floor(getOption("width") * 0.85)), "", sep = "\n") if ((x$converged)==FALSE) { cat("model did not converge\n") } else { if (length(x$coefficients$p.est)) { cat(paste("Coefficients (model for p with ", x$link, " link):\n", sep = "")) print.default(format(x$coefficients$p.est, digits = digits), print.gap = 2, quote = FALSE) cat("\n") } else cat("No coefficients (in mean model)\n\n") if (length(x$coefficients$scalef.est)) { cat(paste("Coefficients (model for scale-factor with log link):\n", sep = "")) print.default(format(x$coefficients$scalef.est, digits = digits), print.gap = 2, quote = FALSE) cat("\n") } else cat("No coefficients (in precision model)\n\n") } invisible(x) }
context("Sample CTR") test_that("sample_ctr returns correct shape", { input_df <- tibble::tibble( option_name = c("A", "B", "C"), sum_impressions = c(10000, 10000, 10000), sum_clicks = c(1000, 950, 1050) ) n_options <- length(unique(input_df$option_name)) n_samples <- 150 expected_col_names <- c("option_name", "sum_impressions", "sum_clicks", "sum_conversions", "beta_params", "samples") output <- sample_ctr(input_df, priors = list(), n_samples = n_samples) expect_true(is.data.frame(output)) expect_true(all(c("option_name", "samples") %in% colnames(output))) expect_length(output$samples, n_options) purrr::walk(output$samples, ~ expect_length(.x, n_samples)) expect_equal(colnames(output), expected_col_names) })
`print.SII` <- function (x, digits=3, ...) { cat("\n") cat("SII:", round(x$sii, digits), "\n") cat("\n") }
test_that("gradethis_setup() sets `grading_problem.type` and `grading_problem.message`", { with_options( list( gradethis.grading_problem.type = NULL, gradethis.grading_problem.message = NULL ), { gradethis_setup( grading_problem.type = "info", grading_problem.message = "TEST PASS" ) expect_equal(gradethis_settings$grading_problem.type(), "info") expect_equal(gradethis_settings$grading_problem.message(), "TEST PASS") } ) }) test_that("gradethis_setup() issues warning for invalid `grading_problem.type`", { with_options(list(gradethis.grading_problem.type = NULL), { testthat::expect_message( gradethis_setup(grading_problem.type = "bad"), 'Defaulting to "warning"' ) expect_equal( gradethis_settings$grading_problem.type(), gradethis_default_options$grading_problem.type ) }) with_options(list(gradethis.grading_problem.type = "PASS"), { testthat::expect_message( gradethis_setup(grading_problem.type = "bad"), 'Defaulting to "warning"' ) }) }) test_that("gradethis_setup() sets default learnr options via chunk opts", { local_knitr_opts_chunk() with_knitr_opts_chunk(list(exercise.checker = "fail"), { gradethis_setup(exercise.checker = "PASS") expect_equal(knitr::opts_chunk$get("exercise.checker"), "PASS") }) with_knitr_opts_chunk(list(exercise.checker = "fail"), { gradethis_setup(exercise.checker = "PASS", exercise.timelimit = 42) expect_equal(knitr::opts_chunk$get("exercise.checker"), "PASS") expect_equal(knitr::opts_chunk$get("exercise.timelimit"), 42) }) })
rowTabulates <- function(x, rows = NULL, cols = NULL, values = NULL, ..., useNames = NA) { if (is.integer(x)) { } else if (is.logical(x)) { } else if (is.raw(x)) { } else { stop(sprintf("Argument '%s' is not integer, logical, or raw: %s", "x", class(x)[1])) } if (!is.null(rows) && !is.null(cols)) x <- x[rows, cols, drop = FALSE] else if (!is.null(rows)) x <- x[rows, , drop = FALSE] else if (!is.null(cols)) x <- x[, cols, drop = FALSE] if (is.null(values)) { values <- as.vector(x) values <- unique(values) if (is.raw(values)) { values <- as.integer(values) values <- sort.int(values) names <- sprintf("%x", values) names <- paste("0x", names, sep = "") values <- as.raw(values) } else { values <- sort.int(values, na.last = TRUE) names <- as.character(values) } } else { if (is.raw(values)) { names <- sprintf("%x", as.integer(values)) names <- paste("0x", names, sep = "") } else { names <- as.character(values) } } nbr_of_values <- length(values) counts <- matrix(0L, nrow = nrow(x), ncol = nbr_of_values) colnames(counts) <- names na.rm <- anyMissing(x) for (kk in seq_len(nbr_of_values)) { counts[, kk] <- rowCounts(x, value = values[kk], na.rm = na.rm) } if (!is.na(useNames)) { if (useNames) { rownames <- rownames(x) if (!is.null(rownames)) rownames(counts) <- rownames } else { rownames(counts) <- NULL } } counts } colTabulates <- function(x, rows = NULL, cols = NULL, values = NULL, ..., useNames = NA) { if (is.integer(x)) { } else if (is.logical(x)) { } else if (is.raw(x)) { } else { stop(sprintf("Argument '%s' is not integer, logical, or raw: %s", "x", class(x)[1])) } if (!is.null(rows) && !is.null(cols)) x <- x[rows, cols, drop = FALSE] else if (!is.null(rows)) x <- x[rows, , drop = FALSE] else if (!is.null(cols)) x <- x[, cols, drop = FALSE] if (is.null(values)) { values <- as.vector(x) values <- unique(values) if (is.raw(values)) { values <- as.integer(values) values <- sort.int(values) names <- sprintf("%x", values) names <- paste("0x", names, sep = "") values <- as.raw(values) } else { values <- sort.int(values, na.last = TRUE) names <- as.character(values) } } else { if (is.raw(values)) { names <- sprintf("%x", as.integer(values)) names <- paste("0x", names, sep = "") } else { names <- as.character(values) } } transpose <- FALSE if (!transpose) { nbr_of_values <- length(values) counts <- matrix(0L, nrow = ncol(x), ncol = nbr_of_values) colnames(counts) <- names na.rm <- anyMissing(x) for (kk in seq_len(nbr_of_values)) { counts[, kk] <- colCounts(x, value = values[kk], na.rm = na.rm) } } if (!is.na(useNames)) { if (useNames) { colnames <- colnames(x) if (!is.null(colnames)) rownames(counts) <- colnames } else { rownames(counts) <- NULL } } counts }
getCells <- function(x) { return(dimnames(x)[[1]]) } `getCells<-` <- function(x, value) { if (length(value) != ncells(x)) stop("Wrong number of cell names supplied!") if (ncells(x) == 0) return(x) if (length(value) == 1) value <- list(value) dimnames(x)[[1]] <- value return(x) }
person_formats_female_ne_np = c( '{{first_names_female}} {{last_names}}', '{{first_names_female}} {{last_names}}', '{{first_names_female}} {{last_names}}', '{{first_names_female}} {{last_names}}', '{{first_names_female}} {{last_names}}', '{{prefixes_female}} {{first_names_female}} {{last_names}}' ) person_formats_male_ne_np = c( '{{first_names_male}} {{last_names}}', '{{first_names_male}} {{last_names}}', '{{first_names_male}} {{last_names}}', '{{first_names_male}} {{last_names}}', '{{first_names_male}} {{last_names}}', '{{prefixes_male}} {{first_names_male}} {{last_names}}' ) person_formats_ne_np = c(person_formats_male_ne_np, person_formats_female_ne_np) person_first_names_female_ne_np = c( "\u0905\u0902\u0917\u0941\u0930", "\u0905\u091c\u093f\u0924\u093e", "\u0905\u091e\u094d\u091c\u0928\u093e", "\u0905\u0926\u093f\u0924\u0940", "\u0905\u0928\u0927\u093e", "\u0905\u0928\u093f\u0924\u093e", "\u0905\u0928\u093f\u0924\u093e", "\u0905\u0928\u093f\u0924\u093e", "\u0905\u0928\u093f\u0924\u093e", "\u0905\u0928\u0941", "\u0905\u0928\u0941\u092a\u092e\u093e", "\u0905\u0928\u0941\u0930\u093e", "\u0905\u0928\u0941\u0936\u0941\u092f\u093e", "\u0905\u0928\u094d\u091c\u0932\u0940", "\u0905\u0928\u094d\n\u0928\u092a\u0942\u0930\u094d\u0923", "\u0905\u092a\u0930\u094d\u0923\u093e", "\u0905\u092e\u0930\u093e\u0935\u0924\u0940", "\u0905\u092e\u093f\u0915\u093e", "\u0905\u092e\u0943\u0924", "\u0905\u092e\u0943\u0924\u093e", "\u0905\u092e\u094d\u0935\u093f\u0915\u093e", "\u0905\u092e\u094d\u0935\u093f\u0915\u093e", "\u0905\u092e\u094d\u0935\u0940\u0915\u093e", "\u0905\u0930\u0941\u0923\u093e", "\u0905\u0930\u094d\u091a\u0928\u093e", "\u0905\u0930\u094d\u091a\u0928\u093e", "\u0905\u0930\u094d\u091a\u0928\u093e", "\u0905\u0930\u094d\u091a\u0928\u093e", "\u0905\u0938\u094d\n\u092e\u093f\u0924\u093e", "\u0906\u091c\u094d\u091e\u093e", "\u0906\u092d\u093e", "\u0906\u092f\u0941\u0937\u093e", "\u0906\u092f\u0941\u0937\u094d\n\u092e\u093e", "\u0906\u0935\u0943\u0924\u093e", "\u0906\u0936\u093e", "\u0907\u091a\u094d\u091b\u093e", "\u0907\u0928\u094d\u0926\u093f\u0930\u093e", "\u0907\u0928\u094d\u0926\u093f\u0930\u093e", "\u0907\u0928\u094d\u0926\u093f\u0930\u093e", "\u0907\u0928\u094d\u0926\u093f\u0930\u093e", "\u0907\u0928\u094d\u0926\u0940\u0930\u093e", "\u0907\u0928\u094d\u0926\u0941", "\u0907\u0928\u094d\u0926\u0941", "\u0907\u0928\u094d\u0926\u094d\u0930", "\u0907\u0928\u094d\u0926\u094d\u0930", "\u0907\u0928\u094d\n\u0926\u094d\u0930", "\u0907\u092d\u0928", "\u0907\u092d\u093e", "\u0907\u0936\u0941", "\u0908\u0924\u093e\u0938\u093e", "\u0908\u0928\u094d\u0926\u0941", "\u0908\u0932\u093e", "\u0908\u0936\u093e", "\u0908\u0936\u093e", "\u0908\u0936\u094d\n\u0935\u0930\u0940", "\u0908\u0936\u094d\n\u0935\u0930\u0940", "\u0908\u0936\u094d\n\u0935\u0930\u0940", "\u0909\u0924\u094d\u0924\u0930\u093e", "\u0909\u092a\u093e\u0938\u0928\u093e", "\u0909\u092e\u093e", "\u0909\u092e\u093e", "\u0909\u092e\u093e", "\u0909\u092e\u093e", "\u0909\u0930\u094d\u092e\u093f\u0932\u093e", "\u0909\u0930\u094d\u092e\u093f\u0932\u093e", "\u0909\u0930\u094d\u092e\u093f\u0932\u093e", "\u0909\u0937\u093e", "\u0909\u0937\u093e", "\u0909\u0937\u093e", "\u0909\u0937\u093e", "\u0909\u0937\u093e", "\u0909\u0937\u093e", "\u090f\u0932\u093f\u0936\u093e", "\u090f\u0932\u093f\u0938\u093e", "\u090f\u0932\u093f\u0938\u093e", "\u0910\u0930\u093f\u0915\u093e", "\u0915\u092e\u0932\u093e", "\u0915\u092e\u0932\u093e", "\u0915\u092e\u0932\u093e", "\u0915\u092e\u0932\u093e", "\u0915\u092e\u0932\u093e", "\u0915\u0930\u094d\u0938\u093e\u0919", "\u0915\u0932\u094d\u092a\u0928\u093e", "\u0915\u0935\u093f\u0924\u093e", "\u0915\u0935\u093f\u0924\u093e", "\u0915\u093e\u0928\u094d\u0924\u0940", "\u0915\u093e\u0928\u094d\n\u0924\u093e", "\u0915\u093e\u092e\u0928\u093e", "\u0915\u093e\u0932\u0938\u093e\u0919\u094d\u0917", "\u0915\u093f\u0930\u0923", "\u0915\u093f\u0930\u0923", "\u0915\u093f\u0930\u0923", "\u0915\u0941\u0938\u0941\u092e", "\u0915\u0943\u0924\u093f\u0915\u093e", "\u0915\u0943\u0937\u094d\u091f\u093f\u0928\u093e", "\u0915\u0943\u0937\u094d\u0923", "\u0915\u0943\u0937\u094d\u0923", "\u0915\u0943\u0937\u094d\u0923", "\u0915\u0943\u0937\u094d\u0923", "\u0915\u0943\u0937\u094d\n\u0923", "\u0915\u0943\u0937\u094d\n\u0923", "\u0915\u0947\u092e\u093e", "\u0915\u0947\u0936\u0930\u0940", "\u0915\u094b\u092e\u0932", "\u0917\u0902\u0917\u093e", "\u0917\u0902\u0917\u093e", "\u0917\u0902\u0917\u093e", "\u0917\u0923\u0947\u0936", "\u0917\u0930\u0940\u092e\u093e", "\u0917\u093e\u092f\u0924\u094d\u0930\u0940", "\u0917\u0940\u0924\u093e", "\u0917\u0940\u0924\u093e", "\u0917\u0940\u0924\u093e", "\u0917\u0940\u0924\u093e", "\u0917\u094c\u0930\u0940", "\u091a\u0923\u094d\u0921\u093f\u0915\u093e", "\u091a\u0928\u094d\u0926\u093e", "\u091a\u0928\u094d\u0926\u093e", "\u091a\u0928\u094d\u0926\u093e", "\u091a\u0928\u094d\u0926\u093e", "\u091a\u0928\u094d\u0926\u094d\u0930\u092e\u093e\u092f\u093e", "\u091a\u0928\u094d\u0926\u094d\u0930\u0932\u0915\u094d\u0937\u094d\u092e\u0940", "\u091a\u0928\u094d\u0926\u094d\u0930\u093e", "\u091a\u092e\u094d\u092a\u093e", "\u091a\u093e\u0901\u0926\u0928\u0940", "\u091a\u093f\u0928\u0940", "\u091a\u093f\u0928\u0940", "\u091a\u0941\u0928\u0941", "\u091a\u0941\u0930\u0940\u0928\u093e\u0928\u0940", "\u091b\u093f\u0930\u093f\u0919", "\u091b\u093f\u0930\u093f\u0919", "\u091b\u093f\u0930\u093f\u0919", "\u091b\u0941\u0919\u0921\u094d\u092f\u093e\u0915", "\u091b\u0947\u0924\u0928", "\u091b\u094b\u0915\u094d\u092a\u093e", "\u091c\u0924\u0928", "\u091c\u0928\u0915", "\u091c\u092e\u0941\u0928\u093e", "\u091c\u092e\u0941\u0928\u093e", "\u091c\u092f\u0936\u094d\u0930\u0940", "\u091c\u0941\u0928\u093e", "\u091c\u0941\u0928\u0941", "\u091c\u0941\u0932\u0941\u092e", "\u091c\u094d\u091e\u093e\u0928\u0939\u0947\u0930\u093e", "\u091c\u094d\u091e\u093e\u0928\u0940", "\u091c\u094d\u091e\u093e\u0928\u0941", "\u091c\u094d\u092f\u093e\u0938\u094d\u092e\u0940\u0928", "\u091d\u093f\u0928\u093e\u0932\u093e", "\u091f\u093e\u0938\u0940", "\u091f\u093f\u0928\u093e", "\u0921\u093f\u0932\u0941", "\u0921\u094b\u092e\u093e", "\u0921\u094b\u0932\u0940", "\u0921\u094b\u0932\u094d\u092e\u093e", "\u0924\u093e\u0928\u093f\u092f\u093e", "\u0924\u093e\u0930\u093e", "\u0924\u093e\u0930\u093e", "\u0924\u0941\u0932\u0938\u0940", "\u0924\u0947\u091c\u0938\u094d\u0935\u0940", "\u0924\u094b\u092f\u093e", "\u0924\u094b\u0930\u0923", "\u0925\u093f\u0928\u094d\u0932\u0947", "\u0926\u092e\u092f\u0928\u094d\u0924\u093f", "\u0926\u093f\u092a", "\u0926\u093f\u092a\u093e", "\u0926\u093f\u092a\u093e\u091e\u094d\n\u091c\u0932\u0940", "\u0926\u093f\u092a\u093f\u0938\u093e", "\u0926\u093f\u0932", "\u0926\u0940\u0915\u094d\u0937\u093e", "\u0926\u0941\u0930\u094d\u0917\u093e", "\u0926\u0947\u091a\u0947\u0928", "\u0926\u0947\u092c\u0915\u0940", "\u0926\u0947\u0935\u0915\u0940", "\u0926\u0947\u0935\u0940", "\u0927\u0928\u092e\u093e\u092f\u093e", "\u0927\u0928\u094d\u091c\u0941", "\u0927\u0928\u094d\u0936\u094d\n\u0935\u0930\u0940", "\u0927\u0930\u094d\u092e", "\u0928\u0917\u093f\u0928\u093e", "\u0928\u092e\u094d\u0930\u0924\u093e", "\u0928\u093e\u0924\u0940", "\u0928\u093e\u0928\u0941", "\u0928\u093e\u0930\u0928", "\u0928\u093e\u0930\u093e\u092f\u0923", "\u0928\u093f\u0915\u093f\u0924\u093e", "\u0928\u093f\u0915\u094d\u0937\u093e", "\u0928\u093f\u0927\u0940", "\u0928\u093f\u092d\u093e", "\u0928\u093f\u092e\u093e", "\u0928\u093f\u092e\u094d\u092e\u0940", "\u0928\u093f\u092e\u094d\u092e\u0940", "\u0928\u093f\u0930\u091c\u093e", "\u0928\u093f\u0930\u093e", "\u0928\u093f\u0930\u093e", "\u0928\u093f\u0930\u0941", "\u0928\u093f\u0930\u0941", "\u0928\u093f\u0930\u094d\u092e\u0932", "\u0928\u093f\u0930\u094d\u092e\u0932\u093e", "\u0928\u093f\u0930\u094d\u092e\u0932\u093e", "\u0928\u093f\u0932\u0941", "\u0928\u093f\u0936\u0930\u0924", "\u0928\u0940\u0930\u093e", "\u092a\u0926\u092e", "\u092a\u0926\u094d\n\u092e\u093e", "\u092a\u0930\u0932\u093e", "\u092a\u0932\u093f\u0938\u093e", "\u092a\u0935\u093f\u0924\u094d\u0930\u093e", "\u092a\u093e\u0930\u094d\u0935\u0924\u0940", "\u092a\u093e\u0930\u094d\u0935\u0924\u0940", "\u092a\u093f\u0928\u0941", "\u092a\u0941\u091c\u0928", "\u092a\u0941\u091c\u093e", "\u092a\u0941\u091c\u093e", "\u092a\u0941\u091c\u093e", "\u092a\u0941\u0928", "\u092a\u0941\u0937\u094d\u092a\u093e", "\u092a\u0941\u0937\u094d\n\u0937\u093e", "\u092a\u0942\u091c\u093e", "\u092a\u0942\u0930\u094d\u0923", "\u092a\u0942\u0930\u094d\u0923", "\u092a\u0942\u0930\u094d\u0923\u092e\u093e\u092f\u093e", "\u092a\u0947\u0928\u094d\u091c\u0940\u0932\u093e", "\u092a\u094d\u0930\u0924\u093f\u0924\u093f", "\u092a\u094d\u0930\u0924\u093f\u092d\u093e", "\u092a\u094d\u0930\u0924\u093f\u092d\u093e", "\u092a\u094d\u0930\u0924\u093f\u0938\u0930\u093e", "\u092a\u094d\u0930\u092e\u093f\u0932\u093e", "\u092a\u094d\u0930\u092e\u093f\u0932\u093e", "\u092a\u094d\u0930\u0935\u093f\u0928\u093e", "\u092a\u094d\u0930\u093f\u0924\u0940", "\u092a\u094d\u0930\u093f\u092f\u093e", "\u092a\u094d\u0930\u093f\u092f\u093e", "\u092a\u094d\u0930\u093f\u092f\u093e", "\u092a\u094d\u0930\u093f\u092f\u093e", "\u092a\u094d\u0930\u093f\u092f\u093e", "\u092a\u094d\u0930\u0947\u092e\u093e", "\u092a\u094d\u0930\u0947\u0930\u0923\u093e", "\u092a\u094d\u0930\u0947\u0930\u0923\u093e", "\u092b\u0941\u092e\u093f\u0928\u0940", "\u092b\u0941\u0932\u093e\u0935\u0924\u0940", "\u092b\u094c\u091c\u093f\u092f\u093e", "\u092c\u0928\u093f\u0924\u093e", "\u092c\u0928\u094d\u0926\u0928\u093e", "\u092c\u092c\u093f\u0924\u093e", "\u092c\u0935\u093f\u0924\u093e", "\u092c\u093f\u0923\u093e", "\u092c\u093f\u0928\u093f\u0924\u093e", "\u092c\u093f\u092e\u0932\u093e", "\u092c\u0940\u0923\u093e", "\u092c\u0941\u0926\u094d\u0927", "\u092c\u0948\u0937\u094d\u0923\u0935\u0940", "\u092d\u0917\u0935\u0924\u0940", "\u092d\u0917\u0935\u0924\u0940", "\u092d\u0917\u0935\u0924\u0940", "\u092d\u0917\u0935\u0924\u0940", "\u092d\u0917\u0935\u0924\u0940", "\u092d\u0935\u093e\u0928\u0940", "\u092d\u093e\u0930\u0924\u0940", "\u092d\u093e\u0935\u0928\u093e", "\u092d\u0941\u0935\u0928", "\u092d\u094b\u091c\u0915\u0932\u093e", "\u092e\u0902\u0917\u0932\u0940", "\u092e\u091e\u094d\u091c\u0941", "\u092e\u0923\u093f", "\u092e\u0927\u0941", "\u092e\u0928", "\u092e\u0928", "\u092e\u0928\u093f\u0932\u093e", "\u092e\u0928\u093f\u0937\u093e", "\u092e\u0928\u093f\u0937\u093e", "\u092e\u0928\u0940\u0937\u093e", "\u092e\u0928\u094d\u091c\u0941", "\u092e\u0928\u094d\u091c\u0941", "\u092e\u0928\u094d\u091c\u0941", "\u092e\u0928\u094d\u0926\u0940\u0930\u093e", "\u092e\u092e\u0924\u093e", "\u092e\u092e\u0924\u093e", "\u092e\u092f\u0919\u094d\u0916\u0941", "\u092e\u0932\u094d\u0932\u0940\u0915\u093e", "\u092e\u0932\u094d\u0932\u0940\u0915\u093e", "\u092e\u0939\u093e\u0935\u0924\u0940", "\u092e\u093e\u0927\u0941\u0930\u0940", "\u092e\u093e\u0928\u0938\u0940", "\u092e\u093f\u0919\u092e\u0930", "\u092e\u093f\u0920\u0941", "\u092e\u093f\u0928\u093e", "\u092e\u093f\u0928\u093e", "\u092e\u093f\u0928\u093e", "\u092e\u093f\u0928\u093e", "\u092e\u093f\u0928\u0941", "\u092e\u093f\u0930\u093e", "\u092e\u093f\u0930\u093e", "\u092e\u093f\u0936\u094d\u0930\u0940", "\u092e\u0940\u0928\u093e", "\u092e\u0940\u0928\u093e", "\u092e\u0940\u0930\u093e", "\u092e\u0940\u0930\u093e", "\u092e\u0941\u0928\u092e\u0941\u0928", "\u092e\u0942\u0928", "\u092e\u0947\u0928\u093e", "\u092e\u0947\u0928\u094d\n\u0916\u0941", "\u092e\u0947\u0930\u093f\u0928\u093e", "\u092e\u0947\u0930\u093f\u0928\u093e", "\u092e\u0948\u092f\u093e", "\u092e\u094b\u0939\u093f\u0928\u0940", "\u092f\u094b\u0919\u092e\u0940", "\u0930\u0902\u091c\u0940\u0924\u093e", "\u0930\u0915\u0940\u0932\u093e", "\u0930\u091a\u093f\u0924\u093e", "\u0930\u091c\u0928\u0940", "\u0930\u091c\u0928\u0940", "\u0930\u091c\u093f\u0924\u093e", "\u0930\u0928\u094d\u091c\u0928\u093e", "\u0930\u092c\u093f\u0928\u093e", "\u0930\u092c\u0940\u0928\u093e", "\u0930\u092e\u093e", "\u0930\u092e\u093e", "\u0930\u092e\u093e", "\u0930\u092e\u093f\u0924\u093e", "\u0930\u092e\u093f\u0924\u093e", "\u0930\u092e\u093f\u0932\u093e", "\u0930\u0935\u093f\u0928\u093e", "\u0930\u0935\u093f\u0936\u094d\u0930\u0940", "\u0930\u0936\u094d\u092e\u093f", "\u0930\u0936\u094d\u092e\u093f", "\u0930\u0936\u094d\n\u092e\u0940", "\u0930\u093e\u091c\u0932\u0915\u094d\u0937\u094d\u092e\u0940", "\u0930\u093e\u091c\u094d\u092f\u0932\u0915\u094d\u0937\u094d\u092e\u0940", "\u0930\u093e\u0927\u093e", "\u0930\u093e\u0927\u093f\u0915\u093e", "\u0930\u093e\u092e", "\u0930\u093e\u092e", "\u0930\u093e\u092e", "\u0930\u093f\u0924\u093e", "\u0930\u093f\u0924\u093e", "\u0930\u093f\u0924\u093e", "\u0930\u093f\u0924\u0941", "\u0930\u093f\u092e\u093e", "\u0930\u0940\u0924\u093e", "\u0930\u0940\u0924\u093e", "\u0930\u0940\u0924\u093e", "\u0930\u0940\u0928\u093e", "\u0930\u0941\u091c\u093e", "\u0930\u0941\u0926\u094d\u0930", "\u0930\u0941\u092a\u093e", "\u0930\u0941\u092a\u093e", "\u0930\u0941\u092a\u093e", "\u0930\u0941\u092a\u093e", "\u0930\u0941\u092a\u093e", "\u0930\u0941\u092a\u093e", "\u0930\u0941\u092a\u093e", "\u0930\u0941\u0935\u093f\u0928\u093e", "\u0930\u0947\u0916\u093e", "\u0930\u0947\u0923\u0941", "\u0930\u0947\u0935\u0924\u0940", "\u0930\u094b\u091c\u093f\u0928\u093e", "\u0932\u0915\u094d\u0937\u094d\u092e\u0940", "\u0932\u0915\u094d\u0937\u094d\u092e\u0940", "\u0932\u0915\u094d\u0937\u094d\u092e\u0940", "\u0932\u0915\u094d\u0937\u094d\u092e\u0940", "\u0932\u0915\u094d\u0937\u094d\n\u092e\u0940", "\u0932\u0915\u094d\u0937\u094d\n\u092e\u0940", "\u0932\u0932\u093f\u0924\u093e", "\u0932\u093f\u0932\u093e\u0932\u0915\u094d\u0937\u094d\u092e\u0940", "\u0932\u0940\u0932\u093e", "\u0932\u094d\u0939\u093e\u091c\u0940", "\u0935\u0928\u094d\u0926\u093f\u0928\u0940", "\u0935\u0930\u094d\u0937\u093e", "\u0935\u0935\u0940", "\u0935\u093f\u091c\u092f\u093e", "\u0935\u093f\u091c\u092f\u093e", "\u0935\u093f\u0926\u094d\u092f\u093e", "\u0935\u093f\u0927\u094d\u092f\u093e", "\u0935\u093f\u0928\u093e", "\u0935\u093f\u0928\u093e", "\u0935\u093f\u0928\u093f\u0924\u093e", "\u0935\u093f\u0928\u093f\u0924\u093e", "\u0935\u093f\u092d\u093e", "\u0935\u093f\u092e\u0932\u093e", "\u0935\u093f\u092e\u0932\u093e", "\u0935\u093f\u092e\u0932\u093e", "\u0935\u093f\u092e\u0932\u093e", "\u0935\u093f\u0937\u094d\n\u0923\u0941", "\u0935\u093f\u0937\u094d\n\u0923\u0941", "\u0936\u0930\u094d\u092e\u093f\u0932\u093e", "\u0936\u0930\u094d\u092e\u093f\u0932\u093e", "\u0936\u0930\u094d\u092e\u093f\u0932\u093e", "\u0936\u0930\u094d\u092e\u093f\u0932\u093e", "\u0936\u0936\u0940", "\u0936\u0936\u0940", "\u0936\u0936\u0940", "\u0936\u0936\u0940", "\u0936\u093e\u0928\u094d\u0924\u093e", "\u0936\u093e\u0928\u094d\u0924\u093f", "\u0936\u093e\u0928\u094d\u0924\u0940", "\u0936\u093e\u0928\u094d\u0924\u0940", "\u0936\u093e\u0928\u094d\u0924\u0940", "\u0936\u093e\u0928\u094d\u0924\u0940", "\u0936\u093e\u0928\u094d\u0924\u0940", "\u0936\u093f\u0916\u093e", "\u0936\u093f\u0916\u093e", "\u0936\u093f\u0932\u093e", "\u0936\u093f\u0932\u0941", "\u0936\u0940\u0932\u093e", "\u0936\u0941\u092d\u0947\u091a\u094d\u091b\u093e", "\u0936\u0941\u0936\u093f\u0932\u093e", "\u0936\u0941\u0936\u093f\u0932\u093e", "\u0936\u0941\u0938\u093f\u0932\u093e", "\u0936\u094b\u092d\u093e", "\u0936\u094b\u092d\u093e", "\u0936\u094b\u092d\u093e", "\u0936\u094d\u0930\u0926\u094d\u0927\u093e", "\u0936\u094d\u0930\u0926\u094d\u0927\u093e", "\u0936\u094d\u0930\u0940\u092a\u094d\u0930\u093e\u092a\u094d\n\u0924\u0940", "\u0936\u094d\u0930\u0940\u092e\u0924\u0940", "\u0936\u094d\u0930\u0940\u092f\u093e", "\u0936\u094d\u0930\u0943\u0937\u094d\n\u091f\u093f", "\u0936\u094d\u0930\u0947\u092f\u0936\u0940", "\u0936\u094d\n\u092f\u093e\u092e\u093e", "\u0936\u094d\n\u0935\u0947\u0924\u093e", "\u0938\u0902\u0917\u093f\u0924\u093e", "\u0938\u0902\u0917\u093f\u0924\u093e", "\u0938\u0902\u0917\u0940\u0924\u093e", "\u0938\u091a\u093f\u0924\u093e", "\u0938\u091c\u0928\u093e", "\u0938\u0924\u094d\u092f", "\u0938\u0924\u094d\u092f\u0935\u094d\u0930\u0924\u093e", "\u0938\u092a\u0928\u093e", "\u0938\u092b\u0932\u0924\u093e", "\u0938\u092c\u0928\u092e", "\u0938\u092e\u093e\u0928\u0924\u093e", "\u0938\u092e\u0940\u0928\u093e", "\u0938\u092e\u094d\u092a\u0926\u093e", "\u0938\u0930\u0932\u093e", "\u0938\u0930\u0938\u094d\u0935\u0924\u0940", "\u0938\u0930\u0938\u094d\u0935\u0924\u0940", "\u0938\u0930\u0938\u094d\u0935\u0924\u0940", "\u0938\u0930\u0938\u094d\u0935\u0924\u0940", "\u0938\u0930\u0938\u094d\u0935\u0924\u0940", "\u0938\u0930\u093f\u0924\u093e", "\u0938\u0930\u093f\u0924\u093e", "\u0938\u0930\u093f\u0924\u093e", "\u0938\u0930\u093f\u0924\u093e", "\u0938\u0930\u093f\u0924\u093e", "\u0938\u0930\u0940\u0924\u093e", "\u0938\u0930\u0940\u0924\u093e", "\u0938\u0930\u094b\u091c", "\u0938\u0930\u094b\u091c", "\u0938\u0930\u094b\u091c\u093e", "\u0938\u0930\u094d\u092e\u093f\u0932\u093e", "\u0938\u0932\u093f\u0928\u093e", "\u0938\u0932\u093f\u092e\u093e", "\u0938\u0932\u094d\u092d\u093f\u092f\u093e", "\u0938\u0935\u093f\u0924\u093e", "\u0938\u0935\u093f\u0924\u093e", "\u0938\u0935\u093f\u0924\u093e", "\u0938\u0935\u093f\u0924\u093e", "\u0938\u0935\u093f\u0924\u093e", "\u0938\u0935\u093f\u0928\u093e", "\u0938\u093e\u0907\u092e\u0941", "\u0938\u093e\u0917\u0930", "\u0938\u093e\u0928\u0941", "\u0938\u093e\u0928\u0941", "\u0938\u093e\u0928\u0941", "\u0938\u093e\u0928\u094d\u0928\u093e\u0928\u0940", "\u0938\u093e\u0928\u094d\u0928\u093e\u0928\u0940", "\u0938\u093e\u0935\u093f\u0924\u094d\u0930\u0940", "\u0938\u093e\u0935\u093f\u0924\u094d\u0930\u0940", "\u0938\u093e\u0935\u093f\u0924\u094d\u0930\u0940", "\u0938\u093f\u0924\u093e", "\u0938\u093f\u0924\u093e", "\u0938\u093f\u0930\u0941", "\u0938\u0940\u0924\u093e", "\u0938\u0941\u0915\u0943\u0924\u0940", "\u0938\u0941\u0927\u093e", "\u0938\u0941\u0927\u093e", "\u0938\u0941\u0927\u093e", "\u0938\u0941\u0927\u093e", "\u0938\u0941\u0928", "\u0938\u0941\u0928\u093e\u092e", "\u0938\u0941\u0928\u093f\u0924\u093e", "\u0938\u0941\u0928\u093f\u0924\u093e", "\u0938\u0941\u0928\u093f\u0924\u093e", "\u0938\u0941\u092a\u094d\u0930\u092d\u093e", "\u0938\u0941\u092d\u0926\u094d\u0930\u093e", "\u0938\u0941\u092e\u0928", "\u0938\u0941\u092e\u093f\u0924\u094d\u0930\u093e", "\u0938\u0941\u092e\u093f\u0924\u094d\u0930\u093e", "\u0938\u0941\u092e\u093f\u0924\u094d\u0930\u093e", "\u0938\u0941\u092e\u0948\u092f\u093e", "\u0938\u0941\u0930\u0941\u091a\u0940", "\u0938\u0941\u0930\u0947\u0928\u094d\n\u0926\u094d\u0930\u093e", "\u0938\u0941\u0935\u0930\u094d\u0923\u093e", "\u0938\u0941\u0936\u093f\u0932\u093e", "\u0938\u0941\u0936\u093f\u0932\u093e", "\u0938\u0941\u0936\u093f\u0932\u093e", "\u0938\u0941\u0936\u093f\u0932\u093e", "\u0938\u0941\u0937\u092e\u093e", "\u0938\u0941\u0937\u094d\n\u092e\u093e", "\u0938\u0941\u0937\u094d\n\u092e\u093e", "\u0938\u0941\u0938\u093f\u0932\u093e", "\u0938\u0943\u091c\u0928\u093e", "\u0938\u0943\u091c\u0928\u093e", "\u0938\u0943\u091c\u0928\u093e", "\u0938\u094b\u0928\u0940", "\u0938\u094b\u0928\u0941", "\u0938\u094d\u092e\u0943\u0924\u0940", "\u0938\u094d\u092e\u0943\u0924\u0940", "\u0938\u094d\u0935\u0924\u093f", "\u0938\u094d\u0935\u0947\u091a\u094d\n\u091b\u093e", "\u0938\u094d\n\u0935\u0940\u0915\u0943\u0924\u0940", "\u0939\u0928\u0940", "\u0939\u0930\u093f", "\u0939\u093f\u092e\u093e", "\u0939\u093f\u0930\u093e", "\u0939\u093f\u0930\u093e" ) person_first_names_male_ne_np = c( "\u0905\u0915\u094d\u0937\u092f", "\u0905\u091a\u094d\u092f\u0941\u0924", "\u0905\u091c\u092f", "\u0905\u091c\u092f", "\u0905\u0928\u0915", "\u0905\u0928\u093f\u0930", "\u0905\u0928\u093f\u0932", "\u0905\u0928\u093f\u0932", "\u0905\u0928\u093f\u0932", "\u0905\u0928\u093f\u0932", "\u0905\u0928\u093f\u0937", "\u0905\u0928\u0941\u092a", "\u0905\u0928\u0941\u092a", "\u0905\u0928\u094b\u091c", "\u0905\u092d\u093f\u0937\u0947\u0915", "\u0905\u092d\u093f\u0937\u0947\u0915", "\u0905\u092d\u093f\u0937\u0947\u0915", "\u0905\u092e\u093f\u0924", "\u0905\u092e\u093f\u0924", "\u0905\u092e\u093f\u0924", "\u0905\u092e\u093f\u0928", "\u0905\u092e\u0943\u0924", "\u0905\u092e\u0943\u0924", "\u0905\u0930\u0941\u0923", "\u0905\u0930\u0941\u0923", "\u0905\u0930\u094d\u091c\u0941\u0928", "\u0905\u0932\u0902\u0915\u093e\u0930", "\u0905\u0935\u0932\u094b\u0915", "\u0905\u0935\u093f\u0928\u093e\u0936", "\u0905\u0935\u093f\u0936\u0947\u0915", "\u0905\u0936\u094b\u0915", "\u0905\u0936\u094b\u0915", "\u0905\u0936\u094b\u0915", "\u0905\u0936\u094b\u0915", "\u0905\u0936\u094b\u0915", "\u0905\u0936\u094b\u092c", "\u0905\u0938\u093f\u0928", "\u0905\u0938\u094b\u0915", "\u0906\u0915\u093e\u0936", "\u0906\u0924\u094d\u092e\u0947\u0936", "\u0906\u0932\u094b\u0915", "\u0906\u0932\u094b\u0915", "\u0906\u0936\u092f", "\u0906\u0936\u093f\u0937", "\u0906\u0936\u093f\u0937", "\u0906\u0936\u093f\u0937", "\u0906\u0936\u093f\u0937", "\u0906\u0936\u093f\u0937", "\u0906\u0936\u0940\u0937", "\u0908\u092c\u094d\u0930\u093e\u0939\u0940\u092e", "\u0908\u0938\u0940", "\u0909\u091c\u094d\u091c\u094d\u0935\u0932", "\u0909\u0924\u094d\u0924\u092e", "\u0909\u0924\u094d\u0924\u092e", "\u0909\u0926\u094d\u0927\u0935", "\u0909\u0926\u094d\u0927\u0935", "\u0909\u092e\u0947\u0936", "\u0909\u092e\u094d\u092e\u0947\u0926", "\u090b\u0915\u0941", "\u090b\u0936\u0941", "\u090b\u0937\u093f", "\u090b\u0937\u093f\u0915\u0947\u0938", "\u090f\u0915", "\u0913\u092e", "\u0915\u092a\u093f\u0932", "\u0915\u092e\u0932", "\u0915\u092e\u0932", "\u0915\u0930\u0928", "\u0915\u0930\u0928", "\u0915\u0930\u094d\u092e\u093e", "\u0915\u0932\u094d\u092f\u093e\u0923", "\u0915\u093e\u091c\u093f", "\u0915\u093e\u091c\u0940", "\u0915\u093f\u0930\u0923", "\u0915\u093f\u0930\u0923", "\u0915\u093f\u0930\u0923", "\u0915\u093f\u0930\u0923", "\u0915\u093f\u0936\u0928", "\u0915\u093f\u0936\u094b\u0930", "\u0915\u093f\u0936\u094b\u0930", "\u0915\u093f\u0936\u094b\u0930", "\u0915\u0940\u0930\u094d\u0924\u093f", "\u0915\u0941\u092e\u093e\u0930", "\u0915\u0941\u092e\u093e\u0930", "\u0915\u0941\u0935\u0947\u0930", "\u0915\u0941\u0936\u0932", "\u0915\u0943\u091c\u0932", "\u0915\u0943\u0937\u094d\u0923", "\u0915\u0943\u0937\u094d\u0923", "\u0915\u0943\u0937\u094d\u0923\u092e\u093e\u0928", "\u0915\u0943\u0937\u094d\n\u0923", "\u0915\u0943\u0937\u094d\n\u0923", "\u0915\u0943\u0937\u094d\n\u0923", "\u0915\u0943\u0937\u094d\n\u0923", "\u0915\u0943\u0937\u094d\n\u0923", "\u0915\u0943\u0937\u094d\n\u0923", "\u0915\u0943\u0937\u094d\n\u0923", "\u0915\u0943\u0937\u094d\n\u0923", "\u0915\u0943\u0937\u094d\n\u0923", "\u0915\u0943\u0937\u094d\n\u0923", "\u0915\u0943\u0937\u094d\n\u0923", "\u0915\u0947\u0936\u0930", "\u0915\u0947\u0936\u0935", "\u0915\u0947\u0936\u0935", "\u0915\u0947\u0936\u0935", "\u0915\u0947\u0936\u0935\u0932\u093e\u0932", "\u0915\u0947\u0938\u0930", "\u0915\u094c\u0936\u0932", "\u0916\u0917\u0947\u0928\u094d\u0926\u094d\u0930", "\u0916\u0921\u094d\u0917", "\u0917\u0923\u0947\u0936", "\u0917\u094b\u092a\u093e\u0932", "\u0917\u094b\u092a\u093e\u0932", "\u0917\u094b\u092a\u0940", "\u0917\u094b\u0935\u093f\u0928\u094d\u0926", "\u0917\u094b\u0935\u093f\u0928\u094d\u0926", "\u0917\u094b\u0935\u093f\u0928\u094d\u0926", "\u0917\u094c\u0924\u092e", "\u091a\u0928\u094d\u0926", "\u091a\u0928\u094d\u0926\u094d\u0930", "\u091a\u0928\u094d\u0926\u094d\u0930\u0947\u0936", "\u091a\u093f\u0930\u091e\u094d\u091c\u0940\u092c\u093f", "\u091a\u093f\u0930\u0928\u091c\u0940\u0935\u0940", "\u091a\u0948\u0924\u094d\u092f", "\u091b\u0935\u093f", "\u091b\u0947\u0935\u093e\u0919", "\u091c\u0917\u0928\u093e\u0925", "\u091c\u0917\u0928\u094d\u0928\u093e\u0925", "\u091c\u0917\u0928\u094d\u0928\u093e\u0925", "\u091c\u0917\u0935\u093f\u0930", "\u091c\u092f\u0928\u094d\u0924", "\u091c\u092f\u0928\u094d\u0926\u094d\u0930", "\u091c\u092f\u0930\u093e\u092e", "\u091c\u093f\u0924\u0947\u0928\u094d\u0926\u094d\u0930", "\u091c\u0940\u092c\u0928", "\u091c\u0941\u0917\u0932", "\u091c\u094d\u091e\u093e\u0928", "\u091c\u094d\u091e\u093e\u0928\u0941", "\u091c\u094d\u091e\u093e\u0928\u0947\u0936\u094d\n\u0935\u0930", "\u091c\u094d\u092f\u094b\u0924\u0940", "\u091c\u094d\u092f\u094b\u0924\u0940", "\u091c\u094d\n\u092f\u094b\u092d\u093e\u0928", "\u091f\u0938\u0940", "\u091f\u093e\u0938\u0940", "\u091f\u093f\u0915\u093e", "\u091f\u0947\u0915", "\u0921\u093e.", "\u0921\u093e.", "\u0921\u093e.", "\u0921\u0947\u0928\u093f\u0938", "\u0924\u093f\u0930\u094d\u0925", "\u0924\u0947\u091c\u0936\u094d\n\u0935\u0940", "\u0924\u094b\u092a\u094d\u0932\u093e", "\u0924\u094b\u0932\u093e\u0930\u093e\u092e", "\u0924\u094d\u0930\u093f\u0930\u0924\u094d\n\u0928", "\u0925\u094b\u0915\u0947\u0932", "\u0926\u092e\u094b\u0926\u0930", "\u0926\u0930\u094d\u0936\u0928", "\u0926\u0935\u093e", "\u0926\u093e\u0935\u093e", "\u0926\u093f\u0917\u0935\u093f\u091c\u092f\u093e", "\u0926\u093f\u0928\u0947\u0936", "\u0926\u093f\u0928\u0947\u0938", "\u0926\u093f\u092a\u0915", "\u0926\u093f\u092a\u0915", "\u0926\u093f\u092a\u0915", "\u0926\u093f\u092a\u0915", "\u0926\u093f\u092a\u0915", "\u0926\u093f\u092a\u0915", "\u0926\u093f\u092a\u0915", "\u0926\u093f\u092a\u0915", "\u0926\u093f\u092a\u0915", "\u0926\u093f\u092a\u0915\u0938\u094d\u0935\u0930", "\u0926\u093f\u092a\u0940\u0928", "\u0926\u093f\u092a\u0947\u0928\u094d\u0926\u094d\u0930", "\u0926\u093f\u092a\u0947\u0928\u094d\u0926\u094d\u0930", "\u0926\u093f\u092a\u0947\u0928\u094d\u0926\u094d\u0930", "\u0926\u093f\u092a\u0947\u0936", "\u0926\u093f\u092a\u0947\u0936", "\u0926\u093f\u0932\u093f\u092a", "\u0926\u093f\u0935\u093e\u0915\u0930", "\u0926\u0940\u092a\u0915", "\u0926\u0940\u092a\u0947\u0936", "\u0926\u0941\u0930\u094d\u0917\u093e", "\u0926\u0947\u0935", "\u0926\u0947\u0935\u0947\u0928\u094d\u0926\u094d\u0930", "\u0926\u0947\u0935\u0947\u0928\u094d\u0926\u094d\u0930", "\u0926\u0947\u0935\u0947\u0928\u094d\u0926\u094d\u0930", "\u0926\u0947\u0935\u0947\u0928\u094d\n\u0926\u094d\u0930", "\u0926\u094d\u0935\u093e\u0930\u0940\u0915\u093e", "\u0927\u0930\u094d\u092e\u0947\u0928\u094d\u0926\u094d\u0930", "\u0927\u093f\u0930\u091c", "\u0927\u094d\u0930\u0941\u0935", "\u0928\u092c\u093f\u0928", "\u0928\u092c\u093f\u0928\u094d\u0926\u094d\u0930", "\u0928\u0930\u092a\u0932", "\u0928\u0930\u092d\u0942\u092a\u093e\u0932", "\u0928\u0930\u0947\u0928\u094d\u0926\u094d\u0930", "\u0928\u0930\u0947\u0928\u094d\u0926\u094d\u0930", "\u0928\u0935\u0930\u093e\u091c", "\u0928\u0935\u093f\u0928", "\u0928\u0935\u093f\u0928", "\u0928\u093e\u0930\u093e\u092f\u0923", "\u0928\u093e\u0930\u093e\u092f\u0923", "\u0928\u093f\u092e\u0947\u0936", "\u0928\u093f\u0930\u091c", "\u0928\u093f\u0930\u091c", "\u0928\u093f\u0930\u094b\u091c", "\u0928\u093f\u0930\u094d\u092d\u092f", "\u0928\u093f\u0930\u094d\u092e\u0932", "\u0928\u093f\u0930\u094d\u092e\u0947\u0936", "\u092a\u0902\u0915\u091c", "\u092a\u0902\u091a", "\u092a\u0935\u0928", "\u092a\u0935\u0928", "\u092a\u093e\u0930\u0938", "\u092a\u093e\u0938\u093e\u0919\u094d\u0917", "\u092a\u0941\u0930\u0941\u0937\u094b\u0924\u094d\u0924\u092e", "\u092a\u0941\u0930\u094d\u0923\u092d\u0915\u094d\n\u0924", "\u092a\u0941\u0932\u0915\u093f\u0924", "\u092a\u0941\u0937\u094d\n\u092a", "\u092a\u094d\u0930\u0915\u093e\u0936", "\u092a\u094d\u0930\u0915\u093e\u0936", "\u092a\u094d\u0930\u0915\u093e\u0936", "\u092a\u094d\u0930\u0915\u093e\u0936", "\u092a\u094d\u0930\u0915\u093e\u0938", "\u092a\u094d\u0930\u091c\u0940\u0924", "\u092a\u094d\u0930\u091c\u094d\u091e\u093e\u0928", "\u092a\u094d\u0930\u091c\u094d\u0935\u0932", "\u092a\u094d\u0930\u0926\u093f\u092a", "\u092a\u094d\u0930\u0926\u094d\u092e\u0941\u092e\u094d\u0928", "\u092a\u094d\u0930\u092b\u0941\u0932\u094d\u0932", "\u092a\u094d\u0930\u092d\u0941", "\u092a\u094d\u0930\u092e\u0947\u0936\u094d\n\u0935\u0930", "\u092a\u094d\u0930\u092e\u094b\u0926", "\u092a\u094d\u0930\u0932\u094d\n\u0939\u093e\u0926", "\u092a\u094d\u0930\u0935\u093f\u0923", "\u092a\u094d\u0930\u0935\u0947\u0936", "\u092a\u094d\u0930\u0936\u093e\u0928\u094d\u0924", "\u092a\u094d\u0930\u0936\u093e\u0928\u094d\u0928", "\u092a\u094d\u0930\u0938\u0919\u094d\u0917", "\u092a\u094d\u0930\u0947\u092e", "\u092b\u0923\u093f\u0928\u094d\u0926\u094d\u0930", "\u092c\u0926\u094d\u0930\u093f", "\u092c\u0926\u094d\u0930\u0940", "\u092c\u0926\u094d\u0930\u0940", "\u092c\u0928\u0935\u093e\u0930\u0940", "\u092c\u092c\u093f", "\u092c\u092c\u093f", "\u092c\u0932\u0915\u093f\u0938\u0928", "\u092c\u0932\u0930\u093e\u092e", "\u092c\u0932\u094d\u0932\u0941", "\u092c\u0938\u0928\u094d\u0924", "\u092c\u093e\u0938\u0941", "\u092c\u093e\u0938\u0941", "\u092c\u093f\u0915\u093e\u0936", "\u092c\u093f\u0915\u093e\u0938", "\u092c\u093f\u0930\u093e\u091f", "\u092c\u0941\u0926\u094d\u0927\u093f", "\u092c\u0941\u0927\u094d\u0926", "\u092d\u0930\u0924", "\u092d\u0930\u0924", "\u092d\u0930\u0924", "\u092d\u0935\u093f\u0928\u094d\n\u0926\u094d\u0930", "\u092d\u093e\u0907", "\u092d\u0941\u092e\u093e", "\u092d\u0948\u092f\u093e", "\u092d\u0948\u0930\u0935\u0932\u093e\u0932", "\u092d\u094b\u0932\u093e", "\u092e\u0902\u091c\u093f\u0932", "\u092e\u0923\u0940", "\u092e\u0923\u0940\u0930\u093e\u091c", "\u092e\u0926\u0928", "\u092e\u0926\u0928", "\u092e\u0926\u0928", "\u092e\u0928\u093f\u0937", "\u092e\u0928\u0940\u0937", "\u092e\u0928\u094b\u091c", "\u092e\u0928\u094b\u091c", "\u092e\u0928\u094b\u091c", "\u092e\u0928\u094b\u091c", "\u092e\u0928\u094b\u091c", "\u092e\u0928\u094b\u0939\u0930", "\u092e\u0928\u094b\u0939\u0930", "\u092e\u0928\u094d\u0928\u093e", "\u092e\u092f\u0941\u0936", "\u092e\u0939\u0947\u0928\u094d\u0926\u094d\u0930", "\u092e\u0939\u0947\u0936", "\u092e\u0939\u0947\u0936", "\u092e\u0939\u0947\u0936", "\u092e\u0939\u0947\u0936", "\u092e\u0939\u0947\u0936", "\u092e\u093e\u0927\u0935", "\u092e\u093e\u0927\u0935", "\u092e\u093e\u0932\u091a\u0928\u094d\u0926", "\u092e\u093f\u0924\u094d\u0930", "\u092e\u093f\u0928\u0930\u093e\u091c", "\u092e\u0941\u0915\u0941\u0928\u094d\u0926", "\u092e\u0941\u0915\u0941\u0928\u094d\n\u0926", "\u092e\u0941\u0915\u0947\u0936", "\u092e\u0941\u0916\u094d\u092f\u093e", "\u092e\u0941\u0930\u093e\u0930\u0940\u0932\u093e\u0932", "\u092e\u0947\u0918", "\u092e\u0948\u0924\u094d\u0930\u0940", "\u092e\u094b\u0924\u0940", "\u092e\u094b\u0924\u0940", "\u092e\u094b\u0939\u0928", "\u092e\u094b\u0939\u0928", "\u092e\u094b\u0939\u0928", "\u092f\u0936", "\u092f\u093e\u092e", "\u092f\u0941\u0935\u0930\u093e\u091c", "\u092f\u094b\u0917\u0947\u0928\u094d\u0926\u094d\u0930", "\u0930\u091c\u0924", "\u0930\u0924\u0928", "\u0930\u0924\u094d\n\u0928", "\u0930\u092e\u0923", "\u0930\u092e\u0947\u0936", "\u0930\u092e\u0947\u0936", "\u0930\u0935\u093f", "\u0930\u0935\u093f", "\u0930\u0935\u093f", "\u0930\u0935\u093f\u0928", "\u0930\u0935\u093f\u0928\u094d\u0926\u094d\u0930", "\u0930\u0935\u093f\u0928\u094d\u0926\u094d\u0930", "\u0930\u0935\u093f\u0928\u094d\u0926\u094d\u0930", "\u0930\u0935\u093f\u0928\u094d\u0926\u094d\u0930", "\u0930\u093e\u0918\u0935", "\u0930\u093e\u091c", "\u0930\u093e\u091c\u0915\u0941\u092e\u093e\u0930", "\u0930\u093e\u091c\u0928", "\u0930\u093e\u091c\u0928", "\u0930\u093e\u091c\u093f\u0935", "\u0930\u093e\u091c\u0940\u0935", "\u0930\u093e\u091c\u0941", "\u0930\u093e\u091c\u0941", "\u0930\u093e\u091c\u0941", "\u0930\u093e\u091c\u0941", "\u0930\u093e\u091c\u0941", "\u0930\u093e\u091c\u0941", "\u0930\u093e\u091c\u0947\u0928\u094d\u0926\u094d\u0930", "\u0930\u093e\u091c\u0947\u0928\u094d\u0926\u094d\u0930", "\u0930\u093e\u091c\u0947\u0928\u094d\u0926\u094d\u0930", "\u0930\u093e\u091c\u0947\u0928\u094d\u0926\u094d\u0930", "\u0930\u093e\u091c\u0947\u0936", "\u0930\u093e\u091c\u0947\u0936", "\u0930\u093e\u091c\u0947\u0936", "\u0930\u093e\u091c\u0947\u0936", "\u0930\u093e\u091c\u0947\u0936", "\u0930\u093e\u091c\u0947\u0936", "\u0930\u093e\u092e", "\u0930\u093e\u092e", "\u0930\u093e\u092e", "\u0930\u093e\u092e", "\u0930\u093e\u092e", "\u0930\u093e\u092e", "\u0930\u093e\u092e", "\u0930\u093e\u092e", "\u0930\u093e\u092e", "\u0930\u093e\u092e\u091a\u0928\u094d\u0926\u094d\u0930", "\u0930\u093e\u092e\u091c\u093e\u0928", "\u0930\u093e\u092e\u0936\u0930\u0923", "\u0930\u093e\u0939\u0941\u0932", "\u0930\u093e\u0939\u0941\u0932", "\u0930\u093e\u094d\u091c\u0947\u0928\u094d\u0926\u094d\u0930", "\u0930\u0941\u092a\u0947\u0936", "\u0930\u094b\u091c\u093f\u0928", "\u0930\u094b\u091c\u0940\u0928", "\u0930\u094b\u092e\u0947\u0928\u094d\n\u0926\u094d\u0930", "\u0930\u094b\u0939\u0928", "\u0930\u094c\u0928\u0915", "\u0932\u0915\u094d\u0937\u094d\u092e\u0923", "\u0932\u0915\u094d\u0937\u094d\u092e\u0940", "\u0932\u0915\u094d\u0937\u094d\n\u092e\u0923", "\u0932\u0935", "\u0932\u093e\u0932", "\u0932\u093f\u091f\u0928", "\u0935\u0938\u0928\u094d\u0924", "\u0935\u093f\u0915\u093e\u0938", "\u0935\u093f\u0915\u094d\u0930\u092e", "\u0935\u093f\u091c\u092f", "\u0935\u093f\u091c\u0947\u0936", "\u0935\u093f\u0927\u094d\u092f\u093e\u092e\u093e\u0928", "\u0935\u093f\u0928\u093f\u0932", "\u0935\u093f\u0928\u094b\u0926", "\u0935\u093f\u0928\u094b\u0926", "\u0935\u093f\u0930\u092d\u0926\u094d\u0930", "\u0935\u093f\u0930\u0947\u0928\u094d\u0926\u094d\u0930", "\u0935\u093f\u0935\u0947\u0915", "\u0935\u093f\u0935\u0947\u0915", "\u0935\u093f\u0935\u0947\u0915", "\u0935\u093f\u0936\u094d\n\u0935", "\u0935\u093f\u0937\u094d\u0923\u0941", "\u0935\u093f\u0937\u094d\n\u0923\u0941", "\u0935\u0941\u0937\u094d\n\u0915\u0930", "\u0936\u0902\u0915\u0930", "\u0936\u0902\u0915\u0930", "\u0936\u0902\u0915\u0930", "\u0936\u0902\u0915\u0930", "\u0936\u0915\u094d\u0924\u093f", "\u0936\u091a\u093f\u0928\u094d\u0926\u094d\u0930", "\u0936\u0930\u0926", "\u0936\u0930\u0926", "\u0936\u0930\u0926", "\u0936\u0936\u0940", "\u0936\u093e\u0928\u094d\u0924", "\u0936\u093e\u0939\u093f\u0926", "\u0936\u093f\u0935", "\u0936\u093f\u0935", "\u0936\u0941\u0915\u094d\u0930", "\u0936\u0941\u0936\u093e\u0928\u094d\u0924", "\u0936\u0941\u0936\u093f\u0932", "\u0936\u0947\u0932\u0947\u0928\u094d\n\u0926\u094d\u0930", "\u0936\u0948\u0932\u0947\u0928\u094d\u0926\u094d\u0930", "\u0936\u0948\u0932\u0947\u0928\u094d\u0926\u094d\u0930", "\u0936\u0948\u0932\u0947\u0938", "\u0936\u094d\u092f\u093e\u092e", "\u0936\u094d\u0930\u0940\u091c\u0919\u094d\u0917", "\u0936\u094d\u0930\u0940\u0935\u0924\u094d\u0938", "\u0936\u094d\u0930\u0947\u092f\u0938", "\u0936\u094d\n\u092f\u093e\u092e", "\u0936\u094d\n\u092f\u093e\u092e\u0930\u093e\u091c", "\u0938\u0902\u0915\u0930", "\u0938\u0902\u091c\u092f", "\u0938\u0902\u091c\u092f", "\u0938\u0902\u091c\u093f\u0935", "\u0938\u0902\u091c\u093f\u0935", "\u0938\u0902\u091c\u0940\u092c", "\u0938\u0902\u091c\u0940\u0935", "\u0938\u0902\u0926\u093f\u092a", "\u0938\u0917\u0941\u0928", "\u0938\u091c\u0928", "\u0938\u091c\u0947\u0928\u094d\n\u0926\u094d\u0930", "\u0938\u0928\u094d\u091c\u092f", "\u0938\u0928\u094d\u091c\u092f", "\u0938\u0928\u094d\u091c\u0940\u092c", "\u0938\u0928\u094d\u0924\u094b\u0937", "\u0938\u092b\u0930\u093e\u091c", "\u0938\u092e\u0941\u0928\u094d\n\u0926\u094d\u0930", "\u0938\u092e\u094d\u092a\u0941\u0930\u094d\u0923", "\u0938\u0930\u094b\u091c", "\u0938\u0930\u094b\u091c", "\u0938\u0930\u094b\u091c", "\u0938\u0930\u094d\u0935\u0947\u0936", "\u0938\u093e\u0917\u0930", "\u0938\u093e\u0928\u0941", "\u0938\u093f\u0926\u094d\u0927\u093f", "\u0938\u0940\u0924\u093e\u0930\u093e\u092e", "\u0938\u0941\u091c\u0928", "\u0938\u0941\u091c\u0928", "\u0938\u0941\u0926\u0928", "\u0938\u0941\u0926\u0930\u094d\u0936\u0928", "\u0938\u0941\u0927\u093f\u0930", "\u0938\u0941\u0928\u093f\u0932", "\u0938\u0941\u0928\u093f\u0932", "\u0938\u0941\u0928\u093f\u0932", "\u0938\u0941\u0928\u093f\u0932", "\u0938\u0941\u0928\u094d\u0926\u0930", "\u0938\u0941\u092e\u0928", "\u0938\u0941\u092e\u0928", "\u0938\u0941\u0930\u091c", "\u0938\u0941\u0930\u091c", "\u0938\u0941\u0930\u091c", "\u0938\u0941\u0930\u0947\u0928", "\u0938\u0941\u0930\u0947\u0928\u094d\u0926\u094d\u0930", "\u0938\u0941\u0930\u0947\u0928\u094d\n\u0926\u094d\u0930", "\u0938\u0941\u0930\u0947\u0936", "\u0938\u0941\u0930\u0947\u0936", "\u0938\u0941\u0930\u0947\u0936", "\u0938\u0941\u0930\u0947\u0936", "\u0938\u0941\u0935\u0930\u094d\u0923", "\u0938\u0941\u0935\u0930\u094d\u0923", "\u0938\u0941\u0935\u094b\u0927", "\u0938\u0941\u0936\u093e\u0928\u094d\u0924", "\u0938\u0941\u0936\u093f\u0932", "\u0938\u0941\u0936\u093f\u0932", "\u0938\u0943\u091c\u0928", "\u0938\u0947\u0916\u0930", "\u0938\u0948\u092c\u0940", "\u0938\u094b\u092e", "\u0938\u094c\u0930\u092c", "\u0938\u094c\u0930\u092d", "\u0938\u094d\u0935\u093e\u0917\u0924", "\u0938\f\u0902\u091c\u092f", "\u0939\u0930\u093f", "\u0939\u0930\u093f", "\u0939\u0930\u093f", "\u0939\u0930\u093f\u0939\u0930", "\u0939\u0930\u094d\u0915", "\u0939\u093f\u0930\u093e", "\u0939\u093f\u0930\u093e", "\u0939\u093f\u0930\u093e", "\u0939\u093f\u0930\u0947\u0928\u094d\u0926\u094d\u0930", "\u0939\u0947\u092e\u0928", "\u0939\u0947\u092e\u0930\u093e\u091c" ) person_first_names_ne_np = c(person_first_names_male_ne_np, person_first_names_female_ne_np) person_last_names_ne_np = c( "\u0905\u0917\u094d\u0930\u0935\u093e\u0932", "\u0928\u0947\u092a\u093e\u0932", "\u0928\u094d\u092f\u094c\u092a\u093e\u0928\u0947", "\u092e\u0939\u0930\u094d\u091c\u0928", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0925\u093e\u092a\u093e", "\u0932\u093e\u092e\u093e", "\u0916\u0921\u094d\u0917\u0940", "\u0936\u093e\u0939", "\u092e\u093e\u0928\u0928\u094d\u0927\u0930", "\u092e\u093e\u0928\u0928\u094d\n\u0927\u0930", "\u0905\u0917\u094d\u0930\u0935\u093e\u0932", "\u0925\u093e\u092a\u093e", "\u0930\u093f\u092e\u093e\u0932", "\u0905\u0917\u094d\u0930\u0935\u093e\u0932", "\u0938\u0930\u0940\u092f\u093e", "\u0925\u093e\u092a\u093e", "\u0926\u0941\u0917\u0932", "\u092e\u0939\u0930\u094d\u091c\u0928", "\u092c\u0947\u0917\u093e\u092e\u0940", "\u0938\u093f\u0902\u0939", "\u0917\u0941\u0930\u0941\u0919\u094d\u0917", "\u092a\u0928\u094d\n\u0924", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u092a\u093e\u0923\u094d\u0921\u0947", "\u092e\u0939\u0930\u094d\u091c\u0928", "\u091c\u0948\u0928", "\u0936\u093e\u0915\u094d\u092f", "\u0905\u0917\u094d\u0930\u0935\u093e\u0932", "\u0925\u093e\u092a\u093e", "\u092a\u093e\u0923\u094d\n\u0921\u0947", "\u092e\u093e\u0928\u0928\u094d\u0927\u0930", "\u0930\u093e\u091c\u0915\u0930\u094d\u0923\u093f\u0915\u093e\u0930", "\u0930\u0947\u0917\u094d\u092e\u0940", "\u0938\u0930\u093f\u092f\u093e", "\u092a\u094b\u0916\u0930\u0947\u0932", "\u0915\u093e\u0930\u094d\u0915\u0940", "\u0905\u0917\u094d\u0930\u0935\u093e\u0932", "\u092d\u091f\u094d\u091f\u0930\u093e\u0908", "\u092a\u094c\u0921\u094d\u092f\u093e\u0932", "\u0905\u0917\u094d\u0930\u0935\u093e\u0932", "\u092a\u093e\u0923\u094d\u0921\u0947", "\u0909\u092a\u093e\u0927\u094d\u092f\u093e\u092f", "\u0930\f\u091c\u093f\u0924\u0915\u093e\u0930", "\u0905\u0927\u093f\u0915\u093e\u0930\u0940", "\u092a\u093e\u0923\u094d\u0921\u0947", "\u092e\u093e\u0928\u0928\u094d\u0927\u0930", "\u092a\u093e\u0923\u094d\n\u0921\u0947", "\u0905\u0917\u094d\u0930\u0935\u093e\u0932", "\u092e\u0941\u0938\u094d\n\u0932\u0940\u092e", "\u0917\u0941\u0930\u0941\u0919\u094d\u0917", "\u0915\u0915\u094d\u0937\u092a\u0924\u0940", "\u092e\u093e\u0928\u0928\u094d\u0927\u0930", "\u092e\u093e\u0938\u094d\u0915\u0947", "(\u0915\u094d\u0937\u0947\u0924\u094d\u0930\u0940)", "\u0925\u093e\u092a\u093e", "\u0938\u093e\u092a\u0915\u094b\u091f\u093e", "\u092c\u094b\u0925\u0930\u093e", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u092d\u0941\u0938\u093e\u0932", "\u092a\u0928\u094d\u0924", "(\u092a\u093e\u0923\u094d\u0921\u0947)", "\u091f\u093f\u092c\u094d\u0930\u0947\u0935\u093e\u0932", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u092c\u0947\u0917\u093e\u0928\u0940", "\u092a\u0928\u0947\u0930\u0941", "\u0936\u094d\u0930\u0947\u0937\u094d\u0920", "\u0930\u093e\u0920\u094c\u0930", "\u0917\u0941\u0930\u0941\u0919", "\u092a\u093e\u0923\u094d\u0921\u0947", "\u092e\u0939\u0930\u094d\u091c\u0928", "\u092e\u093e\u0928\u0928\u094d\u0927\u0930", "\u0932\u093e\u092e\u093e", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0925\u093e\u092a\u093e", "\u0930\u093e\u0923\u093e", "\u0926\u0941\u0917\u0921", "\u092a\u094d\n\u092f\u093e\u0915\u0941\u0930\u0947\u0932", "\u0905\u0917\u094d\u0930\u0935\u093e\u0932", "\u0905\u0927\u093f\u0915\u093e\u0930\u0940", "\u091c\u094b\u0936\u0940", "\u0917\u0941\u0930\u0941\u0919\u094d\u0917", "\u0938\u093f\u0932\u0935\u093e\u0932", "\u0938\u093f\u0932\u094d\u0935\u093e\u0932", "\u092a\u093e\u0923\u094d\u0921\u0947", "\u092a\u094c\u0921\u094d\u092f\u093e\u0932", "\u0918\u093f\u092e\u093f\u0930\u0947", "\u0915\u094d\u0937\u0947\u0924\u094d\u0930\u0940", "\u0915\u0930\u094d\u092e\u093e\u091a\u093e\u0930\u094d\u092f", "\u0915\u0947.\u0938\u0940.", "\u0925\u093e\u092a\u093e", "\u092e\u0939\u0930\u094d\u091c\u0928", "\u0918\u093f\u092e\u093f\u0930\u0947", "\u0921\u0902\u0917\u094b\u0932", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0916\u0924\u094d\u0930\u0940", "\u0938\u093e\u0939\u0940", "\u0925\u093e\u092a\u093e", "\u092e\u0932\u094d\u0932", "\u0930\u093e\u091c\u0915\u0930\u094d\u0923\u093f\u0915\u093e\u0930", "\u0924\u093f\u0935\u093e\u0930\u0940", "\u092e\u0932\u094d\u0932", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0936\u094d\u0930\u0947\u0937\u094d\u0920", "\u092a\u094d\u0930\u091c\u093e\u092a\u0924\u093f", "\u0938\u093f\u091f\u094c\u0932\u093e", "\u0917\u093f\u0930\u0940", "(\u0927\u0947\u0915\u0947)", "\u0915\u0947.\u0938\u0940.", "\u0936\u0930\u094d\u092e\u093e", "\u0926\u0935\u093e\u0921\u0940", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u092e\u0932\u094d\u0932", "\u0938\u093f\u0932\u094d\u0935\u093e\u0932", "\u0936\u093e\u0915\u094d\u092f", "\u092a\u094d\u0930\u0927\u093e\u0928\u093e\u0919\u094d\u0917", "\u0938\u0941\u0935\u093e\u0932", "\u091c\u0948\u0928", "\u0930\u093f\u092e\u093e\u0932", "\u092a\u094c\u0921\u0947\u0932", "\u092e\u093e\u0928\u0928\u094d\u0927\u0930", "\u091c\u094b\u0936\u0940", "\u0917\u0941\u0930\u0941\u0919\u094d\u0917", "\u092a\u094c\u0921\u0947\u0932", "\u0906\u091a\u093e\u0930\u094d\u092f", "\u0924\u093f\u0935\u093e\u0930\u0940", "\u092e\u0939\u0930\u094d\u091c\u0928", "\u0926\u0941\u0917\u0921", "\u0915\u0947.\u0938\u0940", "\u0915\u0947.\u0938\u0940", "\u092e\u093e\u0928\u0928\u094d\u0927\u0930", "\u0930\u093e\u0923\u093e", "\u0927\u0928\u093e\u0935\u0924", "\u092e\u093e\u0928\u0928\u094d\u0927\u0930", "\u0935\u091c\u094d\u0930\u093e\u091a\u093e\u0930\u094d\u092f", "\u0915\u0915\u094d\u0937\u092a\u0924\u093f", "\u092c\u0947\u0917\u093e\u0928\u0940", "\u092d\u091f\u094d\u091f\u0930\u093e\u0908", "\u092d\u0941\u091c\u0942", "\u0918\u0932\u0947", "\u0917\u0941\u0930\u0941\u0919\u094d\u0917", "\u092c\u0917\u093e\u0932\u0947", "\u092a\u094b\u0916\u0930\u0947\u0932", "\u0925\u093e\u092a\u093e", "\u0925\u093e\u092a\u093e", "\u092e\u0939\u0924\u094b", "\u0932\u094b\u0939\u0928\u0940", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0936\u093e\u0939\u0940", "\u0909\u0915\u094d\u092f\u093e\u0935", "\u0926\u0941\u0917\u0921", "\u0930\u093e\u091c\u0915\u0930\u094d\u0923\u093f\u0915\u093e\u0930", "\u0917\u0941\u0930\u0941\u0919\u094d\u0917", "\u0936\u0930\u094d\u092e\u093e", "\u091c\u0948\u0928", "\u0917\u0941\u0930\u0941\u0919", "\u092c\u0938\u094d\u0928\u0947\u0924", "\u0935\u091c\u094d\u0930\u093e\u091a\u093e\u0930\u094d\u092f", "\u092e\u093e\u0928\u0928\u094d\n\u0927\u0930", "\u092e\u0948\u0928\u093e\u0932\u0940", "\u091a\u094c\u0932\u093e\u0917\u093e\u0908", "\u0928\u094d\u092f\u094c\u092a\u093e\u0928\u0947", "\u092e\u0939\u0930\u094d\u091c\u0928", "\u092e\u093e\u0928\u0928\u094d\u0927\u0930", "\u0930\u093e\u091c\u0915\u0930\u094d\u0923\u093f\u0915\u093e\u0930", "\u0938\u093f\u0902\u0939", "\u0924\u0941\u0932\u093e\u0927\u0930", "\u0905\u0927\u093f\u0915\u093e\u0930\u0940", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0905\u092e\u093e\u0924\u094d\u092f", "\u092e\u0939\u0930\u094d\u091c\u0928", "\u0905\u0917\u094d\u0930\u0935\u093e\u0932", "\u0915\u0947.\u0938\u0940", "\u0905\u0917\u094d\u0930\u0935\u093e\u0932", "\u0905\u0927\u093f\u0915\u093e\u0930\u0940", "\u0928\u094d\u092f\u094c\u092a\u093e\u0928\u0947", "\u0932\u093e\u092e\u093e", "\u092a\u094c\u0921\u0947\u0932", "\u0936\u093e\u0939", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0936\u0930\u094d\u092e\u093e", "\u0936\u093e\u0915\u094d\u092f", "\u092a\u0930\u093e\u091c\u0941\u0932\u0940", "\u0936\u093e\u0939\u0940", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u092a\u094c\u0921\u0947\u0932", "\u0928\u094d\u092f\u094c\u092a\u093e\u0928\u0947", "\u092e\u093e\u0928\u0928\u094d\u0927\u0930", "\u0938\u093f\u0902\u0939", "\u092d\u091f\u094d\u091f\u0930\u093e\u0908", "\u0938\u0941\u0928\u0941\u0935\u093e\u0930", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u091c\u0948\u0928", "\u0936\u093e\u0939", "\u0932\u094b\u0939\u0928\u0940", "\u0924\u0941\u0932\u093e\u0927\u0930", "\u0938\u093f\u0902\f\u0916\u0921\u093e", "\u092a\u094d\u0930\u091c\u093e\u092a\u0924\u093f", "\u092a\u094b\u0926\u094d\u0935\u093e\u0930", "\u0915\u0947.\u0938\u0940", "\u0936\u0930\u094d\u092e\u093e", "\u0936\u0930\u094d\u092e\u093e", "\u0936\u094d\u0930\u0947\u0937\u094d\u0920", "\u0938\u093f\u0902\u0918\u0932", "\u0915\u0947.\u0938\u0940.", "\u0926\u0947\u0909\u091c\u093e", "\u0926\u093e\u0939\u093e\u0932", "\u0916\u0928\u093e\u0932", "\u092a\u0928\u0947\u0930\u0941", "\u092e\u093e\u0928\u0928\u094d\u0927\u0930", "\u0917\u094b\u092f\u0932", "\u091c\u094b\u0936\u0940", "\u0905\u092e\u093e\u0924\u094d\n\u092f", "\u0936\u0947\u0930\u094d\u092a\u093e", "\u0936\u094d\u0930\u0947\u0937\u094d\u0920", "\u092a\u094d\u0930\u0927\u093e\u0928\u093e\u0919", "\u092d\u093f\u092e\u0938\u0930\u093f\u092f\u093e", "\u0938\u0941\u0935\u093e\u0932", "\u0924\u0923\u094d\u0921\u0941\u0915\u093e\u0930", "\u0924\u0941\u0932\u093e\u0927\u0930", "\u0917\u0941\u0930\u093e\u0917\u093e\u0908", "\u092e\u093e\u0928\u0928\u094d\u0927\u0930", "\u091a\u094d\u092f\u093e\u092e\u0947", "\u0938\u0940", "\u0917\u094c\u0924\u092e", "\u091c\u094b\u0936\u0940", "\u0936\u093e\u0939", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0936\u094d\u0930\u0947\u0937\u094d\u0920", "\u0917\u094c\u0924\u092e", "\u0938\u093e\u0939", "\u091c\u094b\u0936\u0940", "\u0917\u0941\u0930\u0941\u0919", "\u092e\u094b\u0915\u094d\u0924\u093e\u0928", "\u0930\u093e\u091c\u0915\u0930\u094d\u0923\u093f\u0915\u093e\u0930", "\u0938\u0941\u0935\u093e\u0932", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u092a\u0928\u094d\u0924", "\u0921\u0902\u0917\u094b\u0932", "\u0909\u092a\u093e\u0927\u094d\n\u092f\u093e\u092f", "\u092a\u094d\u0930\u0927\u093e\u0928", "\u0916\u0928\u093e\u0932", "(\u0928\u094d\u092f\u094c\u092a\u093e\u0928\u0947)", "\u092e\u093f\u0924\u094d\u0924\u0932", "\u0936\u0930\u094d\u092e\u093e", "\u0917\u0921\u0924\u094c\u0932\u093e", "\u0917\u094b\u092f\u0932", "\u0930\u0947\u0917\u094d\u092e\u0940", "\u0916\u0921\u094d\u0917\u0940", "\u0932\u094b\u0939\u0928\u0940", "\u092a\u093e\u0923\u094d\u0921\u0947\u092f", "\u0932\u094b\u0939\u0928\u0940", "\u092a\u093e\u0923\u094d\u0921\u0947", "\u0932\u093f\u092e\u094d\u092c\u0941", "\u0936\u093e\u0939\u0940", "\u0930\u093e\u091c\u0915\u0930\u094d\u0923\u093f\u0915\u093e\u0930", "\u0921\u0902\u0917\u094b\u0932", "\u0938\u093f\f\u0939", "\u092e\u093e\u0928\u0928\u094d\u0927\u0930", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0916\u0924\u094d\u0930\u0940", "\u0939\u093e\u092f\u093e\u091c\u0941", "\u092a\u093e\u0923\u094d\u0921\u0947", "\u0916\u0928\u093e\u0932", "\u0930\u093e\u091c\u0915\u0930\u094d\u0923\u093f\u0915\u093e\u0930", "\u0925\u093e\u092a\u093e", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0936\u093e\u0915\u094d\u092f", "\u092a\u094d\u0930\u091c\u093e\u092a\u0924\u0940", "\u0916\u0921\u094d\u0917\u0940", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u091c\u0948\u0928", "\u0905\u0917\u094d\u0930\u0935\u093e\u0932", "\u0917\u094c\u0924\u092e", "\u0930\u0938\u093e\u092f\u0932\u0940", "\u0916\u0921\u094d\u0917\u0940", "\u0938\u093f\u0932\u0935\u093e\u0932", "\u0936\u093e\u0939\u0940", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0936\u093e\u0939\u0940", "\u0930\u093e\u091c\u0915\u0930\u094d\u0923\u093f\u0915\u093e\u0930", "\u091c\u0948\u0928", "\u092e\u093e\u0928\u0928\u094d\u0927\u0930", "\u091c\u094d\u091e\u0935\u093e\u0932\u0940", "\u092d\u093f\u092e\u0938\u0930\u0940\u092f\u093e", "\u0922\u0919\u094d\u0917\u0947\u0932", "\u092c\u0938\u094d\u0928\u0947\u0924", "\u092a\u094d\u092f\u093e\u0915\u0941\u0930\u0947\u0932", "\u092a\u093e\u0923\u094d\u0921\u0947", "\u0926\u0941\u0917\u0921", "\u0930\u093e\u091c\u0915\u0930\u094d\u0923\u093f\u0915\u093e\u0930", "\u092a\u093e\u0923\u094d\u0921\u0947", "\u0930\u093e\u091c\u0915\u0930\u094d\u0923\u093f\u0915\u093e\u0930", "\u0915\u0941\u0907\u0915\u0947\u0932", "\u0905\u0917\u094d\u0930\u0935\u093e\u0932", "\u0917\u0941\u0930\u0941\u0919\u094d\u0917", "\u0905\u0917\u094d\u0930\u0935\u093e\u0932", "\u092a\u094c\u0921\u0947\u0932", "\u0915\u0902\u0938\u093e\u0915\u093e\u0930", "\u0926\u0941\u0917\u0921", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u092d\u091f\u094d\u091f\u0930\u093e\u0908", "\u0915\u094d\u0937\u0947\u0924\u094d\u0930\u0940", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0928\u093e\u0939\u091f\u093e", "\u092c\u0938\u094d\u0928\u0947\u0924", "\u0930\u093e\u091c\u0915\u0930\u094d\u0923\u093f\u0915\u093e\u0930", "\u0915\u0947.\u0938\u0940.", "\u0915\u0947.\u0938\u0940.", "\u0917\u0941\u092a\u094d\n\u0924\u093e", "\u092c\u091c\u094d\u0930\u093e\u091a\u093e\u0930\u094d\u092f", "\u091c\u094b\u0936\u0940", "\u091c\u094d\u091e\u0935\u093e\u0932\u0940", "\u092a\u0928\u094d\u0924", "\u0938\u093f\u0939\u0902", "\u0917\u0941\u092a\u094d\n\u0924\u093e", "\u091c\u094b\u0936\u0940", "\u0936\u0930\u094d\u092e\u093e", "\u0915\u0947.\u0938\u0940", "\u0926\u0947\u0909\u091c\u093e", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0932\u094b\u0939\u0928\u0940", "\u0930\u0947\u0917\u094d\n\u092e\u0940", "\u0915\u094d\u0937\u0947\u0924\u094d\u0930\u0940", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u091a\u093e\u0932\u093f\u0938\u0947", "\u0939\u093e\u092f\u091c\u0941", "\u092e\u0928\u0928\u094d\u0927\u0930", "\u0936\u094d\u0930\u0947\u0937\u094d\u0920", "\u0915\u0947.\u0938\u0940.", "\u0917\u0941\u0930\u0941\u0919", "\u092e\u093e\u0928\u0928\u094d\u0927\u0930", "\u0930\u093e\u0923\u093e", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u092e\u093e\u0928\u0928\u094d\u0927\u0930", "\u092e\u093e\u0928\u0928\u094d\u0927\u0930", "\u0915\u093e\u092c\u0930\u093e", "\u0936\u093e\u0939\u0940", "\u0930\u093e\u0920\u094c\u0930", "\u0909\u092a\u093e\u0927\u094d\u092f\u093e\u092f", "\u0916\u0928\u093e\u0932", "\u091a\u093e\u0932\u093f\u0938\u0947", "\u0924\u0941\u0932\u093e\u0927\u0930", "\u092e\u0917\u0930", "\u091c\u0948\u0928", "\u092e\u0932\u094d\n\u0932", "\u091c\u0948\u0928", "\u0930\u093e\u0920\u0940", "\u0905\u0927\u093f\u0915\u093e\u0930\u0940", "\u092a\u0928\u094d\n\u0924", "\u0917\u0941\u0930\u0941\u0919\u094d\u0917", "\u0925\u093e\u092a\u093e", "\u092a\u094c\u0921\u0947\u0932", "\u0938\u0941\u0935\u0947\u0926\u0940", "\u0905\u0927\u093f\u0915\u093e\u0930\u0940", "\u092e\u0941\u0938\u0932\u092e\u093e\u0928", "\u0915\u093f\u0932\u094d\u0932\u093e", "\u092e\u094b\u0915\u094d\u0924\u093e\u0928", "\u092c\u0938\u094d\u0928\u094d\u092f\u093e\u0924", "\u0905\u0927\u093f\u0915\u093e\u0930\u0940", "\u0936\u094d\u0930\u0947\u0937\u094d\u0920", "\u0924\u0941\u0932\u093e\u0927\u0930", "\u092c\u091c\u094d\u0930\u093e\u091a\u093e\u0930\u094d\u092f", "\u0926\u0947\u0909\u091c\u093e", "\u0936\u093e\u0915\u094d\u092f", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0917\u0941\u0930\u0941\u0919\u094d\u0917", "\u0932\u0947\u0916\u0915", "\u0916\u0921\u094d\u0915\u093e", "\u092e\u0939\u0930\u094d\u091c\u0928", "\u0915\u093e\u0930\u094d\u0915\u0940", "\u0925\u093e\u092a\u093e", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u092a\u0928\u094d\u0924", "\u0930\u093e\u0908", "\u092a\u093e\u0923\u094d\u0921\u0947", "\u0932\u093e\u092e\u093e", "\u0921\u0902\u0917\u094b\u0932", "\u092e\u093e\u0928\u0928\u094d\u0927\u0930", "\u092a\u0928\u094d\n\u0924", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0936\u093e\u0939", "\u0932\u094b\u0939\u0928\u0940", "\u0926\u0941\u0917\u0921", "\u0932\u093e\u092e\u093e", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0936\u093e\u0939", "\u092e\u093e\u0928\u0928\u094d\u0927\u0930", "\u0905\u0927\u093f\u0915\u093e\u0930\u0940", "\u092a\u093e\u0923\u094d\u0921\u0947", "\u0936\u093e\u0939", "\u0909\u092a\u093e\u0927\u094d\u092f\u093e\u092f", "\u0926\u0947\u0909\u091c\u093e", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u092c\u0947\u0917\u093e\u0928\u0940", "\u0936\u0930\u094d\u092e\u093e", "\u0917\u093f\u0930\u0940", "\u0917\u0941\u0930\u0941\u0919\u094d\u0917", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0925\u093e\u092a\u093e", "\u0930\u093e\u091c\u0915\u0930\u094d\u0923\u093f\u0915\u093e\u0930", "\u0906\u0932\u092e", "\u0905\u0927\u093f\u0915\u093e\u0930\u0940", "\u092e\u093e\u0928\u0928\u094d\n\u0927\u0930", "\u0936\u094d\u0930\u0947\u0937\u094d\u0920", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u092a\u093e\u0923\u094d\u0921\u0947", "\u0930\u0938\u093e\u092f\u0932\u0940", "\u0915\u0947.\u0938\u0940", "\u0930\u093e\u091c\u0915\u0930\u094d\u0923\u093f\u0915\u093e\u0930", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0922\u0915\u093e\u0932", "\u0920\u0941\u0915\u0930\u0940", "\u0922\u0941\u0919\u094d\u0917\u0947\u0932", "\u0930\u093e\u091c\u0915\u0930\u094d\u0923\u093f\u0915\u093e\u0930", "\u092d\u091f\u094d\u091f\u0930\u093e\u0908", "\u0930\u093e\u091c\u0915\u0930\u094d\u0923\u093f\u0915\u093e\u0930", "\u0936\u094d\u0930\u0947\u0937\u094d\u0920", "\u0928\u0947\u092a\u093e\u0932", "\u092e\u0939\u0930\u094d\u091c\u0928", "\u0917\u0941\u0930\u0941\u0919\u094d\u0917", "\u0936\u093e\u0939", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0938\u0924\u094d\u092f\u093e\u0932", "\u0938\u093f\u0902\u0939", "\u092e\u093e\u0928\u0928\n\u0927\u0930", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0928\u0947\u092a\u093e\u0932\u0940", "\u0936\u093e\u0939", "\u0936\u0902\u0915\u0930", "\u0938\u0941\u0928\u0941\u0935\u093e\u0930", "\u0906\u0932\u092e", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0930\u093e\u091c\u0915\u0930\u094d\u0923\u093f\u0915\u093e\u0930", "\u0924\u0941\u0932\u093e\u0927\u0930", "\u0926\u0947\u0909\u091c\u093e", "(\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920)", "\u091c\u094d\u091e\u0935\u093e\u0932\u0940", "\u0924\u0941\u0932\u093e\u0927\u0930", "\u0916\u0921\u094d\u0917\u0940", "\u092c\u091c\u094d\u0930\u093e\u091a\u093e\u0930\u094d\u092f", "\u092a\u0928\u094d\u0924", "\u0939\u093e\u092f\u091c\u0941", "\u0936\u094d\u0930\u0947\u0937\u094d\u0920", "\u0938\u093f\u0902\u0939", "\u0917\u094c\u0924\u092e", "\u092e\u093f\u0924\u094d\u0924\u0932", "\u0920\u0915\u0941\u0930\u0940", "\u0925\u093e\u092a\u093e", "\u092e\u093e\u0928\u0928\u094d\u0927\u0930", "\u0928\u094d\u092f\u094c\u092a\u093e\u0928\u0947", "(\u0905\u092e\u093e\u0924\u094d\u092f)", "\u0932\u093e\u092e\u093e", "\u0938\u093f\u0902\u0939", "\u0925\u093e\u092a\u093e", "\u092e\u093e\u0928\u0928\u094d\u0927\u0930", "\u0921\f\u0902\u0917\u094b\u0932", "\u092e\u093e\u0928\u0928\u094d\u0927\u0930", "\u0924\u0941\u0932\u093e\u0927\u0930", "\u0930\u0938\u093e\u0907\u0932\u0940", "\u0905\u0917\u094d\u0930\u0935\u093e\u0932", "\u091c\u0948\u0928", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0924\u093f\u0935\u093e\u0930\u0940", "\u0936\u094d\u0930\u0947\u0937\u094d\n\u0920", "\u0928\u094d\u092f\u094c\u092a\u093e\u0928\u0947", "\u0924\u093f\u0935\u093e\u0930\u0940", "\u091c\u0948\u0928", "\u0922\u0941\u0919\u094d\u0917\u0947\u0932", "\u092e\u0932\u094d\u0932", "\u0917\u093f\u0930\u0940", "\u0930\u093e\u091c\u0915\u0930\u094d\u0923\u093f\u0915\u093e\u0930", "\u0925\u093e\u092a\u093e", "\u0905\u0917\u094d\u0930\u0935\u093e\u0932", "\u0938\u093f\u091f\u094c\u0932\u093e", "\u0925\u093e\u092a\u093e", "\u0915\u0930\u094d\u092e\u093e\u091a\u093e\u0930\u094d\u092f", "\u0915\u093f\u0930\u093e\u0901\u0924", "\u0938\u093f\u0902\u0939", "\u0938\u093f\u0902\u0939", "\u091c\u094b\u0936\u0940", "\u0936\u093e\u0939\u0940", "\u0926\u093e\u0939\u093e\u0932", "\u092e\u0939\u0930\u094d\u091c\u0928", "\u092e\u0939\u0930\u094d\u091c\u0928", "\u091c\u094b\u0936\u0940", "\u0938\u093f\u0902\u0939", "\u091c\u094b\u0936\u0940" ) person_prefixes_female_ne_np = c("\u0936\u094d\u0930\u0940\u092e\u0924\u0940", "\u0938\u0941\u0936\u094d\u0930\u0940") person_prefixes_male_ne_np = c("\u0936\u094d\u0930\u0940", "\u0936\u094d\u0930\u0940\u092e\u093e\u0928") person_prefixes_ne_np <- c(person_prefixes_female_ne_np, person_prefixes_male_ne_np) person_ne_np <- list( first_names = person_first_names_ne_np, first_names_female = person_first_names_female_ne_np, first_names_male = person_first_names_male_ne_np, last_names = person_last_names_ne_np, prefixes_female = person_prefixes_female_ne_np, prefixes_male = person_prefixes_male_ne_np, prefixes = person_prefixes_ne_np )
imfill <- function(x=1,y=1,z=1,val=0,dim=NULL) { if (!is.null(dim)) { x <- dim[1];y <- dim[2];z <- dim[3] } if (is.character(val)) { val <- col2rgb(val)[,1]/255 } if (length(val) == 1) { if (is.logical(val)) { array(val,c(x,y,z,1)) %>% pixset } else { array(val,c(x,y,z,1)) %>% cimg } } else { map(val,function(v) imfill(x,y,z,val=v)) %>% imappend("c") } } imnoise <- function(x=1,y=1,z=1,cc=1,mean=0,sd=1,dim=NULL) { if (is.null(dim)) { dim <- c(x,y,z,cc) } rnorm(prod(dim),mean=mean,sd=sd) %>% array(dim=dim) %>% cimg } as.cimg.function <- function(obj,width,height,depth=1,spectrum=1,standardise=FALSE,dim=NULL,...) { if (!is.null(dim)) { width <- dim[1] height <- dim[2] depth <- dim[3] spectrum <- dim[4] } fun <- obj args <- formals(fun) %>% names gr <- pixel.grid(dim=c(width,height,depth,spectrum),standardise=standardise,drop.unused=TRUE) if (depth == 1) { if (setequal(args,c("x","y"))) { val <- fun(x=gr$x,y=gr$y) } else if (setequal(args,c("x","y","cc"))) { val <- fun(x=gr$x,y=gr$y,cc=gr$cc) } else{ stop("Input must be a function with arguments (x,y) or (x,y,cc)") } } else { if (setequal(args,c("x","y","z"))) { val <- fun(x=gr$x,y=gr$y,z=gr$z) } else if (setequal(args,c("x","y","z","cc"))) { val <- fun(x=gr$x,y=gr$y,z=gr$z,cc=gr$cc) } else{ stop("Input must be a function with arguments (x,y,z) or (x,y,z,cc)") } } dim(val) <- c(width,height,depth,spectrum) cimg(val) }
spMisalignGLM <- function(formula, family="binomial", weights, data = parent.frame(), coords, starting, tuning, priors, cov.model, amcmc, n.samples, verbose=TRUE, n.report=100, ...){ formal.args <- names(formals(sys.function(sys.parent()))) elip.args <- names(list(...)) for(i in elip.args){ if(! i %in% formal.args) warning("'",i, "' is not an argument") } if(missing(formula)){stop("error: formula must be specified")} if(is.list(formula) && is.list(coords)){ if(length(formula) != length(coords)){ stop("error: formula and coords are misspecified") } mod.dat <- mkMisalignYX(formula, data) Y <- mod.dat[[1]] X <- mod.dat[[2]] misalign.n <- mod.dat[[3]] misalign.p <- mod.dat[[4]] x.names <- mod.dat[[5]] m <- length(formula) storage.mode(misalign.n) <- "integer" storage.mode(misalign.p) <- "integer" }else{ stop("error: formula is misspecified") } p <- ncol(X) n <- nrow(X) n.ltr <- m*(m+1)/2 storage.mode(Y) <- "double" storage.mode(X) <- "double" storage.mode(m) <- "integer" storage.mode(p) <- "integer" storage.mode(n) <- "integer" if(!family %in% c("binomial","poisson")) stop("error: family must be binomial or poisson") if(missing(weights)){ weights <- rep(1, n) }else if(is.list(weights) && length(weights) == m && all(sapply(weights, length) == misalign.n)){ weights<- do.call(c, weights) }else{ stop(paste("error: weights must be a list length ", m," consisting of weight vectors of lengths ", paste(misalign.n, collapse=" "), sep="")) } storage.mode(weights) <- "integer" n.batch <- 0 batch.length <- 0 accept.rate <- 0 is.amcmc <- TRUE if(missing(amcmc)){ stop("error: amcmc must be be specified") }else{ names(amcmc) <- tolower(names(amcmc)) if(!"n.batch" %in% names(amcmc)){stop("error: n.batch must be specified in amcmc list")} n.batch <- amcmc[["n.batch"]] if(!"batch.length" %in% names(amcmc)){stop("error: batch.length must be specified in amcmc list")} batch.length <- amcmc[["batch.length"]] if(!"accept.rate" %in% names(amcmc)){ warning("accept.rate was not specified in the amcmc list and was therefore set to the default 0.43") accept.rate <- 0.43 }else{ accept.rate <- amcmc[["accept.rate"]] } } storage.mode(is.amcmc) <- "integer" storage.mode(n.batch) <- "integer" storage.mode(batch.length) <- "integer" storage.mode(accept.rate) <- "double" if(missing(coords)){stop("error: coords must be specified")} coords <- as.matrix(do.call(rbind, coords)) if(ncol(coords) != 2 || nrow(coords) != n){ stop("error: either the coords have more than two columns or then number of rows is different than data used in the model formula") } coords.D <- iDist(coords) storage.mode(coords.D) <- "double" if(missing(cov.model)){stop("error: cov.model must be specified")} if(!cov.model%in%c("gaussian","exponential","matern","spherical")) {stop("error: specified cov.model '",cov.model,"' is not a valid option; choose, from gaussian, exponential, matern, spherical.")} beta.starting <- 0 A.starting <- 0 phi.starting <- 0 nu.starting <- 0 w.starting <- 0 if(missing(starting)){stop("error: starting value list for the parameters must be specified")} names(starting) <- tolower(names(starting)) if("beta" %in% names(starting)){ beta.starting <- starting[["beta"]] if(length(beta.starting) != p){stop(paste("error: starting values for beta must be of length ",p,sep=""))} }else{ stop("error: beta must be specified in starting") } if(!"a" %in% names(starting)){stop("error: A must be specified in starting")} A.starting <- starting[["a"]] if(length(A.starting) != n.ltr){stop(paste("error: A must be of length ",n.ltr," in starting value list",sep=""))} if(!"phi" %in% names(starting)){stop("error: phi must be specified in starting")} phi.starting <- starting[["phi"]] if(length(phi.starting) != m){stop(paste("error: phi must be of length ",m," in starting value list",sep=""))} if(cov.model == "matern"){ if(!"nu" %in% names(starting)){stop("error: nu must be specified in starting")} nu.starting <- starting[["nu"]] if(length(nu.starting) != m){stop(paste("error: nu must be of length ",m," in starting value list",sep=""))} } if(!"w" %in% names(starting)){stop("error: w must be specified in starting value list")} w.starting <- starting[["w"]] if(is.numeric(w.starting) && length(w.starting) == 1){ w.starting <- rep(w.starting, n) }else if(is.list(w.starting) && length(w.starting) == m && all(sapply(w.starting, length) == misalign.n)){ w.starting <- do.call(c, w.starting) }else{ stop(paste("error: w in the starting value list must be a scalar of length 1 or a list of length ",m, " consisting of vectors of lengths ", paste(misalign.n, collapse=" "), sep="")) } storage.mode(beta.starting) <- "double" storage.mode(phi.starting) <- "double" storage.mode(A.starting) <- "double" storage.mode(nu.starting) <- "double" storage.mode(w.starting) <- "double" beta.Norm <- 0 beta.prior <- "flat" K.IW <- 0 nu.Unif <- 0 phi.Unif <- 0 if(missing(priors)) {stop("error: prior list for the parameters must be specified")} names(priors) <- tolower(names(priors)) if("beta.norm" %in% names(priors)){ beta.Norm <- priors[["beta.normal"]] if(!is.list(beta.Norm) || length(beta.Norm) != 2){stop("error: beta.Norm must be a list of length 2")} if(length(beta.Norm[[1]]) != p ){stop(paste("error: beta.Norm[[1]] must be a vector of length, ",p, " with elements corresponding to betas' mean",sep=""))} if(length(beta.Norm[[2]]) != p ){stop(paste("error: beta.Norm[[2]] must be a vector of length, ",p, " with elements corresponding to betas' sd",sep=""))} beta.prior <- "normal" } if(!"k.iw" %in% names(priors)){stop("error: K.IW must be specified")} K.IW <- priors[["k.iw"]] if(!is.list(K.IW) || length(K.IW) != 2){stop("error: K.IW must be a list of length 2")} if(length(K.IW[[1]]) != 1 ){stop("error: K.IW[[1]] must be of length 1 (i.e., the IW df hyperparameter)")} if(length(K.IW[[2]]) != m^2 ){stop(paste("error: K.IW[[2]] must be a vector or matrix of length, ",m^2, ", (i.e., the IW scale matrix hyperparameter)",sep=""))} if(!"phi.unif" %in% names(priors)){stop("error: phi.Unif must be specified")} phi.Unif <- priors[["phi.unif"]] if(!is.list(phi.Unif) || length(phi.Unif) != 2){stop("error: phi.Unif must be a list of length 2")} if(length(phi.Unif[[1]]) != m){stop(paste("error: phi.Unif[[1]] must be a vector of length, ",m, "",sep=""))} if(length(phi.Unif[[2]]) != m){stop(paste("error: phi.Unif[[2]] must be a vector of length, ",m, "",sep=""))} if(any(phi.Unif[[2]]-phi.Unif[[1]] <= 0)){stop("error: phi.Unif has zero support")} phi.Unif <- as.vector(t(cbind(phi.Unif[[1]],phi.Unif[[2]]))) if(cov.model == "matern"){ if(!"nu.unif" %in% names(priors)){stop("error: nu.Unif must be specified")} nu.Unif <- priors[["nu.unif"]] if(!is.list(nu.Unif) || length(nu.Unif) != 2){stop("error: nu.Unif must be a list of length 2")} if(length(nu.Unif[[1]]) != m){stop(paste("error: nu.Unif[[1]] must be a vector of length, ",m, "",sep=""))} if(length(nu.Unif[[2]]) != m){stop(paste("error: nu.Unif[[2]] must be a vector of length, ",m, "",sep=""))} if(any(nu.Unif[[2]]-nu.Unif[[1]] <= 0)){stop("error: nu.Unif has zero support")} nu.Unif <- as.vector(t(cbind(nu.Unif[[1]],nu.Unif[[2]]))) } storage.mode(K.IW[[1]]) <- "double"; storage.mode(K.IW[[2]]) <- "double" storage.mode(nu.Unif) <- "double" storage.mode(phi.Unif) <- "double" beta.tuning <- 0 phi.tuning <- 0 A.tuning <- 0 nu.tuning <- 0 w.tuning <- 0 if(!missing(tuning)){ names(tuning) <- tolower(names(tuning)) if(!"beta" %in% names(tuning)){stop("error: beta must be specified in tuning value list")} beta.tuning <- tuning[["beta"]] if(is.matrix(beta.tuning)){ if(nrow(beta.tuning) != p || ncol(beta.tuning) != p){ stop(paste("error: if beta tuning is a matrix, it must be of dimension ",p,sep="")) } if(is.amcmc){ beta.tuning <- diag(beta.tuning) } }else if(is.vector(beta.tuning)){ if(length(beta.tuning) != p){ stop(paste("error: if beta tuning is a vector, it must be of length ",p,sep="")) } if(!is.amcmc){ beta.tuning <- diag(beta.tuning) } }else{ stop("error: beta tuning is misspecified") } if(!"a" %in% names(tuning)){stop("error: A must be specified in tuning value list")} A.tuning <- as.vector(tuning[["a"]]) if(length(A.tuning) != n.ltr){stop(paste("error: A must be of length ",n.ltr," in tuning value list",sep=""))} if(!"phi" %in% names(tuning)){stop("error: phi must be specified in tuning value list")} phi.tuning <- tuning[["phi"]] if(length(phi.tuning) != m){stop(paste("error: phi must be of length ",m," in tuning value list",sep=""))} if(cov.model == "matern"){ if(!"nu" %in% names(tuning)){stop("error: nu must be specified in tuning value list")} nu.tuning <- tuning[["nu"]] if(length(nu.tuning) != m){stop(paste("error: nu must be of length ",m," in tuning value list",sep=""))} } if(!"w" %in% names(tuning)){stop("error: w must be specified in tuning value list")} w.tuning <- tuning[["w"]] if(is.numeric(w.tuning) && length(w.tuning) == 1){ w.tuning <- rep(w.tuning, n) }else if(is.list(w.tuning) && length(w.tuning) == m && all(sapply(w.tuning, length) == misalign.n)){ w.tuning <- do.call(c, w.tuning) }else{ stop(paste("error: w in the tuning value list must be a scalar of length 1 or a list of length ",m, " consisting of vectors of lengths ", paste(misalign.n, collapse=" "), sep="")) } }else{ if(!is.amcmc){ stop("error: tuning value list must be specified") } beta.tuning <- rep(0.01,p) phi.tuning <- rep(0.01,m) A.tuning <- rep(0.01,m*(m-1)/2+m) nu.tuning <- rep(0.01,m) w.tuning <- rep(0.01,n) } storage.mode(beta.tuning) <- "double" storage.mode(phi.tuning) <- "double" storage.mode(A.tuning) <- "double" storage.mode(nu.tuning) <- "double" storage.mode(w.tuning) <- "double" storage.mode(n.report) <- "integer" storage.mode(verbose) <- "integer" ptm <- proc.time() out <- .Call("spGLMMisalign_AMCMC", Y, X, misalign.p, misalign.n, m, coords.D, family, weights, beta.prior, beta.Norm, K.IW, nu.Unif, phi.Unif, phi.starting, A.starting, nu.starting, beta.starting, w.starting, phi.tuning, A.tuning, nu.tuning, beta.tuning, w.tuning, cov.model, n.batch, batch.length, accept.rate, verbose, n.report) run.time <- proc.time() - ptm out$p.beta.theta.samples <- mcmc(t(out$p.beta.theta.samples)) col.names <- rep("null",ncol(out$p.beta.theta.samples)) if(cov.model != "matern"){ col.names <- c(x.names, rep("K",n.ltr), paste("phi[",1:m,"]",sep="")) }else{ col.names <- c(x.names, rep("K",n.ltr), paste("phi[",1:m,"]",sep=""), paste("nu[",1:m,"]",sep="")) } colnames(out$p.beta.theta.samples) <- col.names AtA <- function(x, m){ A <- matrix(0, m, m) A[lower.tri(A, diag=TRUE)] <- x (A%*%t(A))[lower.tri(A, diag=TRUE)] } K.names <- paste("K[",matrix(apply(cbind(expand.grid(1:m,1:m)), 1, function(x) paste(x, collapse=",")),m,m)[lower.tri(matrix(0,m,m), diag=TRUE)],"]",sep="") colnames(out$p.beta.theta.samples)[colnames(out$p.beta.theta.samples)%in%"K"] <- K.names out$p.beta.theta.samples[,K.names] <- t(apply(out$p.beta.theta.samples[,K.names,drop=FALSE], 1, AtA, m)) out$weights <- weights out$family <- family out$Y <- Y out$X <- X out$m <- m out$misalign.p <- misalign.p out$misalign.n <- misalign.n out$coords <- coords out$x.names <- x.names out$cov.model <- cov.model out$run.time <- run.time class(out) <- "spMisalignGLM" out }
"ts_AR1_t"
structure(list(url = "https://api.twitter.com/2/tweets/search/all?query=%23IchBinHanna%20place%3ABerlin&max_results=500&start_time=2021-06-01T00%3A00%3A00Z&end_time=2021-06-13T00%3A00%3A00Z&tweet.fields=attachments%2Cauthor_id%2Ccontext_annotations%2Cconversation_id%2Ccreated_at%2Centities%2Cgeo%2Cid%2Cin_reply_to_user_id%2Clang%2Cpublic_metrics%2Cpossibly_sensitive%2Creferenced_tweets%2Csource%2Ctext%2Cwithheld&user.fields=created_at%2Cdescription%2Centities%2Cid%2Clocation%2Cname%2Cpinned_tweet_id%2Cprofile_image_url%2Cprotected%2Cpublic_metrics%2Curl%2Cusername%2Cverified%2Cwithheld&expansions=author_id%2Centities.mentions.username%2Cgeo.place_id%2Cin_reply_to_user_id%2Creferenced_tweets.id%2Creferenced_tweets.id.author_id&place.fields=contained_within%2Ccountry%2Ccountry_code%2Cfull_name%2Cgeo%2Cid%2Cname%2Cplace_type", status_code = 200L, headers = structure(list(date = "Sun, 13 Jun 2021 15:35:04 UTC", server = "tsa_o", `content-type` = "application/json; charset=utf-8", `cache-control` = "no-cache, no-store, max-age=0", `content-length` = "24084", `x-access-level` = "read", `x-frame-options` = "SAMEORIGIN", `content-encoding` = "gzip", `x-xss-protection` = "0", `x-rate-limit-limit` = "300", `x-rate-limit-reset` = "1623598738", `content-disposition` = "attachment; filename=json.json", `x-content-type-options` = "nosniff", `x-rate-limit-remaining` = "292", `strict-transport-security` = "max-age=631138519", `x-connection-hash` = "666b068b934aea113795347145b978a8aca3707fcb16212cb4ada53f1cc9822b"), class = c("insensitive", "list")), all_headers = list(list(status = 200L, version = "HTTP/2", headers = structure(list(date = "Sun, 13 Jun 2021 15:35:04 UTC", server = "tsa_o", `content-type` = "application/json; charset=utf-8", `cache-control` = "no-cache, no-store, max-age=0", `content-length` = "24084", `x-access-level` = "read", `x-frame-options` = "SAMEORIGIN", `content-encoding` = "gzip", `x-xss-protection` = "0", `x-rate-limit-limit` = "300", `x-rate-limit-reset` = "1623598738", `content-disposition` = "attachment; filename=json.json", `x-content-type-options` = "nosniff", `x-rate-limit-remaining` = "292", `strict-transport-security` = "max-age=631138519", `x-connection-hash` = "666b068b934aea113795347145b978a8aca3707fcb16212cb4ada53f1cc9822b"), class = c("insensitive", "list")))), cookies = structure(list(domain = c(".twitter.com", ".twitter.com"), flag = c(TRUE, TRUE), path = c("/", "/"), secure = c(TRUE, TRUE), expiration = structure(c(1686667649, 1686667649), class = c("POSIXct", "POSIXt")), name = c("personalization_id", "guest_id"), value = c("REDACTED", "REDACTED")), row.names = c(NA, -2L), class = "data.frame"), content = charToRaw("{\"data\":[{\"entities\":{\"hashtags\":[{\"start\":57,\"end\":69,\"tag\":\"IchbinHanna\"}]},\"id\":\"1403438596695134209\",\"author_id\":\"14451880\",\"lang\":\"de\",\"created_at\":\"2021-06-11T19:46:50.000Z\",\"source\":\"Twitter for Android\",\"text\":\"was hat es mit den 12 jahren auf sich und wer ist hanna? date = structure(1623598504, class = c("POSIXct", "POSIXt" ), tzone = "GMT"), times = c(redirect = 0, namelookup = 3.2e-05, connect = 3.3e-05, pretransfer = 0.000118, starttransfer = 0.818008, total = 0.820733)), class = "response")
source("qq_plot_v7.R") args <- commandArgs(TRUE) root <- args[1] gwas1<-read.table(paste(root, sep=""),head=T) x1<-gwas1$P pdf(paste(root,".QQ.pdf",sep=""),width=8,height=6) qq.plot(x1, alpha=0.05, datatype="pvalue", scaletype="pvalue", df=1, plot.concentration.band=TRUE, one.sided=FALSE,frac=0.1, print=F, xat=NULL, yat=NULL, main=NULL, xlab=NULL, ylab=NULL, pch="x", cex=0.5, col="black") text(x=12,y=4,paste("lambda--median=", format((median(qchisq(p=1-x1,df=1)))/0.4549,digits=3),sep="")) dev.off()
summary.mniptw <- function (object, ...){ nFits <- object$nFits summaryList <- vector(mode = "list", length = nFits) for (i in 1:nFits) { summaryList[[i]] <- summary(object$psList[[i]], ...) } retObj <- list(summaryList = summaryList, nFit = object$nFit, uniqueTimes = object$uniqueTimes) class(retObj) <- "summary.mniptw" return(retObj) }
context("Testing mode difference functions") run_mode_test <- function( dsin1, dsin2 , expect_diff ){ CALL <- match.call() expect_equal( identify_mode_differences(dsin1, dsin2) %>% nrow, expect_diff, info = str_c("dsin1 = " , as.character(CALL[2]) , "\ndsin2 = " , as.character(CALL[3])) , label = "identify_mode_differences returns a row count" ) } run_mode_test_with_N_obs <-function(N){ X_1col_int <- data_frame( x = seq(1, N) ) X_1col_num <- data_frame( x = rnorm(N) ) X_1col_num2 <- data_frame( x = round(rnorm(N)) ) X_1col_char <- data_frame( x = letters[1:N] ) X_1col_char2 <- data_frame( x = rep('cat', N) ) X_1col_fact <- data_frame( x = factor(letters[1:N]) ) X_1col_fact2 <- data_frame( x = factor(rep(c('cat', 'dog'), c(floor(N/2), ceiling(N/2)))) ) X_1col_lgl <- data_frame( x = rep(T, N) ) X_1col_lgl2 <- data_frame( x = rep(c(T,F), c(floor(N/2), ceiling(N/2))) ) X_2col_numint <- data_frame( x = X_1col_num$x, y = X_1col_int$x ) X_2col_charint <- data_frame( x = X_1col_char$x, y = X_1col_int$x ) X_2col_intchar <- data_frame( x = X_1col_int$x, y = X_1col_char$x ) X_2col_numchar <- data_frame( x = X_1col_num$x, y = X_1col_char$x ) X_2col_numnum <- data_frame( x = X_1col_num$x, y = X_1col_num2$x ) X_2col_numlgl <- data_frame( x = X_1col_num$x, y = X_1col_lgl$x ) X_2col_numfact <- data_frame( x = X_1col_num$x, y = X_1col_fact$x ) X_2col_charlgl <- data_frame( x = X_1col_char$x, y = X_1col_lgl$x ) X_2col_charfact <- data_frame( x = X_1col_char$x, y = X_1col_fact$x ) X_2col_charchar <- data_frame( x = X_1col_char$x, y = X_1col_char2$x ) X_2col_lglfact <- data_frame( x = X_1col_lgl$x, y = X_1col_fact$x ) X_2col_lgllgl <- data_frame( x = X_1col_lgl$x, y = X_1col_lgl$x ) X_2col_factfact <- data_frame( x = X_1col_fact$x, y = X_1col_fact2$x ) test_that( "Check comparision of equal objects",{ run_mode_test( X_1col_int , X_1col_int , 0 ) run_mode_test( X_1col_int , X_1col_fact , 0 ) run_mode_test( X_1col_int , X_1col_fact2 , 0 ) run_mode_test( X_1col_int , X_1col_num , 0 ) run_mode_test( X_1col_int , X_1col_num2 , 0 ) run_mode_test( X_1col_int , X_2col_factfact , 0 ) run_mode_test( X_1col_num , X_1col_num , 0 ) run_mode_test( X_1col_num , X_1col_num2 , 0 ) run_mode_test( X_1col_num , X_1col_fact , 0 ) run_mode_test( X_1col_num , X_1col_fact2 , 0 ) run_mode_test( X_1col_num2 , X_1col_fact , 0 ) run_mode_test( X_1col_num2 , X_1col_fact2 , 0 ) run_mode_test( X_1col_char , X_1col_char , 0 ) run_mode_test( X_1col_char , X_1col_char2 , 0 ) run_mode_test( X_1col_fact , X_1col_fact , 0 ) run_mode_test( X_1col_fact , X_1col_fact2 , 0 ) run_mode_test( X_1col_lgl , X_1col_lgl , 0 ) run_mode_test( X_1col_lgl , X_1col_lgl2 , 0 ) run_mode_test( X_2col_numnum , X_2col_numnum , 0 ) run_mode_test( X_2col_numchar , X_2col_numchar , 0 ) run_mode_test( X_2col_numlgl , X_2col_numlgl , 0 ) run_mode_test( X_2col_numfact , X_2col_numfact , 0 ) run_mode_test( X_2col_numnum , X_2col_numfact , 0 ) run_mode_test( X_2col_charlgl , X_2col_charlgl , 0 ) run_mode_test( X_2col_charfact , X_2col_charfact , 0 ) run_mode_test( X_2col_charchar , X_2col_charchar , 0 ) run_mode_test( X_2col_lglfact , X_2col_lglfact , 0 ) run_mode_test( X_2col_lgllgl , X_2col_lgllgl , 0 ) run_mode_test( X_2col_factfact , X_2col_factfact , 0 ) run_mode_test( X_2col_numint , X_2col_factfact , 0 ) run_mode_test( X_2col_numnum , X_2col_factfact , 0 ) }) test_that( "Check comparision of non equal objects aiming for differences of length 1",{ run_mode_test( X_1col_int , X_1col_char , 1 ) run_mode_test( X_1col_int , X_1col_char2 , 1 ) run_mode_test( X_1col_int , X_1col_lgl , 1 ) run_mode_test( X_1col_int , X_1col_lgl2 , 1 ) run_mode_test( X_1col_int , X_2col_charlgl , 1 ) run_mode_test( X_1col_num , X_1col_char , 1 ) run_mode_test( X_1col_num , X_1col_char2 , 1 ) run_mode_test( X_1col_num , X_1col_lgl , 1 ) run_mode_test( X_1col_num , X_1col_lgl2 , 1 ) run_mode_test( X_1col_num , X_2col_charlgl , 1 ) run_mode_test( X_1col_num2 , X_1col_char , 1 ) run_mode_test( X_1col_num2 , X_1col_char2 , 1 ) run_mode_test( X_1col_num2 , X_1col_lgl , 1 ) run_mode_test( X_1col_num2 , X_1col_lgl2 , 1 ) run_mode_test( X_1col_num2 , X_2col_charlgl , 1 ) run_mode_test( X_1col_char , X_1col_lgl , 1 ) run_mode_test( X_1col_char , X_1col_lgl2 , 1 ) run_mode_test( X_1col_char , X_1col_fact , 1 ) run_mode_test( X_1col_char , X_1col_fact2 , 1 ) run_mode_test( X_1col_char2 , X_1col_lgl , 1 ) run_mode_test( X_1col_char2 , X_1col_lgl2 , 1 ) run_mode_test( X_1col_char2 , X_1col_fact , 1 ) run_mode_test( X_1col_char2 , X_1col_fact2 , 1 ) run_mode_test( X_1col_lgl , X_1col_fact , 1 ) run_mode_test( X_1col_lgl , X_1col_fact2 , 1 ) run_mode_test( X_1col_lgl2 , X_1col_fact , 1 ) run_mode_test( X_1col_lgl2 , X_1col_fact2 , 1 ) run_mode_test( X_2col_numnum , X_2col_numchar , 1 ) run_mode_test( X_2col_numnum , X_2col_numlgl , 1 ) run_mode_test( X_2col_numchar , X_2col_numlgl , 1 ) run_mode_test( X_2col_numchar , X_2col_numfact , 1 ) run_mode_test( X_2col_numlgl , X_2col_numfact , 1 ) run_mode_test( X_2col_charchar , X_2col_charlgl , 1 ) run_mode_test( X_2col_charchar , X_2col_charfact , 1 ) run_mode_test( X_2col_lgllgl , X_2col_lglfact , 1 ) run_mode_test( X_2col_factfact , X_2col_intchar , 1 ) run_mode_test( X_2col_numnum , X_2col_charfact , 1 ) }) test_that( "Check comparision of non equal objects aiming for differences of length 2",{ run_mode_test( X_2col_numnum , X_2col_charlgl , 2 ) run_mode_test( X_2col_numnum , X_2col_charchar , 2 ) run_mode_test( X_2col_numnum , X_2col_lgllgl , 2 ) run_mode_test( X_2col_charchar , X_2col_lglfact , 2 ) run_mode_test( X_2col_charchar , X_2col_lgllgl , 2 ) run_mode_test( X_2col_charchar , X_2col_factfact , 2 ) run_mode_test( X_2col_lgllgl , X_2col_factfact , 2 ) }) } run_mode_test_with_N_obs(1) run_mode_test_with_N_obs(10) run_mode_test_with_N_obs(100) run_mode_test_with_N_obs(1000)
context("link_ethoscope_metadata") test_that("link_ethoscope_metadata with single file", { dir <- scopr_example_dir() test_file <- paste(dir, "ethoscope_results/029/E_029/2016-01-25_21-14-55/2016-01-25_21-14-55_029.db",sep="/") out <- link_ethoscope_metadata(test_file) expect_equal(nrow(out), 20) expect_equal(unique(sapply(out$file_info, function(x) x$path)), test_file) expect_equal(sort(out$region_id), 1:20) out }) test_that("link_ethoscope_metadata with date and machine name", { dir <- paste0(scopr_example_dir(), "/ethoscope_results/") query <- data.frame(machine_name = c("E_014", "E_014","E_029"), date = c("2016-01-25", "2016-02-17","2016-01-25"), time = c("21:46:14", NA, NA), test=c(1,2,3) ) out <- link_ethoscope_metadata(query, dir) expect_equal(nrow(out), 60) }) test_that("link_ethoscope_metadata with name of a text csv", { dir <- paste0(scopr_example_dir(), "/ethoscope_results/") query <- data.frame(machine_name = c("E_014", "E_014","E_029"), date = c("2016-01-25", "2016-02-17","2016-01-25"), time = c("21:46:14", NA, NA), test=c(1,2,3) ) file <- tempfile(fileext = ".txt") write.csv(query, file, row.names = F) out <- link_ethoscope_metadata(file, dir) expect_equal(nrow(out), 60) }) test_that("link_ethoscope_metadata with date, machine name, and ROIs", { dir <- paste0(scopr_example_dir(), "/ethoscope_results/") query <- data.frame(machine_name = c("E_014", "E_014","E_029"), date = c("2016-01-25", "2016-02-17","2016-01-25"), time = c("21:46:14", NA, NA), test=c(1,2,3) ) query <- data.table::as.data.table(query) query <- query[,.(region_id=1:5),by=c(colnames(query))] query[, treatment := rep(1:3,length.out=.N)] out <- link_ethoscope_metadata(query, dir) expect_equal(nrow(out), 3*5) }) test_that("link_ethoscope_metadata with path", { dir <- scopr_example_dir() test_file <- paste(dir, "ethoscope_results/029/E_029/2016-01-25_21-14-55/2016-01-25_21-14-55_029.db",sep="/") query <- data.frame(path =test_file, test=c(1,2,3), region_id=1:3) out <- link_ethoscope_metadata(query, dir) expect_equal(nrow(out), 3) expect_equal(unique(sapply(out$file_info, function(x) x$path)), test_file) expect_equal(sort(out$region_id), 1:3) }) test_that("link_ethoscope_metadata detect duplicated rows", { dir <- paste0(scopr_example_dir(), "/ethoscope_results/") query <- data.frame(machine_name = c("E_014", "E_014","E_029"), date = c("2016-01-25", "2016-02-17","2016-01-25"), time = c("21:46:14", NA, NA), test=c(1,2,3) ) query <- data.table::as.data.table(query) query <- query[,.(region_id=1:3),by=c(colnames(query))] query[machine_name=="E_029" & region_id==3, region_id := 2] expect_warning(out <- scopr:::link_ethoscope_metadata(query, dir), "Duplicated row") expect_equal(nrow(out), 3*3-1) })
norm3 <- function(X,n,m,p,mode){ Y=as.matrix(X) if (mode==1){ Y=t(nrm2(t(Y))) Y=((m*p)^.5)*Y } if (mode==2){ Y=permnew(Y,n,m,p) Y=t(nrm2(t(Y))) Y=permnew(Y,m,p,n) Y=permnew(Y,p,n,m) Y=((n*p)^.5)*Y } if (mode==3){ Y=permnew(Y,n,m,p) Y=permnew(Y,m,p,n) Y=t(nrm2(t(Y))) Y=permnew(Y,p,n,m) Y=((n*m)^.5)*Y } return(Y) }
moler <- function(n) { if (length(n) != 1 || n != round(n)) stop("Argument 'n' must be an integer.") if (n <= 0) return(c()) A <- matrix(0, nrow = n, ncol = n) for (i in 1:n) { A[i, 1:i] <- (1:i) - 2 } A <- A + t(A) diag(A) <- 1:n A }
skewness.test <- function(x) { x.n <- length(x) x.mean <- mean(x) x.demeaned <- x - x.mean numer <- I(x.n^2)*sum(x.demeaned^3)^2 denom <- 6*sum(x.demeaned^2)^3 statistic <- numer/denom out <- list() out$statistic <- statistic out$p.value <- pchisq(statistic, 1, lower.tail=FALSE) return(out) }
library(hamcrest) library(stats) set.seed(1) test.rchisq.1 <- function() assertThat({set.seed(1);rchisq(n = 0x1p+0, df = c(0x1p+0, 0x1p+1, 0x1.8p+1, 0x1p+2))}, identicalTo(0x1.94bd88c398c42p-3, tol = 0.000100)) test.rchisq.2 <- function() assertThat({set.seed(1);rchisq(n = 1:5, df = c(0x1p+0, 0x1p+1, 0x1.8p+1, 0x1p+2))}, identicalTo(c(0x1.94bd88c398c42p-3, 0x1.46cd823ef4d7ep+0, 0x1.5b132294fbe7fp-1, 0x1.068100b13bcdap+2, 0x1.5eb0939be9dd7p-7), tol = 0.000100)) test.rchisq.3 <- function() assertThat({set.seed(1);rchisq(n = 0x1.ep+3, df = c(0x1p+0, 0x1p+1, 0x1.8p+1, 0x1p+2))}, identicalTo(c(0x1.94bd88c398c42p-3, 0x1.46cd823ef4d7ep+0, 0x1.5b132294fbe7fp-1, 0x1.068100b13bcdap+2, 0x1.5eb0939be9dd7p-7, 0x1.e306a9618224cp-4, 0x1.dfe626302fd5fp+1, 0x1.24df5b420433ap+2, 0x1.9e9b6af708fb9p-2, 0x1.11f75bd9ab545p+2, 0x1.6d86c51058b56p+1, 0x1.abd6e04a61b6fp+0, 0x1.a3c1b1643823p-2, 0x1.637523ae26e75p+0, 0x1.3a53a48fe671ep-1), tol = 0.000100)) test.rchisq.4 <- function() assertThat({set.seed(1);rchisq(n = numeric(0), df = c(0x1p+0, 0x1p+1, 0x1.8p+1, 0x1p+2))}, identicalTo(numeric(0))) test.rchisq.5 <- function() assertThat({set.seed(1);rchisq(n = 0x1.8p+1, df = c(NA, 0x1p+1, 0x1.8p+1, 0x1p+2))}, identicalTo(c(NaN, 0x1.3dbac065e1d86p-2, 0x1.62cd513230be6p+2)))
try(dev.off(),silent=TRUE) plot.new() plot(as.dendrogram(hc))
fluidRow( column( width = 7, help_dynamic, dygraphOutput_175px("dynamic_trace_diagnostic_stepsize_out"), br(),br(), plotOutput("stepsize_vs_lp_out", height = "150px") ), column(width = 5, plotOutput_400px("stepsize_vs_accept_stat_out")) )
rayleigh.test <- function(x, mu=NULL) { x <- na.omit(x) if (length(x)==0) { warning("No observations (at least after removing missing values)") return(NULL) } x <- conversion.circular(x, units="radians", zero=0, rotation="counter", modulo="2pi") attr(x, "circularp") <- attr(x, "class") <- NULL if (!is.null(mu)) { mu <- conversion.circular(mu, units="radians", zero=0, rotation="counter", modulo="2pi") attr(mu, "circularp") <- attr(mu, "class") <- NULL } result <- RayleighTestRad(x, mu) result$call <- match.call() class(result) <- "rayleigh.test" return(result) } RayleighTestRad <- function(x, mu=NULL) { n <- length(x) if (is.null(mu)) { ss <- sum(sin(x)) cc <- sum(cos(x)) rbar <- (sqrt(ss^2 + cc^2))/n z <- (n * rbar^2) p.value <- exp( - z) if (n < 50) temp <- 1 + (2 * z - z^2)/(4 * n) - (24 * z - 132 * z^2 + 76 * z^3 - 9 * z^4)/(288 * n^2) else temp <- 1 p.value <- min(max(p.value * temp,0),1) result <- list(statistic = rbar, p.value = p.value, mu=NA) } else { r0.bar <- (sum(cos(x - mu)))/n z0 <- sqrt(2 * n) * r0.bar pz <- pnorm(z0) fz <- dnorm(z0) p.value <- 1 - pz + fz * ((3 * z0 - z0^3)/(16 * n) + (15 * z0 + 305 * z0^3 - 125 * z0^5 + 9 * z0^7)/(4608 * n^2)) p.value <- min(max(p.value,0),1) result <- list(statistic = r0.bar, p.value = p.value, mu=mu) } return(result) } print.rayleigh.test <- function(x, digits=4, ...) { rbar <- x$statistic p.value <- x$p.value mu <- x$mu cat("\n", " Rayleigh Test of Uniformity \n") if (is.na(mu)) { cat(" General Unimodal Alternative \n\n") } else { cat(" Alternative with Specified Mean Direction: ", mu, "\n\n") } cat("Test Statistic: ", round(rbar, digits=digits), "\n") cat("P-value: ", round(p.value, digits=digits), "\n\n") invisible(x) }