# NOT RUN {
# Simulate 3 random variables, Y, X1 and X2, such that
# Y is correlated with both X1 and X2, but X1 and X2
# are uncorrelated.
set.seed( 2421 );
Z <- matrix( rnorm( 300 ), 100, 3 );
R1 <- cbind( c( 1, 0.8, 0.6 ), c( 0.8, 1, 0 ), c( 0.6, 0, 1 ) );
R2 <- MatrixSqrt( R1 );
# R1;
# R2 %*% t( R2 );
# zapsmall( R2 %*% t( R2 ) );
Z <- Z
# }
# NOT RUN {
<!-- %*% R2; -->
# }
# NOT RUN {
Y <- Z[,1];
X1 <- Z[,2];
X2 <- Z[,3];
cor( Y, X1 );
cor( Y, X2 );
cor( X1, X2 );
plot( Y, X1, pch = 20, col = "darkblue",
bg = "darkblue", cex = 1.5 );
points( Y, X2, col = "darkgray", pch = "+", cex = 1.5 );
plot( X1, X2 );
# }
# NOT RUN {
# The following line will give an error message.
# chol( R1 );
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab