diff --git a/DESCRIPTION b/DESCRIPTION index 901986976..8f9386320 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: NNS Type: Package Title: Nonlinear Nonparametric Statistics -Version: 10.9.3 -Date: 2024-10-14 +Version: 10.9.4 +Date: 2024-12-02 Authors@R: c( person("Fred", "Viole", role=c("aut","cre"), email="ovvo.financial.systems@gmail.com"), person("Roberto", "Spadim", role=c("ctb")) diff --git a/NNS_10.9.3.tar.gz b/NNS_10.9.3.tar.gz deleted file mode 100644 index 1bbd275c9..000000000 Binary files a/NNS_10.9.3.tar.gz and /dev/null differ diff --git a/NNS_10.9.3.zip b/NNS_10.9.3.zip deleted file mode 100644 index fc6e273fa..000000000 Binary files a/NNS_10.9.3.zip and /dev/null differ diff --git a/NNS_10.9.4.tar.gz b/NNS_10.9.4.tar.gz new file mode 100644 index 000000000..68290eacb Binary files /dev/null and b/NNS_10.9.4.tar.gz differ diff --git a/NNS_10.9.4.zip b/NNS_10.9.4.zip new file mode 100644 index 000000000..b4e9adda2 Binary files /dev/null and b/NNS_10.9.4.zip differ diff --git a/R/NNS_MC.R b/R/NNS_MC.R index 34758e5ee..a34637c2e 100644 --- a/R/NNS_MC.R +++ b/R/NNS_MC.R @@ -9,7 +9,8 @@ #' @param by numeric; \code{.01} default will set the \code{by} argument in \code{seq(-1, 1, step)}. #' @param exp numeric; \code{1} default will exponentially weight maximum rho value if \code{exp > 1}. Shrinks values towards \code{upper_rho}. #' @param type options("spearman", "pearson", "NNScor", "NNSdep"); \code{type = "spearman"}(default) dependence metric desired. -#' @param drift logical; \code{TRUE} default preserves the drift of the original series. +#' @param drift logical; \code{drift = TRUE} (default) preserves the drift of the original series. +#' @param target_drift numerical; code{NULL} (default) Specifies the desired drift when \code{drift = TRUE}, i.e. a risk-free rate of return. #' @param xmin numeric; the lower limit for the left tail. #' @param xmax numeric; the upper limit for the right tail. #' @param ... possible additional arguments to be passed to \link{NNS.meboot}. @@ -38,6 +39,7 @@ NNS.MC <- function(x, exp = 1, type = "spearman", drift = TRUE, + target_drift = NULL, xmin = NULL, xmax = NULL, ...){ @@ -51,8 +53,8 @@ NNS.MC <- function(x, exp_rhos <- rev(c((neg_rhos^exp)*-1, pos_rhos^(1/exp))) - samples <- suppressWarnings(NNS.meboot(x = x, reps = reps, rho = exp_rhos, type = type, drift = drift, - xmin = xmin, xmax = xmax, ...)) + samples <- suppressWarnings(NNS.meboot(x = x, reps = reps, rho = exp_rhos, type = type, + drift = drift, target_drift = target_drift, xmin = xmin, xmax = xmax, ...)) replicates <- samples["replicates",] diff --git a/R/NNS_meboot.R b/R/NNS_meboot.R index f04d3fa69..cd0233884 100644 --- a/R/NNS_meboot.R +++ b/R/NNS_meboot.R @@ -6,14 +6,15 @@ #' @param reps numeric; number of replicates to generate. #' @param rho numeric [-1,1] (vectorized); A \code{rho} must be provided, otherwise a blank list will be returned. #' @param type options("spearman", "pearson", "NNScor", "NNSdep"); \code{type = "spearman"}(default) dependence metric desired. -#' @param drift logical; \code{TRUE} default preserves the drift of the original series. -#' @param trim numeric [0,1]; The mean trimming proportion, defaults to \code{trim=0.1}. +#' @param drift logical; \code{drift = TRUE} (default) preserves the drift of the original series. +#' @param target_drift numerical; code{NULL} (default) Specifies the desired drift when \code{drift = TRUE}, i.e. a risk-free rate of return. +#' @param trim numeric [0,1]; The mean trimming proportion, defaults to \code{trim = 0.1}. #' @param xmin numeric; the lower limit for the left tail. #' @param xmax numeric; the upper limit for the right tail. #' @param reachbnd logical; If \code{TRUE} potentially reached bounds (xmin = smallest value - trimmed mean and #' xmax = largest value + trimmed mean) are given when the random draw happens to be equal to 0 and 1, respectively. -#' @param expand.sd logical; If \code{TRUE} the standard deviation in the ensemble is expanded. See \code{expand.sd} in meboot::meboot. -#' @param force.clt logical; If \code{TRUE} the ensemble is forced to satisfy the central limit theorem. See \code{force.clt} in meboot::meboot. +#' @param expand.sd logical; If \code{TRUE} the standard deviation in the ensemble is expanded. See \code{expand.sd} in \code{meboot::meboot}. +#' @param force.clt logical; If \code{TRUE} the ensemble is forced to satisfy the central limit theorem. See \code{force.clt} in \code{meboot::meboot}. #' @param scl.adjustment logical; If \code{TRUE} scale adjustment is performed to ensure that the population variance of the transformed series equals the variance of the data. #' @param sym logical; If \code{TRUE} an adjustment is performed to ensure that the ME density is symmetric. #' @param elaps logical; If \code{TRUE} elapsed time during computations is displayed. @@ -59,27 +60,28 @@ #' boots <- NNS.meboot(AirPassengers, reps=100, rho = 0, xmin = 0) #' #' # Verify correlation of replicates ensemble to original -#' cor(boots["ensemble",], AirPassengers, method = "spearman") +#' cor(boots["ensemble",]$ensemble, AirPassengers, method = "spearman") #' #' # Plot all replicates -#' matplot(boots["replicates",] , type = 'l') +#' matplot(boots["replicates",]$replicates , type = 'l') #' #' # Plot ensemble -#' lines(boots["ensemble",], lwd = 3) +#' lines(boots["ensemble",]$ensemble, lwd = 3) #' } #' @export NNS.meboot <- function(x, - reps=999, - rho=NULL, - type="spearman", - drift=TRUE, - trim=0.10, - xmin=NULL, - xmax=NULL, - reachbnd=TRUE, - expand.sd=TRUE, force.clt=TRUE, - scl.adjustment = FALSE, sym = FALSE, elaps=FALSE, + reps = 999, + rho = NULL, + type = "spearman", + drift = TRUE, + target_drift = NULL, + trim = 0.10, + xmin = NULL, + xmax = NULL, + reachbnd = TRUE, + expand.sd = TRUE, force.clt = TRUE, + scl.adjustment = FALSE, sym = FALSE, elaps = FALSE, digits = 6, colsubj, coldata, coltimes,...) { @@ -206,47 +208,48 @@ m <- c(matrix2) l <- length(e) - func <- function(ab, d=drift, ty=type){ + func <- function(ab, d = drift, ty = type) { a <- ab[1] b <- ab[2] - - if(ty=="spearman" || ty=="pearson"){ - ifelse(d, - (abs(cor((a*m + b*e)/(a + b), e, method = ty) - rho) + - abs(mean((a*m + b*e))/mean(e) - 1) + - abs( cor((a*m + b*e)/(a + b), 1:l) - cor(e, 1:l)) - ), - abs(cor((a*m + b*e)/(a + b), e, method = ty) - rho) + - abs(mean((a*m + b*e))/mean(e) - 1) - ) + + # Compute the adjusted ensemble + combined <- (a * m + b * e) / (a + b) + + # Check correlation or dependence structure + if (ty == "spearman" || ty == "pearson") { + error <- abs(cor(combined, e, method = ty) - rho) + } else if (ty == "nnsdep") { + error <- abs(NNS.dep(combined, e)$Dependence - rho) } else { - if(ty=="nnsdep"){ - ifelse(d, - (abs(NNS.dep((a*m + b*e)/(a + b), e)$Dependence - rho) + - abs(mean((a*m + b*e))/mean(e) - 1) + - abs( NNS.dep((a*m + b*e)/(a + b), 1:l)$Dependence - NNS.dep(e, 1:l)$Dependence) - ), - abs(NNS.dep((a*m + b*e)/(a + b), e)$Dependence - rho) + - abs(mean((a*m + b*e))/mean(e) - 1) - ) - } else { - ifelse(d, - (abs(NNS.dep((a*m + b*e)/(a + b), e)$Correlation - rho) + - abs(mean((a*m + b*e))/mean(e) - 1) + - abs( NNS.dep((a*m + b*e)/(a + b), 1:l)$Correlation - NNS.dep(e, 1:l)$Correlation) - ), - abs(NNS.dep((a*m + b*e)/(a + b), e)$Correlation - rho) + - abs(mean((a*m + b*e))/mean(e) - 1) - ) - } + error <- abs(NNS.dep(combined, e)$Correlation - rho) } + return(error) } - + res <- optim(c(.01,.01), func, control=list(abstol = .01)) ensemble <- (res$par[1]*matrix2 + res$par[2]*ensemble) / (sum(abs(res$par))) + + + # Drift + orig_coef <- fast_lm(1:n, x)$coef + orig_intercept <- orig_coef[1] + orig_drift <- orig_coef[2] + + new_coef <- apply(ensemble, 2, function(i) fast_lm(1:n, i)$coef) + slopes <- new_coef[2,] + + if(drift){ + if(is.null(target_drift)) new_slopes <- (orig_drift - slopes) else new_slopes <- (target_drift - slopes) + ensemble <- ensemble + t(t(sapply(new_slopes, function(slope) cumsum(rep(slope, n))))) + + new_intercepts <- orig_intercept - new_coef[1,] + ensemble <- sweep(ensemble, 2, new_intercepts, FUN = "+") + } + + if(identical(ordxx_2, ordxx)){ if(reps>1) ensemble <- t(apply(ensemble, 1, function(x) sample(x, size = reps, replace = TRUE))) @@ -257,6 +260,8 @@ if(expand.sd) ensemble <- NNS.meboot.expand.sd(x=x, ensemble=ensemble, ...) if(force.clt && reps > 1) ensemble <- force.clt(x=x, ensemble=ensemble) + + # scale adjustment @@ -279,6 +284,9 @@ # Force min / max values if(!is.null(trim[[2]])) ensemble <- apply(ensemble, 2, function(z) pmax(trim[[2]], z)) if(!is.null(trim[[3]])) ensemble <- apply(ensemble, 2, function(z) pmin(trim[[3]], z)) + + + if(is.ts(x)){ ensemble <- ts(ensemble, frequency=frequency(x), start=start(x)) @@ -287,7 +295,8 @@ if(reps>1) dimnames(ensemble)[[2]] <- paste("Replicate", 1:reps) } - + + final <- list(x=x, replicates=round(ensemble, digits = digits), ensemble=Rfast::rowmeans(ensemble), xx=xx, z=z, dv=dv, dvtrim=dvtrim, xmin=xmin, xmax=xmax, desintxb=desintxb, ordxx=ordxx, kappa = kappa) diff --git a/R/Normalization.R b/R/Normalization.R index ac729768c..5c4eff921 100644 --- a/R/Normalization.R +++ b/R/Normalization.R @@ -14,7 +14,7 @@ #' @examples #' \dontrun{ #' set.seed(123) -#' x <- rnorm(100) ; y<-rnorm(100) +#' x <- rnorm(100) ; y <- rnorm(100) #' A <- cbind(x, y) #' NNS.norm(A) #' diff --git a/R/RcppExports.R b/R/RcppExports.R index d8ec77493..f56b6211a 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -18,8 +18,7 @@ fast_lm_mult <- function(x, y) { #' @param variable a numeric vector. \link{data.frame} or \link{list} type objects are not permissible. #' @return LPM of variable #' @author Fred Viole, OVVO Financial Systems -#' @references Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" -#' \url{https://www.amazon.com/dp/1490523995/ref=cm_sw_su_dp} +#' @references Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" (ISBN: 1490523995) #' @examples #' set.seed(123) #' x <- rnorm(100) @@ -37,8 +36,7 @@ LPM <- function(degree, target, variable) { #' @param variable a numeric vector. \link{data.frame} or \link{list} type objects are not permissible. #' @return UPM of variable #' @author Fred Viole, OVVO Financial Systems -#' @references Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" -#' \url{https://www.amazon.com/dp/1490523995/ref=cm_sw_su_dp} +#' @references Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" (ISBN: 1490523995) #' @examples #' set.seed(123) #' x <- rnorm(100) @@ -56,10 +54,8 @@ UPM <- function(degree, target, variable) { #' @param variable a numeric vector. #' @return Standardized LPM of variable #' @author Fred Viole, OVVO Financial Systems -#' @references Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" -#' \url{https://www.amazon.com/dp/1490523995/ref=cm_sw_su_dp} -#' @references Viole, F. (2017) "Continuous CDFs and ANOVA with NNS" -#' \url{https://www.ssrn.com/abstract=3007373} +#' @references Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" (ISBN: 1490523995) +#' @references Viole, F. (2017) "Continuous CDFs and ANOVA with NNS" \doi{10.2139/ssrn.3007373} #' @examples #' set.seed(123) #' x <- rnorm(100) @@ -92,8 +88,7 @@ LPM.ratio <- function(degree, target, variable) { #' @param variable a numeric vector. #' @return Standardized UPM of variable #' @author Fred Viole, OVVO Financial Systems -#' @references Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" -#' \url{https://www.amazon.com/dp/1490523995/ref=cm_sw_su_dp} +#' @references Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" (ISBN: 1490523995) #' @examples #' set.seed(123) #' x <- rnorm(100) @@ -121,8 +116,7 @@ UPM.ratio <- function(degree, target, variable) { #' @param target_y numeric; Target for lower deviations of variable Y. Typically the mean of Variable Y for classical statistics equivalences, but does not have to be. #' @return Co-LPM of two variables #' @author Fred Viole, OVVO Financial Systems -#' @references Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" -#' \url{https://www.amazon.com/dp/1490523995/ref=cm_sw_su_dp} +#' @references Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" (ISBN: 1490523995) #' @examples #' set.seed(123) #' x <- rnorm(100) ; y <- rnorm(100) @@ -143,8 +137,7 @@ Co.LPM <- function(degree_lpm, x, y, target_x, target_y) { #' @param target_y numeric; Target for upside deviations of variable Y. Typically the mean of Variable Y for classical statistics equivalences, but does not have to be. #' @return Co-UPM of two variables #' @author Fred Viole, OVVO Financial Systems -#' @references Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" -#' \url{https://www.amazon.com/dp/1490523995/ref=cm_sw_su_dp} +#' @references Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" (ISBN: 1490523995) #' @examples #' set.seed(123) #' x <- rnorm(100) ; y <- rnorm(100) @@ -166,8 +159,7 @@ Co.UPM <- function(degree_upm, x, y, target_x, target_y) { #' @param target_y numeric; Target for lower deviations of variable Y. Typically the mean of Variable Y for classical statistics equivalences, but does not have to be. #' @return Divergent LPM of two variables #' @author Fred Viole, OVVO Financial Systems -#' @references Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" -#' \url{https://www.amazon.com/dp/1490523995/ref=cm_sw_su_dp} +#' @references Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" (ISBN: 1490523995) #' @examples #' set.seed(123) #' x <- rnorm(100) ; y <- rnorm(100) @@ -189,8 +181,7 @@ D.LPM <- function(degree_lpm, degree_upm, x, y, target_x, target_y) { #' @param target_y numeric; Target for upper deviations of variable Y. Typically the mean of Variable Y for classical statistics equivalences, but does not have to be. #' @return Divergent UPM of two variables #' @author Fred Viole, OVVO Financial Systems -#' @references Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" -#' \url{https://www.amazon.com/dp/1490523995/ref=cm_sw_su_dp} +#' @references Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" (ISBN: 1490523995) #' @examples #' set.seed(123) #' x <- rnorm(100) ; y <- rnorm(100) @@ -212,10 +203,8 @@ D.UPM <- function(degree_lpm, degree_upm, x, y, target_x, target_y) { #' @return Matrix of partial moment quadrant values (CUPM, DUPM, DLPM, CLPM), and overall covariance matrix. Uncalled quadrants will return a matrix of zeros. #' @note For divergent asymmetical \code{"D.LPM" and "D.UPM"} matrices, matrix is \code{D.LPM(column,row,...)}. #' @author Fred Viole, OVVO Financial Systems -#' @references Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" -#' \url{https://www.amazon.com/dp/1490523995/ref=cm_sw_su_dp} -#' @references Viole, F. (2017) "Bayes' Theorem From Partial Moments" -#' \url{https://www.ssrn.com/abstract=3457377} +#' @references Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" (ISBN: 1490523995) +#' @references Viole, F. (2017) "Bayes' Theorem From Partial Moments" \doi{10.2139/ssrn.3457377} #' @examples #' set.seed(123) #' x <- rnorm(100) ; y <- rnorm(100) ; z <- rnorm(100) diff --git a/README.md b/README.md index 0c14efb9b..eb2586b5a 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ -[![packageversion](https://img.shields.io/badge/NNS%20version-10.9.3-blue.svg?style=flat-square)](https://github.com/OVVO-Financial/NNS/commits/NNS-Beta-Version) [![Licence](https://img.shields.io/badge/licence-GPL--3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0.en.html) +[![packageversion](https://img.shields.io/badge/NNS%20version-10.9.4-blue.svg?style=flat-square)](https://github.com/OVVO-Financial/NNS/commits/NNS-Beta-Version) [![Licence](https://img.shields.io/badge/licence-GPL--3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0.en.html)
@@ -59,7 +59,7 @@ Please see https://github.com/OVVO-Financial/NNS/blob/NNS-Beta-Version/examples/ title = {NNS: Nonlinear Nonparametric Statistics}, author = {Fred Viole}, year = {2016}, - note = {R package version 10.9.3}, + note = {R package version 10.9.4}, url = {https://CRAN.R-project.org/package=NNS}, } ``` diff --git a/doc/NNSvignette_Sampling.R b/doc/NNSvignette_Sampling.R index 87976c6b1..d16bc8028 100644 --- a/doc/NNSvignette_Sampling.R +++ b/doc/NNSvignette_Sampling.R @@ -149,7 +149,7 @@ legend('left', legend = c('ecdf', 'LPM.ratio'), fill=c('black','red'), border=NA # sapply(boots, function(r) cor(r, x, method = "spearman")) # # rho = 1 rho = 0.5 rho = -0.5 rho = -1 -# 1.0000000 0.4988059 -0.4995740 -0.9982358 +# 1.0000000 0.4989619 -0.4984818 -0.9779778 ## ----multisim, eval=FALSE----------------------------------------------------- # set.seed(123) @@ -171,8 +171,8 @@ legend('left', legend = c('ecdf', 'LPM.ratio'), fill=c('black','red'), border=NA # NNS.copula(original.data) # NNS.copula(new.dep.data) # -# [1] 0.4379469 -# [1] 0.4390599 +# [1] 0.4353849 +# [1] 0.4357026 ## ----eval=FALSE--------------------------------------------------------------- # head(original.data) @@ -206,17 +206,17 @@ legend('left', legend = c('ecdf', 'LPM.ratio'), fill=c('black','red'), border=NA ## ----eval=FALSE--------------------------------------------------------------- # for(i in 1:4) print(cor(new.boot.dep.matrix[,i], original.data[,i], method = "spearman")) # -# [1] 0.9453275 -# [1] 0.9523726 -# [1] 0.9498499 -# [1] 0.9524516 +# [1] 0.9432899 +# [1] 0.9460947 +# [1] 0.9442031 +# [1] 0.9423242 ## ----eval=FALSE--------------------------------------------------------------- # NNS.copula(original.data) # NNS.copula(new.boot.dep.matrix) # -# [1] 0.4379469 -# [1] 0.4302545 +# [1] 0.4353849 +# [1] 0.4263725 ## ----eval=FALSE--------------------------------------------------------------- # head(original.data) @@ -230,12 +230,12 @@ legend('left', legend = c('ecdf', 'LPM.ratio'), fill=c('black','red'), border=NA # [5,] 0.12928774 -2.54934277 0.1741359 0.12928774 # [6,] 1.71506499 1.04057346 -0.6152683 1.71506499 # x y z x -# ensemble1 -0.4667731 -0.8418413 -0.6139059 -0.4708890 -# ensemble2 -0.2333747 -1.0908710 0.3748315 -0.2711240 -# ensemble3 1.4799734 0.2893831 -0.3851513 1.3645317 -# ensemble4 0.1751654 0.2995113 1.1342461 0.1486429 -# ensemble5 0.4128802 -2.9789634 -0.1141124 0.3846150 -# ensemble6 1.5592660 1.1800553 -0.5285532 1.5041917 +# ensemble1 -0.4268047 -0.7794553 -0.6364458 -0.4642642 +# ensemble2 -0.2965744 -1.0682197 0.3297265 -0.2531178 +# ensemble3 1.3302149 0.3054734 -0.4014515 1.4914884 +# ensemble4 0.2257378 0.3108846 1.0603892 0.1728540 +# ensemble5 0.4716743 -3.3344967 -0.1917697 0.4309379 +# ensemble6 1.3984978 1.1881374 -0.5295386 1.5326055 ## ----threads, echo = FALSE---------------------------------------------------- Sys.setenv("OMP_THREAD_LIMIT" = "") diff --git a/doc/NNSvignette_Sampling.Rmd b/doc/NNSvignette_Sampling.Rmd index 380b3028f..0e559a0a5 100644 --- a/doc/NNSvignette_Sampling.Rmd +++ b/doc/NNSvignette_Sampling.Rmd @@ -224,7 +224,7 @@ Checking our replicate correlations: sapply(boots, function(r) cor(r, x, method = "spearman")) rho = 1 rho = 0.5 rho = -0.5 rho = -1 - 1.0000000 0.4988059 -0.4995740 -0.9982358 + 1.0000000 0.4989619 -0.4984818 -0.9779778 ``` More replicates and ensembles thereof can be generated for any number of $\rho$ values. Please see the full **`NNS.meboot`** and **`NNS.MC`** argument documentation. @@ -270,8 +270,8 @@ Similar dependence with radically different values, since we used $N(10, 20)$ in NNS.copula(original.data) NNS.copula(new.dep.data) -[1] 0.4379469 -[1] 0.4390599 +[1] 0.4353849 +[1] 0.4357026 ``` ```{r, eval=FALSE} @@ -316,10 +316,10 @@ Checking `ensemble` correlations with `original.data`: ```{r, eval=FALSE} for(i in 1:4) print(cor(new.boot.dep.matrix[,i], original.data[,i], method = "spearman")) -[1] 0.9453275 -[1] 0.9523726 -[1] 0.9498499 -[1] 0.9524516 +[1] 0.9432899 +[1] 0.9460947 +[1] 0.9442031 +[1] 0.9423242 ``` ### Compare Multivariate Dependence Structures @@ -330,8 +330,8 @@ Similar dependence with similar values. NNS.copula(original.data) NNS.copula(new.boot.dep.matrix) -[1] 0.4379469 -[1] 0.4302545 +[1] 0.4353849 +[1] 0.4263725 ``` ```{r, eval=FALSE} @@ -346,12 +346,12 @@ head(new.boot.dep.matrix) [5,] 0.12928774 -2.54934277 0.1741359 0.12928774 [6,] 1.71506499 1.04057346 -0.6152683 1.71506499 x y z x -ensemble1 -0.4667731 -0.8418413 -0.6139059 -0.4708890 -ensemble2 -0.2333747 -1.0908710 0.3748315 -0.2711240 -ensemble3 1.4799734 0.2893831 -0.3851513 1.3645317 -ensemble4 0.1751654 0.2995113 1.1342461 0.1486429 -ensemble5 0.4128802 -2.9789634 -0.1141124 0.3846150 -ensemble6 1.5592660 1.1800553 -0.5285532 1.5041917 +ensemble1 -0.4268047 -0.7794553 -0.6364458 -0.4642642 +ensemble2 -0.2965744 -1.0682197 0.3297265 -0.2531178 +ensemble3 1.3302149 0.3054734 -0.4014515 1.4914884 +ensemble4 0.2257378 0.3108846 1.0603892 0.1728540 +ensemble5 0.4716743 -3.3344967 -0.1917697 0.4309379 +ensemble6 1.3984978 1.1881374 -0.5295386 1.5326055 ``` # References {#references} diff --git a/doc/NNSvignette_Sampling.html b/doc/NNSvignette_Sampling.html index 2089ea982..03b30c4db 100644 --- a/doc/NNSvignette_Sampling.html +++ b/doc/NNSvignette_Sampling.html @@ -471,12 +471,12 @@NNS.meboot
)Checking our replicate correlations:
sapply(boots, function(r) cor(r, x, method = "spearman"))
rho = 1 rho = 0.5 rho = -0.5 rho = -1
- 1.0000000 0.4988059 -0.4995740 -0.9982358
More replicates and ensembles thereof can be generated for any number
of \(\rho\) values. Please see the full
NNS.meboot
and
@@ -531,8 +531,8 @@
head(original.data)
head(new.dep.data)
@@ -572,18 +572,18 @@ Alternative Using NNS.meboot
original.data
:
for(i in 1:4) print(cor(new.boot.dep.matrix[,i], original.data[,i], method = "spearman"))
-[1] 0.9453275
-[1] 0.9523726
-[1] 0.9498499
-[1] 0.9524516
+[1] 0.9432899
+[1] 0.9460947
+[1] 0.9442031
+[1] 0.9423242
Similar dependence with similar values.
+[1] 0.4353849 +[1] 0.4263725head(original.data)
head(new.boot.dep.matrix)
@@ -595,12 +595,12 @@ Compare Multivariate Dependence Structures
[5,] 0.12928774 -2.54934277 0.1741359 0.12928774
[6,] 1.71506499 1.04057346 -0.6152683 1.71506499
x y z x
-ensemble1 -0.4667731 -0.8418413 -0.6139059 -0.4708890
-ensemble2 -0.2333747 -1.0908710 0.3748315 -0.2711240
-ensemble3 1.4799734 0.2893831 -0.3851513 1.3645317
-ensemble4 0.1751654 0.2995113 1.1342461 0.1486429
-ensemble5 0.4128802 -2.9789634 -0.1141124 0.3846150
-ensemble6 1.5592660 1.1800553 -0.5285532 1.5041917
NNS.part()
x = seq(-5, 5, .05); y = x ^ 3
for(i in 1 : 4){NNS.part(x, y, order = i, Voronoi = TRUE, obs.req = 0)}
NNS.part
offers a partitioning based on
@@ -375,7 +375,7 @@
Note the partition identifications are limited to 1’s and 2’s (left and right of the partition respectively), not the 4 values per the \(x\) and \(y\) partitioning.
## $order
@@ -404,7 +404,7 @@ X-only Partitioning
## 5: q211 0.5866563 0.2366875
## 6: q212 1.8366563 6.6437852
## 7: q221 3.0862812 30.1590941
-## 8: q222 4.3613732 84.1050922
+## 8: q222 4.3572065 83.8672381
NNS
partitioning.
-
+
NNS.reg(iris[ , 1 : 4], iris[ , 5], dim.red.method = "cor", threshold = .75, location = "topleft", ncores = 1)$equation
## Variable Coefficient
## 1: Sepal.Length 0.7980781
## 2: Sepal.Width 0.0000000
@@ -707,7 +707,7 @@ Threshold
the full regression above, again called with
NNS.reg(...)$Point.est
.
NNS.reg(iris[ , 1 : 4], iris[ , 5], dim.red.method = "cor", threshold = .75, point.est = iris[1 : 10, 1 : 4], location = "topleft", ncores = 1)$Point.est
-
+
## [1] 1 1 1 1 1 1 1 1 1 1
Note the fact that all observations occupy the co-partial moment quadrants.
- +## [1] 0.6610183
@@ -394,7 +394,7 @@ NNS.dep
.
-
+
## [1] -0.1297766
@@ -404,15 +404,40 @@ The asymmetrical analysis is critical for further determining a +causal path between variables which should be identifiable, i.e., it is +asymmetrical in causes and effects.
+The previous cyclic example visually highlights the asymmetry of
+dependence between the variables, which can be confirmed using
+NNS.dep(..., asym = TRUE)
.
## [1] -0.1297766
+
+## $Correlation
+## [1] -0.0002077384
+##
+## $Dependence
+## [1] 0.8938585
+
+## [1] -0.1297766
+
+## $Correlation
+## [1] -0.07074914
+##
+## $Dependence
+## [1] 0.07074914
+Note the fact that all observations occupy only co- or divergent partial moment quadrants for a given subquadrant.
-set.seed(123)
-df <- data.frame(x = runif(10000, -1, 1), y = runif(10000, -1, 1))
-df <- subset(df, (x ^ 2 + y ^ 2 <= 1 & x ^ 2 + y ^ 2 >= 0.95))
set.seed(123)
+df <- data.frame(x = runif(10000, -1, 1), y = runif(10000, -1, 1))
+df <- subset(df, (x ^ 2 + y ^ 2 <= 1 & x ^ 2 + y ^ 2 >= 0.95))
## $Correlation
## [1] 0.05741863
##
@@ -430,30 +455,31 @@ p-values for NNS.dep()
Simply set
NNS.dep(..., p.value = TRUE, print.map = TRUE)
to run 100 permutations and plot the results.
-
-
-
-
+
+
+
+
## $Correlation
-## [1] -0.03697032
+## [1] 0.2003584
##
## $`Correlation p.value`
-## [1] 0.23
+## [1] 0.24
##
## $`Correlation 95% CIs`
## 2.5% 97.5%
-## -0.1649756 0.3423353
+## -0.1748792 0.3783630
##
## $Dependence
-## [1] 0.8373177
+## [1] 0.8886629
##
## $`Dependence p.value`
## [1] 0
##
## $`Dependence 95% CIs`
## 2.5% 97.5%
-## 0.3414161 0.5663028
+## 0.3342770 0.5537688
NNS.copula()
NNS.copula()
set.seed(123)
-x <- rnorm(1000); y <- rnorm(1000); z <- rnorm(1000)
-NNS.copula(cbind(x, y, z), plot = TRUE, independence.overlay = TRUE)
set.seed(123)
+x <- rnorm(1000); y <- rnorm(1000); z <- rnorm(1000)
+NNS.copula(cbind(x, y, z), plot = TRUE, independence.overlay = TRUE)
## [1] 0.1231362
NNS.meboot
)Checking our replicate correlations:
sapply(boots, function(r) cor(r, x, method = "spearman"))
rho = 1 rho = 0.5 rho = -0.5 rho = -1
- 1.0000000 0.4988059 -0.4995740 -0.9982358
More replicates and ensembles thereof can be generated for any number
of \(\rho\) values. Please see the full
NNS.meboot
and
@@ -531,8 +531,8 @@
head(original.data)
head(new.dep.data)
@@ -572,18 +572,18 @@ Alternative Using NNS.meboot
original.data
:
for(i in 1:4) print(cor(new.boot.dep.matrix[,i], original.data[,i], method = "spearman"))
-[1] 0.9453275
-[1] 0.9523726
-[1] 0.9498499
-[1] 0.9524516
+[1] 0.9432899
+[1] 0.9460947
+[1] 0.9442031
+[1] 0.9423242
Similar dependence with similar values.
+[1] 0.4353849 +[1] 0.4263725head(original.data)
head(new.boot.dep.matrix)
@@ -595,12 +595,12 @@ Compare Multivariate Dependence Structures
[5,] 0.12928774 -2.54934277 0.1741359 0.12928774
[6,] 1.71506499 1.04057346 -0.6152683 1.71506499
x y z x
-ensemble1 -0.4667731 -0.8418413 -0.6139059 -0.4708890
-ensemble2 -0.2333747 -1.0908710 0.3748315 -0.2711240
-ensemble3 1.4799734 0.2893831 -0.3851513 1.3645317
-ensemble4 0.1751654 0.2995113 1.1342461 0.1486429
-ensemble5 0.4128802 -2.9789634 -0.1141124 0.3846150
-ensemble6 1.5592660 1.1800553 -0.5285532 1.5041917