Learn R Programming

⚠️There's a newer version (1.2.6) of this package.Take me there.

generalCorr (version 1.2.3)

Generalized Correlations, Causal Paths and Portfolio Selection

Description

Since causal paths from data are important for all sciences, the package provides many sophisticated functions. causeSummBlk() and causeSum2Blk() give easy-to-interpret causal paths. Let Z denote control variables and compare two flipped kernel regressions: X=f(Y, Z)+e1 and Y=g(X,Z)+e2. Our criterion Cr1 says that if |e1*Y|>|e2*X| then variation in X is more "exogenous or independent" than in Y and causal path is X to Y. Criterion Cr2 requires |e2|<|e1|. These inequalities between many absolute values are quantified by four orders of stochastic dominance. Our third criterion Cr3 for the causal path X to Y requires new generalized partial correlations to satisfy |r*(x|y,z)|< |r*(y|x,z)|. The function parcorVec() reports generalized partials between the first variable and all others. The package provides several R functions including get0outliers() for outlier detection, bigfp() for numerical integration by the trapezoidal rule, stochdom2() for stochastic dominance, pillar3D() for 3D charts, canonRho() for generalized canonical correlations, depMeas() measures nonlinear dependence, and causeSummary(mtx) reports summary of causal paths among matrix columns is easiest to use. Portfolio selection: decileVote(), momentVote(), dif4mtx(), exactSdMtx() can rank several stocks. Several functions whose names begin with 'boot' provide bootstrap statistical inference including a new bootGcRsq() test for "Granger-causality" allowing nonlinear relations. A new tool for evaluation of out-of-sample portfolio performance is outOFsamp(). Panel data implementation is now included. See six vignettes of the package for theory and usage tips. See Vinod (2019) \doi{10.1080/03610918.2015.1122048}.

Copy Link

Version

Install

install.packages('generalCorr')

Monthly Downloads

443

Version

1.2.3

License

GPL (>= 2)

Maintainer

Hrishikesh Vinod

Last Published

May 1st, 2023

Functions in generalCorr (1.2.3)

EuroCrime

European Crime Data
GcRsqYXc

Nonlinear Granger causality between two time series workhorse function.(local constant version)
absBstdres

Block version of abs-stdres Absolute values of residuals of kernel regressions of standardized x on standardized y, no control variables.
GcRsqYX

Nonlinear Granger causality between two time series workhorse function.
PanelLag

Function for computing a vector of one-lagged values of xj, a variable from panel data.
GcRsqX12

Generalized Granger-Causality. If dif>0, x2 Granger-causes x1.
GcRsqX12c

Generalized Granger-Causality. If dif>0, x2 Granger-causes x1.
absBstdresC

Block version of Absolute values of residuals of kernel regressions of standardized x on standardized y and control variables.
NLhat

Compute fitted values from kernel regression of x on y and y on x
Panel2Lag

Function to compute a vector of 2 lagged values of a variable from panel data.
abs_res

Absolute residuals of kernel regression of x on y.
abs_stdapdC

