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 @@

Bootstrapping (NNS.meboot)

plot(x, type = "l", lwd = 3, ylim = c(min(reps), max(reps))) matplot(reps, type = "l", col = rainbow(length(boots)), add = TRUE) -

+

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 @@ -531,8 +531,8 @@

Compare Multivariate Dependence Structures

NNS.copula(original.data)
 NNS.copula(new.dep.data)
 
-[1] 0.4379469
-[1] 0.4390599
+[1] 0.4353849 +[1] 0.4357026
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

Compare Multivariate Dependence Structures

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
head(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
+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 diff --git a/man/Co.LPM.Rd b/man/Co.LPM.Rd index d615ad1ed..0aff04872 100644 --- a/man/Co.LPM.Rd +++ b/man/Co.LPM.Rd @@ -30,8 +30,7 @@ x <- rnorm(100) ; y <- rnorm(100) Co.LPM(0, x, y, mean(x), mean(y)) } \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} +Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" (ISBN: 1490523995) } \author{ Fred Viole, OVVO Financial Systems diff --git a/man/Co.UPM.Rd b/man/Co.UPM.Rd index 50b717ddf..efa53574e 100644 --- a/man/Co.UPM.Rd +++ b/man/Co.UPM.Rd @@ -30,8 +30,7 @@ x <- rnorm(100) ; y <- rnorm(100) Co.UPM(0, x, y, mean(x), mean(y)) } \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} +Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" (ISBN: 1490523995) } \author{ Fred Viole, OVVO Financial Systems diff --git a/man/D.LPM.Rd b/man/D.LPM.Rd index 74a1e7f21..679e68fde 100644 --- a/man/D.LPM.Rd +++ b/man/D.LPM.Rd @@ -32,8 +32,7 @@ x <- rnorm(100) ; y <- rnorm(100) D.LPM(0, 0, x, y, mean(x), mean(y)) } \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} +Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" (ISBN: 1490523995) } \author{ Fred Viole, OVVO Financial Systems diff --git a/man/D.UPM.Rd b/man/D.UPM.Rd index 0be8c5edf..b0f646a20 100644 --- a/man/D.UPM.Rd +++ b/man/D.UPM.Rd @@ -32,8 +32,7 @@ x <- rnorm(100) ; y <- rnorm(100) D.UPM(0, 0, x, y, mean(x), mean(y)) } \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} +Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" (ISBN: 1490523995) } \author{ Fred Viole, OVVO Financial Systems diff --git a/man/LPM.Rd b/man/LPM.Rd index b8750f854..3cae67b1e 100644 --- a/man/LPM.Rd +++ b/man/LPM.Rd @@ -25,8 +25,7 @@ x <- rnorm(100) LPM(0, mean(x), x) } \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} +Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" (ISBN: 1490523995) } \author{ Fred Viole, OVVO Financial Systems diff --git a/man/LPM.ratio.Rd b/man/LPM.ratio.Rd index e9391ca25..e07defb64 100644 --- a/man/LPM.ratio.Rd +++ b/man/LPM.ratio.Rd @@ -40,11 +40,9 @@ zlab = "Probability", box = FALSE) } } \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} +Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" (ISBN: 1490523995) -Viole, F. (2017) "Continuous CDFs and ANOVA with NNS" -\url{https://www.ssrn.com/abstract=3007373} +Viole, F. (2017) "Continuous CDFs and ANOVA with NNS" \doi{10.2139/ssrn.3007373} } \author{ Fred Viole, OVVO Financial Systems diff --git a/man/NNS.MC.Rd b/man/NNS.MC.Rd index 93db8e31f..89b8caa09 100644 --- a/man/NNS.MC.Rd +++ b/man/NNS.MC.Rd @@ -13,6 +13,7 @@ NNS.MC( exp = 1, type = "spearman", drift = TRUE, + target_drift = NULL, xmin = NULL, xmax = NULL, ... @@ -33,7 +34,9 @@ NNS.MC( \item{type}{options("spearman", "pearson", "NNScor", "NNSdep"); \code{type = "spearman"}(default) dependence metric desired.} -\item{drift}{logical; \code{TRUE} default preserves the drift of the original series.} +\item{drift}{logical; \code{drift = TRUE} (default) preserves the drift of the original series.} + +\item{target_drift}{numerical; code{NULL} (default) Specifies the desired drift when \code{drift = TRUE}, i.e. a risk-free rate of return.} \item{xmin}{numeric; the lower limit for the left tail.} diff --git a/man/NNS.meboot.Rd b/man/NNS.meboot.Rd index 70bf1cab2..23fb4a8d7 100644 --- a/man/NNS.meboot.Rd +++ b/man/NNS.meboot.Rd @@ -10,6 +10,7 @@ NNS.meboot( rho = NULL, type = "spearman", drift = TRUE, + target_drift = NULL, trim = 0.1, xmin = NULL, xmax = NULL, @@ -35,9 +36,11 @@ NNS.meboot( \item{type}{options("spearman", "pearson", "NNScor", "NNSdep"); \code{type = "spearman"}(default) dependence metric desired.} -\item{drift}{logical; \code{TRUE} default preserves the drift of the original series.} +\item{drift}{logical; \code{drift = TRUE} (default) preserves the drift of the original series.} -\item{trim}{numeric [0,1]; The mean trimming proportion, defaults to \code{trim=0.1}.} +\item{target_drift}{numerical; code{NULL} (default) Specifies the desired drift when \code{drift = TRUE}, i.e. a risk-free rate of return.} + +\item{trim}{numeric [0,1]; The mean trimming proportion, defaults to \code{trim = 0.1}.} \item{xmin}{numeric; the lower limit for the left tail.} @@ -46,9 +49,9 @@ NNS.meboot( \item{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.} -\item{expand.sd}{logical; If \code{TRUE} the standard deviation in the ensemble is expanded. See \code{expand.sd} in meboot::meboot.} +\item{expand.sd}{logical; If \code{TRUE} the standard deviation in the ensemble is expanded. See \code{expand.sd} in \code{meboot::meboot}.} -\item{force.clt}{logical; If \code{TRUE} the ensemble is forced to satisfy the central limit theorem. See \code{force.clt} in meboot::meboot.} +\item{force.clt}{logical; If \code{TRUE} the ensemble is forced to satisfy the central limit theorem. See \code{force.clt} in \code{meboot::meboot}.} \item{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.} @@ -94,13 +97,13 @@ Adapted maximum entropy bootstrap routine from \code{meboot} \url{https://cran.r 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) } } \references{ diff --git a/man/NNS.norm.Rd b/man/NNS.norm.Rd index 4e5a39cab..6e1f8d5a9 100644 --- a/man/NNS.norm.Rd +++ b/man/NNS.norm.Rd @@ -28,7 +28,7 @@ Unequal vectors provided in a list will only generate \code{linear=TRUE} normali \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/man/PM.matrix.Rd b/man/PM.matrix.Rd index 1189c3864..e2464e582 100644 --- a/man/PM.matrix.Rd +++ b/man/PM.matrix.Rd @@ -44,11 +44,9 @@ cov.mtx$cupm cov.mtx$cov.matrix } \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} +Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" (ISBN: 1490523995) -Viole, F. (2017) "Bayes' Theorem From Partial Moments" -\url{https://www.ssrn.com/abstract=3457377} +Viole, F. (2017) "Bayes' Theorem From Partial Moments" \doi{10.2139/ssrn.3457377} } \author{ Fred Viole, OVVO Financial Systems diff --git a/man/UPM.Rd b/man/UPM.Rd index d96dedc3a..d1ad793c8 100644 --- a/man/UPM.Rd +++ b/man/UPM.Rd @@ -25,8 +25,7 @@ x <- rnorm(100) UPM(0, mean(x), x) } \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} +Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" (ISBN: 1490523995) } \author{ Fred Viole, OVVO Financial Systems diff --git a/man/UPM.ratio.Rd b/man/UPM.ratio.Rd index 284b660ca..f61ce6e9b 100644 --- a/man/UPM.ratio.Rd +++ b/man/UPM.ratio.Rd @@ -32,8 +32,7 @@ zlab = "Probability", box = FALSE) } } \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} +Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" (ISBN: 1490523995) } \author{ Fred Viole, OVVO Financial Systems diff --git a/src/NNS.dll b/src/NNS.dll index c5cbcdbb5..4e04d1780 100644 Binary files a/src/NNS.dll and b/src/NNS.dll differ diff --git a/src/partial_moments_rcpp.cpp b/src/partial_moments_rcpp.cpp index ecf0000ae..1e29f2265 100644 --- a/src/partial_moments_rcpp.cpp +++ b/src/partial_moments_rcpp.cpp @@ -14,8 +14,7 @@ using namespace Rcpp; //' @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) @@ -48,8 +47,7 @@ NumericVector LPM_RCPP(const double °ree, const RObject &target, const RObjec //' @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) @@ -82,10 +80,8 @@ NumericVector UPM_RCPP(const double °ree, const RObject &target, const RObjec //' @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) @@ -135,8 +131,7 @@ NumericVector LPM_ratio_RCPP(const double °ree, const RObject &target, const //' @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) @@ -181,8 +176,7 @@ NumericVector UPM_ratio_RCPP(const double °ree, const RObject &target, const //' @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) @@ -232,8 +226,7 @@ NumericVector CoLPM_RCPP( //' @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) @@ -284,8 +277,7 @@ NumericVector CoUPM_RCPP( //' @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) @@ -336,8 +328,7 @@ NumericVector DLPM_RCPP( //' @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) @@ -387,10 +378,8 @@ NumericVector DUPM_RCPP( //' @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/tests/testthat/Rplots.pdf b/tests/testthat/Rplots.pdf index ca3762381..0f3253f71 100644 Binary files a/tests/testthat/Rplots.pdf and b/tests/testthat/Rplots.pdf differ diff --git a/vignettes/NNSvignette_Classification.html b/vignettes/NNSvignette_Classification.html index 70e6dfc1b..c50f656fa 100644 --- a/vignettes/NNSvignette_Classification.html +++ b/vignettes/NNSvignette_Classification.html @@ -397,7 +397,7 @@

NNS Partitions

## 15: 5.800000 3.619048 4.383333 1.800000 ## 16: 5.983333 3.800000 4.500000 1.900000 ## 17: 6.100000 3.900000 4.600000 2.000000 -## 18: 6.200000 4.200000 4.700000 2.114583 +## 18: 6.200000 4.137305 4.700000 2.114583 ## 19: 6.300000 4.400000 4.863889 2.300000 ## 20: 6.400000 NA 5.000000 2.433333 ## 21: 6.500000 NA 5.100000 2.500000 @@ -405,8 +405,8 @@

NNS Partitions

## 23: 6.700000 NA 5.333333 NA ## 24: 6.864286 NA 5.500000 NA ## 25: 7.153750 NA 5.614583 NA -## 26: 7.400000 NA 5.929049 NA -## 27: 7.710000 NA 6.612109 NA +## 26: 7.400000 NA 5.924883 NA +## 27: 7.710000 NA 6.607943 NA ## 28: 7.900000 NA 6.900000 NA ## V1 V2 V3 V4 diff --git a/vignettes/NNSvignette_Clustering_and_Regression.html b/vignettes/NNSvignette_Clustering_and_Regression.html index 7819aa4c8..38d0b35a7 100644 --- a/vignettes/NNSvignette_Clustering_and_Regression.html +++ b/vignettes/NNSvignette_Clustering_and_Regression.html @@ -366,7 +366,7 @@

NNS Partitioning 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)}
-

