Description Usage Arguments Value Author(s) References See Also Examples
Confidence intervals for causal effects in a regression setting.
1 2 3 4 5 6 7 8 9 |
X |
A matrix (or data frame) with the predictor variables for all experimental settings |
Y |
The response or target variable of interest. Can be numeric for regression or a factor with two levels for binary classification. |
ExpInd |
Indicator of the experiment or the intervention type an observation belongs to.
Can be a numeric vector of the same length as |
alpha |
Determines coverage of the confidence regions. |
test |
Use "exact" for an exact test in a regression setting, especially if sample size is small. However, this test is computationally demanding if sample size is high. The default "normal" tests for a shift in mean and variance of the residuals between different populations/environments. Using "correlation" tests additionally for vanishing correlation between predictor variables and residuals in each environment. Other options are "ranks" that uses a rank-based alternative and "ks" for a Kolmogorov-Smirnov test to detect differences in the distributions of the residuals between different environments. It is also possible to supply a function of the form |
selection |
The method for pre-selection of variables to save computational resources. Can use "all" for no pre-selection (which guarantees coverage but might take longer to compute), "boosting" for a boosting-type, "lasso" for Lasso cross-validated or "stability" for a stability-selection-type pre-selection. Default is "all" if p does not exceed 10 and "boosting" otherwise. |
maxNoVariables |
The maximal number of variables to pre-select (choosing smaller values saves computational resources but increases approximation error). |
maxNoVariablesSimult |
The maximal size of sets of variables considered in the procedure
(same comment as for |
maxNoObs |
The maximal number of observations used for the "exact" test
(same comment as for |
showAcceptedSets |
If |
showCompletion |
If |
stopIfEmpty |
If |
gof |
If no set of variables (including the empty set) leads to a p-value larger than the goodness-of-fit cutoff |
A list with elements
ConfInt |
The matrix with confidence intervals for the causal coefficient of all variables. First row is the upper bound and second row the lower bound. |
maximinCoefficients |
The value in the confidence interval closest to 0. Is hence non-zero for variables with significant effects. |
colnames |
The names of the variables (replaced with generic "Variable 1" etc. if not available). |
factor |
Logical indicating whether the response is a factor or not. |
dimX |
The dimensions of the matrix with predictor variables. |
Coeff |
A list which contains for all variables the vector with point-estimates among all accepted sets where the variable was part of the set. |
CoeffVar |
Same as |
modelReject |
Logical indicating if the whole model was rejected (the p-value of the best fitting model is too low). |
acceptedSets |
A list with one element per accepted set. For each accepted model the list entry is a vector that contains the indices of the variables in the accepted set. |
usedvariables |
The pre-selected variables if not all variables are used for the analysis; otherwise all variables. |
pvalues |
The p-values of all variables. |
stopIfEmpty |
A boolean value indicating whether computations stop as soon as intersection of accepted sets is empty. |
noEnv |
The number of distinct environments. |
gof |
The goodness-of-fit cutoff |
bestModel |
The largest p-value across all tested sets of variables. |
Nicolai Meinshausen <meinshausen@stat.math.ethz.ch>
Jonas Peters, Peter Buhlmann, Nicolai Meinshausen (2015):
Causal inference using invariant prediction: identification and confidence intervals
arxiv preprint http://arxiv.org/abs/1501.01332
hiddenICP
for reconstructing the parents of a variable in the presence of hidden variables (but assuming shift/additive interventions), which also allows construction of confidence intervals for the causal coefficients. See package "backShift" for constructing point estimates of causal cyclic models in the presence of hidden variables (again under shift interventions).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | ##########################################
####### 1st example:
####### Simulate data with interventions
set.seed(1)
## sample size n
n <- 4000
## 5 predictor variables
p <- 5
## simulate as independent Gaussian variables
X <- matrix(rnorm(n*p),nrow=n)
## divide data into observational (ExpInd=1) and interventional (ExpInd=2)
ExpInd <- c(rep(1,n/2),rep(2,n/2))
## for interventional data (ExpInd==2): change distribution
X[ExpInd==2,] <- sweep(X[ExpInd==2,],2, 5*rnorm(p) ,FUN="*")
## first two variables are the causal predictors of Y
beta <- c(1,1,rep(0,p-2))
## response variable Y
Y <- as.numeric(X%*%beta + rnorm(n))
## optinal: make last variable a child of Y (so last variable is non-causal for Y)
X[,p] <- 0.3*Y + rnorm(n)
####### Compute "Invariant Causal Prediction" Confidence Intervals
icp <- ICP(X,Y,ExpInd)
###### Print/plot/show summary of output
print(icp)
plot(icp)
#### compare with linear model
cat("\n compare with linear model \n")
print(summary(lm(Y~X)))
##########################################
####### 2nd example:
####### Simulate a DAG where X1 -> Y, Y -> X2 and Y -> X3
####### noise interventions on second half of data on X1
####### structure of DAG (at Y -> X2) is changing under interventions
n1 <- 400
n2 <- 500
ExpInd <- c(rep(1,n1), rep(2,n2))
## index for observational (ExpInd=1) and intervention data (ExpInd=2)
X1 <- c(rnorm(n1), 2 * rnorm(n2) + 1)
Y <- 0.5 * X1 + 0.2 * rnorm(n1 + n2)
X2 <- c(1.5 * Y[1:n1] + 0.4 * rnorm(n1),
-0.3 * Y[(n1+1):n2] + 0.4 * rnorm(n2))
X3 <- -0.4 * Y + 0.2 * rnorm(n1 + n2)
X <- cbind(X1, X2, X3)
### Compute "Invariant Causal Prediction" Confidence Intervals
## use a rank-based test to detect shift in distribution of residuals
icp <- ICP(X, Y, ExpInd,test="ranks")
## use a Kolmogorov-Smirnov test to detect shift in distribution of residuals
icp <- ICP(X, Y, ExpInd,test="ks")
## can also supply test as a function
## here chosen to be equivalent to option "ks" above
icp <- ICP(X, Y, ExpInd,test=function(x,z) ks.test(x,z)$p.val)
## use a test based on normal approximations
icp <- ICP(X, Y, ExpInd, test="normal")
### Print/plot/show summary of output
print(icp)
plot(icp)
#### compare with linear model
cat("\n compare with linear model \n")
print(summary(lm(Y~X)))
## Not run:
##########################################
####### 3rd example:
####### College Distance data
library(AER)
data("CollegeDistance")
CD <- CollegeDistance
## define two experimental settings by
## distance to closest 4-year college
ExpInd <- list()
ExpInd[[1]] <- which(CD$distance < quantile(CD$distance,0.5))
ExpInd[[2]] <- which(CD$distance >= quantile(CD$distance,0.5))
## target variable is binary (did education lead at least to BA degree?)
Y <- as.factor(CD$education>=16)
## use these predictors
X <- CD[,c("gender","ethnicity","score","fcollege","mcollege","home",
"urban","unemp","wage","tuition","income","region")]
## searching all subsets (use selection="lasso" or selection="stability"
## to select a subset of subsets to search)
## with selection="all" the function will take several minutes
icp <- ICP(X,Y,ExpInd,selection="all",alpha=0.1)
## Print/plot/show summary of output
print(icp)
summary(icp)
plot(icp)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.