Learn R Programming

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

generalCorr (version 1.2.1)

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() gives 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. See five 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

249

Version

1.2.1

License

GPL (>= 2)

Maintainer

Hrishikesh Vinod

Last Published

December 8th, 2021

Functions in generalCorr (1.2.1)

PanelLag

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

Granger nonlinear causality R^2 for x1=f(x1,x2), R^2 for flipped x1 and x2 and the difference between the two R^2 values
Panel2Lag

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

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

Granger nonlinear causality R^2 for x1=f(x1,x2) minus R^2 for flipped 1 and 2
GcRsqYX

Nonlinear Granger causality between two time series workhorse function.
NLhat

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

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

European Crime Data
absBstdresC

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

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

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

Absolute residuals of kernel regression of x on y.
bootSignPcent

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

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

Compute vector of n999 nonlinear Granger causality paths
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.
badCol

internal badCol
bootGcRsq

Compute vector of n999 nonlinear Granger causality paths
abs_stdrhserC

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

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

internal da
canonRho

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

All Pair Version Kernel (block) causality summary paths from three criteria
diff.e0

Internal diff.e0
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).
da2Lag

internal da2Lag
dig

Internal dig
gmc0

internal gmc0
getSeq

Two sequences: starting+ending values from n and blocksize (internal use)
causeSummBlk

Block Version Kernel causality summary causal paths from three criteria
bootDom12

bootstrap confidence intervals for exact stochastic dominance SD1 to SD4.
decileVote

Function compares nine deciles of a matrix to reference minimum (eg p stock returns)
bigfp

Compute the numerical integration by the trapezoidal rule.
causeSumNoP

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

compute the matrix R* of generalized correlation coefficients.
gmcmtxBlk

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

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

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

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

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

Function to do pairwise deletion of missing rows.
kern

Kernel regression with options for residuals and gradients.
out1

internal out1
j

internal j
momentVote

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

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

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

internal min.e0
naTriplet

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

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

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

Vector of hybrid generalized partial correlation coefficients, hybrid version of parcorVec subtracting only linear effects but using generlized correlation between OLS residuals
rhs1

internal rhs1
parcorVec

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

Absolute values of gradients (apd's) of kernel regressions of x on y when both x and y are standardized.
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.
bootPairs0

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

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

internal ridgek
rij

internal rij
parcorSilent

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

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

generalCorr package description:
causeSummary

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

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

internal rijMrji
summaryRank

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

internal e0
gmc1

internal gmc1
kern_ctrl

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

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

Exact stochastic dominance computation from areas above ECDFs compared to common reference minimum (refmin) for order SD1 to SD4
gmcmtx0

Matrix R* of generalized correlation coefficients captures nonlinearities.
comp_portfo2

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

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

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

internal mtx
get0outliers

Function to compute outliers and their count using Tukey method using 1.5 times interquartile range (IQR) to define boundaries.
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.
goodCol

internal goodCol
kern2

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

internal nall
gmcxy_np

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

internal sales2Lag
salesLag

internal salesLag
silentPairs0

Older version, kernel causality weighted sum allowing control variables
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)
parcorHijk2

Generalized partial correlation coefficients between Xi and Xj, (second version) after removing the effect of Xk, via OLS regression residuals.
parcor_ridg

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

Compute the bootstrap probability of correct causal direction.
parcorMany

Report many generalized partial correlation coefficients allowing control variables.
nam.badCol

internal nam.badCol
dif4

order 4 differencing of a time series vector
heurist

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

order 4 differencing of a matrix of time series
mtx0

internal mtx0
nam.mtx0

internal nam.mtx0
nam.goodCol

internal nam.goodCol
parcor_ijkOLD

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

internal i
seed

internal seed
rrji

internal rrji
sort.e0

internal sort.e0
prelec2

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

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

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

internal sgn.e0
somePairs2

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

Compute probability of positive or negative sign from bootPairs output
parcor_linear

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

internal rhs.lag2
stochdom2

Compute vectors measuring stochastic dominance of four orders.
sort.abse0

internal sort.abse0
sudoCoefParcor

Peudo regression coefficients from generalized partial correlation coefficients, (GPCC).
sort_matrix

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

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

Kernel causality computations admitting control variables reporting a 7-column matrix (has older Cr1)
siPairsBlk

Block Version of silentPairs for causality scores with control variables
silentMtx

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

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

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

internal ii
n

internal n
parcorBMany

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

internal mtx2
p1

internal p1
parcorVecH2

Vector of hybrid generalized partial correlation coefficients, hybrid version of parcorVec subtracting only linear effects but using generlized correlation between OLS residuals
ibad

internal object
parcor_ijk

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

internal rji
rrij

internal rrij
symmze

Replace asymmetric matrix by max of abs values of [ij] or [ji] elements useful in symmetrizing gmcmtx0 general correlation matrix
silentPairs

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

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

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

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

Creates input for the stochastic dominance function stochdom2