+

X-only Partitioning

NNS.part offers a partitioning based on @@ -375,7 +375,7 @@

X-only Partitioning

the entire bandwidth in its regression point derivation, and shares the same limit condition as partitioning via both \(x\) and \(y\) values.

for(i in 1 : 4){NNS.part(x, y, order = i, type = "XONLY", Voronoi = TRUE)}
-

+

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
@@ -413,7 +413,7 @@

Clusters Used in Regression

endpoints and central point) for the order of NNS partitioning.

for(i in 1 : 3){NNS.part(x, y, order = i, obs.req = 0, Voronoi = TRUE, type = "XONLY") ; NNS.reg(x, y, order = i, ncores = 1)}
-

+

@@ -693,7 +693,7 @@

Threshold

offers a method of reducing regressors further by controlling the absolute value of required correlation.

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
diff --git a/vignettes/NNSvignette_Correlation_and_Dependence.R b/vignettes/NNSvignette_Correlation_and_Dependence.R index 167089d63..831446487 100644 --- a/vignettes/NNSvignette_Correlation_and_Dependence.R +++ b/vignettes/NNSvignette_Correlation_and_Dependence.R @@ -42,6 +42,14 @@ NNS.part(x, y, Voronoi = TRUE, order = 3, obs.req = 0) cor(x, y) NNS.dep(x, y) +## ----asym1-------------------------------------------------------------------- +cor(x, y) +NNS.dep(x, y, asym = TRUE) + +## ----asym2-------------------------------------------------------------------- +cor(y, x) +NNS.dep(y, x, asym = TRUE) + ## ----dependence,fig.width=5,fig.height=3,fig.align = "center"----------------- set.seed(123) df <- data.frame(x = runif(10000, -1, 1), y = runif(10000, -1, 1)) @@ -55,6 +63,7 @@ NNS.dep(df$x, df$y) ## ----permutations------------------------------------------------------------- ## p-values for [NNS.dep] +set.seed(123) x <- seq(-5, 5, .1); y <- x^2 + rnorm(length(x)) ## ----perm1,fig.width=5,fig.height=3,fig.align = "center", results='hide', echo=FALSE---- diff --git a/vignettes/NNSvignette_Correlation_and_Dependence.html b/vignettes/NNSvignette_Correlation_and_Dependence.html index 5b851d8f5..5cea34b18 100644 --- a/vignettes/NNSvignette_Correlation_and_Dependence.html +++ b/vignettes/NNSvignette_Correlation_and_Dependence.html @@ -378,7 +378,7 @@