Absolute values of gradients (apd's) of kernel regressions of x on y when both x and y are standardized and control variables are present.
abs_stdres

Absolute values of residuals of kernel regressions of x on y when both x and y are standardized.
abs_stdrhserr

Absolute values of Hausman-Wu null in kernel regressions of x on y when both x and y are standardized.
abs_stdresC

Absolute values of residuals of kernel regressions of x on y when both x and y are standardized and control variables are present (C for control presence).
badCol

internal badCol
absBstdrhserC

Block version abs_stdrhser Absolute residuals kernel regressions of standardized x on y and control variables, Cr1 has abs(Resid*RHS).
abs_stdapd

Absolute values of gradients (apd's) of kernel regressions of x on y when both x and y are standardized.
abs_stdrhserC

Absolute residuals kernel regressions of standardized x on y and control variables, Cr1 has abs(RHS*y) not gradients.
allPairs

Report causal identification for all pairs of variables in a matrix (deprecated function). It is better to choose a target variable and pair it with all others, instead of considering all possible targets.
bigfp

Compute the numerical integration by the trapezoidal rule.
bootPairs0

Compute matrix of n999 rows and p-1 columns of bootstrap `sum' index (strength from older criterion Cr1, with newer Cr2 and Cr3).
bootGcRsq

Compute vector of n999 nonlinear Granger causality paths
bootGcLC

Compute vector of n999 nonlinear Granger causality paths
bootDom12

bootstrap confidence intervals for (x2-x1) exact SD1 to SD4 stochastic dominance .
bootSignPcent

Probability of unambiguously correct (+ or -) sign from bootPairs output transformed to percentages.
bootSign

Probability of unambiguously correct (+ or -) sign from bootPairs output
bootPair2

Compute matrix of n999 rows and p-1 columns of bootstrap `sum' (scores from Cr1 to Cr3).
bootPairs

Compute matrix of n999 rows and p-1 columns of bootstrap `sum' (strength from Cr1 to Cr3).
bootQuantile

Compute confidence intervals [quantile(s)] of indexes from bootPairs output
canonRho

Generalized canonical correlation, estimating alpha, beta, rho.
causeSumNoP

No print (NoP) version of causeSummBlk summary causal paths from three criteria
causeSummary0

Older Kernel causality summary of evidence for causal paths from three criteria
causeSummary

Kernel causality summary of evidence for causal paths from three criteria
causeAllPair

All Pair Version Kernel (block) causality summary paths from three criteria
bootSummary

Compute usual summary stats of 'sum' indexes from bootPairs output
causeSum2Blk

Block Version 2: Kernel causality summary of causal paths from three criteria
bootSummary2

Compute usual summary stats of 'sum' index in (-100, 100) from bootPair2
causeSummBlk

Block Version 2: Kernel causality summary of causal paths from three criteria
da

internal da
compPortfo

Compares two vectors (portfolios) using momentVote, DecileVote and exactSdMtx functions.
causeSum2Panel

Kernel regressions based causal paths in Panel Data.
dif4

order 4 differencing of a time series vector
cofactor

Compute cofactor of a matrix based on row r and column c.
comp_portfo2

Compares two vectors (portfolios) using stochastic dominance of orders 1 to 4.
causeSummary2

Kernel causality summary of evidence for causal paths from three criteria using new exact stochastic dominance. The function develops a unanimity index regarding the which flip (y on xi) or (xi on y) is best. Relevant signs determine the causal direction and unanimity index among three criteria. While allowing the researcher to keep some variables as controls, or outside the scope of causal path determination (e.g., age or latitude) this function produces detailed causal path information in a 5 column matrix identifying the names of variables, causal path directions, path strengths re-scaled to be in the range [--100, 100], (table reports absolute values of the strength) plus Pearson correlation and its p-value. The `2' in the name of the function suggests a second implementation where exact stochastic dominance, decileVote and momentVote are used and where we avoid Anderson's trapezoidal approximation.
decileVote

Function compares nine deciles of stock return distributions.
da2Lag

internal da2Lag
dif4mtx

order four differencing of a matrix of time series
exactSdMtx

Exact stochastic dominance computation from areas above ECDF pillars.
getSeq

Two sequences: starting+ending values from n and blocksize (internal use)
diff.e0

Internal diff.e0
e0

internal e0
generalCorrInfo

generalCorr package description:
depMeas

depMeas Signed measure of nonlinear nonparametric dependence between two vectors.
get0outliers

Function to compute outliers and their count using Tukey method using 1.5 times interquartile range (IQR) to define boundaries.
gmcxy_np

Function to compute generalized correlation coefficients r*(x|y) and r*(y|x) from two vectors (not matrices)
gmcmtxZ

compute the matrix R* of generalized correlation coefficients.
gmc0

internal gmc0
gmcmtxBlk

Matrix R* of generalized correlation coefficients captures nonlinearities using blocks.
j

internal j
kern

Kernel regression with options for residuals and gradients.
gmcmtx0

Matrix R* of generalized correlation coefficients captures nonlinearities.
gmc1

internal gmc1
i

internal i
momentVote

Function compares Pearson Stats and Sharpe Ratio for a matrix of stock returns
heurist

Heuristic t test of the difference between two generalized correlations.
minor

Function to do compute the minor of a matrix defined by row r and column c.
dig

Internal dig
min.e0

internal min.e0
ii

internal ii
mag_ctrl

After removing control variables, magnitude of effect of x on y, and of y on x.
kern2

Kernel regression version 2 with optional residuals and gradients with regtype="ll" for local linear, bwmethod="cv.aic" for AIC-based bandwidth selection.
mtx

internal mtx
ibad

internal object
mtx0

internal mtx0
out1

internal out1
outOFsamp

Compare out-of-sample portfolio choice algorithms by a leave-percent-out method.
goodCol

internal goodCol
mtx2

internal mtx2
p1

internal p1
napair

Function to do pairwise deletion of missing rows.
kern2ctrl

Kernel regression with control variables and optional residuals and gradients. version 2 regtype="ll" for local linear, bwmethod="cv.aic" for AIC-based bandwidth selection. It admits control variables.
nall

internal nall
naTriple

Function to do matched deletion of missing rows from x, y and z variable(s).
n

internal n
parcorHijk

Generalized partial correlation coefficients between Xi and Xj, after removing the effect of Xk, via OLS regression residuals.
nam.goodCol

internal nam.goodCol
mag

Approximate overall magnitudes of kernel regression partials dx/dy and dy/dx.
kern_ctrl

Kernel regression with control variables and optional residuals and gradients.
parcor_ridg

Compute generalized (ridge-adjusted) partial correlation coefficients from matrix R*. (deprecated)
naTriplet

Function to do matched deletion of missing rows from x, y and control variable(s).
parcorHijk2

Generalized partial correlation coefficients between Xi and Xj,
parcor_linear

Partial correlation coefficient between Xi and Xj after removing the linear effect of all others.
parcorBMany

Block version reports many generalized partial correlation coefficients allowing control variables.
parcorBijk

Block version of generalized partial correlation coefficients between Xi and Xj, after removing the effect of xk, via nonparametric regression residuals.
rank2return

Compute the portfolio return knowing the rank of a stock in the input `mtx'.
probSign

Compute probability of positive or negative sign from bootPairs output
prelec2

Intermediate weighting function giving Non-Expected Utility theory weights.
rhs1

internal rhs1
ridgek

internal ridgek
rji

internal rji
parcorVecH

Vector of hybrid generalized partial correlation coefficients.
rrij

internal rrij
parcorVecH2

Vector of hybrid generalized partial correlation coefficients.
parcor_ijk

Generalized partial correlation coefficients between Xi and Xj, after removing the effect of xk, via nonparametric regression residuals.
nam.badCol

internal nam.badCol
parcorMtx

Matrix of generalized partial correlation coefficients, always leaving out control variables, if any.
parcorMany

Report many generalized partial correlation coefficients allowing control variables.
parcor_ijkOLD

Generalized partial correlation coefficient between Xi and Xj after removing the effect of all others. (older version, deprecated)
parcorVec

Vector of generalized partial correlation coefficients (GPCC), always leaving out control variables, if any.
parcorSilent

Silently compute generalized (ridge-adjusted) partial correlation coefficients from matrix R*.
nam.mtx0

internal nam.mtx0
salesLag

internal salesLag
sales2Lag

internal sales2Lag
rhs.lag2

internal rhs.lag2
siPair2Blk

Block Version of silentPair2 for causality scores with control variables
siPairsBlk

Block Version of silentPairs for causality scores with control variables
silentPair2

kernel causality (version 2) scores with control variables
silentPairs

No-print kernel causality scores with control variables Hausman-Wu Criterion 1
someCPairs

Kernel causality computations admitting control variables.
silentMtx

No-print kernel-causality unanimity score matrix with optional control variables
silentMtx0

Older kernel-causality unanimity score matrix with optional control variables
someMagPairs

Summary magnitudes after removing control variables in several pairs where dependent variable is fixed.
somePairs

Function reporting kernel causality results as a 7-column matrix.(deprecated)
someCPairs2

Kernel causality computations admitting control variables reporting a 7-column matrix, version 2.
rstar

Function to compute generalized correlation coefficients r*(x,y).
rrji

internal rrji
pcause

Compute the bootstrap probability of correct causal direction.
rij

internal rij
somePairs2

Function reporting kernel causality results as a 7-column matrix, version 2.
rijMrji

internal rijMrji
sort.e0

internal sort.e0
pillar3D

Create a 3D pillar chart to display (x, y, z) data coordinate surface.
sgn.e0

internal sgn.e0
seed

internal seed
silentPairs0

Older version, kernel causality weighted sum allowing control variables
sort_matrix

Sort all columns of matrix x with respect to the j-th column.
sort.abse0

internal sort.abse0
symmze

Replace asymmetric matrix by max of abs values of [i,j] or [j,i] elements.
stochdom2

Compute vectors measuring stochastic dominance of four orders.
some0Pairs

Function reporting detailed kernel causality results in a 7-column matrix (uses deprecated criterion 1, no longer recommended but may be useful for second and third criterion typ=2,3)
sudoCoefParcor

Pseudo regression coefficients from generalized partial correlation coefficients, (GPCC).
sudoCoefParcorH

Peudo regression coefficients from hybrid generalized partial correlation coefficients (HGPCC).
stdres

Residuals of kernel regressions of x on y when both x and y are standardized.
stdz_xy

Standardize x and y vectors to achieve zero mean and unit variance.
wtdpapb

Creates input for the stochastic dominance function stochdom2
summaryRank

Compute ranks of rows of matrix and summarize them into a choice suggestion.