Learn R Programming

sisVIVE (version 1.4)

cv.sisVIVE: Computes K-fold cross validation for selecting lambda

Description

Computes a K-fold cross validation for

Usage

cv.sisVIVE(Y, D, Z, lambdaSeq, K = 10, intercept = TRUE, normalize = TRUE)

Arguments

Y

A numeric vector of outcomes

D

A numeric vector of exposures

Z

A numeric matrix of instruments, with each column referring to one instrument

lambdaSeq

A numeric vector of lambdas to cross-validate from. Cross-validation will be performed only on these sequence of lambdas. You can either supply lambdaSeq or nLambda. See Details

K

Number of cross-validation folds

intercept

A logical declaring whether the intercept be included. Default is TRUE

normalize

A logical declaring whether the columns of Z should be scaled with variance 1. Default is TRUE

Value

A list is returned, which contains the estimates of alpha, beta, and the set of invalid instruments for the "best" lambda chosen by cross validation

lambda

"best" lambda as chosen by cross validation

estCVError

Estimated cross-validated error at this lambda

alpha

Estimate of alpha at the said lambda

beta

Estimate of beta, the causal effect of exposure on outcome, at the said lambda

whichInvalid

Estimate of set of invalid instruments at the said lambda

Details

Performs K-fold cross validiation to select lambda and returns the "best" lambda based on this cross-validation. If lambdaSeq is unspecified, the algorithm defaults to using the sequence of lambdas selected by sisVIVE. If lambdaSeq is specified, the algorithm will only evaluate its cross-validation on the specified lambdaSeq.

Examples

Run this code
library(MASS)
library(lars)

n = 1000; L = 10; s= 3;
Z <- matrix(rnorm(n*L),n,L)
error <- mvrnorm(n,rep(0,2),matrix(c(1,0.8,0.8,1),2,2))
intD = rnorm(1); ZtoD =   rnorm(L,0,1); ZtoY = c(rnorm(s),rep(0,L-s)); DtoY = 1; intY = rnorm(1)
D = intD + Z %*% ZtoD + error[,1]
Y = intY + Z %*% ZtoY + D * DtoY + error[,2]

result = cv.sisVIVE(Y,D,Z,K=10)

Run the code above in your browser using DataLab