Nonlinear Relationship

Note the fact that all observations occupy the co-partial moment quadrants.

x = seq(0, 3, .01) ; y = x ^ 10
-

+

cor(x, y)
## [1] 0.6610183
NNS.dep(x, y)
@@ -394,7 +394,7 @@

Cyclic Relationship

divergent partial moment quadrants, are properly compensated for in NNS.dep.

x = seq(0, 12*pi, pi/100) ; y = sin(x)
-

+

cor(x, y)
## [1] -0.1297766
NNS.dep(x, y)
@@ -404,15 +404,40 @@

Cyclic Relationship

## $Dependence ## [1] 0.8938585
+
+

Asymmetrical Analysis

+

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).

+
cor(x, y)
+
## [1] -0.1297766
+
NNS.dep(x, y, asym = TRUE)
+
## $Correlation
+## [1] -0.0002077384
+## 
+## $Dependence
+## [1] 0.8938585
+
cor(y, x)
+
## [1] -0.1297766
+
NNS.dep(y, x, asym = TRUE)
+
## $Correlation
+## [1] -0.07074914
+## 
+## $Dependence
+## [1] 0.07074914
+

Dependence

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))
-

-
NNS.dep(df$x, df$y)
+
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))
+

+
NNS.dep(df$x, df$y)
## $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.

-
## p-values for [NNS.dep]
-x <- seq(-5, 5, .1); y <- x^2 + rnorm(length(x))
-

-
NNS.dep(x, y, p.value = TRUE, print.map = TRUE)
-

+
## p-values for [NNS.dep]
+set.seed(123)
+x <- seq(-5, 5, .1); y <- x^2 + rnorm(length(x))
+

+
NNS.dep(x, y, p.value = TRUE, print.map = TRUE)
+

## $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

Multivariate Dependence NNS.copula()

@@ -461,9 +487,9 @@

Multivariate Dependence NNS.copula()

multivariate instances and deliver a dependence measure \((D)\) such that \(D \in [0,1]\). This level of analysis is simply impossible with Pearson or other rank based correlation methods, which are restricted to bivariate cases.

-
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
diff --git a/vignettes/NNSvignette_Sampling.R b/vignettes/NNSvignette_Sampling.R index 87976c6b1..d16bc8028 100644 --- a/vignettes/NNSvignette_Sampling.R +++ b/vignettes/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/vignettes/NNSvignette_Sampling.Rmd b/vignettes/NNSvignette_Sampling.Rmd index 380b3028f..0e559a0a5 100644 --- a/vignettes/NNSvignette_Sampling.Rmd +++ b/vignettes/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/vignettes/NNSvignette_Sampling.html b/vignettes/NNSvignette_Sampling.html index 2089ea982..03b30c4db 100644 --- a/vignettes/NNSvignette_Sampling.html +++ b/vignettes/NNSvignette_Sampling.html @@ -471,12 +471,12 @@

Bootstrapping (NNS.meboot)

plot(x, type = "l", lwd = 3, ylim = c(min(reps), max(reps))) matplot(reps, type = "l", col = rainbow(length(boots)), add = TRUE)
-

+

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 @@ -531,8 +531,8 @@

Compare Multivariate Dependence Structures

NNS.copula(original.data)
 NNS.copula(new.dep.data)
 
-[1] 0.4379469
-[1] 0.4390599
+[1] 0.4353849 +[1] 0.4357026
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

Compare Multivariate Dependence Structures

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
head(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
+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 diff --git a/vignettes/images/NNSmc_1.png b/vignettes/images/NNSmc_1.png index a556a7b42..e3c46f2a2 100644 Binary files a/vignettes/images/NNSmc_1.png and b/vignettes/images/NNSmc_1.png differ